blob: 393abba697fb6afeed4d48276088e7f9f39fc690 [file] [log] [blame]
# 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("fuchsia_component.gni")
import("fuchsia_package.gni")
# Defines a package that contains a single component.
# See: https://fuchsia.dev/fuchsia-src/development/components/build
#
# Developers often define a package that contains a single component.
# This template fuses together fuchsia_package() and fuchsia_component() as a
# convenience.
#
# Packages are units of distribution. It is beneficial to define multiple
# components in the same package if you need to guarantee that several
# components are always co-present, or if you'd like to be able to update
# several components at once (by updating a single package).
# This pattern is also commonly used to create hermetic integration tests.
# For instance an integration test between two components where one is a client
# of a service implemented in another component would include both the client
# and server components.
# However for the sake of simplicity, if you're developing a package with just
# a single component then this template will save you some boilerplate.
#
# Example:
# ```
# executable("rot13_encoder_decoder") {
# sources = [ "rot13_encoder_decoder.cc" ]
# }
#
# fuchsia_package_with_single_component("rot13") {
# manifest = "meta/rot13.cmx"
# deps = [ ":rot13_encoder_decoder" ]
# }
# ```
#
# Parameters
#
# package_name (optional)
# The name of the package.
# Type: string
# Default: target_name
#
# component_name (optional)
# The name of the component.
# Type: string
# Default: package_name
#
# manifest (required)
# The component manifest.
# Type: path
#
# unstable_features (optional)
# The set of unstable CML features to allow. Only applicable to v2 components.
# The set of features is allowlisted here: //tools/cmc/build/unstable_features/BUILD.gn
# where each feature name is represented by a group of the same name.
# Type: list of strings
# Default: []
#
# deps
# testonly
# visibility
template("fuchsia_package_with_single_component") {
assert(
defined(invoker.manifest),
"A `manifest` argument was missing when calling fuchsia_package_with_single_component($target_name)")
package_name = target_name
if (defined(invoker.package_name)) {
package_name = invoker.package_name
}
component_name = package_name
if (defined(invoker.component_name)) {
component_name = invoker.component_name
}
component_target = "${target_name}_component"
fuchsia_component(component_target) {
forward_variables_from(invoker,
[
"deps",
"manifest",
"unstable_features",
"testonly",
])
component_name = component_name
visibility = [ ":*" ]
}
fuchsia_package(target_name) {
forward_variables_from(invoker,
[
"disable_elf_binaries_checks",
"testonly",
"visibility",
])
package_name = package_name
deps = [ ":$component_target" ]
}
}