• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Copyright 2018 The Chromium Authors
2# Use of this source code is governed by a BSD-style license that can be
3# found in the LICENSE file.
4
5import("//build/config/cast.gni")
6import("//build/config/fuchsia/config.gni")
7import("//build/config/fuchsia/fuchsia_package_metadata.gni")
8import("//build/config/gclient_args.gni")
9import("//build/config/sysroot.gni")
10import("//build/util/generate_wrapper.gni")
11
12assert(is_fuchsia)
13
14declare_args() {
15  # Sets the Fuchsia Amber repository which will be used by default by the
16  # generated installation scripts. If not specified, then no default directory
17  # will be used.
18  default_fuchsia_out_dir = ""
19
20  # Sets the Fuchsia device node name which will be used by default by the
21  # generated runner scripts. If not specficed, then no default node name will
22  # be used.
23  default_fuchsia_device_node_name = ""
24
25  # CPU architecture of the host used to run the tests.
26  test_host_cpu = host_cpu
27
28  # Sets whether emulators need to be included in the test isolates
29  test_isolate_uses_emulator = true
30
31  # A list of additional Fuchsia boot images to include in the test isolates.
32  fuchsia_additional_boot_images = []
33
34  # This variable controls the browser included in the Telemetry based test
35  # targets.
36  fuchsia_browser_type = "web_engine_shell"
37}
38
39# Generates a wrapper script under root_build_dir/bin that performs an
40# operation, such as deployment or execution, using a package and its
41# dependencies.
42#
43# Parameters:
44#   output_name_format: The format string for the generated script's filename.
45#                       The placeholder string %package% will be substituted
46#                       with |package| (or |package_name|, if set).
47#                       Examples: "run_%package%", "install_%package%"
48#   package: The package() target to run.
49#   package_name: Specifies the name of the generated package, if its
50#       filename is different than the |package| target name. This value must
51#       match package_name in the |package| target.
52#   package_deps: An array of [package, package_name] array pairs
53#       which specify additional dependency packages to be installed
54#       prior to execution.
55#   executable: The underlying script to be called by the script.
56#   executable_args: The list of arguments to pass to |executable|.
57#                    Runtime commandline arguments can be passed to
58#                    |executable| using the placeholder %args%.
59#
60#                    In addition, the script is passed the following
61#                    executable_args:
62#                      --package - the path to a .FAR package to install.
63#                      --package_name - the name of the package to use as an
64#                                       entry point.
65#   include_fuchsia_out_dir: If true, adds |default_fuchsia_out_dir|
66#                            to executable_args (when set in GN args).
67template("fuchsia_run_script_with_packages") {
68  if (defined(invoker.package_name)) {
69    _pkg_shortname = invoker.package_name
70  } else {
71    _pkg_shortname = get_label_info(invoker.package, "name")
72  }
73
74  _generated_script_path =
75      "$root_build_dir/bin/" +
76      string_replace(invoker.output_name_format, "%package%", _pkg_shortname)
77
78  generate_wrapper(target_name) {
79    forward_variables_from(invoker,
80                           TESTONLY_AND_VISIBILITY + [
81                                 "executable",
82                                 "executable_args",
83                                 "data",
84                                 "include_fuchsia_out_dir",
85                                 "target",
86                               ])
87
88    wrapper_script = _generated_script_path
89    deps = [ invoker.package ]
90
91    if (!defined(data_deps)) {
92      data_deps = []
93    }
94    data_deps += [ "//build/config/fuchsia:deployment_resources" ]
95
96    _combined_package_list = [ invoker.package ]
97
98    if (defined(invoker.package_deps)) {
99      foreach(package_dep, invoker.package_deps) {
100        _combined_package_list += [ package_dep[0] ]
101      }
102    }
103    foreach(package_dep, _combined_package_list) {
104      data_deps += [
105        package_dep,
106        package_dep + "__archive-manifest",
107        package_dep + "__archive-metadata",
108      ]
109    }
110
111    if (defined(invoker.data_deps)) {
112      data_deps += invoker.data_deps
113    }
114
115    # Compute the list of full paths to package files, including dependencies.
116    if (defined(invoker.package_deps)) {
117      foreach(package_dep, invoker.package_deps) {
118        package_dep_target = package_dep[0]
119        deps += [ package_dep_target ]
120        data_deps += [ package_dep_target ]
121      }
122    }
123
124    # Include package information inside the wrapper script.
125    if (!defined(executable_args)) {
126      executable_args = []
127    }
128
129    if (defined(include_fuchsia_out_dir) && include_fuchsia_out_dir &&
130        default_fuchsia_out_dir != "") {
131      executable_args += [
132        "--fuchsia-out-dir",
133        default_fuchsia_out_dir,
134      ]
135    }
136  }
137
138  # Create a wrapper script rather than using a group() in order to ensure
139  # "ninja $target_name" always works.
140  if (defined(invoker.executable_wrapper)) {
141    generate_wrapper(invoker.executable_wrapper) {
142      forward_variables_from(invoker, TESTONLY_AND_VISIBILITY)
143      executable = _generated_script_path
144      wrapper_script = "$root_build_dir/${invoker.executable_wrapper}"
145      deps = [
146        ":${invoker._install_target}",
147        ":${invoker._run_target}",
148      ]
149    }
150  }
151}
152
153# Generates a script which deploys a package to the TUF repo of a Fuchsia
154# build output directory.
155template("fuchsia_package_installer") {
156  if (defined(invoker.package_name)) {
157    pkg_shortname = invoker.package_name
158  } else {
159    pkg_shortname = get_label_info(invoker.package, "name")
160  }
161  fuchsia_package_metadata(pkg_shortname) {
162    forward_variables_from(invoker,
163                           TESTONLY_AND_VISIBILITY + [
164                                 "package",
165                                 "package_deps",
166                               ])
167  }
168  fuchsia_run_script_with_packages(target_name) {
169    forward_variables_from(invoker,
170                           "*",
171                           TESTONLY_AND_VISIBILITY + [ "executable_args" ])
172    forward_variables_from(invoker, TESTONLY_AND_VISIBILITY)
173    executable = rebase_path("//build/fuchsia/test/deploy_to_fuchsia.py")
174    executable_args = [
175      "--out-dir",
176      "@WrappedPath(.)",
177      pkg_shortname,
178    ]
179    output_name_format = "deploy_%package%"
180    include_fuchsia_out_dir = true
181  }
182}
183
184# Generates scripts for installing and running test packages.
185# See fuchsia_run_script_with_packages() for the full list of parameters.
186template("fuchsia_test_runner") {
187  _run_target = "${target_name}__runner"
188  _install_target = "${target_name}__installer"
189
190  fuchsia_run_script_with_packages(_run_target) {
191    forward_variables_from(invoker,
192                           TESTONLY_AND_VISIBILITY + [
193                                 "data",
194                                 "data_deps",
195                                 "package",
196                                 "package_name",
197                                 "package_deps",
198                               ])
199
200    _test_runner_py = "//build/fuchsia/test/run_test.py"
201
202    executable = rebase_path(_test_runner_py)
203
204    if (defined(invoker.is_test_exe) && invoker.is_test_exe) {
205      data += [ "//.vpython3" ]
206    }
207    output_name_format = "run_%package%"
208    executable_wrapper = invoker.target_name
209
210    # Populate the arguments used by the test runner, defined at build-time.
211    executable_args = [
212      "--out-dir",
213      "@WrappedPath(.)",
214    ]
215
216    executable_args += [ package_name ]
217
218    if (defined(invoker.use_test_server) && invoker.use_test_server) {
219      executable_args += [ "--enable-test-server" ]
220    }
221
222    if (default_fuchsia_device_node_name != "") {
223      executable_args += [
224        "--target-id",
225        default_fuchsia_device_node_name,
226      ]
227    }
228
229    # Declare the files that are needed for test execution on LUCI swarming
230    # test clients, both directly (via data) or indirectly (via data_deps).
231    if (!defined(data)) {
232      data = []
233    }
234    data += [
235      _test_runner_py,
236      "$root_gen_dir/package_metadata/${invoker.package_name}.meta",
237    ]
238
239    # TODO(crbug.com/1256870): Remove this once all out-of-tree references
240    # to "package_name_override" are migrated to "package_name".
241    if (defined(invoker.package_name_override)) {
242      package_name = invoker.package_name_override
243    }
244  }
245  fuchsia_package_installer(_install_target) {
246    forward_variables_from(invoker,
247                           TESTONLY_AND_VISIBILITY + [
248                                 "package",
249                                 "package_name",
250                                 "package_deps",
251                               ])
252  }
253}
254