| # Copyright 2016 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 Bloaty.""" |
| |
| from PB.recipes.fuchsia.contrib.bloaty import InputProperties |
| |
| PYTHON_VERSION_COMPATIBILITY = "PY3" |
| |
| DEPS = [ |
| "fuchsia/buildbucket_util", |
| "fuchsia/cipd_util", |
| "fuchsia/git", |
| "fuchsia/goma", |
| "fuchsia/macos_sdk", |
| "recipe_engine/cipd", |
| "recipe_engine/context", |
| "recipe_engine/file", |
| "recipe_engine/path", |
| "recipe_engine/platform", |
| "recipe_engine/properties", |
| "recipe_engine/raw_io", |
| "recipe_engine/step", |
| ] |
| |
| PROPERTIES = InputProperties |
| |
| PLATFORM_TO_TRIPLE = { |
| "linux-amd64": "x86_64-linux-gnu", |
| "linux-arm64": "aarch64-linux-gnu", |
| "mac-amd64": "x86_64-apple-darwin", |
| } |
| |
| |
| def RunSteps(api, props): |
| repo = props.repository or "https://fuchsia.googlesource.com/third_party/bloaty" |
| api.goma.ensure() |
| target_platform = props.platform or api.cipd_util.platform_name |
| |
| checkout_root, revision = api.git.checkout_from_build_input( |
| repo, rebase_merges=True |
| ) |
| |
| build_dir = api.path["start_dir"].join("bloaty_build") |
| api.file.ensure_directory("ensure build dir", build_dir) |
| |
| cipd_dir = api.path["start_dir"].join("cipd") |
| with api.step.nest("ensure_packages"), api.context(infra_steps=True): |
| pkgs = api.cipd.EnsureFile() |
| pkgs.add_package("infra/cmake/${platform}", "version:3.9.2") |
| pkgs.add_package("infra/ninja/${platform}", "version:1.8.2") |
| pkgs.add_package( |
| "fuchsia/third_party/clang/${platform}", |
| "git_revision:7a34dca0f3918ab1c0397e56dd64a3c04164c8b6", |
| ) |
| pkgs.add_package( |
| "fuchsia/rust/${platform}", |
| "git_revision:cbe7c5ce705896d4e22bf6096590bc1f17993b78", |
| ) |
| if target_platform.startswith("linux"): |
| pkgs.add_package( |
| "fuchsia/sysroot/%s" % target_platform, "latest", "sysroot" |
| ) |
| api.cipd.ensure(cipd_dir, pkgs) |
| |
| with api.goma.build_with_goma(): |
| env = {"RUSTC": cipd_dir.join("bin", "rustc")} |
| with api.macos_sdk(), api.context(cwd=build_dir, env=env): |
| cmake(api, cipd_dir, checkout_root, target_platform) |
| api.step("build", [cipd_dir.join("ninja"), "-j%d" % api.goma.jobs]) |
| api.step("test", [cipd_dir.join("ninja"), "test"]) |
| |
| if not api.buildbucket_util.is_tryjob: |
| api.cipd_util.upload_package( |
| pkg_name="fuchsia/third_party/bloaty/" + target_platform, |
| pkg_root=build_dir, |
| pkg_paths=[build_dir.join("bloaty")], |
| search_tag={"git_revision": revision}, |
| repository=repo, |
| ) |
| |
| |
| def platform_sysroot(api, cipd_dir, platform): |
| if platform.startswith("linux"): |
| return cipd_dir.join("sysroot") |
| elif platform.startswith("mac"): |
| # TODO(fxbug.dev/3043): Eventually use our own hermetic sysroot as for Linux. |
| step_result = api.step( |
| "xcrun", |
| ["xcrun", "--sdk", "macosx", "--show-sdk-path"], |
| stdout=api.raw_io.output_text(name="sdk-path", add_output_log=True), |
| step_test_data=lambda: api.raw_io.test_api.stream_output_text( |
| "/some/xcode/path" |
| ), |
| ) |
| return step_result.stdout.strip() |
| else: |
| assert False, "unsupported platform" # pragma: no cover |
| |
| |
| def cmake(api, cipd_dir, checkout_root, platform, step_name="cmake"): |
| platform_sysroot(api, cipd_dir, platform) |
| options = ( |
| [ |
| "-DCMAKE_LINKER=%s" % cipd_dir.join("bin", "ld.lld"), |
| "-DCMAKE_NM=%s" % cipd_dir.join("bin", "llvm-nm"), |
| "-DCMAKE_OBJCOPY=%s" % cipd_dir.join("bin", "llvm-objcopy"), |
| "-DCMAKE_OBJDUMP=%s" % cipd_dir.join("bin", "llvm-objdump"), |
| "-DCMAKE_RANLIB=%s" % cipd_dir.join("bin", "llvm-ranlib"), |
| "-DCMAKE_STRIP=%s" % cipd_dir.join("bin", "llvm-strip"), |
| "-DCMAKE_EXE_LINKER_FLAGS=-static-libstdc++ -ldl -lpthread", |
| ] |
| if platform.startswith("linux") |
| else [] |
| ) |
| |
| target = PLATFORM_TO_TRIPLE[platform] |
| return api.step( |
| step_name, |
| [ |
| cipd_dir.join("bin", "cmake"), |
| "-GNinja", |
| "-DCMAKE_BUILD_TYPE=Release", |
| "-DCMAKE_MAKE_PROGRAM=%s" % cipd_dir.join("ninja"), |
| "-DCMAKE_C_COMPILER_LAUNCHER=%s" % api.goma.goma_dir.join("gomacc"), |
| "-DCMAKE_C_COMPILER=%s" % cipd_dir.join("bin", "clang"), |
| "-DCMAKE_C_COMPILER_TARGET=%s" % target, |
| "-DCMAKE_CXX_COMPILER_LAUNCHER=%s" % api.goma.goma_dir.join("gomacc"), |
| "-DCMAKE_CXX_COMPILER=%s" % cipd_dir.join("bin", "clang++"), |
| "-DCMAKE_CXX_COMPILER_TARGET=%s" % target, |
| "-DRUST_TOOLCHAIN_PREFIX=%s" % cipd_dir.join("bin"), |
| ] |
| + options |
| + [checkout_root], |
| ) |
| |
| |
| def GenTests(api): |
| yield ( |
| api.buildbucket_util.test("linux_ci", repo="third_party/bloaty") |
| + api.properties(platform="linux-amd64") |
| ) |
| yield ( |
| api.buildbucket_util.test("mac_try", tryjob=True, repo="third_party/bloaty") |
| + api.platform.name("mac") |
| + api.properties(platform="mac-amd64") |
| ) |