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