From 527a41d730119ba32cf85bd99da24cedd0be5d68 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 --- rules/legacy_xcodeproj.bzl | 2 +- tools/xcodeproj_shims/BUILD.bazel | 1 + tools/xcodeproj_shims/install.sh | 30 ++++++++++++++++++++++++++++++ 3 files changed, 32 insertions(+), 1 deletion(-) diff --git a/rules/legacy_xcodeproj.bzl b/rules/legacy_xcodeproj.bzl index 4d99c0a07..aa80837ee 100644 --- a/rules/legacy_xcodeproj.bzl +++ b/rules/legacy_xcodeproj.bzl @@ -737,7 +737,7 @@ export BAZEL_BUILD_EVENT_TEXT_FILENAME="$BAZEL_DIAGNOSTICS_DIR/build-event-$DATE export BAZEL_BUILD_EXECUTION_LOG_FILENAME="$BAZEL_DIAGNOSTICS_DIR/build-execution-log-$DATE_SUFFIX.log" export BAZEL_PROFILE_FILENAME="$BAZEL_DIAGNOSTICS_DIR/build-profile-$DATE_SUFFIX.log" env -u RUBYOPT -u RUBY_HOME -u GEM_HOME $BAZEL_BUILD_EXEC $BAZEL_BUILD_TARGET_LABEL -$BAZEL_INSTALLER +bazel run $BAZEL_INSTALLER """ # See https://github.com/yonaskolb/XcodeGen/blob/master/Docs/ProjectSpec.md#scheme 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..adb486a28 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. +# 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