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 b16636e
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 2 deletions.
4 changes: 2 additions & 2 deletions rules/legacy_xcodeproj.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -1066,7 +1066,7 @@ def _xcodeproj_impl(ctx):
"BAZEL_WORKSPACE_ROOT": "$SRCROOT/%s" % script_dot_dots,
"BAZEL_STUBS_DIR": "$PROJECT_FILE_PATH/bazelstubs",
"BAZEL_INSTALLERS_DIR": "$PROJECT_FILE_PATH/bazelinstallers",
"BAZEL_INSTALLER": "$BAZEL_INSTALLERS_DIR/%s" % ctx.executable.installer.basename,
"BAZEL_INSTALLER": str(ctx.attr.installer.label),
"BAZEL_EXECUTION_LOG_ENABLED": ctx.attr.bazel_execution_log_enabled,
"BAZEL_PROFILE_ENABLED": ctx.attr.bazel_profile_enabled,
"BAZEL_CONFIGS": ctx.attr.configs.keys(),
Expand Down
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.
# 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 b16636e

Please sign in to comment.