Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ bazel_dep(
repo_name = "build_bazel_rules_apple",
)
bazel_dep(name = "rules_python", version = "0.27.1")
bazel_dep(
name = "rsync",
version = "3.4.1",
)

internal = use_extension("//xcodeproj:extensions.bzl", "internal")
use_repo(internal, "rules_xcodeproj_generated")
Expand Down
22 changes: 22 additions & 0 deletions xcodeproj/internal/bazel_integration_files/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ _BASE_FILES = [
filegroup(
name = "bazel_integration_files",
srcs = _BASE_FILES + [
":renamed_rsync",
":renamed_swiftc_stub",
":rsync_excludes",
] + glob(
Expand Down Expand Up @@ -125,6 +126,27 @@ fi
],
)

genrule(
name = "renamed_rsync",
srcs = ["@rsync"],
outs = ["rsync"],
# Make `rsync` have the right name
cmd = """\
readonly output="$@"
if [[ $$(stat -f '%d' "$<") == $$(stat -f '%d' "$${output%/*}") ]]; then
cp -c "$<" "$@"
else
cp "$<" "$@"
fi
""",
message = "Renaming rsync",
tags = [
"manual",
"no-sandbox",
],
visibility = ["//visibility:public"],
)

# Release

filegroup(
Expand Down
9 changes: 3 additions & 6 deletions xcodeproj/internal/bazel_integration_files/copy_dsyms.sh
Original file line number Diff line number Diff line change
Expand Up @@ -46,16 +46,13 @@ function patch_dsym() {
EOF
}

readonly rsync="$BAZEL_INTEGRATION_DIR/rsync"

if [[ -n "${BAZEL_OUTPUTS_DSYM:-}" ]]; then
cd "${BAZEL_OUT%/*}"

# NOTE: use `which` to find the path to `rsync`.
# In macOS 15.4, the system `rsync` is using `openrsync` which contains some permission issues.
# This allows users to workaround the issue by overriding the system `rsync` with a working version.
# Remove this once we no longer support macOS versions with broken `rsync`.
# shellcheck disable=SC2046
PATH="/opt/homebrew/bin:/usr/local/bin:$PATH" \
rsync \
"$rsync" \
--copy-links \
--recursive \
--times \
Expand Down
9 changes: 3 additions & 6 deletions xcodeproj/internal/bazel_integration_files/copy_outputs.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ readonly test_frameworks=(
"XCUnit.framework"
)

readonly rsync="$BAZEL_INTEGRATION_DIR/rsync"

if [[ "$ACTION" != indexbuild ]]; then
# Copy product
if [[ -n ${BAZEL_OUTPUTS_PRODUCT:-} ]]; then
Expand All @@ -32,12 +34,7 @@ if [[ "$ACTION" != indexbuild ]]; then
ln -sfh "$PWD/$BAZEL_OUTPUTS_PRODUCT_BASENAME" "$TARGET_BUILD_DIR/$PRODUCT_NAME"
else
# Product is a bundle
# NOTE: use `which` to find the path to `rsync`.
# In macOS 15.4, the system `rsync` is using `openrsync` which contains some permission issues.
# This allows users to workaround the issue by overriding the system `rsync` with a working version.
# Remove this once we no longer support macOS versions with broken `rsync`.
PATH="/opt/homebrew/bin:/usr/local/bin:$PATH" \
rsync \
"$rsync" \
--copy-links \
--recursive \
--times \
Expand Down
14 changes: 5 additions & 9 deletions xcodeproj/internal/templates/installer.sh
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ fi
readonly src_generated_xcfilelist="$PWD/%generated_xcfilelist%"
readonly src_generated_directories_filelist="$PWD/%generated_directories_filelist%"
readonly src_project_pbxproj="$PWD/%project_pbxproj%"
readonly src_rsync="$PWD/%rsync%"
readonly src_xcschememanagement="$PWD/%xcschememanagement%"
readonly src_xcschemes="$PWD/%xcschemes%/"
readonly src_xcworkspacedata="$PWD/%contents_xcworkspacedata%"
Expand All @@ -82,13 +83,7 @@ readonly dest_xcschemes="$dest/xcshareddata/xcschemes"

mkdir -p "$dest_xcschemes"

# NOTE: use `which` to find the path to `rsync`.
# In macOS 15.4, the system `rsync` is using `openrsync` which contains some permission issues.
# This allows users to workaround the issue by overriding the system `rsync` with a working version.
# Remove this once we no longer support macOS versions with broken `rsync`.
# shellcheck disable=SC2046
PATH="/opt/homebrew/bin:/usr/local/bin:$PATH" \
rsync \
"$src_rsync" \
--archive \
--perms \
--chmod=u+w,F-x \
Expand Down Expand Up @@ -124,6 +119,7 @@ mkdir -p "$dest/rules_xcodeproj/bazel"
rm -rf "$dest/rules_xcodeproj/bazel"/*
$cp_cmd "${bazel_integration_files[@]}" "$dest/rules_xcodeproj/bazel"
$cp_cmd "$xcodeproj_bazelrc" "$dest/rules_xcodeproj/bazel/xcodeproj.bazelrc"
chmod u+rx "$dest/rules_xcodeproj/bazel/rsync"

if [[ -s "${extra_flags_bazelrc:-}" ]]; then
$cp_cmd "$extra_flags_bazelrc" "$dest/rules_xcodeproj/bazel/xcodeproj_extra_flags.bazelrc"
Expand All @@ -141,10 +137,10 @@ chmod u+w "$dest_generated_xcfilelist"

# - Keep only scripts as runnable
find "$dest/rules_xcodeproj/bazel" \
-type f \( -name "*.sh" -o -name "*.py" -o -name "ld" -o -name "libtool" \) \
-type f \( -name "*.sh" -o -name "*.py" -o -name "ld" -o -name "libtool" -o -name "rsync" \) \
-print0 | xargs -0 chmod u+x
find "$dest/rules_xcodeproj/bazel" \
-type f ! \( -name "swiftc" -o -name "ld" -o -name "libtool" -o -name "import_indexstores" -o -name "*.sh" -o -name "*.py" \) \
-type f ! \( -name "swiftc" -o -name "ld" -o -name "libtool" -o -name "import_indexstores" -o -name "rsync" -o -name "*.sh" -o -name "*.py" \) \
-print0 | xargs -0 chmod -x

# Copy over `project.xcworkspace/contents.xcworkspacedata` if needed
Expand Down
8 changes: 8 additions & 0 deletions xcodeproj/internal/xcodeproj_rule.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,7 @@ def _write_installer(
install_path,
name,
project_pbxproj,
rsync,
template,
xcschememanagement,
xcschemes):
Expand All @@ -303,6 +304,7 @@ def _write_installer(
"%generated_xcfilelist%": generated_xcfilelist.short_path,
"%output_path%": install_path,
"%project_pbxproj%": project_pbxproj.short_path,
"%rsync%": rsync.short_path,
"%xcschememanagement%": xcschememanagement.short_path,
"%xcschemes%": xcschemes.short_path,
},
Expand Down Expand Up @@ -772,6 +774,7 @@ Are you using an `alias`? `xcodeproj.focused_targets` and \
install_path = install_path,
name = name,
project_pbxproj = project_pbxproj,
rsync = ctx.file._rsync,
template = ctx.file._installer_template,
xcschememanagement = xcschememanagement,
xcschemes = xcschemes,
Expand Down Expand Up @@ -930,6 +933,11 @@ A dict mapping of Labels for StoreKit Testing configuration files to their File
),
executable = True,
),
"_rsync": attr.label(
allow_single_file = True,
cfg = "exec",
default = Label("//xcodeproj/internal/bazel_integration_files:renamed_rsync"),
),
"_selected_model_versions_generator": attr.label(
cfg = "exec",
default = Label(
Expand Down