Avoid globals when ivars will do

This commit is contained in:
Jack Nagel 2013-11-21 14:50:35 -06:00
parent ce5f4ad4df
commit be08993a79
2 changed files with 11 additions and 10 deletions

View File

@ -25,9 +25,13 @@ end
LOGGER = Logger.new LOGGER = Logger.new
class Cmd class Cmd
attr_reader :brewfix, :sdkroot
def initialize path, args def initialize path, args
@arg0 = File.basename(path).freeze @arg0 = File.basename(path).freeze
@args = args.freeze @args = args.freeze
@brewfix = ENV['HOMEBREW_PREFIX']
@sdkroot = ENV['HOMEBREW_SDKROOT']
end end
def mode def mode
if @arg0 == 'cpp' or @arg0 == 'ld' if @arg0 == 'cpp' or @arg0 == 'ld'
@ -74,9 +78,9 @@ class Cmd
refurbished_args refurbished_args
end end
if tool != 'ld' if tool != 'ld'
args << "--sysroot=#$sdkroot" args << "--sysroot=#{sdkroot}"
else else
args << "-syslibroot" << $sdkroot args << "-syslibroot" << sdkroot
end if nclt? end if nclt?
allflags = case mode allflags = case mode
when :ccld when :ccld
@ -133,7 +137,7 @@ class Cmd
when /^-L(.+)/ when /^-L(.+)/
path = $1.chuzzle || whittler.next path = $1.chuzzle || whittler.next
doit = case path.cleanpath doit = case path.cleanpath
when %r{^#$brewfix} when %r{^#{brewfix}}
# maybe homebrew is installed to /sw or /opt/brew # maybe homebrew is installed to /sw or /opt/brew
true true
when %r{^/opt}, %r{^/sw}, %r{/usr/X11} when %r{^/opt}, %r{^/sw}, %r{/usr/X11}
@ -180,7 +184,7 @@ class Cmd
end end
def syspath def syspath
if nclt? if nclt?
%W{#$sdkroot/usr #$sdkroot/usr/local} %W{#{sdkroot}/usr #{sdkroot}/usr/local}
else else
%W{/usr /usr/local} %W{/usr /usr/local}
end end
@ -189,7 +193,7 @@ class Cmd
# We reject brew's lib as we explicitly add this as a -L flag, thus it # We reject brew's lib as we explicitly add this as a -L flag, thus it
# is given higher priority by cc, so it surpasses the system libpath. # is given higher priority by cc, so it surpasses the system libpath.
# NOTE this only counts if Homebrew is installed at /usr/local # NOTE this only counts if Homebrew is installed at /usr/local
syspath.map{|d| "#{d}/lib" }.reject{|d| d == "#$brewfix/lib" } syspath.map{|d| "#{d}/lib" }.reject{|d| d == "#{brewfix}/lib" }
end end
def syscpath def syscpath
isystem, _ = cpath isystem, _ = cpath
@ -197,7 +201,7 @@ class Cmd
end end
def cpath def cpath
cpath = ENV['CMAKE_PREFIX_PATH'].split(':').map{|d| "#{d}/include" } + ENV['CMAKE_INCLUDE_PATH'].split(':') cpath = ENV['CMAKE_PREFIX_PATH'].split(':').map{|d| "#{d}/include" } + ENV['CMAKE_INCLUDE_PATH'].split(':')
opt = cpath.grep(%r{^#$brewfix/opt}) opt = cpath.grep(%r{^#{brewfix}/opt})
sys = cpath - opt sys = cpath - opt
[sys, opt] [sys, opt]
end end
@ -243,7 +247,7 @@ class Cmd
ENV.key? 'as_nl' ENV.key? 'as_nl'
end end
def nclt? def nclt?
$sdkroot != nil sdkroot != nil
end end
def cccfg? flags def cccfg? flags
flags.split('').all?{|c| ENV['HOMEBREW_CCCFG'].include? c } if ENV['HOMEBREW_CCCFG'] flags.split('').all?{|c| ENV['HOMEBREW_CCCFG'].include? c } if ENV['HOMEBREW_CCCFG']

View File

@ -20,6 +20,3 @@ class Array
select { |path| File.directory? path }.uniq.map { |path| prefix + path } select { |path| File.directory? path }.uniq.map { |path| prefix + path }
end end
end end
$brewfix = ENV['HOMEBREW_PREFIX']
$sdkroot = ENV['HOMEBREW_SDKROOT']