| # Copyright 2020 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 uploading jq to CIPD.""" |
| |
| from PB.recipes.fuchsia.contrib.jq import InputProperties |
| |
| DEPS = [ |
| "fuchsia/cas_util", |
| "fuchsia/cipd_util", |
| "fuchsia/git_checkout", |
| "fuchsia/macos_sdk", |
| "recipe_engine/cipd", |
| "recipe_engine/context", |
| "recipe_engine/file", |
| "recipe_engine/path", |
| "recipe_engine/platform", |
| "recipe_engine/properties", |
| "recipe_engine/step", |
| ] |
| |
| PROPERTIES = InputProperties |
| |
| JQ_REPO_URL = "https://fuchsia.googlesource.com/third_party/github.com/jqlang/jq" |
| |
| # CIPD packages required for building jq. |
| CIPD_DEPENDENCIES = ( |
| ("fuchsia/third_party/autoconf/${platform}", "version:2.69"), |
| ("fuchsia/third_party/automake/${platform}", "version:1.16.2"), |
| ("fuchsia/third_party/bison/${platform}", "version:3.7"), |
| ("fuchsia/third_party/clang/${platform}", "integration"), |
| ("fuchsia/third_party/libtool/${platform}", "version:2.4.6"), |
| ("fuchsia/third_party/m4/${platform}", "version:1.4.18"), |
| ("fuchsia/third_party/make/${platform}", "version:4.3"), |
| ) |
| LINUX_SYSROOT_PKG = ( |
| "fuchsia/third_party/sysroot/linux", |
| "integration", |
| "sysroot", |
| ) |
| |
| |
| def RunSteps(api, props): |
| cipd_dir = api.path.start_dir / "cipd" |
| with api.context(infra_steps=True): |
| to_ensure = list(CIPD_DEPENDENCIES) |
| if api.platform.is_linux: |
| to_ensure.append(LINUX_SYSROOT_PKG) |
| |
| pkgs = api.cipd.EnsureFile() |
| for pkg in to_ensure: |
| pkgs.add_package(*pkg) |
| api.cipd.ensure(cipd_dir, pkgs) |
| |
| src_dir, revision = api.git_checkout(JQ_REPO_URL, recursive=True, submodules=True) |
| |
| install_dir = api.path.start_dir / "install" |
| with api.macos_sdk(), api.context( |
| cwd=src_dir, |
| env_prefixes={"PATH": [cipd_dir / "bin"]}, |
| # TODO(fxbug.dev/58251): remove environment variable when possible. |
| env={"M4": cipd_dir.joinpath("bin", "m4")}, |
| ): |
| api.step( |
| "autoreconf", |
| ["autoreconf", "--verbose", "--install", "--force"], |
| ) |
| |
| configure_flags = [f"--sysroot={sysroot(api, cipd_dir)}", "-O3"] |
| if not api.platform.is_mac: |
| # TODO: LTO is currently failing on macOS |
| configure_flags.append("-flto") |
| configure_variables = { |
| "CC": "clang", |
| "CXX": "clang++", |
| "CFLAGS": " ".join(configure_flags), |
| "CPPFLAGS": " ".join(configure_flags), |
| "CXXFLAGS": " ".join(configure_flags), |
| "LDFLAGS": " ".join(configure_flags), |
| } |
| if api.platform.is_linux: |
| configure_variables.update( |
| { |
| "AR": "llvm-ar", |
| "RANLIB": "llvm-ranlib", |
| "NM": "llvm-nm", |
| "STRIP": "llvm-strip", |
| "OBJCOPY": "llvm-objcopy", |
| } |
| ) |
| |
| api.step( |
| "configure", |
| [ |
| "./configure", |
| "--without-oniguruma", |
| "--prefix=", |
| "--disable-dependency-tracking", |
| "--disable-shared", |
| "--enable-all-static", |
| ] |
| + sorted([f"{k}={v}" for k, v in configure_variables.items()]), |
| ) |
| |
| api.step("make", ["make", f"-j{int(api.platform.cpu_count)}"]) |
| if not api.platform.is_mac: |
| # The shtests seem to fail the NO_COLOR tests on mac-arm64 due to |
| # something around using `script` to make a fake tty not working |
| # as expected. All the other tests pass and I have no reason to |
| # believe this is broken in any other way, so skip the tests on |
| # macs. |
| try: |
| api.step("make check", ["make", "check"]) |
| finally: |
| # Record the test suite log so we can see what failed |
| try: |
| api.file.read_text( |
| "test-suite.log", |
| src_dir / "test-suite.log", |
| test_data="", |
| ) |
| except api.step.StepFailure: # pragma: no cover |
| pass |
| api.step( |
| "make install", |
| ["make", "install", f"DESTDIR={install_dir}"], |
| ) |
| |
| if props.dry_run: |
| api.cas_util.upload(install_dir, output_property="isolated") |
| else: |
| api.cipd_util.upload_package( |
| f"fuchsia/third_party/jq/{api.cipd_util.platform_name}", |
| install_dir, |
| search_tag={"git_revision": revision}, |
| ) |
| |
| |
| def sysroot(api, cipd_dir): |
| if api.platform.is_linux: |
| return cipd_dir / LINUX_SYSROOT_PKG[-1] |
| elif api.platform.is_mac: |
| # TODO(fxbug.dev/3043): Eventually use our own hermetic sysroot as for Linux. |
| return api.macos_sdk.sysroot |
| raise api.step.StepFailure("unsupported platform") # pragma: no cover |
| |
| |
| def GenTests(api): |
| yield api.test("mac") + api.platform.name("mac") |
| yield ( |
| api.test("linux_dry_run") |
| + api.properties(dry_run=True) |
| + api.platform.name("linux") |
| ) |