| # Copyright 2019 The Fuchsia Authors. All rights reserved. |
| # Use of this source code is governed by a BSD-style license that can be |
| # found in the LICENSE file. |
| """Recipe for building and publishing fastboot to CIPD.""" |
| |
| DEPS = [ |
| "fuchsia/archive", |
| "fuchsia/buildbucket_util", |
| "fuchsia/git", |
| "fuchsia/macos_sdk", |
| "fuchsia/status_check", |
| "fuchsia/upload", |
| "recipe_engine/buildbucket", |
| "recipe_engine/cipd", |
| "recipe_engine/context", |
| "recipe_engine/file", |
| "recipe_engine/path", |
| "recipe_engine/platform", |
| "recipe_engine/raw_io", |
| "recipe_engine/step", |
| ] |
| |
| ANDROID_SOURCE_REPO = "https://android.googlesource.com/platform/manifest" |
| ANDROID_SOURCE_BRANCH = "platform-tools-29.0.4" |
| FASTBOOT_CIPD_NAME = "fuchsia/third_party/fastboot/${platform}" |
| REPO_CIPD_PKG = ("fuchsia/third_party/repo", "version:1.13.2", "repo") |
| |
| # The source file that checks whether the host filesystem is case-sensitive, |
| # a fails if not, along with the pattern that matches the invocation of that |
| # check within. |
| FILE_WITH_CASE_SENSITIVITY_CHECK = ("build", "soong", "ui", "build", "build.go") |
| CASE_SENSITIVITY_CHECK_PATTERN = "checkCaseSensitivity(ctx, config)" |
| |
| |
| def RunSteps(api): |
| cipd_dir = api.path["start_dir"].join("cipd") |
| pkgs = api.cipd.EnsureFile() |
| pkgs.add_package(*REPO_CIPD_PKG) |
| api.cipd.ensure(cipd_dir, pkgs) |
| repo_dir = cipd_dir.join("repo") |
| |
| src_dir = api.path["start_dir"].join("android", "src") |
| api.file.ensure_directory("ensure source directory", src_dir) |
| with api.context(cwd=src_dir): |
| api.step( |
| "repo init", |
| [ |
| repo_dir.join("repo"), |
| "init", |
| "-u", |
| ANDROID_SOURCE_REPO, |
| "-b", |
| ANDROID_SOURCE_BRANCH, |
| ], |
| ) |
| api.step( |
| "repo sync", |
| [repo_dir.join("repo"), "sync", "-j%d" % api.platform.cpu_count,], |
| ) |
| |
| if api.platform.is_mac: |
| with api.step.nest("disable case-sensitivity check"): |
| # Necessary hack! Disable the check so that we can build on macs. |
| case_checking_file = src_dir.join(*FILE_WITH_CASE_SENSITIVITY_CHECK) |
| relpath = api.path.join(*FILE_WITH_CASE_SENSITIVITY_CHECK) |
| contents = api.file.read_text( |
| "read in %s" % relpath, |
| case_checking_file, |
| test_data="blah\n%s\nblah" % CASE_SENSITIVITY_CHECK_PATTERN, |
| ) |
| contents = contents.replace(CASE_SENSITIVITY_CHECK_PATTERN, "") |
| api.file.write_text( |
| "write back to %s" % relpath, case_checking_file, contents |
| ) |
| |
| fastboot_dir = src_dir.join("system", "core", "fastboot") |
| with api.context(cwd=fastboot_dir): |
| repository = api.git.get_remote_url("aosp") |
| revision = api.git.get_hash() |
| |
| out_dir = api.path.mkdtemp("fastboot").join("out") |
| with api.macos_sdk(), api.context(cwd=src_dir, env={"OUT_DIR": out_dir}): |
| # Soong is a work-in-progress build system that works well enough to build |
| # fastboot alone. |
| # (See https://source.android.com/setup/build#what_is_soong.) |
| # We can bootstrap everything needed to invoke soong through the 'soong_ui' |
| # bash script. |
| soong_ui_script = src_dir.join("build", "soong", "soong_ui.bash") |
| android_host_os = {"linux": "linux", "mac": "darwin",}[api.platform.name] |
| android_host_arch = {"intel": {64: "x86",}}[api.platform.arch][ |
| api.platform.bits |
| ] |
| android_host_platform = "%s-%s" % (android_host_os, android_host_arch) |
| out_bin_dir = out_dir.join("host", android_host_platform, "bin") |
| fastboot = out_bin_dir.join("fastboot") |
| api.step("build fastboot", [soong_ui_script, "--make-mode", fastboot]) |
| |
| upload_paths = [api.upload.FilePath(fastboot)] |
| if api.buildbucket_util.is_tryjob: |
| api.archive.upload( |
| out_bin_dir, upload_paths=upload_paths, output_property="isolated" |
| ) |
| else: |
| api.upload.cipd_package( |
| FASTBOOT_CIPD_NAME, |
| out_bin_dir, |
| upload_paths, |
| search_tag={"git_revision": revision}, |
| extra_tags={"git_branch": ANDROID_SOURCE_BRANCH}, |
| repository=repository, |
| ) |
| |
| |
| def GenTests(api): |
| revision = "a" * 40 |
| ci_build = api.buildbucket.ci_build( |
| project="android", |
| bucket="ci", |
| git_repo="https://android.googlesource.com/platform/system/core", |
| revision=revision, |
| ) |
| try_build = api.buildbucket.try_build( |
| project="android", |
| bucket="try", |
| git_repo="https://android.googlesource.com/platform/system/core", |
| revision=revision, |
| ) |
| |
| yield api.status_check.test("mac") + try_build + api.platform.name("mac") |
| |
| yield api.status_check.test("ci_cipd_pkg_exists") + ci_build |
| |
| yield ( |
| api.status_check.test("ci_cipd_pkg_new") |
| + ci_build |
| + api.step_data("git rev-parse", api.raw_io.stream_output(revision)) |
| + api.step_data( |
| "cipd.cipd search %s git_revision:%s" % (FASTBOOT_CIPD_NAME, revision), |
| api.cipd.example_search(FASTBOOT_CIPD_NAME, []), |
| ) |
| ) |