diff --git a/MODULE.bazel b/MODULE.bazel index b7fae4a72..7b8a5fd93 100644 --- a/MODULE.bazel +++ b/MODULE.bazel @@ -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") diff --git a/xcodeproj/internal/bazel_integration_files/BUILD b/xcodeproj/internal/bazel_integration_files/BUILD index 690594f74..7410d1384 100644 --- a/xcodeproj/internal/bazel_integration_files/BUILD +++ b/xcodeproj/internal/bazel_integration_files/BUILD @@ -9,6 +9,7 @@ _BASE_FILES = [ filegroup( name = "bazel_integration_files", srcs = _BASE_FILES + [ + ":renamed_rsync", ":renamed_swiftc_stub", ":rsync_excludes", ] + glob( @@ -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( diff --git a/xcodeproj/internal/bazel_integration_files/copy_dsyms.sh b/xcodeproj/internal/bazel_integration_files/copy_dsyms.sh index e03e52103..95a74571c 100644 --- a/xcodeproj/internal/bazel_integration_files/copy_dsyms.sh +++ b/xcodeproj/internal/bazel_integration_files/copy_dsyms.sh @@ -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 \ diff --git a/xcodeproj/internal/bazel_integration_files/copy_outputs.sh b/xcodeproj/internal/bazel_integration_files/copy_outputs.sh index 07018742e..6c1ce5c72 100755 --- a/xcodeproj/internal/bazel_integration_files/copy_outputs.sh +++ b/xcodeproj/internal/bazel_integration_files/copy_outputs.sh @@ -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 @@ -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 \ diff --git a/xcodeproj/internal/templates/installer.sh b/xcodeproj/internal/templates/installer.sh index ae7f3cced..c00121058 100644 --- a/xcodeproj/internal/templates/installer.sh +++ b/xcodeproj/internal/templates/installer.sh @@ -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%" @@ -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 \ @@ -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" @@ -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 diff --git a/xcodeproj/internal/xcodeproj_rule.bzl b/xcodeproj/internal/xcodeproj_rule.bzl index 2b2591a35..79e11ec43 100644 --- a/xcodeproj/internal/xcodeproj_rule.bzl +++ b/xcodeproj/internal/xcodeproj_rule.bzl @@ -280,6 +280,7 @@ def _write_installer( install_path, name, project_pbxproj, + rsync, template, xcschememanagement, xcschemes): @@ -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, }, @@ -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, @@ -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(