os/mac: prefer newest Xcode when searching using mdfind
We're currently returning the first match for `com.apple.dt.Xcode`, which could be any version if a user has multiple installed. Instead, let's try to find the newest if all our results have an `Info.plist` that we can interrogate for the version. Maybe resolves #18736?
This commit is contained in:
parent
a8a4c07361
commit
09fc83667c
@ -195,10 +195,15 @@ module OS
|
||||
|
||||
sig { params(ids: String).returns(T.nilable(Pathname)) }
|
||||
def self.app_with_bundle_id(*ids)
|
||||
path = mdfind(*ids)
|
||||
.reject { |p| p.include?("/Backups.backupdb/") }
|
||||
.first
|
||||
Pathname.new(path) if path.present?
|
||||
require "bundle_version"
|
||||
|
||||
paths = mdfind(*ids).filter_map do |bundle_path|
|
||||
Pathname.new(bundle_path) if bundle_path.exclude?("/Backups.backupdb/")
|
||||
end
|
||||
return paths.first unless paths.all? { |bp| (bp/"Contents/Info.plist").exist? }
|
||||
|
||||
# Prefer newest one, if we can find it.
|
||||
paths.max_by { |bundle_path| Homebrew::BundleVersion.from_info_plist(bundle_path/"Contents/Info.plist") }
|
||||
end
|
||||
|
||||
sig { params(ids: String).returns(T::Array[String]) }
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user