| # 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") |
| import("//build/product.gni") |
| |
| # Generates a virtual device specification JSON from a product and board |
| # definition. |
| # |
| # There is normally a single such target in the build graph that generates |
| # metadata for the currently active board/product. 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. |
| # |
| # Parameters |
| # |
| # name(required) |
| # The name or identifier of the device. This name will be referenced from |
| # the product bundle metadata. |
| # |
| # testonly (optional) |
| # visibility (optional) |
| # Standard GN meaning. |
| # |
| # GN args pulled from build environment |
| # |
| # emu_window_size_width (optional) |
| # The emulator window size width. Defaults to 1280. |
| # Defined in //build/product.gni. |
| # emu_window_size_height (optional) |
| # The emulator window size height. Defaults to 800. |
| # Defined in //build/product.gni. |
| # board_description (optional) |
| # The human readable board description corresponding to the board name. |
| # Defaults to "". Defined in //build/board.gni. |
| # target_cpu |
| # Standard GN meaning. |
| template("virtual_device_specification") { |
| assert(defined(invoker.name), "Device name is required.") |
| |
| # This is the most recent schema. |
| schema_file = "virtual_device-93A41932.json" |
| schema_target = "//build/sdk/meta/${schema_file}" |
| |
| # Schema ID must match the schema file. |
| schema_id = "http://fuchsia.com/schemas/sdk/${schema_file}" |
| |
| template_output = "${target_out_dir}/emulator_flags.json.template" |
| template_target = "${target_name}_copy_template_file" |
| |
| emu_window_size = { |
| height = 800 |
| width = 1280 |
| units = "pixels" |
| } |
| |
| if (emu_window_size_width != false) { |
| assert(emu_window_size_width > 0, |
| "The window width must be > 0 in order to be visible") |
| emu_window_size.width = emu_window_size_width |
| } |
| if (emu_window_size_height != false) { |
| assert(emu_window_size_height > 0, |
| "The window height must be > 0 in order to be visible") |
| emu_window_size.height = emu_window_size_height |
| } |
| |
| file_contents = { |
| schema_id = schema_id |
| data = { |
| type = "virtual_device" |
| name = invoker.name |
| description = board_description |
| hardware = { |
| cpu = { |
| arch = target_cpu |
| } |
| audio = { |
| model = "hda" |
| } |
| inputs = { |
| # Touch is the default to avoid issues with mouse capture |
| # especially with cloudtops. |
| pointing_device = "touch" |
| } |
| window_size = emu_window_size |
| memory = { |
| quantity = 8192 |
| units = "megabytes" |
| } |
| storage = { |
| quantity = 2 |
| units = "gigabytes" |
| } |
| } |
| ports = { |
| ssh = 22 |
| mdns = 5353 |
| debug = 2345 |
| } |
| |
| # TODO(fxbug.dev/94125): remove once solution is available. |
| start_up_args_template = rebase_path(template_output, root_build_dir) |
| } |
| } |
| |
| output = "${target_gen_dir}/virtual_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 = [ output ] |
| metadata = { |
| images = [ |
| { |
| label = get_label_info(":$target_name", "label_with_toolchain") |
| name = "virtual_device" |
| path = rebase_path(output, root_build_dir) |
| type = "manifest" |
| }, |
| ] |
| } |
| } |
| |
| copy(template_target) { |
| sources = [ "//src/developer/ffx/plugins/emulator/templates/emulator_flags.json.template" ] |
| outputs = [ template_output ] |
| metadata = { |
| images = [ |
| { |
| label = get_label_info(":$target_name", "label_with_toolchain") |
| name = "emulator_flags" |
| path = rebase_path(template_output, root_build_dir) |
| type = "manifest" |
| }, |
| ] |
| } |
| } |
| |
| validator_target = "${target_name}_json_validator" |
| validate_json(validator_target) { |
| visibility = [ ":*" ] |
| forward_variables_from(invoker, [ "testonly" ]) |
| data = output |
| deps = [ ":${generator_target}" ] |
| schema = schema_target |
| sources = [ |
| # Included schemata. |
| "//build/sdk/meta/common.json", |
| "//build/sdk/meta/hardware-f6f47515.json", |
| "//build/sdk/meta/virtual_device-93A41932.json", |
| ] |
| allow_comments = true |
| } |
| |
| group(target_name) { |
| forward_variables_from(invoker, |
| [ |
| "testonly", |
| "visibility", |
| ]) |
| deps = [ |
| ":${generator_target}", |
| ":${template_target}", |
| ":${validator_target}", |
| ] |
| } |
| } |