| # 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("component.gni") |
| import("config/config.gni") |
| import("package.gni") |
| |
| # Define a test executable, which is packaged in a Fuchsia package. |
| # Metadata is generated for the target to enable programmatic execution. |
| # |
| # Parameters |
| # |
| # deps |
| # Optional: Dependencies for this component. These dependencies are external |
| # to the component, such as other components that are used via FIDL. The deps |
| # are added to the executable as well as a the component. |
| # |
| # data_deps |
| # Required: Dependencies examined for metadata. These dependencies define |
| # the contents of the component. These are executables and libraries. The |
| # data_deps are added to the component. |
| # |
| # manifest |
| # Required: The manifest file for this component. The executable name |
| # must be of the form ${target_name}__exec |
| # |
| # resources |
| # Optional: Non-executable resources to include in the component. |
| # |
| template("fuchsia_test") { |
| _output_name = invoker.target_name |
| _component_target = "${_output_name}_component" |
| _pkg_target = "${_output_name}_package" |
| _exec_target = "${_output_name}__exec" |
| |
| # This is the executable for the test. |
| executable(_exec_target) { |
| visibility = [ ":*" ] |
| forward_variables_from(invoker, |
| [ |
| "testonly", |
| "sources", |
| "deps", |
| ]) |
| testonly = true |
| output_name = _exec_target |
| } |
| |
| # The component encapsulates the executable, |
| # and all the dependencies and resources needed. |
| fuchsia_component(_component_target) { |
| visibility = [ ":*" ] |
| testonly = true |
| forward_variables_from(invoker, |
| [ |
| "manifest", |
| "data_deps", |
| "deps", |
| "resources", |
| ]) |
| if (!defined(data_deps)) { |
| data_deps = [] |
| } |
| data_deps += [ ":$_exec_target" ] |
| } |
| |
| # Package the component. |
| fuchsia_package(_pkg_target) { |
| testonly = true |
| data_deps = [ ":$_component_target" ] |
| package_name = _output_name |
| } |
| |
| # Create metadata JSON which enables building the |
| # command line to execute the test. |
| group(target_name) { |
| testonly = true |
| metadata = { |
| test_metadata = [ |
| { |
| package_name = _output_name |
| manifest_name = get_path_info(invoker.manifest, "file") |
| archive_file = rebase_path( |
| "${target_gen_dir}/${_output_name}/${_output_name}.far") |
| }, |
| ] |
| } |
| |
| deps = [ ":${_pkg_target}" ] |
| } |
| } |