summaryrefslogtreecommitdiffstats
path: root/third_party/libwebrtc/build/config/fuchsia/generate_runner_scripts.gni
blob: 3349b2b8698def3d8551e16015a36349d41c6943 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
# 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.

assert(is_fuchsia)

import("//build/config/chromecast_build.gni")
import("//build/config/fuchsia/config.gni")
import("//build/config/fuchsia/package.gni")
import("//build/config/gclient_args.gni")
import("//build/config/sysroot.gni")
import("//build/util/generate_wrapper.gni")

declare_args() {
  # Sets the Fuchsia Amber repository which will be used by default by the
  # generated installation scripts. If not specified, then no default directory
  # will be used.
  default_fuchsia_build_dir_for_installation = ""

  # Sets the Fuchsia device node name which will be used by default by the
  # generated runner scripts. If not specficed, then no default node name will
  # be used.
  default_fuchsia_device_node_name = ""

  # CPU architecture of the host used to run the tests.
  test_host_cpu = host_cpu

  # Sets whether emulators need to be included in the test isolates
  test_isolate_uses_emulator = true

  # A list of additional Fuchsia boot images to include in the test isolates.
  fuchsia_additional_boot_images = []
}

# Generates a script which deploys and optionally executes a package on a
# device.
#
# Parameters:
#   package: The package() target which will be run.
#   package_name_override: Specifies the name of the generated package, if its
#       name is different than the |package| target name. This value must match
#       package_name_override in the |package| target.
#   package_deps: An array of [package, package_name_override] array pairs
#       which specify additional dependency packages to be installed
#       prior to execution.
#   runner_script: The runner script implementation to use, relative to
#       "build/fuchsia". Defaults to "test_runner.py".
#   install_only: If true, executing the script will only install the package
#       on the device, but not run it.
#   is_test_exe: If true, the generated script will run the command under
#       test_env.py and add arguments expected to be passed to test exes.
template("fuchsia_package_runner") {
  forward_variables_from(invoker, TESTONLY_AND_VISIBILITY + [ "runner_script" ])

  if (defined(invoker.package_name_override)) {
    _pkg_shortname = invoker.package_name_override
  } else {
    _pkg_shortname = get_label_info(invoker.package, "name")
  }

  _pkg_dir = "$root_out_dir/gen/" + get_label_info(invoker.package, "dir") +
             "/" + _pkg_shortname
  _package_path = "$_pkg_dir/${_pkg_shortname}.far"

  generated_run_pkg_script_path = "$root_build_dir/bin/run_${_pkg_shortname}"
  generated_install_pkg_script_path =
      "$root_build_dir/bin/install_$_pkg_shortname"

  _generate_runner_target = "${target_name}__generate_runner"
  _generate_installer_target = "${target_name}__generate_installer"

  # Generates a script which installs and runs a test.
  generate_wrapper(_generate_runner_target) {
    forward_variables_from(invoker, [ "target" ])

    _is_test_exe = defined(invoker.is_test_exe) && invoker.is_test_exe

    if (defined(runner_script)) {
      _runner_script = runner_script
    } else {
      _runner_script = "//build/fuchsia/test_runner.py"
    }

    if (_is_test_exe) {
      executable = "//testing/test_env.py"
      executable_args =
          [ "@WrappedPath(" + rebase_path(_runner_script, root_out_dir) + ")" ]
      data = [
        _runner_script,
        "//.vpython",
      ]
      data_deps = [ "//testing:test_scripts_shared" ]
    } else {
      executable = rebase_path(_runner_script)
      executable_args = []
      data = []
      data_deps = []
    }

    if (defined(invoker.data)) {
      data += invoker.data
    }

    wrapper_script = generated_run_pkg_script_path

    data_deps += [
      invoker.package,

      # Runner scripts require access to "ids.txt" for symbolization, and to
      # the "package" from which to get the name & version to deploy, which
      # are outputs of the archive manifest generation action.
      "${invoker.package}__archive-manifest",

      # Runner scripts require access to "meta.far" from which to calculate the
      # expected Merkle root for the package, to verify it has been cached.
      "${invoker.package}__archive-metadata",
    ]
    if (defined(invoker.data_deps)) {
      data_deps += invoker.data_deps
    }

    # Declares the files that are needed for test execution on the
    # swarming test client.
    data += [
      "//build/fuchsia/",
      "//build/util/lib/",
      "//third_party/fuchsia-sdk/sdk/.build-id/",
      "//third_party/fuchsia-sdk/sdk/bin/fpave.sh",
      "//third_party/fuchsia-sdk/sdk/bin/fuchsia-common.sh",
      "//third_party/fuchsia-sdk/sdk/meta/manifest.json",
    ]

    # TODO(crbug.com/1137662): Remove checkout_fuchsia_for_arm64_host from
    # gclient_gn_args in //DEPS as well as this condition when builders have
    # test_host_cpu set correctly.
    if (checkout_fuchsia_for_arm64_host) {
      test_host_cpu = "arm64"
    }

    if (test_host_cpu == "x64") {
      data_deps +=
          [ "//build/config/clang:llvm-symbolizer_data($host_toolchain)" ]
    }

    data += [
      "//third_party/fuchsia-sdk/sdk/tools/${test_host_cpu}/device-finder",
      "//third_party/fuchsia-sdk/sdk/tools/${test_host_cpu}/ffx",
      "//third_party/fuchsia-sdk/sdk/tools/${test_host_cpu}/fvm",
      "//third_party/fuchsia-sdk/sdk/tools/${test_host_cpu}/merkleroot",
      "//third_party/fuchsia-sdk/sdk/tools/${test_host_cpu}/pm",

      # TODO(crbug.com/1162314) Remove "symbolize" when transition to
      # "symbolizer" is complete.
      "//third_party/fuchsia-sdk/sdk/tools/${test_host_cpu}/symbolize",

      "//third_party/fuchsia-sdk/sdk/tools/${test_host_cpu}/symbolizer",
      "//third_party/fuchsia-sdk/sdk/tools/${test_host_cpu}/zbi",
    ]

    if (test_isolate_uses_emulator) {
      data += [
        "${boot_image_root}/qemu/qemu-kernel.kernel",
        "${boot_image_root}/qemu/storage-full.blk",
        "${boot_image_root}/qemu/zircon-a.zbi",
        "//third_party/fuchsia-sdk/sdk/tools/${test_host_cpu}/fvdl",
        "//third_party/qemu-${host_os}-${test_host_cpu}/",
        "${aemu_root}/",
      ]
    }

    foreach(fuchsia_additional_boot_image, fuchsia_additional_boot_images) {
      data += [ "${fuchsia_additional_boot_image}/" ]
    }

    package_paths = [ rebase_path(_package_path, root_build_dir) ]
    if (defined(invoker.package_deps)) {
      foreach(package_dep, invoker.package_deps) {
        package_dep_target = package_dep[0]
        package_dep_name = package_dep[1]

        data_deps += [
          package_dep_target,
          package_dep_target + "__archive-manifest",
          package_dep_target + "__archive-metadata",
        ]
        package_dep_path = rebase_path(
                get_label_info(package_dep_target, "target_gen_dir") + "/" +
                    package_dep_name + "/" + package_dep_name + ".far",
                root_build_dir)
        package_paths += [ package_dep_path ]
      }
    }

    foreach(package_path, package_paths) {
      executable_args += [
        "--package",
        "@WrappedPath(${package_path})",
      ]
    }

    executable_args += [
      "--out-dir",
      "@WrappedPath(.)",
      "--target-cpu",
      target_cpu,
      "--package-name",
      _pkg_shortname,
    ]

    if (defined(invoker.use_run_test_component) &&
        invoker.use_run_test_component) {
      executable_args += [ "--use-run-test-component" ]
    }

    if (defined(invoker.use_test_server) && invoker.use_test_server) {
      executable_args += [ "--enable-test-server" ]
    }

    if (default_fuchsia_build_dir_for_installation != "") {
      executable_args += [
        "--fuchsia-out-dir",
        default_fuchsia_build_dir_for_installation,
      ]
    }

    if (default_fuchsia_device_node_name != "") {
      executable_args += [
        "--node-name",
        default_fuchsia_device_node_name,
      ]
    }
  }

  # Produces a script which installs a package and its dependencies into the
  # package repository of a pre-existing Fuchsia build directory.
  generate_wrapper(_generate_installer_target) {
    executable = rebase_path("//build/fuchsia/deploy_to_pkg_repo.py")
    wrapper_script = generated_install_pkg_script_path

    data_deps = [ invoker.package ]
    if (defined(invoker.data_deps)) {
      data_deps += invoker.data_deps
    }

    # Build a list of all packages to install, and pass the list to the runner
    # script.
    package_paths = [ rebase_path(_package_path, root_build_dir) ]
    if (defined(invoker.package_deps)) {
      foreach(package_dep, invoker.package_deps) {
        package_dep_target = package_dep[0]
        package_dep_name = package_dep[1]

        data_deps += [ package_dep_target ]
        package_dep_path = rebase_path(
                get_label_info(package_dep_target, "target_gen_dir") + "/" +
                    package_dep_name + "/" + package_dep_name + ".far",
                root_build_dir)
        package_paths += [ package_dep_path ]
      }
    }
    executable_args = []
    foreach(package_path, package_paths) {
      executable_args += [
        "--package",
        "@WrappedPath(${package_path})",
      ]

      if (default_fuchsia_build_dir_for_installation != "") {
        executable_args += [
          "--fuchsia-out-dir",
          default_fuchsia_build_dir_for_installation,
        ]
      }
    }
  }

  group(target_name) {
    deps = [ ":${_generate_installer_target}" ]

    if (!defined(invoker.install_only) || invoker.install_only == false) {
      deps += [ ":${_generate_runner_target}" ]
    }
  }
}