Skip to content

Commit

Permalink
Update install.sh to support bzlmod repo mappings
Browse files Browse the repository at this point in the history
  • Loading branch information
luispadron committed Aug 22, 2023
1 parent fc58aea commit 4dc8ac1
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
1 change: 1 addition & 0 deletions tools/xcodeproj_shims/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ sh_binary(
srcs = ["install.sh"],
data = [":installer_runfiles"],
visibility = STUB_VISIBILITY,
deps = ["@bazel_tools//tools/bash/runfiles"],
)

sh_binary(
Expand Down
30 changes: 30 additions & 0 deletions tools/xcodeproj_shims/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit 4dc8ac1

Please sign in to comment.