Always find git and svn without trying hard
Two wrapper scripts that find git and svn using the ENV variables we support and then searching through the PATH and looking inside Xcode.app if necessary. Now just calling git or svn in Homebrew code will find and exec the right tool and we can stop fussing. Apologies to @adamv who is probably unimpressed that the cmds directory has non-commands in it now. If it's consolation these are temporary pending some more work on superenv whereby some more directories are created under the superenv root.
This commit is contained in:
parent
0ac3e83a7a
commit
672388d4f7
51
Library/Contributions/cmds/git
Executable file
51
Library/Contributions/cmds/git
Executable file
@ -0,0 +1,51 @@
|
||||
#!/usr/bin/ruby -W0
|
||||
# This script because we support $GIT, $HOMEBREW_SVN, etc. and Xcode-only
|
||||
# configurations. Order is careful to be what the user would want.
|
||||
|
||||
F = File.basename(__FILE__).freeze
|
||||
D = File.expand_path(File.dirname(__FILE__)).freeze
|
||||
|
||||
def exec *args
|
||||
# prevent fork-bombs
|
||||
arg0 = if args.size == 1
|
||||
args.first.split(' ')
|
||||
else
|
||||
args
|
||||
end.first
|
||||
return if arg0 =~ /^#{F}/i
|
||||
return if File.expand_path(arg0) == File.expand_path(__FILE__)
|
||||
|
||||
if args[1] == '-print-path' and File.executable? args[0]
|
||||
puts args[0]
|
||||
exit 0
|
||||
else
|
||||
Kernel.exec *args
|
||||
end
|
||||
end
|
||||
|
||||
case F.downcase
|
||||
when 'git' then %W{HOMEBREW_GIT GIT}
|
||||
when 'svn' then "HOMEBREW_SVN"
|
||||
else []
|
||||
end.each do |key|
|
||||
exec ENV[key], *ARGV if ENV[key] and File.executable? ENV[key]
|
||||
end
|
||||
|
||||
brew_version = File.expand_path("#{D}/../../../bin/#{F}")
|
||||
exec brew_version, *ARGV if File.executable? brew_version
|
||||
|
||||
`/usr/bin/which -a #{F} 2>/dev/null`.split("\n").each do |path|
|
||||
exec path, *ARGV
|
||||
end
|
||||
|
||||
# xcrun hangs if xcode-select is set to "/"
|
||||
path = `/usr/bin/xcode-select -print-path 2>/dev/null`.chomp
|
||||
if path != "/"
|
||||
path = `/usr/bin/xcrun -find #{F} 2>/dev/null`.chomp
|
||||
exec path, *ARGV if File.executable? path
|
||||
end
|
||||
|
||||
path = "/Applications/Xcode.app/Contents/Developer/usr/bin/#{F}"
|
||||
exec path, *ARGV if File.executable? path
|
||||
|
||||
abort "You must: brew install #{F}"
|
||||
1
Library/Contributions/cmds/svn
Symbolic link
1
Library/Contributions/cmds/svn
Symbolic link
@ -0,0 +1 @@
|
||||
git
|
||||
@ -23,7 +23,7 @@ module Homebrew extend self
|
||||
CMAKE_PREFIX_PATH CMAKE_INCLUDE_PATH CMAKE_FRAMEWORK_PATH MAKEFLAGS
|
||||
MACOSX_DEPLOYMENT_TARGET PKG_CONFIG_PATH HOMEBREW_BUILD_FROM_SOURCE
|
||||
HOMEBREW_DEBUG HOMEBREW_MAKE_JOBS HOMEBREW_VERBOSE HOMEBREW_USE_CLANG
|
||||
HOMEBREW_USE_GCC HOMEBREW_USE_LLVM HOMEBREW_SVN
|
||||
HOMEBREW_USE_GCC HOMEBREW_USE_LLVM HOMEBREW_SVN HOMEBREW_GIT
|
||||
MAKE GIT CPP
|
||||
ACLOCAL_PATH OBJC PATH ].select{ |key| env[key] }
|
||||
end
|
||||
|
||||
@ -210,7 +210,7 @@ end
|
||||
class SubversionDownloadStrategy < AbstractDownloadStrategy
|
||||
def initialize name, package
|
||||
super
|
||||
@@svn ||= find_svn
|
||||
@@svn ||= 'svn'
|
||||
@unique_token="#{name}--svn" unless name.to_s.empty? or name == '__UNKNOWN__'
|
||||
@unique_token += "-HEAD" if ARGV.include? '--HEAD'
|
||||
@co=HOMEBREW_CACHE+@unique_token
|
||||
@ -269,20 +269,12 @@ class SubversionDownloadStrategy < AbstractDownloadStrategy
|
||||
args << '--ignore-externals' if ignore_externals
|
||||
quiet_safe_system(*args)
|
||||
end
|
||||
|
||||
# Try HOMEBREW_SVN, a Homebrew-built svn, and finally the OS X system svn.
|
||||
# Not all features are available in the 10.5 system-provided svn.
|
||||
def find_svn
|
||||
return ENV['HOMEBREW_SVN'] if ENV['HOMEBREW_SVN']
|
||||
return "#{HOMEBREW_PREFIX}/bin/svn" if File.exist? "#{HOMEBREW_PREFIX}/bin/svn"
|
||||
return MacOS.locate 'svn'
|
||||
end
|
||||
end
|
||||
|
||||
# Require a newer version of Subversion than 1.4.x (Leopard-provided version)
|
||||
class StrictSubversionDownloadStrategy < SubversionDownloadStrategy
|
||||
def find_svn
|
||||
exe = super
|
||||
exe = `svn -print-path`
|
||||
`#{exe} --version` =~ /version (\d+\.\d+(\.\d+)*)/
|
||||
svn_version = $1
|
||||
version_tuple=svn_version.split(".").collect {|v|Integer(v)}
|
||||
@ -316,7 +308,7 @@ end
|
||||
class GitDownloadStrategy < AbstractDownloadStrategy
|
||||
def initialize name, package
|
||||
super
|
||||
@@git ||= find_git
|
||||
@@git ||= 'git'
|
||||
@unique_token="#{name}--git" unless name.to_s.empty? or name == '__UNKNOWN__'
|
||||
@clone=HOMEBREW_CACHE+@unique_token
|
||||
end
|
||||
@ -334,7 +326,7 @@ class GitDownloadStrategy < AbstractDownloadStrategy
|
||||
end
|
||||
|
||||
def fetch
|
||||
raise "You must install Git: brew install git" unless which "git"
|
||||
raise "You must: brew install git" unless which "git"
|
||||
|
||||
ohai "Cloning #{@url}"
|
||||
|
||||
@ -405,13 +397,6 @@ class GitDownloadStrategy < AbstractDownloadStrategy
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
# Try GIT, a Homebrew-built Git, and finally the OS X system Git.
|
||||
def find_git
|
||||
return ENV['GIT'] if ENV['GIT']
|
||||
return "#{HOMEBREW_PREFIX}/bin/git" if File.exist? "#{HOMEBREW_PREFIX}/bin/git"
|
||||
return MacOS.locate 'git'
|
||||
end
|
||||
end
|
||||
|
||||
class CVSDownloadStrategy < AbstractDownloadStrategy
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user