| # Copyright 2019 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/config.gni") |
| import("//build/json/validate_json.gni") |
| import("//build/sdk/sdk_data.gni") |
| |
| declare_args() { |
| # Indicates whether to include basemgr.cmx in the boot sequence for the |
| # product image. |
| launch_basemgr_on_boot = true |
| } |
| |
| # Validates a modular framework configuration file against a schema |
| # |
| # Ensures the file is valid JSON, with optional (non-standard JSON) |
| # C-style comments (`/* block */` and `// inline`). |
| # |
| # Parameters |
| # config (required) |
| # This is a modular framework configuration file that needs to be validated. |
| template("modular_config_validate") { |
| validate_json(target_name) { |
| forward_variables_from(invoker, |
| [ |
| "deps", |
| "public_deps", |
| "testonly", |
| "visibility", |
| ]) |
| |
| data = invoker.config |
| schema = "//sdk/docs/modular_config_schema.json" |
| allow_comments = true |
| } |
| } |
| |
| # Packages a modular framework configuration after validating the configuration. |
| # Configuration will be found in basemgr's /config/data directory. |
| # |
| # Parameters |
| # config (required) |
| # This is a file containing configuration for the modular framework. |
| # It will be schema-validated. |
| # |
| # output_name (optional) |
| # The output name for the configuration file. |
| # For example, if output_name is `foo.config`, basemgr can read this |
| # configuration file from `/config/data/foo.config`. |
| # Default: startup.config |
| # |
| # for_pkg (optional) |
| # The destination package that will contain the configuration file. |
| # Default: basemgr |
| # |
| # sdk_category (optional) |
| # Publication level of the library in SDKs. |
| # See //build/sdk/sdk_atom.gni. |
| template("modular_config") { |
| assert(defined(invoker.config), "config must be defined for $target_name") |
| |
| output_name = "startup.config" |
| if (defined(invoker.output_name)) { |
| output_name = invoker.output_name |
| } |
| |
| for_pkg = "basemgr" |
| if (defined(invoker.for_pkg)) { |
| for_pkg = invoker.for_pkg |
| } |
| |
| modular_config_validate(target_name + "_validate") { |
| forward_variables_from(invoker, |
| [ |
| "deps", |
| "testonly", |
| "visibility", |
| ]) |
| |
| config = invoker.config |
| } |
| |
| config_data_deps = [ ":${invoker.target_name}_validate" ] |
| |
| if (for_pkg == "basemgr") { |
| config_data(target_name + "_basemgr.config") { |
| for_pkg = "sysmgr" |
| sources = [ "//src/modular/build/modular_config/basemgr.config" ] |
| outputs = [ "basemgr.config" ] |
| } |
| |
| # By default, add the sysmgr config to automatically launch basemgr.cmx, |
| # unless the invoker explicitly disables this with |
| # launch_basemgr_on_boot = false. |
| if (launch_basemgr_on_boot) { |
| config_data_deps += [ ":" + target_name + "_basemgr.config" ] |
| } |
| } |
| |
| config_data(invoker.target_name) { |
| for_pkg = for_pkg |
| sources = [ rebase_path(invoker.config) ] |
| outputs = [ output_name ] |
| |
| deps = config_data_deps |
| } |
| |
| if (defined(invoker.sdk_category) && invoker.sdk_category != "excluded") { |
| sdk_data("${invoker.target_name}_sdk") { |
| category = invoker.sdk_category |
| name = invoker.target_name |
| type = "config" |
| file = invoker.config |
| } |
| } |
| } |