-
-
Notifications
You must be signed in to change notification settings - Fork 9.9k
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
cask/quarantine: avoid xcrun when executing Swift #16796
Conversation
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.
This makes sense. Thanks for tracking this down. Do you have any idea why they added this unusual behavior to xcurn
?
def self.swift | ||
@swift ||= DevelopmentTools.locate("swift") | ||
@swift ||= begin | ||
# /usr/bin/swift (which runs via xcrun) adds `/usr/local/include` to the top of the include path, | ||
# which allows really broken local setups to break our Swift usage here. Using the underlying | ||
# Swift executable directly however (returned by `xcrun -find`) avoids this CPATH mess. | ||
xcrun_swift = ::Utils.popen_read("/usr/bin/xcrun", "-find", "swift", err: :close).chomp | ||
if $CHILD_STATUS.success? && File.executable?(xcrun_swift) | ||
xcrun_swift | ||
else | ||
DevelopmentTools.locate("swift") | ||
end | ||
end | ||
end |
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.
It looks the old method returns a Pathname here but all the usages seem to just get coerced to strings so it's probably fine. On that note, it might be good to add types to this method.
Before:
brew(main):001:0> Cask::Quarantine.send(:swift)
=> #<Pathname:/usr/bin/swift>
After:
brew(main):001:0> Cask::Quarantine.send(:swift)
=> "/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift"
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.
Yeah maybe will keep it as a string because it's very slightly cheaper and is a private_class_method
rather than API.
My guess would be the transition from That's just a theory though. In any case, it hasn't scaled well with modules being introduced and generally with Swift. It makes some sense when working with Clang etc directly, but does raise a point that maybe this is something we want to avoid in the superenv, particularly on /opt/homebrew installs. |
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.
Makes sense, thanks again @Bo98!
Fixes things breaking when people put broken stuff into
/usr/local/include
:We were using
/usr/bin/swift
which is the same as/usr/bin/xcrun swift
. This has a weird documented behaviour:We can avoid this by using
xcrun -find
to find the underlying Swift executable and invoking that directly.