-
Notifications
You must be signed in to change notification settings - Fork 24k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix compatibility issue with 'cp' command in shell script. #43080
Conversation
Hi @sebastiancarlos! Thank you for your pull request and welcome to our community. Action RequiredIn order to merge any pull request (code, docs, etc.), we require contributors to sign our Contributor License Agreement, and we don't seem to have one on file for you. ProcessIn order for us to review and merge your suggested changes, please sign at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need to sign the corporate CLA. Once the CLA is signed, our tooling will perform checks and validations. Afterwards, the pull request will be tagged with If you have received this in error or have any questions, please contact us at cla@meta.com. Thanks! |
This change addresses a compatibility issue arising from the use of the macOS-specific '-X' flag in the 'cp' command withing a shell script called during the 'npm run ios' command. The '-X' flag prevents the copying of Extended Attributes and resource forks, which indeed prevents possible issues on macOS. However the flag is not supported by GNU's 'cp', commonly installed via homebrew on macOS systems, and usually added to the user's PATH. This fix basically does a feature test to figure out if the '-X' flag is available, and only uses it is the test is possitive. The intended behavior of not copying Extended Attributes and resources forks is still preserved in the script even if GNU's cp is in the path, as GNU's cp doesn't copy these by default. In short, the script will behave correctly regardless of the 'cp' version installed, but the script will now be more POSIX compatible. The fix helps prevent unnecessary debugging time as, in my experience, the source of this error is not always displayed in the output of 'npm run ios.
986bd00
to
0b96aec
Compare
Base commit: 8ff05b5 |
Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Meta Open Source project. Thanks! |
Is there a tmp fix for that? |
touch /tmp/test-cp-X-flag-one /tmp/test-cp-X-flag-two | ||
if cp -X /tmp/test-cp-X-flag-one /tmp/test-cp-X-flag-two > /dev/null 2>&1; then |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for this change! 🙂
Can we test by [[ "$OSTYPE" == "darwin"* ]]
instead? I appreciate this does direct feature detection, but would prefer if we avoided the file system side effects.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @huntie. I agree that a way of feature detection without file systems side effect is desireable.
Can we test by [[ "$OSTYPE" == "darwin"* ]] instead?
Unfortunately the OSTYPE
detection is not enough, as it identifies the OS but not the specific implementation of cp
that's being used. The problem can happen when the OS is Darwin and the cp
command in the PATH
does not support the -X
flag (e.g. GNU's cp
).
The use of temporary files test was chosen since macOS's native cp
does not provide a --help
or --version
command to use instead. It does print its usage on wrong input, but it also emits a non-zero exit code, which is a problem because script_phases.sh
has pipefail
set.
In short, making another test is a bit convoluted and I'm not sure if I have the bandwidth to come up with a working solution for that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think perhaps we can replace this with the EdenFS detection we use in Codegen's build.sh
— this way it's more clear why we are applying this flag against a bulk copy.
I'm happy to test this once imported.
# Detect if we are in an EdenFS checkout
if [ -x "$(command -v eden)" ] && eden info >/dev/null 2>&1; then
CP_FLAGS="-X"
else
CP_FLAGS=""
fi
Looks like this was done already: blakef@e70076a |
Summary:
This change addresses a compatibility issue arising from the use of the macOS-specific
-X
flag in thecp
command withing a shell script called during thenpm run ios
command.The
-X
flag prevents the copying of Extended Attributes and resource forks, which indeed prevents possible issues on macOS. However the flag is not supported by GNU'scp
, commonly installed via homebrew on macOS systems, and usually added to the user's PATH.This fix basically does a feature test to figure out if the
-X
flag is available, and only uses it is the test is positive.The intended behavior of not copying Extended Attributes and resources forks is still preserved in the script even if GNU's
cp
is in the path, as GNU'scp
doesn't copy these by default.In short, the script will behave correctly regardless of the
cp
version installed, but the script will now be more POSIX compatible.The fix helps prevent unnecessary debugging time as, in my experience, the source of this error is not always displayed in the output of
npm run ios
.As mentioned in:
Relevant Documentation
Changelog:
[IOS] [FIXED] - Fix compatibility issue with 'cp' command in shell script.
Test Plan: