| # 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 |
| |
| PYTHON_VERSION_COMPATIBILITY = "PY3" |
| |
| DEPS = [ |
| "fuchsia/cas_util", |
| "fuchsia/cipd_util", |
| "fuchsia/git", |
| "fuchsia/status_check", |
| "recipe_engine/cipd", |
| "recipe_engine/context", |
| "recipe_engine/path", |
| "recipe_engine/platform", |
| "recipe_engine/properties", |
| "recipe_engine/raw_io", |
| "recipe_engine/step", |
| ] |
| |
| PROPERTIES = InputProperties |
| |
| JQ_REPO_URL = "https://fuchsia.googlesource.com/third_party/github.com/stedolan/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", |
| "git_revision:c912d089c3d46d8982fdef76a50514cca79b6132", |
| "sysroot", |
| ) |
| |
| |
| def RunSteps(api, props): |
| cipd_dir = api.path["start_dir"].join("cipd") |
| src_dir = api.path["start_dir"].join("jq") |
| 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) |
| |
| revision = api.git.checkout_from_build_input( |
| repo=JQ_REPO_URL, path=src_dir, recursive=True, submodules=True |
| ) |
| |
| install_dir = api.path["start_dir"].join("install") |
| with api.context( |
| cwd=src_dir, |
| env_prefixes={"PATH": [cipd_dir.join("bin")]}, |
| # TODO(fxbug.dev/58251): remove environment variable when possible. |
| env={"M4": cipd_dir.join("bin", "m4")}, |
| ): |
| api.step( |
| "autoreconf", |
| ["autoreconf", "--verbose", "--install", "--force"], |
| ) |
| |
| configure_flags = ["--sysroot=%s" % 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", |
| "--with-oniguruma=builtin", |
| "--prefix=", |
| "--disable-dependency-tracking", |
| "--disable-shared", |
| "--enable-all-static", |
| ] |
| + sorted(["%s=%s" % (k, v) for k, v in configure_variables.items()]), |
| ) |
| |
| api.step("make", ["make", "-j%d" % api.platform.cpu_count]) |
| api.step("make check", ["make", "check"]) |
| api.step( |
| "make install", |
| ["make", "install", "DESTDIR=%s" % install_dir], |
| ) |
| |
| if props.dry_run: |
| api.cas_util.upload(install_dir, output_property="isolated") |
| else: |
| api.cipd_util.upload_package( |
| "fuchsia/third_party/jq/%s" % api.cipd_util.platform_name, |
| install_dir, |
| [install_dir], |
| {"git_revision": revision}, |
| ) |
| |
| |
| def sysroot(api, cipd_dir): |
| if api.platform.is_linux: |
| return cipd_dir.join(LINUX_SYSROOT_PKG[-1]) |
| elif api.platform.is_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() |
| raise api.step.StepFailure("unsupported platform") # pragma: no cover |
| |
| |
| def GenTests(api): |
| yield api.status_check.test("mac") + api.platform.name("mac") |
| yield ( |
| api.status_check.test("linux_dry_run") |
| + api.properties(dry_run=True) |
| + api.platform.name("linux") |
| ) |