| # Copyright 2021 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/board.gni") |
| import("//build/json/validate_json.gni") |
| |
| # Generates a physical device manifest JSON from a board definition. |
| # |
| # There is normally a single such target in the build graph that generates |
| # metadata for the currently active board. The resulting metadata is uploaded |
| # to the artifact repository. |
| # |
| # A release builder subsequently fetches all available device profiles metadata |
| # and incorporates them into the single SDK release artifact. |
| # |
| # This build rule pulls some of the values it uses from the build environment. |
| # |
| # name(required) |
| # The name or identifier of the device. This name will be referenced from |
| # the product bundle metadata. |
| # |
| # deps (optional) |
| # public_deps (optional) |
| # testonly (optional) |
| # visibility (optional) |
| # Standard GN meaning. |
| template("physical_device_manifest") { |
| assert(defined(invoker.name), "Device name is required.") |
| |
| # The following vars are defined in a board definition file. |
| arch = target_cpu |
| description = board_description |
| |
| # This is the most recent schema. |
| schema_file = "physical_device-0bd5d21f.json" |
| schema_target = "//build/sdk/meta/${schema_file}" |
| |
| # Schema ID must match the schema file. |
| schema_id = "http://fuchsia.com/schemas/sdk/${schema_file}" |
| |
| file_contents = { |
| schema_id = schema_id |
| data = { |
| type = "physical_device" |
| name = invoker.name |
| description = description |
| hardware = { |
| cpu = { |
| arch = arch |
| } |
| } |
| } |
| } |
| file = "$target_gen_dir/physical_device.json" |
| generator_target = "${target_name}_json_generator" |
| generated_file(generator_target) { |
| visibility = [ ":*" ] |
| forward_variables_from(invoker, [ "testonly" ]) |
| contents = file_contents |
| output_conversion = "json" |
| outputs = [ file ] |
| metadata = { |
| images = [ |
| { |
| label = get_label_info(":$target_name", "label_with_toolchain") |
| name = "physical_device" |
| path = rebase_path(file, root_build_dir) |
| type = "manifest" |
| }, |
| ] |
| } |
| } |
| |
| # Verify that the metadata complies with the specified schema. |
| validator_target = "${target_name}_json_validator" |
| validate_json(validator_target) { |
| forward_variables_from(invoker, |
| [ |
| "deps", |
| "public_deps", |
| "testonly", |
| ]) |
| visibility = [ ":*" ] |
| data = file |
| deps = [ ":${generator_target}" ] |
| schema = schema_target |
| sources = [ |
| # Included schemata. |
| "//build/sdk/meta/common.json", |
| "//build/sdk/meta/hardware-f6f47515.json", |
| ] |
| allow_comments = true |
| } |
| |
| group(target_name) { |
| forward_variables_from(invoker, |
| [ |
| "testonly", |
| "visibility", |
| ]) |
| deps = [ |
| ":${generator_target}", |
| ":${validator_target}", |
| ] |
| } |
| } |