Simplify MacOS.locate
Signed-off-by: Jack Nagel <jacknagel@gmail.com>
This commit is contained in:
parent
f471c3e99f
commit
8a9a1d5b00
@ -20,41 +20,23 @@ module MacOS extend self
|
|||||||
# Don't call tools (cc, make, strip, etc.) directly!
|
# Don't call tools (cc, make, strip, etc.) directly!
|
||||||
# Give the name of the binary you look for as a string to this method
|
# Give the name of the binary you look for as a string to this method
|
||||||
# in order to get the full path back as a Pathname.
|
# in order to get the full path back as a Pathname.
|
||||||
tool = tool.to_s
|
@locate ||= {}
|
||||||
|
@locate[tool.to_s] ||= if File.executable? "/usr/bin/#{tool}"
|
||||||
@locate_cache ||= {}
|
Pathname.new "/usr/bin/#{tool}"
|
||||||
return @locate_cache[tool] if @locate_cache.has_key? tool
|
|
||||||
|
|
||||||
if File.executable? "/usr/bin/#{tool}"
|
|
||||||
path = Pathname.new "/usr/bin/#{tool}"
|
|
||||||
else
|
else
|
||||||
# Xcrun was provided first with Xcode 4.3 and allows us to proxy
|
# If the tool isn't in /usr/bin, then we first try to use xcrun to find
|
||||||
# tool usage thus avoiding various bugs.
|
# it. If it's not there, or xcode-select is misconfigured, we have to
|
||||||
p = `/usr/bin/xcrun -find #{tool} 2>/dev/null`.chomp unless Xcode.bad_xcode_select_path?
|
# look in dev_tools_path, and finally in xctoolchain_path, because the
|
||||||
if !p.nil? and !p.empty? and File.executable? p
|
# tools were split over two locations beginning with Xcode 4.3+.
|
||||||
path = Pathname.new p
|
xcrun_path = unless Xcode.bad_xcode_select_path?
|
||||||
else
|
`/usr/bin/xcrun -find #{tool} 2>/dev/null`.chomp
|
||||||
# This is for the use-case where xcode-select is not set up correctly
|
|
||||||
# with Xcode 4.3+. The tools in Xcode 4.3+ are split over two locations,
|
|
||||||
# usually xcrun would figure that out for us, but it won't work if
|
|
||||||
# xcode-select is not configured properly.
|
|
||||||
p = "#{dev_tools_path}/#{tool}"
|
|
||||||
if File.executable? p
|
|
||||||
path = Pathname.new p
|
|
||||||
else
|
|
||||||
# Otherwise lets look in the second location.
|
|
||||||
p = "#{xctoolchain_path}/usr/bin/#{tool}"
|
|
||||||
if File.executable? p
|
|
||||||
path = Pathname.new p
|
|
||||||
else
|
|
||||||
# We digged so deep but all is lost now.
|
|
||||||
path = nil
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
paths = %W[#{xcrun_path}
|
||||||
|
#{dev_tools_path}/#{tool}
|
||||||
|
#{xctoolchain_path}/usr/bin/#{tool}]
|
||||||
|
paths.map { |p| Pathname.new(p) }.find { |p| p.executable? }
|
||||||
end
|
end
|
||||||
@locate_cache[tool] = path
|
|
||||||
return path
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def dev_tools_path
|
def dev_tools_path
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user