| # 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 (required) |
| # 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. |
| template("sdk_molecule") { |
| assert(defined(invoker.category), "Must define an SDK category") |
| |
| gn_deps = [] |
| |
| if (defined(invoker.deps)) { |
| gn_deps += invoker.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 |
| } |
| |
| targets = { |
| 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(targets.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 = [ |
| "--category", |
| invoker.category, |
| "--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) |
| } |
| |
| # Verifies that the manifest is valid. |
| validate_json(targets.validate) { |
| forward_variables_from(invoker, |
| [ |
| "testonly", |
| "visibility", |
| ]) |
| |
| data = files.manifest |
| |
| schema = "//build/sdk/manifest_schema.json" |
| |
| use_valico = true |
| |
| deps = [ ":${targets.manifest}" ] |
| } |
| |
| group(target_name) { |
| forward_variables_from(invoker, |
| [ |
| "assert_no_deps", |
| "testonly", |
| "visibility", |
| ]) |
| public_deps = [ ":${targets.manifest}" ] |
| deps = [ ":${targets.validate}" ] |
| } |
| } |