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