| # 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("//third_party/fuchsia-sdk/build/component.gni") |
| import("//third_party/fuchsia-sdk/build/package.gni") |
| |
| # DEPRECATED: Use the Fuchsia SDK's fuchsia_component() and fuchsia_package() |
| # templates directly, in new code. |
| # |
| # Creates a Fuchsia .far package file containing a Fuchsia component. |
| # |
| # Parameters are: |
| # package_name_override: Specifies the name of the package to generate, |
| # if different than |target_name|. |
| # archive_filename_override: Specifies the filename of the generated FAR. |
| # If left unset, defaults to |package_name_override|. |
| # Defaults to the target name. |
| # binary: The executable target which should be launched. |
| # manifest: A path to the manifest that will be used. |
| # "testonly" targets default to using |
| # //build/config/fuchsia/tests-with-exec.cmx. |
| # Non-test targets must explicitly specify a |manifest|. |
| # additional_manifests: Manifest files that should be included in the package in |
| # the /meta directory. This allows to package more than one component per |
| # manifest. These manifest files must specify program/binary to run, which |
| # is not required for the main manifest file where this parameter is added |
| # during build. |
| # component_name_override: If set, specifies the name of the component. |
| # By default, the component name is the same as the package name. |
| # deps: Additional targets to build and include in the package (optional). |
| # |
| # TODO(https://crbug.com/1050703): Migrate consumers to GN SDK equivalents. |
| template("cr_fuchsia_package") { |
| assert(defined(invoker.binary)) |
| |
| if (defined(invoker.package_name_override)) { |
| _package_name = invoker.package_name_override |
| } else { |
| _package_name = invoker.target_name |
| } |
| |
| _package_contents = [ invoker.binary ] |
| if (defined(invoker.deps)) { |
| _package_contents += invoker.deps |
| } |
| |
| _component_cmx_target = target_name + "__cr-component-cmx" |
| _component_target = target_name + "__cr-component" |
| _package_components = [ ":${_component_target}" ] |
| _component_manifest = "${target_gen_dir}/${target_name}.cmx" |
| |
| # Process the CMX fragment in |manifest| to get a full manifest. |
| action(_component_cmx_target) { |
| forward_variables_from(invoker, [ "testonly" ]) |
| |
| if (!defined(invoker.manifest)) { |
| assert(testonly == true) |
| |
| # TODO(fxbug.dev/1019938): switch the default to tests.cmx which doesn't request |
| # the deprecated-ambient-replace-as-executable feature. |
| _manifest_fragment = "//chromium_compat/build/config/tests-with-exec.cmx" |
| } else { |
| _manifest_fragment = invoker.manifest |
| } |
| |
| script = "//chromium_compat/build/config/build_cmx_from_fragment.py" |
| inputs = [ _manifest_fragment ] |
| outputs = [ _component_manifest ] |
| |
| args = [ |
| "--cmx-fragment", |
| rebase_path(_manifest_fragment), |
| "--cmx", |
| rebase_path(_component_manifest), |
| "--program", |
| get_label_info(invoker.binary, "name"), |
| ] |
| } |
| |
| # Declare the primary component for this package. |
| fuchsia_component(_component_target) { |
| forward_variables_from(invoker, [ "testonly" ]) |
| |
| deps = [ ":${_component_cmx_target}" ] |
| manifest = _component_manifest |
| |
| if (defined(invoker.component_name_override)) { |
| manifest_output_name = "${invoker.component_name_override}" |
| } else { |
| manifest_output_name = "${_package_name}" |
| } |
| |
| data_deps = _package_contents |
| } |
| |
| # Bundle manifests providing additional entrypoints into the package. |
| if (defined(invoker.additional_manifests)) { |
| foreach(filename, invoker.additional_manifests) { |
| _additional_component_target = target_name + "_" + filename |
| _package_components += [ ":${_additional_component_target}" ] |
| fuchsia_component(_additional_component_target) { |
| forward_variables_from(invoker, [ "testonly" ]) |
| data_deps = _package_contents |
| manifest = filename |
| } |
| } |
| } |
| |
| # Generate a Fuchsia ARchive (FAR) of the requested name. |
| if (defined(invoker.archive_name_override)) { |
| _archive_name = invoker.archive_name_override |
| } else { |
| _archive_name = _package_name |
| } |
| |
| if (_archive_name != _package_name) { |
| _archive_target = target_name + "__cr-archive" |
| |
| copy(target_name) { |
| deps = [ ":${_archive_target}" ] |
| _pkg_out_dir = "${target_gen_dir}/${_package_name}" |
| sources = [ "${_pkg_out_dir}/${_package_name}.far" ] |
| outputs = [ "${_pkg_out_dir}/${_archive_name}.far" ] |
| } |
| } else { |
| _archive_target = target_name |
| } |
| |
| fuchsia_package(_archive_target) { |
| forward_variables_from(invoker, [ "testonly" ]) |
| package_name = _package_name |
| if (defined(invoker.excluded_files)) { |
| excluded_files = invoker.excluded_files |
| } |
| deps = _package_components |
| } |
| } |