superenv: More thorough scrubbing of -I & -L args

It's important that -I is scrubbed thoroughly as we add most of our important paths with -isystem and -I is handled *first*.

NOTE this indicates we should probably have used -I rather than -isystem, but too late to test all that now.

Also scrub -L for bad-paths thoroughly (evaluate realpath).
This commit is contained in:
Max Howell 2012-09-03 14:34:42 -04:00
parent 4febf938ae
commit 10aab9a672

View File

@ -14,11 +14,11 @@ end
def nclt? def nclt?
$sdkroot != nil $sdkroot != nil
end end
def cmake_prefixes def syspath
@prefixes ||= ENV['CMAKE_PREFIX_PATH'].split(':').reject do |path| if nclt?
case path %W{#$sdkroot/usr #$sdkroot/usr/local}
when '/usr', '/', "#$sdkroot/usr" then true else
end %W{/usr /usr/local}
end end
end end
@ -75,8 +75,9 @@ class Cmd
end.compact end.compact
end end
def refurbished_args def refurbished_args
iset = Set.new(cmake_prefixes.map{|prefix| "#{prefix}/include" }) lset = Set.new(syslibpath)
lset = Set.new iset = Set.new(syscpath)
args = [] args = []
whittler = @args.each whittler = @args.each
loop do loop do
@ -86,8 +87,6 @@ class Cmd
when /^-g\d?/, /^-gstabs\d+/, '-gstabs+', /^-ggdb\d?/, '-gdwarf-2', when /^-g\d?/, /^-gstabs\d+/, '-gstabs+', /^-ggdb\d?/, '-gdwarf-2',
/^-march=.+/, /^-mtune=.+/, '-m64', '-m32', /^-march=.+/, /^-mtune=.+/, '-m64', '-m32',
/^-O[0-9zs]?/, '-fast', /^-O[0-9zs]?/, '-fast',
%r{^-[IL]/opt/local}, %r{^-[IL]/sw}, # no macports/fink
%r{^-[IL]/usr/X11}, %r{^-[IL]/opt/X11}, # we add X11 ourselves
'-pedantic', '-pedantic-errors' '-pedantic', '-pedantic-errors'
when '-fopenmp', '-lgomp' when '-fopenmp', '-lgomp'
# clang doesn't support OpenMP # clang doesn't support OpenMP
@ -102,9 +101,14 @@ class Cmd
# it is okay to add a space after the -I; so let's support it # it is okay to add a space after the -I; so let's support it
path = $1.chuzzle || whittler.next path = $1.chuzzle || whittler.next
args << "-I#{path}" if iset.add?(path.cleanpath) args << "-I#{path}" if iset.add?(path.cleanpath)
when /^-l(.+)/ when /^-L(.+)/
lib = $1.chuzzle || whittler.next path = $1.chuzzle || whittler.next
args << "-l#{lib}" if lset.add?(lib) case path.cleanpath
when %r{^/opt}, %r{^/sw}, %r{/usr/X11}
# NOOP
else
args << "-L#{path}" if lset.add?(path.cleanpath)
end
else else
args << arg args << arg
end end
@ -123,20 +127,34 @@ class Cmd
[] []
end end
end end
def syslibpath
# 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.
# NOTE this only counts if Homebrew is installed at /usr/local
syspath.map{|d| "#{d}/lib" }.reject{ "#$brewfix/lib" }
end
def syscpath
isystem, _ = cpath
isystem + syspath.map{|d| "#{d}/include" }
end
def cpath
cpath = ENV['CMAKE_PREFIX_PATH'].split(':').map{|d| "#{d}/include" } + ENV['CMAKE_INCLUDE_PATH'].split(':')
opt = cpath.select{|prefix| prefix =~ %r{^#$brewfix/opt} }
sys = cpath - opt
[sys, opt]
end
def libpath
ENV['CMAKE_PREFIX_PATH'].split(':').map{|d| "#{d}/lib" } +
ENV['CMAKE_LIBRARY_PATH'].split(':') -
syslibpath
end
def ldflags def ldflags
libs = cmake_prefixes.map{|prefix| "#{prefix}/lib" } libpath.to_flags('-L')
libs += ENV['CMAKE_LIBRARY_PATH'].split(':')
libs.to_flags('-L')
end end
def cppflags def cppflags
all = cmake_prefixes.map{|prefix| "#{prefix}/include" } sys, opt = cpath
# we need to do this for cppflags and not ldflags as here we use -isystem # we want our keg-only includes to be found before system includes *and*
# but with ld we can only set -L. # before any other includes the build-system adds
all.delete('/usr/local') unless nclt?
opt = all.select{|prefix| prefix =~ %r{^#$brewfix/opt} }
sys = all - opt + ENV['CMAKE_INCLUDE_PATH'].split(':')
# we want our keg-only includes to be found before system includes so that
# they override the system options.
sys.to_flags('-isystem') + opt.to_flags('-I') sys.to_flags('-isystem') + opt.to_flags('-I')
end end
def make_fuss args def make_fuss args