|
| 1 | +#!/bin/bash |
| 2 | + |
| 3 | +set -euo pipefail |
| 4 | + |
| 5 | +readonly tool_location="${BASH_SOURCE[0]}" |
| 6 | +readonly workspace_dir="${tool_location%/*/*}" |
| 7 | +readonly root_dir="${workspace_dir%/*/*}" |
| 8 | +readonly archive_output_base="$workspace_dir/bazel-output-base/release_archive" |
| 9 | +readonly override_bazelrc="$archive_output_base/override.bazelrc" |
| 10 | + |
| 11 | +# Don't update the release archive if doing a build inside of Xcode, or if we |
| 12 | +# are in the inner-bazel invocation |
| 13 | +if [[ -z "${BUILD_WORKSPACE_DIRECTORY:-}" ]]; then |
| 14 | + # Update release archive |
| 15 | + |
| 16 | + echo "Building expanded release.tar.gz" >&2 |
| 17 | + pushd "$root_dir" > /dev/null |
| 18 | + |
| 19 | + # Ensure that we use bazelisk with `.bazelversion`, not whatever is being used |
| 20 | + # in the currenct command |
| 21 | + ppid=$(ps -o ppid= $$) |
| 22 | + bazelisk=$(ps -ewwo comm= "${ppid// /}") |
| 23 | + global_bazel=$(env PATH=/opt/homebrew/bin:/usr/local/bin /usr/bin/which "$bazelisk") |
| 24 | + readonly root_bazel=( |
| 25 | + env |
| 26 | + BAZEL_REAL= |
| 27 | + BAZELISK_SKIP_WRAPPER= |
| 28 | + USE_BAZEL_VERSION= |
| 29 | + PATH=/bin:/usr/bin |
| 30 | + "$global_bazel" |
| 31 | + ) |
| 32 | + |
| 33 | + "${root_bazel[@]}" \ |
| 34 | + "--output_base=$archive_output_base" \ |
| 35 | + build \ |
| 36 | + //distribution:opt_expanded_release_pkg |
| 37 | + |
| 38 | + if [[ $(uname -m) == "arm64" ]]; then |
| 39 | + repository_override="$archive_output_base/execroot/_main/bazel-out/darwin_arm64-opt/bin/distribution/expanded_release" |
| 40 | + else |
| 41 | + repository_override="$archive_output_base/execroot/_main/bazel-out/darwin-opt/bin/distribution/expanded_release" |
| 42 | + fi |
| 43 | + cat > "$override_bazelrc" <<EOF |
| 44 | +common --override_repository=rules_xcodeproj=$repository_override |
| 45 | +common --override_module=rules_xcodeproj=$repository_override |
| 46 | +EOF |
| 47 | + |
| 48 | + popd > /dev/null |
| 49 | + |
| 50 | + # Execute command |
| 51 | + |
| 52 | + echo |
| 53 | + echo "Executing bazel command" >&2 |
| 54 | +fi |
| 55 | + |
| 56 | + |
| 57 | +bazel_version=$("$BAZEL_REAL" info release | /usr/bin/cut -d ' ' -f 2 | /usr/bin/cut -d '.' -f 1) |
| 58 | +if [[ "$bazel_version" == "version" ]]; then |
| 59 | + bazel_version=7 |
| 60 | +fi |
| 61 | + |
| 62 | +flags=("--noworkspace_rc") |
| 63 | + |
| 64 | +readonly root_version_bazelrc="$root_dir/bazel_$bazel_version.bazelrc" |
| 65 | +if [[ -s "$root_version_bazelrc" ]]; then |
| 66 | + flags+=("--bazelrc=$root_version_bazelrc") |
| 67 | +fi |
| 68 | + |
| 69 | +readonly workspace_version_bazelrc="$workspace_dir/bazel_$bazel_version.bazelrc" |
| 70 | +if [[ -s "$workspace_version_bazelrc" ]]; then |
| 71 | + flags+=("--bazelrc=$workspace_version_bazelrc") |
| 72 | +fi |
| 73 | + |
| 74 | +readonly workspace_bazelrc="$workspace_dir/.bazelrc" |
| 75 | +if [[ -s "$workspace_bazelrc" ]]; then |
| 76 | + flags+=("--bazelrc=$workspace_bazelrc") |
| 77 | +fi |
| 78 | + |
| 79 | +flags+=("--bazelrc=$override_bazelrc") |
| 80 | + |
| 81 | +exec "$BAZEL_REAL" "${flags[@]}" "$@" |
0 commit comments