| # Copyright 2020 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/images/manifest.gni") |
| import("//src/sys/cmc/build/cml.gni") |
| |
| # Helper template to create manifests for including items in bootfs. |
| # |
| # Parameters |
| # |
| # binaries (optional) |
| # [list of scopes] Defines binaries in the ZBI. A binary is typically |
| # produced by the build system and is always placed in the `bin/` directory |
| # of the ZBI. |
| # |
| # Entries in a scope in the binaries list: |
| # |
| # name (required) |
| # [string] Name of the binary. |
| # |
| # source (optional) |
| # [path] Location of the binary in the build directory if it is not |
| # at `$root_out_dir/$name`. |
| # |
| # dest (optional) |
| # [path] Location the binary will be placed within `bin/`. |
| # |
| # config (optional) |
| # [list of scopes] Defines config entries in the ZBI. A config entry is |
| # typically a source file and is always placed in the `config/` directory of |
| # the ZBI. |
| # |
| # Entries in a scope in the config list: |
| # |
| # path (required) |
| # [path] Location of entry in source or build directory. If the |
| # resource is checked in, this will typically be specified as a |
| # path relative to the BUILD.gn file containing the `bootfs_manifest()` |
| # target. If the resource is generated, this will typically be |
| # specified relative to `$target_gen_dir`. |
| # |
| # dest (required) |
| # [path] Location the resource will be placed within `meta/`. |
| # |
| # drivers (optional) |
| # [list of scopes] Defines drivers in the ZBI. A driver is typically |
| # produced by the build system and is always placed in the `driver/` |
| # directory of the ZBI. |
| # |
| # Entries in a scope in the binaries list: |
| # |
| # name (required) |
| # [string] Name of the driver. |
| # |
| # source (optional) |
| # [path] Location of the driver in the build directory if it is not |
| # at `$root_out_dir/$name`. |
| # |
| # dest (optional) |
| # [path] Location the driver will be placed within `driver/`. |
| # |
| # meta (optional) |
| # [list of scopes] Defines metadata entries in the ZBI. A metadata entry is |
| # typically a source file and is always placed in the `meta/` directory of |
| # the assembled package. Only CML files may be listed here. |
| # |
| # Entries in a scope in the meta list: |
| # |
| # path (required) |
| # [path] Location of entry in source or build directory. If the |
| # resource is checked in, this will typically be specified as a |
| # path relative to the BUILD.gn file containing the `bootfs_manifest()` |
| # target. If the resource is generated, this will typically be |
| # specified relative to `$target_gen_dir`. |
| # |
| # dest (optional) |
| # [path] Location the resource will be placed within `meta/`. |
| # |
| # deps (optional) |
| # Usual GN meanings. |
| # |
| template("bootfs_manifest") { |
| forward_variables_from(invoker, |
| [ |
| "binaries", |
| "config", |
| "drivers", |
| "meta", |
| ]) |
| if (!defined(binaries)) { |
| binaries = [] |
| } |
| if (!defined(config)) { |
| config = [] |
| } |
| if (!defined(drivers)) { |
| drivers = [] |
| } |
| if (!defined(meta)) { |
| meta = [] |
| } |
| |
| manifest_deps = [] |
| if (defined(invoker.deps)) { |
| manifest_deps = invoker.deps |
| } |
| |
| manifest_args = [] |
| foreach(binary, binaries) { |
| if (defined(binary.dest)) { |
| dest = binary.dest |
| } else { |
| dest = binary.name |
| } |
| dest = "bin/" + dest |
| |
| if (defined(binary.source)) { |
| source = binary.source |
| } else { |
| source = binary.name |
| } |
| source = rebase_path(source, "", root_out_dir) |
| |
| manifest_args += [ "--entry=" + dest + "=" + source ] |
| } |
| |
| foreach(c, config) { |
| assert(defined(c.path), "path is required") |
| assert(defined(c.dest), "dest is required") |
| |
| dest = "config/" + c.dest |
| |
| manifest_args += [ "--entry=" + dest + "=" + rebase_path(c.path) ] |
| } |
| |
| foreach(driver, drivers) { |
| if (defined(driver.dest)) { |
| dest = driver.dest |
| } else { |
| dest = driver.name |
| } |
| dest = "driver/" + dest |
| |
| if (defined(driver.source)) { |
| source = driver.source |
| } else { |
| source = driver.name |
| } |
| source = rebase_path(source, "", root_out_dir) |
| |
| manifest_args += [ "--entry=" + dest + "=" + source ] |
| } |
| |
| foreach(m, meta) { |
| assert(defined(m.path), "path is required") |
| |
| assert(get_path_info(m.path, "extension") == "cml", |
| "only component manifests are supported in /boot/meta") |
| if (defined(m.dest)) { |
| assert(get_path_info(m.dest, "extension") == "cm", |
| "only component manifests are supported in /boot/meta") |
| dest = m.dest |
| } else { |
| filename = get_path_info(m.path, "file") |
| dest = string_replace(filename, ".cml", ".cm") |
| } |
| |
| compile_label = "compile_boot_" + get_path_info(dest, "file") |
| cm(compile_label) { |
| manifest = m.path |
| } |
| manifest_deps += [ ":$compile_label" ] |
| |
| dest = "meta/" + dest |
| |
| cm_out = [] |
| cm_out = get_target_outputs(":$compile_label") |
| |
| source = rebase_path(cm_out[0]) |
| |
| manifest_args += [ "--entry=" + dest + "=" + source ] |
| } |
| |
| generate_manifest(target_name) { |
| deps = manifest_deps |
| args = manifest_args |
| } |
| } |