xref: /aosp_15_r20/external/cronet/build/fuchsia/cipd/BUILD.gn (revision 6777b5387eb2ff775bb5750e3f5d96f37fb7352b)
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
279cipd_archive("chromedriver") {
280  package_subdirectory = "${_host_tools_directory}/\${os}"
281  description = "Prebuilt Chromedriver binary for Fuchsia host."
282  install_mode = "copy"
283  testonly = true
284
285  deps = [ ":strip_chromedriver_binary" ]
286  sources = [ _stripped_chromedriver_file ]
287}
288
289cipd_test_archive("tests") {
290  package_subdirectory = _web_engine_directory
291  description = "Prebuilt Chromium tests for Fuchsia."
292  testonly = true
293
294  _common_tests = [
295    "${root_gen_dir}/base/base_unittests/base_unittests.far",
296    "${root_gen_dir}/ipc/ipc_tests/ipc_tests.far",
297    "${root_gen_dir}/media/media_unittests/media_unittests.far",
298    "${root_gen_dir}/mojo/mojo_unittests/mojo_unittests.far",
299    "${root_gen_dir}/skia/skia_unittests/skia_unittests.far",
300    "${root_gen_dir}/third_party/blink/common/blink_common_unittests/blink_common_unittests.far",
301  ]
302  deps = [
303    "//base:base_unittests_pkg",
304    "//ipc:ipc_tests_pkg",
305    "//media:media_unittests_pkg",
306    "//mojo:mojo_unittests_pkg",
307    "//skia:skia_unittests_pkg",
308    "//third_party/blink/common:blink_common_unittests_pkg",
309  ]
310
311  _web_engine_tests = [ "${root_gen_dir}/fuchsia_web/webengine/web_engine_integration_tests/web_engine_integration_tests.far" ]
312  deps += [ "//fuchsia_web/webengine:web_engine_integration_tests_pkg" ]
313
314  _cast_runner_tests = [ "${root_gen_dir}/fuchsia_web/runners/cast_runner_integration_tests/cast_runner_integration_tests.far" ]
315  deps += [ "//fuchsia_web/runners:cast_runner_integration_tests_pkg" ]
316
317  _all_tests = _common_tests + _web_engine_tests + _cast_runner_tests
318
319  test_sets = [
320    {
321      manifest_path = "${target_gen_dir}/test_manifest.json"
322      far_sources = _all_tests
323    },
324    {
325      manifest_path = "${target_gen_dir}/common_tests_manifest.json"
326      far_sources = _common_tests
327    },
328    {
329      manifest_path = "${target_gen_dir}/web_engine_tests_manifest.json"
330      far_sources = _web_engine_tests
331    },
332    {
333      manifest_path = "${target_gen_dir}/cast_runner_tests_manifest.json"
334      far_sources = _cast_runner_tests
335    },
336  ]
337}
338
339# Construct a consolidated directory of web_engine debugging symbols using the
340# GNU .build_id structure for CIPD archival.
341_web_engine_build_ids_target = "web_engine_debug_symbol_directory"
342_web_engine_debug_symbols_archive_name = "web_engine_debug_symbols"
343_web_engine_debug_symbols_outdir = "${target_gen_dir}/${_web_engine_debug_symbols_archive_name}/${_web_engine_build_ids_target}"
344
345build_id_dir(_web_engine_build_ids_target) {
346  testonly = true  # Some of the archives contain test packages.
347  output_path = _web_engine_debug_symbols_outdir
348  deps = [ ":web_engine_archives_with_tests" ]
349}
350
351fuchsia_cipd_package(_web_engine_debug_symbols_archive_name) {
352  testonly = true
353  package = "${package_base_path}/${_web_engine_directory}/${targetarch}/debug-symbols"
354  package_root = _web_engine_debug_symbols_outdir
355  package_definition_name = "${target_name}.yaml"
356  package_definition_dir = "${target_gen_dir}/${target_name}"
357  description = "Debugging symbols for prebuilt binaries from Chromium."
358  use_absolute_root_path = true
359
360  directories = [ "." ]
361  deps = [ ":${_web_engine_build_ids_target}" ]
362}
363
364# A group for production archives to ensure nothing is testonly.
365group("web_engine_production_archives") {
366  deps = [
367    ":cast_runner${_archive_suffix}",
368    ":web_engine${_archive_suffix}",
369  ]
370}
371
372# Used by both the main group as well as :debug_symbols.
373group("web_engine_archives_with_tests") {
374  testonly = true  # tests and web_engine_shell are testonly.
375  deps = [
376    ":tests${_archive_suffix}",
377    ":web_engine_production_archives",
378    ":web_engine_shell${_archive_suffix}",
379  ]
380}
381
382# TODO(zijiehe): Rename to "cipd_yaml" when possible.
383# This target only creates yaml files and related archives for cipd rather
384# than executing the cipd instance to upload them.
385# Currently it's named as "cipd" to match the folder name which introduces
386# confusions.
387group("cipd") {
388  testonly = true  # Some archives are testonly.
389  deps = [
390    ":web_engine_archives_with_tests",
391
392    # Symbols are not uploaded for the following.
393    ":chromedriver${_archive_suffix}",
394    ":web_engine_debug_symbols",
395  ]
396  visibility = []  # Required to replace the file default.
397  visibility = [ "//:gn_all" ]
398}
399