Skip to content
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

os/mac/xcode: add fast path for Xcode version detection #16388

Merged
merged 1 commit into from
Dec 23, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 26 additions & 16 deletions Library/Homebrew/os/mac/xcode.rb
Original file line number Diff line number Diff line change
Expand Up @@ -192,22 +192,32 @@
# if return is used in the middle, which we do many times in here.
return if !MacOS::Xcode.installed? && !MacOS::CLT.installed?

%W[
#{prefix}/usr/bin/xcodebuild
#{which("xcodebuild")}
].uniq.each do |xcodebuild_path|
next unless File.executable? xcodebuild_path

xcodebuild_output = Utils.popen_read(xcodebuild_path, "-version")
next unless $CHILD_STATUS.success?

xcode_version = xcodebuild_output[/Xcode (\d+(\.\d+)*)/, 1]
return xcode_version if xcode_version

# Xcode 2.x's xcodebuild has a different version string
case xcodebuild_output[/DevToolsCore-(\d+\.\d)/, 1]
when "798.0" then return "2.5"
when "515.0" then return "2.0"
if MacOS::Xcode.installed?
# Fast path that will probably almost always work unless `xcode-select -p` is misconfigured
version_plist = T.must(prefix).parent/"version.plist"
if version_plist.file?
data = Plist.parse_xml(version_plist, marshal: false)
version = data["CFBundleShortVersionString"] if data
return version if version
end

%W[
#{prefix}/usr/bin/xcodebuild

Check warning on line 205 in Library/Homebrew/os/mac/xcode.rb

View check run for this annotation

Codecov / codecov/patch

Library/Homebrew/os/mac/xcode.rb#L205

Added line #L205 was not covered by tests
#{which("xcodebuild")}
].uniq.each do |xcodebuild_path|
next unless File.executable? xcodebuild_path

xcodebuild_output = Utils.popen_read(xcodebuild_path, "-version")

Check warning on line 210 in Library/Homebrew/os/mac/xcode.rb

View check run for this annotation

Codecov / codecov/patch

Library/Homebrew/os/mac/xcode.rb#L210

Added line #L210 was not covered by tests
next unless $CHILD_STATUS.success?

xcode_version = xcodebuild_output[/Xcode (\d+(\.\d+)*)/, 1]

Check warning on line 213 in Library/Homebrew/os/mac/xcode.rb

View check run for this annotation

Codecov / codecov/patch

Library/Homebrew/os/mac/xcode.rb#L213

Added line #L213 was not covered by tests
return xcode_version if xcode_version

# Xcode 2.x's xcodebuild has a different version string
case xcodebuild_output[/DevToolsCore-(\d+\.\d)/, 1]
when "798.0" then return "2.5"
when "515.0" then return "2.0"
end
end
end

Expand Down