From 2d929b8a9f3b0e482bcd672abc65f1729584df5b Mon Sep 17 00:00:00 2001 From: Bo Anderson Date: Sat, 2 Mar 2024 19:31:38 +0000 Subject: [PATCH] cask/quarantine: avoid xcrun when executing Swift --- Library/Homebrew/cask/quarantine.rb | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/Library/Homebrew/cask/quarantine.rb b/Library/Homebrew/cask/quarantine.rb index a93525bd74..2d5fd25892 100644 --- a/Library/Homebrew/cask/quarantine.rb +++ b/Library/Homebrew/cask/quarantine.rb @@ -18,7 +18,17 @@ module Cask COPY_XATTRS_SCRIPT = (HOMEBREW_LIBRARY_PATH/"cask/utils/copy-xattrs.swift").freeze 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 private_class_method :swift