blob: 60879bd12d3930d62e6a552336ccb3cae71865a7 [file] [log] [blame]
# Copyright 2017 The Fuchsia Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
import("//build/json/validate_json.gni")
import("//build/python/python_action.gni")
import("//build/sdk/config.gni")
# Defines a group of SDK elements.
#
# Parameters
#
# category (optional)
# Describes the minimum category that atoms in this molecule must have.
# See //build/sdk/sdk_atom.gni for possible values.
#
# output_name (optional)
# Name of the internal manifest generated by this target, without
# an `.sdk` suffix. Defaults to target_name.
#
# deps (optional)
# List of GN labels referencing the elements of this group.
# These labels must point to "sdk_atom" or "sdk_molecule" targets.
#
# non_sdk_deps (optional)
# List of GN labels which this target needs built.
#
# host_tools_deps (optional)
# A list of sdk_atom() and sdk_molecule() targets that will be walked to
# collect all SDK host tool atom dependencies for this collection.
# Unlike `deps`, this is only walked when host tools are included in the
# current build configuration.
template("sdk_molecule") {
gn_deps = []
if (defined(invoker.deps)) {
gn_deps += invoker.deps
}
# Only build host tools in the main build to save considerable build time.
if (defined(invoker.host_tools_deps)) {
if (sdk_inside_sub_build) {
not_needed(invoker.host_tools_deps)
} else {
gn_deps += invoker.host_tools_deps
}
}
# Add manifests for all of the SDK deps before adding the non-SDK deps.
dep_manifests = []
foreach(dep, gn_deps) {
gen_dir = get_label_info(dep, "target_gen_dir")
name = get_label_info(dep, "name")
dep_manifests += [ "$gen_dir/$name.sdk" ]
}
if (defined(invoker.non_sdk_deps)) {
gn_deps += invoker.non_sdk_deps
}
output_name = target_name
if (defined(invoker.output_name)) {
output_name = invoker.output_name
}
labels = {
manifest = "${target_name}.manifest"
validate = "${target_name}.validate"
}
files = {
manifest = "$target_gen_dir/$output_name.sdk"
areas = "//docs/contribute/governance/areas/_areas.yaml"
}
# Builds a manifest representing members of the group.
python_action(labels.manifest) {
forward_variables_from(invoker,
[
"assert_no_deps",
"testonly",
"visibility",
])
binary_label = "//build/sdk:create_molecule_manifest"
deps = gn_deps
inputs = dep_manifests + [ files.areas ]
outputs = [ files.manifest ]
args = [
"--areas-file-path",
rebase_path(files.areas, root_build_dir),
"--out",
rebase_path(files.manifest, root_build_dir),
"--deps",
] + rebase_path(dep_manifests, root_build_dir)
if (defined(invoker.category)) {
args += [
"--category",
invoker.category,
]
}
}
# Verifies that the manifest is valid.
validate_json(labels.validate) {
forward_variables_from(invoker,
[
"testonly",
"visibility",
])
data = files.manifest
schema = "//build/sdk/manifest_schema.json"
use_valico = true
deps = [ ":${labels.manifest}" ]
}
group(target_name) {
forward_variables_from(invoker,
[
"assert_no_deps",
"testonly",
"visibility",
])
public_deps = [ ":${labels.manifest}" ]
deps = [ ":${labels.validate}" ]
}
}