| # Copyright 2018 The Chromium 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/fuchsia/config.gni") |
| import("//build/config/sysroot.gni") |
| |
| # Creates a Fuchsia .far package file. |
| # |
| # Parameters are: |
| # package_name_override: Specifies the name of the package to generate, |
| # if different than |target_name|. |
| # binary: The executable target which should be launched. |
| # sandbox_policy: A path to the sandbox_policy that will be used. |
| # "testonly" targets default to using |
| # //build/config/fuchsia/testing_sandbox_policy by default. |
| # Non-test targets must explicitly specify a |sandbox_policy|. |
| # deps: Additional targets to build and include in the package (optional). |
| template("fuchsia_package") { |
| pkg = { |
| forward_variables_from(invoker, "*") |
| |
| if (defined(package_name_override)) { |
| package_name = package_name_override |
| } else { |
| package_name = invoker.target_name |
| } |
| |
| if (!defined(sandbox_policy)) { |
| assert(testonly == true) |
| sandbox_policy = "//build/config/fuchsia/testing_sandbox_policy" |
| } |
| } |
| assert(defined(pkg.binary)) |
| |
| _pm_tool_path = "${fuchsia_sdk}/tools/pm" |
| |
| _pkg_out_dir = "${target_gen_dir}/${pkg.package_name}" |
| _runtime_deps_file = "$_pkg_out_dir/${pkg.package_name}.runtime_deps" |
| _archive_manifest = "$_pkg_out_dir/${pkg.package_name}.archive_manifest" |
| _build_ids_file = "$_pkg_out_dir/ids.txt" |
| _component_manifest = "$_pkg_out_dir/${pkg.package_name}.cmx" |
| _key_file = "$_pkg_out_dir/signing-key" |
| _meta_far_file = "$_pkg_out_dir/meta.far" |
| _combined_far_file = "$_pkg_out_dir/${pkg.package_name}-0.far" |
| _final_far_file = "$_pkg_out_dir/${pkg.package_name}.far" |
| _package_info_path = "$_pkg_out_dir/package" |
| |
| _write_manifest_target = "${pkg.package_name}__write_manifest" |
| _generate_key_target = "${pkg.package_name}__genkey" |
| _package_target = "${pkg.package_name}__pkg" |
| _bundle_target = "${pkg.package_name}__bundle" |
| |
| # Generates a manifest file based on the GN runtime deps |
| # suitable for "pm" tool consumption. |
| action(_write_manifest_target) { |
| _depfile = "${target_gen_dir}/${target_name}_stamp.d" |
| |
| forward_variables_from(invoker, |
| [ |
| "deps", |
| "testonly", |
| ]) |
| |
| script = "//build/config/fuchsia/prepare_package_inputs.py" |
| |
| inputs = [ |
| _runtime_deps_file, |
| pkg.sandbox_policy, |
| ] |
| |
| outputs = [ |
| _archive_manifest, |
| _build_ids_file, |
| _component_manifest, |
| ] |
| |
| if (!defined(deps)) { |
| deps = [] |
| } |
| deps += [ pkg.binary ] |
| data_deps = deps |
| |
| # Use a depfile to trigger package rebuilds if any of the files (static |
| # assets, shared libraries, etc.) included by the package have changed. |
| depfile = _depfile |
| |
| args = [ |
| "--root-dir", |
| rebase_path("//", root_build_dir), |
| "--out-dir", |
| rebase_path(root_out_dir, root_build_dir), |
| "--app-name", |
| pkg.package_name, |
| "--app-filename", |
| get_label_info(pkg.binary, "name"), |
| "--sandbox-policy-path", |
| rebase_path(pkg.sandbox_policy, root_build_dir), |
| "--runtime-deps-file", |
| rebase_path(_runtime_deps_file, root_build_dir), |
| "--depfile-path", |
| rebase_path(_depfile, root_build_dir), |
| "--manifest-path", |
| rebase_path(_archive_manifest, root_build_dir), |
| "--build-ids-file", |
| rebase_path(_build_ids_file, root_build_dir), |
| ] |
| |
| if (defined(pkg.excluded_files)) { |
| foreach(filename, pkg.excluded_files) { |
| args += [ |
| "--exclude-file", |
| filename, |
| ] |
| } |
| } |
| |
| write_runtime_deps = _runtime_deps_file |
| } |
| |
| # Generates a signing key to use for building the package. |
| action(_generate_key_target) { |
| forward_variables_from(invoker, [ "testonly" ]) |
| |
| script = "//build/gn_run_binary.py" |
| |
| inputs = [ |
| # Depend on the SDK hash, to ensure rebuild if the SDK tools change. |
| "${fuchsia_sdk}/.hash", |
| ] |
| |
| outputs = [ |
| _key_file, |
| ] |
| |
| args = [ |
| rebase_path(_pm_tool_path, root_build_dir), |
| "-k", |
| rebase_path(_key_file, root_build_dir), |
| "genkey", |
| ] |
| } |
| |
| # Creates a signed Fuchsia metadata package. |
| action(_package_target) { |
| forward_variables_from(invoker, [ "testonly" ]) |
| |
| script = "//build/gn_run_binary.py" |
| |
| deps = [ |
| ":$_generate_key_target", |
| ":$_write_manifest_target", |
| ] |
| |
| inputs = [ |
| # Depend on the SDK hash, to ensure rebuild if the SDK tools change. |
| "${fuchsia_sdk}/.hash", |
| _key_file, |
| ] |
| |
| outputs = [ |
| _meta_far_file, |
| ] |
| |
| args = [ |
| rebase_path(_pm_tool_path, root_build_dir), |
| "-o", |
| rebase_path(_pkg_out_dir, root_build_dir), |
| "-k", |
| rebase_path(_key_file, root_build_dir), |
| "-m", |
| rebase_path(_archive_manifest, root_build_dir), |
| "build", |
| ] |
| } |
| |
| # Creates a package containing the metadata archive and blob data. |
| action(_bundle_target) { |
| forward_variables_from(invoker, [ "testonly" ]) |
| |
| script = "//build/gn_run_binary.py" |
| |
| deps = [ |
| ":$_package_target", |
| ":$_write_manifest_target", |
| ] |
| |
| inputs = [ |
| # Depend on the SDK hash, to ensure rebuild if the SDK tools change. |
| "${fuchsia_sdk}/.hash", |
| _meta_far_file, |
| _archive_manifest, |
| ] |
| |
| outputs = [ |
| _combined_far_file, |
| ] |
| |
| args = [ |
| rebase_path(_pm_tool_path, root_build_dir), |
| "-o", |
| rebase_path(_pkg_out_dir, root_build_dir), |
| "-m", |
| rebase_path(_archive_manifest, root_build_dir), |
| "archive", |
| ] |
| } |
| |
| # Copies the archive to a well-known path. |
| # TODO(kmarshall): Use a 'pm' output flag to write directly to the desired |
| # file path instead. |
| copy(target_name) { |
| forward_variables_from(invoker, [ "testonly" ]) |
| |
| # Allows dependent targets to make use of "ids.txt". |
| public_deps = [ |
| ":$_write_manifest_target", |
| ] |
| |
| deps = [ |
| ":$_bundle_target", |
| ] |
| |
| data = [ |
| _final_far_file, |
| |
| # Files specified here so that they can be read by isolated testbots. |
| _package_info_path, |
| _build_ids_file, |
| ] |
| |
| sources = [ |
| _combined_far_file, |
| ] |
| outputs = [ |
| _final_far_file, |
| ] |
| } |
| } |