blob: fc7be107e2058def7eaadeb0b84b9c16a677307b [file] [log] [blame]
# 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/archive",
"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", "version:2.8", "repo")
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": "/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"),
)
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("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_dir.join("repo"),
"init",
"-u",
"https://android.googlesource.com/platform/manifest",
"-b",
"emu-master-dev",
],
)
api.step(
"repo sync",
[repo_dir.join("repo"), "sync", "-j%d" % api.platform.cpu_count],
)
qemu_dir = src_dir.join("external", "qemu")
with api.macos_sdk(additional_sdks=[("MacOSX10.13.sdk", "9f2000")]), api.context(
cwd=qemu_dir
):
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.archive.upload(pkg_dir, output_property="isolated")
if is_prod:
if not platform:
platform = "%s-%s" % (
api.platform.name.replace("win", "windows"),
{
"intel": {32: "386", 64: "amd64",},
"arm": {32: "armv6", 64: "arm64",},
}[api.platform.arch][api.platform.bits],
)
api.upload.cipd_package(
"fuchsia/third_party/aemu/" + platform,
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", []),
)
)