Skip to content

Commit

Permalink
[macOS] Fix COPY step on macOS 15 Sequoia (#884)
Browse files Browse the repository at this point in the history
macOS build fails on Sequoia beta 2 and later (verified in public beta 3
as well) hosts during COPY step when copying files with the `restricted`
extended attribute set.

The problem appears to be due to the `-a` (archive) option, which is an
alias for `-RpP`. Of these, the `-p` option appears to be the source of
the problem. This flag attempts to preserve file metadata including
Access Control Lists and Extended Attributes. However, the `restricted`
extended attribute is not settable when System Integrity Protection
(SIP) is enabled, which it is by default.

This appears to be a change in the implementation of `cp` in macOS 15
Sequoia beta 2 and later. Previous versions would fail to copy the
attribute, but continue without failing. The current version appears to
fail if it cannot set any extended attribute.

Two alternatives to the previous `cp -af` step:
* Use `cp -Rf`. This succeeds but file metadata such as
  creation time, modification time, etc. are not preserved.
* Use `rsync -a`. rsync's -a flag also copies metadata but on a
  best-efforts basis and doesn't error out when it fails to set the
  restricted attribute.

Of the two, the latter more closely approximates the previous behaviour.

The `rm -rf` step can be replaced with `rsync`'s `--delete` option; with
the default `--delete-before` behaviour, this replicates the function of
the `rm -rf`.

Fixes: flutter/flutter#152978

## Pre-launch Checklist

- [X] I read the [Contributor Guide] and followed the process outlined
there for submitting PRs.
- [X] I read the [Tree Hygiene] wiki page, which explains my
responsibilities.
- [X] I read the [Flutter Style Guide] _recently_, and have followed its
advice.
- [X] I signed the [CLA].
- [X] I listed at least one issue that this PR fixes in the description
above.
- [X] I updated/added relevant documentation (doc comments with `///`).
- [X] I added new tests to check the change I am making, or this PR is
[test-exempt].
- [X] All existing and new tests are passing.

If you need help, consider asking for advice on the #hackers-new channel
on [Discord].

<!-- Links -->
[Contributor Guide]:
https://github.com/flutter/flutter/blob/master/docs/contributing/Tree-hygiene.md#overview
[Tree Hygiene]:
https://github.com/flutter/flutter/blob/master/docs/contributing/Tree-hygiene.md
[test-exempt]:
https://github.com/flutter/flutter/blob/master/docs/contributing/Tree-hygiene.md#tests
[Flutter Style Guide]:
https://github.com/flutter/flutter/blob/master/docs/contributing/Style-guide-for-Flutter-repo.md
[CLA]: https://cla.developers.google.com/
[flutter/tests]: https://github.com/flutter/tests
[breaking change policy]:
https://github.com/flutter/flutter/blob/master/docs/contributing/Tree-hygiene.md#handling-breaking-changes
[Discord]:
https://github.com/flutter/flutter/blob/master/docs/contributing/Chat.md
  • Loading branch information
cbracken authored Aug 7, 2024
1 parent 4f937af commit 6ef931b
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion build/toolchain/mac/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ template("mac_toolchain") {
}

tool("copy") {
command = "ln -f {{source}} {{output}} 2>/dev/null || (rm -rf {{output}} && cp -af {{source}} {{output}})"
command = "ln -f {{source}} {{output}} 2>/dev/null || (rsync -a --delete {{source}} {{output}})"
description = "COPY {{source}} {{output}}"
}

Expand Down

0 comments on commit 6ef931b

Please sign in to comment.