From 4dc8ac13cd4c9a88ae064cf9d3267718ee98ed6a Mon Sep 17 00:00:00 2001 From: Luis Padron Date: Tue, 22 Aug 2023 13:15:46 -0400 Subject: [PATCH] Update install.sh to support bzlmod repo mappings --- tools/xcodeproj_shims/BUILD.bazel | 1 + tools/xcodeproj_shims/install.sh | 30 ++++++++++++++++++++++++++++++ 2 files changed, 31 insertions(+) diff --git a/tools/xcodeproj_shims/BUILD.bazel b/tools/xcodeproj_shims/BUILD.bazel index 55d218d2a..beaae3194 100644 --- a/tools/xcodeproj_shims/BUILD.bazel +++ b/tools/xcodeproj_shims/BUILD.bazel @@ -37,6 +37,7 @@ sh_binary( srcs = ["install.sh"], data = [":installer_runfiles"], visibility = STUB_VISIBILITY, + deps = ["@bazel_tools//tools/bash/runfiles"], ) sh_binary( diff --git a/tools/xcodeproj_shims/install.sh b/tools/xcodeproj_shims/install.sh index f03e4a03f..a140d1ba2 100755 --- a/tools/xcodeproj_shims/install.sh +++ b/tools/xcodeproj_shims/install.sh @@ -5,6 +5,36 @@ set -eux +# --- begin runfiles.bash initialization v3 --- +# Copy-pasted from the Bazel Bash runfiles library v3. +set -uo pipefail; set +e; f=bazel_tools/tools/bash/runfiles/runfiles.bash +source "${RUNFILES_DIR:-/dev/null}/$f" 2>/dev/null || \ +source "$(grep -sm1 "^$f " "${RUNFILES_MANIFEST_FILE:-/dev/null}" | cut -f2- -d' ')" 2>/dev/null || \ +source "$0.runfiles/$f" 2>/dev/null || \ +source "$(grep -sm1 "^$f " "$0.runfiles_manifest" | cut -f2- -d' ')" 2>/dev/null || \ +source "$(grep -sm1 "^$f " "$0.exe.runfiles_manifest" | cut -f2- -d' ')" 2>/dev/null || \ +{ echo>&2 "ERROR: cannot find $f"; exit 1; }; f=; set -e +# --- end runfiles.bash initialization v3 --- + +# Compute the proper BAZEL_BUILD_TARGET_WORKSPACE when using bzlmod. +# This is computed via the runfiles API using `runfiles_current_repository`. +# The repo_mappings file looks like: +# +# current_canonical,target_local,target_canonical +# ,bazel_build_rules_ios,_main +# ... +# We are interested in the target_local name from the target_canonical name. +# For example, if the target_canonical is _main, then the target_local is bazel_build_rules_ios. +if [[ -f "$RUNFILES_REPO_MAPPING" ]]; then + while IFS= read -r line; do + IFS=',' read -ra repo_mapping_entry_parts <<<"$line" + if [[ "${repo_mapping_entry_parts[2]}" == "${BAZEL_BUILD_TARGET_WORKSPACE}" ]]; then + BAZEL_BUILD_TARGET_WORKSPACE="${repo_mapping_entry_parts[1]}" + break + fi + done < "$RUNFILES_REPO_MAPPING" +fi + # Delete all logfiles that are older than 7 days find "${BAZEL_DIAGNOSTICS_DIR}" -type f -atime +7d -delete