| # 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_test_package.gni") |
| |
| # Defines a package that contains a single component with the default component |
| # manifest path: `default.cm`. See: |
| # https://fuchsia.dev/fuchsia-src/development/components/build |
| # |
| # Developers often define a test package that contains a single component. As |
| # a convenience, this |
| # template fuses together fuchsia_test_package() and fuchsia_component(), |
| # automatically declaring both the package and component as `testonly`. |
| # Since the package contains only a single component, the component is given the |
| # default name `"default.cm"`, by convention. To run the test, for example: |
| # |
| # ``` |
| # $ ffx test run fuchsia-pkg://fuchsia.com/my_test#meta/default.cm |
| # ``` |
| # |
| # This template encourage using subpackages to bundle additional component |
| # dependencies, which can be declared using `subpackages` (or optionally, |
| # `renameable_subpackages`). |
| # |
| # Example: |
| # ``` |
| # fuchsia_package_with_single_component("fonts-service") { ... } |
| # |
| # fuchsia_test_package_with_single_component("fonts-service-test") { |
| # manifest = "meta/fonts-service-test.cm" |
| # subpackages = [ ":fonts-service" ] |
| # } |
| # |
| # fuchsia_package_with_single_component("fonts-ui") { ... } |
| # |
| # fuchsia_test_package_with_single_component("fonts-ui-test") { |
| # manifest = "meta/fonts-ui-test.cm" |
| # deps = [ ":fonts-ui" ], |
| # test_specs = { |
| # environments = [ |
| # astro_env, |
| # sherlock_env, |
| # ] |
| # } |
| # } |
| # |
| # Parameters |
| # |
| # package_name (optional) |
| # The name of the package. |
| # Type: string |
| # Default: target_name |
| # |
| # manifest (required) |
| # The component manifest. |
| # Type: path |
| # |
| # restricted_features (optional) |
| # The set of restricted CML features to allow. Only applicable to v2 components. |
| # The set of features is allowlisted here: //tools/cmc/build/restricted_features/BUILD.gn |
| # where each feature name is represented by a group of the same name. |
| # Type: list of strings |
| # Default: [] |
| # |
| # renameable_subpackages (optional) |
| # A list of subpackages defined by scoped variables `package` (a |
| # `fuchsia_package()` target) and an optional `name`. See |
| # `fuchsia_package()` for more details. |
| # Type: list of scopes |
| # |
| # subpackages (optional) |
| # A list of `fuchsia_package` targets. See `fuchsia_package()` for more |
| # details. |
| # Type: list of targets |
| # |
| # data_deps |
| # deps |
| # visibility |
| template("fuchsia_test_package_with_default_component") { |
| assert( |
| defined(invoker.manifest), |
| "A `manifest` argument was missing when calling fuchsia_test_package_with_default_component($target_name)") |
| |
| package_name = target_name |
| if (defined(invoker.package_name)) { |
| package_name = invoker.package_name |
| } |
| component_name = "default" |
| |
| component_target = "${target_name}_test_component" |
| fuchsia_test_component(component_target) { |
| forward_variables_from(invoker, |
| [ |
| "deps", |
| "data_deps", |
| "manifest", |
| "manifest_deps", |
| "restricted_features", |
| ]) |
| if (!defined(deps)) { |
| deps = [] |
| } |
| |
| if (defined(invoker.shell_commands)) { |
| deps += invoker.shell_commands |
| } |
| |
| component_name = component_name |
| visibility = [ ":*" ] |
| } |
| |
| fuchsia_test_package(target_name) { |
| forward_variables_from(invoker, |
| [ |
| "is_shell_package", |
| "shell_commands", |
| "disable_elf_binaries_checks", |
| "renameable_subpackages", |
| "subpackages", |
| "test_specs", |
| "visibility", |
| ]) |
| package_name = package_name |
| test_components = [ ":$component_target" ] |
| } |
| } |