Use Utils.popen_read to avoid shelling out in a few places

This commit is contained in:
Jack Nagel 2014-12-16 15:27:36 -05:00
parent 8c0928ccca
commit 9a2f2aee7e
3 changed files with 6 additions and 12 deletions

View File

@ -436,17 +436,11 @@ class SubversionDownloadStrategy < VCSDownloadStrategy
private private
def repo_url def repo_url
`svn info '#{cached_location}' 2>/dev/null`.strip[/^URL: (.+)$/, 1] Utils.popen_read("svn", "info", cached_location.to_s).strip[/^URL: (.+)$/, 1]
end
def shell_quote str
# Oh god escaping shell args.
# See http://notetoself.vrensk.com/2008/08/escaping-single-quotes-in-ruby-harder-than-expected/
str.gsub(/\\|'/) { |c| "\\#{c}" }
end end
def get_externals def get_externals
`svn propget svn:externals '#{shell_quote(@url)}'`.chomp.each_line do |line| Utils.popen_read("svn", "propget", "svn:externals", @url).chomp.each_line do |line|
name, url = line.split(/\s+/) name, url = line.split(/\s+/)
yield name, url yield name, url
end end

View File

@ -30,21 +30,21 @@ module OS
elsif File.executable?(path = "#{HOMEBREW_PREFIX}/bin/#{tool}") elsif File.executable?(path = "#{HOMEBREW_PREFIX}/bin/#{tool}")
Pathname.new path Pathname.new path
else else
path = `/usr/bin/xcrun -no-cache -find #{tool} 2>/dev/null`.chomp path = Utils.popen_read("/usr/bin/xcrun", "-no-cache", "-find", tool).chomp
Pathname.new(path) if File.executable?(path) Pathname.new(path) if File.executable?(path)
end end
end end
end end
def active_developer_dir def active_developer_dir
@active_developer_dir ||= `xcode-select -print-path 2>/dev/null`.strip @active_developer_dir ||= Utils.popen_read("/usr/bin/xcode-select", "-print-path").strip
end end
def sdk_path(v = version) def sdk_path(v = version)
(@sdk_path ||= {}).fetch(v.to_s) do |key| (@sdk_path ||= {}).fetch(v.to_s) do |key|
opts = [] opts = []
# First query Xcode itself # First query Xcode itself
opts << `#{locate('xcodebuild')} -version -sdk macosx#{v} Path 2>/dev/null`.chomp opts << Utils.popen_read(locate("xcodebuild"), "-version", "-sdk", "macosx#{v}", "Path").chomp
# Xcode.prefix is pretty smart, so lets look inside to find the sdk # Xcode.prefix is pretty smart, so lets look inside to find the sdk
opts << "#{Xcode.prefix}/Platforms/MacOSX.platform/Developer/SDKs/MacOSX#{v}.sdk" opts << "#{Xcode.prefix}/Platforms/MacOSX.platform/Developer/SDKs/MacOSX#{v}.sdk"
# Xcode < 4.3 style # Xcode < 4.3 style

View File

@ -77,7 +77,7 @@ module OS
%W[#{prefix}/usr/bin/xcodebuild #{which("xcodebuild")}].uniq.each do |path| %W[#{prefix}/usr/bin/xcodebuild #{which("xcodebuild")}].uniq.each do |path|
if File.file? path if File.file? path
`#{path} -version 2>/dev/null` =~ /Xcode (\d(\.\d)*)/ Utils.popen_read(path, "-version") =~ /Xcode (\d(\.\d)*)/
return $1 if $1 return $1 if $1
end end
end end