blob: f2ec03686e0a3976400e9c38d067555a4551f138 [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
PYTHON_VERSION_COMPATIBILITY = "PY3"
DEPS = [
"fuchsia/cas_util",
"fuchsia/cipd_util",
"fuchsia/git",
"fuchsia/macos_sdk",
"fuchsia/status_check",
"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/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",
"--no-tests",
"--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.cas_util.upload(pkg_dir, output_property="isolated")
if is_prod:
api.cipd_util.upload_package(
"fuchsia/third_party/aemu/%s" % (platform or api.cipd_util.platform_name),
pkg_dir,
[pkg_dir],
{"git_revision": revision},
repository=repository,
)
def GenTests(api):
yield (
api.status_check.test("linux")
+ 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")
+ 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")
)