Source code

Revision control

Copy as Markdown

Other Tools

# 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/sdk/build/component.gni")
import("//third_party/fuchsia-sdk/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|.
# 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,
[
"deps",
"testonly",
])
script = "//chromium/build/config/fuchsia/build_cmx_from_fragment.py"
inputs = [ invoker.manifest ]
outputs = [ _component_manifest ]
args = [
"--cmx-fragment",
rebase_path(invoker.manifest),
"--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}" ]
data_deps = _package_contents
manifest = _component_manifest
if (defined(invoker.component_name_override)) {
manifest_output_name = "${invoker.component_name_override}"
} else {
manifest_output_name = "${_package_name}"
}
}
# Bundle manifests providing additional entrypoints into the package.
if (defined(invoker.additional_manifests)) {
foreach(filename, invoker.additional_manifests) {
_additional_component_target =
target_name + "_" + get_path_info(filename, "name")
_package_components += [ ":${_additional_component_target}" ]
fuchsia_component(_additional_component_target) {
forward_variables_from(invoker, [ "testonly" ])
data_deps = _package_contents
manifest = filename
# Depend upon the invoker's |deps|, in case they include a dependency
# responsible for generating this additional component's manifest file.
deps = _package_contents
}
}
}
fuchsia_package(target_name) {
forward_variables_from(invoker, [ "testonly" ])
package_name = _package_name
if (defined(invoker.excluded_files)) {
excluded_files = invoker.excluded_files
}
deps = _package_components
}
}