xref: /aosp_15_r20/external/angle/build/fuchsia/cipd/BUILD.gn (revision 8975f5c5ed3d1c378011245431ada316dfb6f244)
1# Copyright 2019 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
5# Build targets for constructing CIPD release archives.
6
7assert(is_fuchsia)
8
9import("//build/cipd/cipd.gni")
10import("//build/config/chrome_build.gni")
11import("//build/config/compiler/compiler.gni")
12import("//build/util/process_version.gni")
13import("//third_party/fuchsia-gn-sdk/src/build_id_dir.gni")
14import("//third_party/fuchsia-gn-sdk/src/cipd.gni")
15
16visibility = [ ":*" ]
17
18# Allows a builder to explicitly declare the CIPD path. The base path is what
19# comes after `.../p/` in the CIPD URL.
20declare_args() {
21  fuchsia_cipd_package_base_path = ""
22}
23
24# TODO(zijiehe): Eliminate the use of 'package_base_path' during the
25# refactoring.
26if (fuchsia_cipd_package_base_path == "") {
27  if (is_chrome_branded) {
28    package_base_path = "chrome_internal/fuchsia"
29  } else {
30    package_base_path = "chromium/fuchsia"
31  }
32} else {
33  package_base_path = fuchsia_cipd_package_base_path
34}
35
36# Archives related specifically to `fuchsia.web`
37_web_engine_directory = "web_engine"
38
39# Archives of tools intended to be run on a Linux/Mac host rather than the
40# Fuchsia device.
41_host_tools_directory = "host_tools"
42
43_archive_suffix = "_archive"
44
45# Extracts the numeric Chrome version and writes it to a file in the output
46# directory.
47#
48# To check out the repository on the commit where the version was generated,
49# simply call `git checkout <version>`, and Git will check out the commit
50# associated with the <version> tag.
51process_version("version") {
52  template_file = "version.template"
53  sources = [ "//chrome/VERSION" ]
54  output = "${target_gen_dir}/VERSION"
55  process_only = true
56}
57
58if (target_cpu == "x64") {
59  targetarch = "amd64"
60} else {
61  targetarch = "arm64"
62}
63
64# Prepares a CIPD archive, produces a corresponding LICENSE file,
65# LICENSE.spdx.json file and generates a manifest file.
66#
67# Parameters:
68#   package_subdirectory: Specify the subdirectory relative to
69#                         |package_base_path| in which the package is put.
70#   description: Sets the "description" field in CIPD package definition.
71#
72# Optional parameters used directly by fuchsia_cipd_package template:
73#   "install_mode",
74#   "sources",
75#   "data",
76#   "data_deps"
77#   "deps",
78#   "testonly",
79
80template("cipd_archive") {
81  forward_variables_from(invoker,
82                         [
83                           "package_subdirectory",
84                           "description",
85                           "install_mode",
86                           "sources",
87                           "data",
88                           "data_deps",
89                           "deps",
90                           "testonly",
91                         ])
92
93  _license_path = "${target_gen_dir}/${target_name}/LICENSE"
94  _invoker_dir = get_label_info(":${invoker.target_name}", "dir")
95  _license_target = "${_invoker_dir}:${invoker.target_name}${_archive_suffix}"
96
97  # GN is used by the script and is thus an input.
98  if (host_os == "mac") {
99    _gn_path = "//buildtools/mac/gn"
100  } else if (host_os == "linux") {
101    _gn_path = "//buildtools/linux64/gn"
102  }
103
104  # Produces a consolidated license file.
105  action("${target_name}_license") {
106    script = "//tools/licenses/licenses.py"
107    inputs = [ "$_gn_path" ]
108    outputs = [ _license_path ]
109    args = [
110      "license_file",
111      rebase_path(_license_path, root_build_dir),
112      "--gn-target",
113      _license_target,
114      "--gn-out-dir",
115      ".",
116    ]
117  }
118
119  # Produces a consolidated license file in spdx format.
120  action("${target_name}_license_spdx") {
121    _license_path_spdx = "${_license_path}.spdx.json"
122
123    script = "//tools/licenses/licenses.py"
124    inputs = [ "$_gn_path" ]
125    outputs = [ _license_path_spdx ]
126    args = [
127      "license_file",
128      rebase_path(_license_path_spdx, root_build_dir),
129      "--gn-target",
130      _license_target,
131      "--gn-out-dir",
132      ".",
133      "--format",
134      "spdx",
135      "--spdx-doc-name",
136      "${invoker.target_name}",
137    ]
138  }
139
140  if (!defined(deps)) {
141    deps = []
142  }
143  deps += [
144    ":${target_name}_license",
145    ":${target_name}_license_spdx",
146    ":version",
147  ]
148
149  if (!defined(sources)) {
150    sources = []
151  }
152  sources += get_target_outputs(":${target_name}_license") +
153             get_target_outputs(":${target_name}_license_spdx") +
154             [ "${target_gen_dir}/VERSION" ]
155
156  fuchsia_cipd_package("${target_name}${_archive_suffix}") {
157    package = "${package_base_path}/${package_subdirectory}/${targetarch}/${invoker.target_name}"
158    package_root = "${target_gen_dir}/${invoker.target_name}"
159    package_definition_name = "${invoker.target_name}.yaml"
160
161    # Always use absolute path.
162    use_absolute_root_path = true
163  }
164}
165
166# Prepares a CIPD test archive, which is a regular CIPD archive that generates
167# test manifests for a given list of test_sets.
168#
169# Parameters:
170#   test_sets: A list of scopes for which test manifests will be created. Each
171#              set contains:
172#     manifest_path: The path to the generated manifest JSON file.
173#     far_sources: An optional list of CFv2 test component .far files.
174#
175# Required parameters used by the cipd_archive template:
176#   "package_subdirectory",
177#
178# Optional parameters used by the cipd_archive template:
179#   "description"
180#   "install_mode",
181#   "data",
182#   "data_deps"
183#   "deps",
184#   "testonly",
185
186template("cipd_test_archive") {
187  forward_variables_from(invoker,
188                         [
189                           "package_subdirectory",
190                           "description",
191                           "install_mode",
192                           "data",
193                           "data_deps",
194                           "deps",
195                           "testonly",
196                           "test_sets",
197                         ])
198
199  assert(defined(test_sets) && defined(testonly) && testonly == true)
200
201  cipd_archive(target_name) {
202    # Build JSON manifests for each suite of tests and include them in the
203    # archive.
204    sources = []
205    foreach(test_set, test_sets) {
206      assert(defined(test_set.far_sources))
207      sources += [ test_set.manifest_path ]
208      _manifest_contents = []
209      if (defined(test_set.far_sources)) {
210        foreach(source, test_set.far_sources) {
211          package_name = get_path_info(source, "name")
212
213          _manifest_contents += [
214            {
215              package = package_name
216              component_name = package_name + ".cm"
217            },
218          ]
219        }
220        sources += test_set.far_sources
221      }
222      write_file(test_set.manifest_path, _manifest_contents, "json")
223    }
224  }
225}
226
227cipd_archive("web_engine") {
228  package_subdirectory = _web_engine_directory
229  description = "Prebuilt WebEngine binaries for Fuchsia."
230
231  deps = [ "//fuchsia_web/webengine:web_engine" ]
232  sources =
233      [ "${root_gen_dir}/fuchsia_web/webengine/web_engine/web_engine.far" ]
234}
235
236cipd_archive("cast_runner") {
237  package_subdirectory = _web_engine_directory
238  description = "Prebuilt Cast application Runner binaries for Fuchsia."
239
240  deps = [ "//fuchsia_web/runners:cast_runner_pkg" ]
241  sources =
242      [ "${root_gen_dir}/fuchsia_web/runners/cast_runner/cast_runner.far" ]
243}
244
245cipd_archive("web_engine_shell") {
246  package_subdirectory = _web_engine_directory
247  description = "Simple command-line embedder for WebEngine."
248  testonly = true
249
250  deps = [ "//fuchsia_web/shell:web_engine_shell_pkg" ]
251  sources = [
252    "${root_gen_dir}/fuchsia_web/shell/web_engine_shell/web_engine_shell.far",
253  ]
254}
255
256_stripped_chromedriver_file = "${root_out_dir}/clang_x64/stripped/chromedriver"
257
258action("strip_chromedriver_binary") {
259  testonly = true
260
261  prog_name = "${root_out_dir}/clang_x64/chromedriver"
262
263  deps = [ "//chrome/test/chromedriver:chromedriver_server($host_toolchain)" ]
264  script = "//build/gn_run_binary.py"
265  sources = [
266    "//buildtools/third_party/eu-strip/bin/eu-strip",
267    prog_name,
268  ]
269  outputs = [ _stripped_chromedriver_file ]
270  args = [
271    rebase_path("//buildtools/third_party/eu-strip/bin/eu-strip",
272                root_build_dir),
273    "-o",
274    rebase_path(_stripped_chromedriver_file, root_build_dir),
275    rebase_path(prog_name, root_build_dir),
276  ]
277
278  visibility = []
279  visibility = [
280    ":*",
281    "//fuchsia_web/av_testing:*",
282  ]
283}
284
285cipd_archive("chromedriver") {
286  package_subdirectory = "${_host_tools_directory}/\${os}"
287  description = "Prebuilt Chromedriver binary for Fuchsia host."
288  install_mode = "copy"
289  testonly = true
290
291  deps = [ ":strip_chromedriver_binary" ]
292  sources = [ _stripped_chromedriver_file ]
293}
294
295cipd_test_archive("tests") {
296  package_subdirectory = _web_engine_directory
297  description = "Prebuilt Chromium tests for Fuchsia."
298  testonly = true
299
300  _common_tests = [
301    "${root_gen_dir}/base/base_unittests/base_unittests.far",
302    "${root_gen_dir}/ipc/ipc_tests/ipc_tests.far",
303    "${root_gen_dir}/media/media_unittests/media_unittests.far",
304    "${root_gen_dir}/mojo/mojo_unittests/mojo_unittests.far",
305    "${root_gen_dir}/skia/skia_unittests/skia_unittests.far",
306    "${root_gen_dir}/third_party/blink/common/blink_common_unittests/blink_common_unittests.far",
307  ]
308  deps = [
309    "//base:base_unittests_pkg",
310    "//ipc:ipc_tests_pkg",
311    "//media:media_unittests_pkg",
312    "//mojo:mojo_unittests_pkg",
313    "//skia:skia_unittests_pkg",
314    "//third_party/blink/common:blink_common_unittests_pkg",
315  ]
316
317  _web_engine_tests = [ "${root_gen_dir}/fuchsia_web/webengine/web_engine_integration_tests/web_engine_integration_tests.far" ]
318  deps += [ "//fuchsia_web/webengine:web_engine_integration_tests_pkg" ]
319
320  _cast_runner_tests = [ "${root_gen_dir}/fuchsia_web/runners/cast_runner_integration_tests/cast_runner_integration_tests.far" ]
321  deps += [ "//fuchsia_web/runners:cast_runner_integration_tests_pkg" ]
322
323  _all_tests = _common_tests + _web_engine_tests + _cast_runner_tests
324
325  test_sets = [
326    {
327      manifest_path = "${target_gen_dir}/test_manifest.json"
328      far_sources = _all_tests
329    },
330    {
331      manifest_path = "${target_gen_dir}/common_tests_manifest.json"
332      far_sources = _common_tests
333    },
334    {
335      manifest_path = "${target_gen_dir}/web_engine_tests_manifest.json"
336      far_sources = _web_engine_tests
337    },
338    {
339      manifest_path = "${target_gen_dir}/cast_runner_tests_manifest.json"
340      far_sources = _cast_runner_tests
341    },
342  ]
343}
344
345# Construct a consolidated directory of web_engine debugging symbols using the
346# GNU .build_id structure for CIPD archival.
347_web_engine_build_ids_target = "web_engine_debug_symbol_directory"
348_web_engine_debug_symbols_archive_name = "web_engine_debug_symbols"
349_web_engine_debug_symbols_outdir = "${target_gen_dir}/${_web_engine_debug_symbols_archive_name}/${_web_engine_build_ids_target}"
350
351build_id_dir(_web_engine_build_ids_target) {
352  testonly = true  # Some of the archives contain test packages.
353  output_path = _web_engine_debug_symbols_outdir
354  deps = [ ":web_engine_archives_with_tests" ]
355}
356
357fuchsia_cipd_package(_web_engine_debug_symbols_archive_name) {
358  testonly = true
359  package = "${package_base_path}/${_web_engine_directory}/${targetarch}/debug-symbols"
360  package_root = _web_engine_debug_symbols_outdir
361  package_definition_name = "${target_name}.yaml"
362  package_definition_dir = "${target_gen_dir}/${target_name}"
363  description = "Debugging symbols for prebuilt binaries from Chromium."
364  use_absolute_root_path = true
365
366  directories = [ "." ]
367  deps = [ ":${_web_engine_build_ids_target}" ]
368}
369
370# A group for production archives to ensure nothing is testonly.
371group("web_engine_production_archives") {
372  deps = [
373    ":cast_runner${_archive_suffix}",
374    ":web_engine${_archive_suffix}",
375  ]
376}
377
378# Used by both the main group as well as :debug_symbols.
379group("web_engine_archives_with_tests") {
380  testonly = true  # tests and web_engine_shell are testonly.
381  deps = [
382    ":tests${_archive_suffix}",
383    ":web_engine_production_archives",
384    ":web_engine_shell${_archive_suffix}",
385  ]
386}
387
388# TODO(zijiehe): Rename to "cipd_yaml" when possible.
389# This target only creates yaml files and related archives for cipd rather
390# than executing the cipd instance to upload them.
391# Currently it's named as "cipd" to match the folder name which introduces
392# confusions.
393group("cipd") {
394  testonly = true  # Some archives are testonly.
395  deps = [
396    ":web_engine_archives_with_tests",
397
398    # Symbols are not uploaded for the following.
399    ":chromedriver${_archive_suffix}",
400    ":web_engine_debug_symbols",
401  ]
402  visibility = []  # Required to replace the file default.
403  visibility = [ "//:gn_all" ]
404}
405