| # 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 AEMU.""" |
| |
| from recipe_engine.recipe_api import Property |
| |
| DEPS = [ |
| "fuchsia/cipd_platform", |
| "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/properties", |
| "recipe_engine/python", |
| "recipe_engine/raw_io", |
| "recipe_engine/step", |
| ] |
| |
| REPO_CIPD_PKG = "fuchsia/third_party/repo" |
| REPO_CIPD_VERSION = "version:2.8" |
| |
| PROPERTIES = { |
| "platform": Property(kind=str, help="CIPD target platform", default=None), |
| } |
| |
| PLATFORM_TO_TARGET = { |
| "linux-amd64": "linux", |
| "linux-arm64": "linux_aarch64", |
| "mac-amd64": "darwin", |
| } |
| |
| BREAKPAD_UPLOAD_KEY_PATH = { |
| "linux": "/creds/aemu/symbols_upload", |
| "mac": "/opt/creds/generic/generic-fuchsia-aemu-symbols-upload-api-token", |
| } |
| |
| |
| def RunSteps(api, platform): |
| is_prod = api.buildbucket.build.builder.bucket == "prod" |
| |
| # AEMU build expects the breakpad upload key in $HOME, so create a fake |
| # $HOME and move the key to it. |
| fake_home = api.path.mkdtemp() |
| if is_prod: |
| api.file.copy( |
| "copy upload key", |
| BREAKPAD_UPLOAD_KEY_PATH[api.platform.name], |
| fake_home.join(".emulator_symbol_server_key"), |
| ) |
| |
| repo_path = api.cipd.ensure_tool(REPO_CIPD_PKG, REPO_CIPD_VERSION) |
| |
| src_dir = api.path["start_dir"].join("aemu", "src") |
| api.file.ensure_directory("aemu src dir", src_dir) |
| install_dir = api.path["start_dir"].join("aemu", "install") |
| with api.context(cwd=src_dir): |
| api.step( |
| "repo init", |
| [ |
| repo_path, |
| "init", |
| "-u", |
| "https://android.googlesource.com/platform/manifest", |
| "-b", |
| "emu-master-dev", |
| ], |
| ) |
| api.step("repo sync", [repo_path, "sync", "-j%d" % api.platform.cpu_count]) |
| qemu_dir = src_dir.join("external", "qemu") |
| |
| env = {"MACOSX_DEPLOYMENT_TARGET": "10.11"} |
| with api.macos_sdk(), api.context(cwd=qemu_dir, env=env): |
| repository = api.git.get_remote_url("aosp") |
| revision = api.git.get_hash() |
| |
| cmd = [ |
| qemu_dir.join("android", "build", "python", "cmake.py"), |
| "--cmake_option", |
| "ANDROIDSTUDIO=OFF", |
| "--no-qtwebengine", |
| "--minbuild", |
| "--dist", |
| install_dir, |
| ] |
| |
| if platform: |
| cmd.extend(["--target", PLATFORM_TO_TARGET[platform]]) |
| if is_prod: |
| cmd.extend(["--crash", "prod"]) |
| |
| with api.context(env={"HOME": fake_home}): |
| api.python("cmake", cmd[0], cmd[1:], venv=api.resource("cmake.vpython")) |
| |
| pkg_dir = qemu_dir.join("objs", "distribution", "emulator") |
| |
| api.file.copy("copy LICENSE", qemu_dir.join("LICENSE"), pkg_dir) |
| api.file.copytree( |
| "copy LICENSES/", qemu_dir.join("LICENSES"), pkg_dir.join("LICENSES") |
| ) |
| |
| api.upload.upload_isolated(pkg_dir) |
| |
| if is_prod: |
| api.upload.cipd_package( |
| "fuchsia/third_party/aemu/%s" % (platform or api.cipd_platform.name), |
| pkg_dir, |
| [api.upload.DirectoryPath(pkg_dir)], |
| {"git_revision": revision}, |
| repository=repository, |
| ) |
| |
| |
| def GenTests(api): |
| yield ( |
| api.status_check.test("cipd_pkg_exists") |
| + api.buildbucket.ci_build( |
| project="fuchsia", |
| bucket="prod", |
| git_repo="https://android.googlesource.com/platform/external/qemu/", |
| revision="a" * 40, |
| ) |
| + api.platform.name("linux") |
| ) |
| |
| yield ( |
| api.status_check.test("mac") |
| + api.buildbucket.ci_build( |
| project="fuchsia", |
| bucket="prod", |
| git_repo="https://android.googlesource.com/platform/external/qemu/", |
| revision="a" * 40, |
| ) |
| + api.platform.name("mac") |
| ) |
| |
| yield ( |
| api.status_check.test("aarch64_cipd_pkg_exists") |
| + api.buildbucket.ci_build( |
| project="fuchsia", |
| bucket="prod", |
| git_repo="https://android.googlesource.com/platform/external/qemu/", |
| revision="a" * 40, |
| ) |
| + api.properties(platform="linux-arm64") |
| ) |
| |
| yield ( |
| api.status_check.test("cipd_pkg_new") |
| + api.buildbucket.ci_build( |
| project="fuchsia", |
| bucket="prod", |
| git_repo="https://android.googlesource.com/platform/external/qemu/", |
| revision="a" * 40, |
| ) |
| + api.step_data("git rev-parse", api.raw_io.stream_output("a" * 40)) |
| + api.platform.name("linux") |
| + api.step_data( |
| "cipd.cipd search fuchsia/third_party/aemu/linux-amd64 " |
| + "git_revision:" |
| + "a" * 40, |
| api.cipd.example_search("fuchsia/third_party/aemu/linux-amd64", []), |
| ) |
| ) |