Skip to content
Snippets Groups Projects
Commit 613292e3 authored by Jack Nagel's avatar Jack Nagel
Browse files

Reorganize superenv include and library path setup

I found the dual use of CMAKE_*_PATH variables to make it difficult to
reason about this code. Now a separate set of variables are used to
communicate with the cc wrapper, and less work is performed in the
wrapper itself.

We no longer pass the SDK include path as a -isystem directory on
Xcode-only setups. Doing so is redundant with `--sysroot` and has other
side effects, namely changing the include path search order, which can
break compilation of some software (e.g. qemu).

On Xcode-only 10.9, we can additionally omit `--sysroot`, as the correct
paths are built into the tools.

A new variable, HOMEBREW_SYSROOT, is used to this information to the
wrapper. It will be unset on Xcode-only 10.9. HOMEBREW_SDKROOT will
continue to be set, as it is used for other things besides setting the
include search path.
parent 10bd849b
No related branches found
No related tags found
No related merge requests found
...@@ -26,14 +26,14 @@ end ...@@ -26,14 +26,14 @@ end
LOGGER = Logger.new LOGGER = Logger.new
class Cmd class Cmd
attr_reader :brewfix, :brewtmp, :sdkroot attr_reader :brewfix, :brewtmp, :sysroot
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'] @brewfix = ENV['HOMEBREW_PREFIX']
@brewtmp = ENV['HOMEBREW_TEMP'] @brewtmp = ENV['HOMEBREW_TEMP']
@sdkroot = ENV['HOMEBREW_SDKROOT'] @sysroot = ENV['HOMEBREW_SYSROOT']
end end
def mode def mode
...@@ -89,11 +89,11 @@ class Cmd ...@@ -89,11 +89,11 @@ class Cmd
args = refurbished_args args = refurbished_args
end end
if sdkroot if sysroot
if tool == "ld" if tool == "ld"
args << "-syslibroot" << sdkroot args << "-syslibroot" << sysroot
else else
args << "--sysroot=#{sdkroot}" args << "--sysroot=#{sysroot}"
end end
end end
...@@ -118,8 +118,8 @@ class Cmd ...@@ -118,8 +118,8 @@ class Cmd
end end
def refurbished_args def refurbished_args
@lset = Set.new(libpath + syslibpath) @lset = Set.new(library_paths + system_library_paths)
@iset = Set.new(cpath.flatten) @iset = Set.new(isystem_paths + include_paths)
args = [] args = []
enum = @args.each enum = @args.each
...@@ -241,40 +241,12 @@ class Cmd ...@@ -241,40 +241,12 @@ class Cmd
ENV["HOMEBREW_ARCHFLAGS"].split(" ") ENV["HOMEBREW_ARCHFLAGS"].split(" ")
end end
def syspath def cppflags
if sdkroot path_flags("-isystem", isystem_paths) + path_flags("-I", include_paths)
%W{#{sdkroot}/usr /usr/local}
else
%W{/usr /usr/local}
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.reject { |d| d == brewfix }.map! { |d| File.join(d, "lib") }
end
# Paths added as "-isystem<path>" and "-I<path>" flags
def cpath
cpath = path_split("CMAKE_PREFIX_PATH").map! { |d| File.join(d, "include") }
cpath += path_split("CMAKE_INCLUDE_PATH")
opt = cpath.grep(%r{^#{Regexp.escape(brewfix)}/opt}o)
sys = cpath - opt
[sys, opt]
end
# Paths added as "-L<path>" flags
def libpath
libpath = path_split("CMAKE_PREFIX_PATH").map! { |d| File.join(d, "lib") }
libpath += path_split("CMAKE_LIBRARY_PATH")
libpath -= syslibpath
libpath
end end
def ldflags def ldflags
args = path_flags("-L", libpath) args = path_flags("-L", library_paths)
case mode case mode
when :ld when :ld
args << "-headerpad_max_install_names" args << "-headerpad_max_install_names"
...@@ -284,12 +256,20 @@ class Cmd ...@@ -284,12 +256,20 @@ class Cmd
args args
end end
# Keg-only opt paths get the "-I" treatment since it has higher priority than def isystem_paths
# "-isystem", and we want them to be searched before system directories as path_split("HOMEBREW_ISYSTEM_PATHS")
# well as any directories added by the build system. end
def cppflags
sys, opt = cpath def include_paths
path_flags("-isystem", sys) + path_flags("-I", opt) path_split("HOMEBREW_INCLUDE_PATHS")
end
def library_paths
path_split("HOMEBREW_LIBRARY_PATHS")
end
def system_library_paths
%W{#{sysroot}/usr/lib /usr/local/lib}
end end
def make_fuss args def make_fuss args
......
...@@ -66,6 +66,15 @@ module Superenv ...@@ -66,6 +66,15 @@ module Superenv
self['CMAKE_LIBRARY_PATH'] = determine_cmake_library_path self['CMAKE_LIBRARY_PATH'] = determine_cmake_library_path
self['ACLOCAL_PATH'] = determine_aclocal_path self['ACLOCAL_PATH'] = determine_aclocal_path
self['M4'] = MacOS.locate("m4") if deps.include? "autoconf" self['M4'] = MacOS.locate("m4") if deps.include? "autoconf"
self["HOMEBREW_ISYSTEM_PATHS"] = determine_isystem_paths
self["HOMEBREW_INCLUDE_PATHS"] = determine_include_paths
self["HOMEBREW_LIBRARY_PATHS"] = determine_library_paths
# On 10.9 the developer tools honor the correct sysroot by default.
# On 10.7 and 10.8 we need to set it ourselves.
if MacOS::Xcode.without_clt? && MacOS.version <= "10.8"
self["HOMEBREW_SYSROOT"] = effective_sysroot
end
# On 10.9, the tools in /usr/bin proxy to the active developer directory. # On 10.9, the tools in /usr/bin proxy to the active developer directory.
# This means we can use them for any combination of CLT and Xcode. # This means we can use them for any combination of CLT and Xcode.
...@@ -100,6 +109,10 @@ module Superenv ...@@ -100,6 +109,10 @@ module Superenv
self["HOMEBREW_CXX"] = super self["HOMEBREW_CXX"] = super
end end
def effective_sysroot
if MacOS::Xcode.without_clt? then MacOS.sdk_path.to_s else "" end
end
def determine_cc def determine_cc
cc = compiler cc = compiler
COMPILER_SYMBOL_MAP.invert.fetch(cc, cc) COMPILER_SYMBOL_MAP.invert.fetch(cc, cc)
...@@ -159,40 +172,53 @@ module Superenv ...@@ -159,40 +172,53 @@ module Superenv
paths.to_path_s paths.to_path_s
end end
def determine_cmake_prefix_path def determine_isystem_paths
paths = keg_only_deps.map{|dep| "#{HOMEBREW_PREFIX}/opt/#{dep}" } paths = []
paths << HOMEBREW_PREFIX.to_s # put ourselves ahead of everything else paths << "#{HOMEBREW_PREFIX}/include"
paths << "#{MacOS.sdk_path}/usr" if MacOS::Xcode.without_clt? paths << "#{effective_sysroot}/usr/include/libxml2" unless deps.include? "libxml2"
paths << "#{effective_sysroot}/usr/include/apache2" if MacOS::Xcode.without_clt?
paths << "#{effective_sysroot}/System/Library/Frameworks/OpenGL.framework/Versions/Current/Headers"
paths << MacOS::X11.include.to_s << "#{MacOS::X11.include}/freetype2" if x11?
paths.to_path_s paths.to_path_s
end end
def determine_cmake_frameworks_path def determine_include_paths
paths = deps.map{|dep| "#{HOMEBREW_PREFIX}/opt/#{dep}/Frameworks" } keg_only_deps.map { |dep| "#{HOMEBREW_PREFIX}/opt/#{dep}/include" }.to_path_s
paths << "#{MacOS.sdk_path}/System/Library/Frameworks" if MacOS::Xcode.without_clt? end
def determine_library_paths
paths = keg_only_deps.map { |dep| "#{HOMEBREW_PREFIX}/opt/#{dep}/lib" }
paths << "#{HOMEBREW_PREFIX}/lib"
paths << "#{effective_sysroot}/System/Library/Frameworks/OpenGL.framework/Versions/Current/Libraries"
paths << MacOS::X11.lib.to_s if x11?
paths.to_path_s
end
def determine_cmake_prefix_path
paths = keg_only_deps.map { |dep| "#{HOMEBREW_PREFIX}/opt/#{dep}" }
paths << HOMEBREW_PREFIX.to_s
paths.to_path_s paths.to_path_s
end end
def determine_cmake_include_path def determine_cmake_include_path
sdk = MacOS.sdk_path if MacOS::Xcode.without_clt?
paths = [] paths = []
paths << "#{sdk}/usr/include/libxml2" unless deps.include? 'libxml2' paths << "#{effective_sysroot}/usr/include/libxml2" unless deps.include? "libxml2"
paths << "#{sdk}/usr/include/apache2" if MacOS::Xcode.without_clt? paths << "#{effective_sysroot}/usr/include/apache2" if MacOS::Xcode.without_clt?
if x11? paths << "#{effective_sysroot}/System/Library/Frameworks/OpenGL.framework/Versions/Current/Headers"
paths << MacOS::X11.include << "#{MacOS::X11.include}/freetype2" paths << MacOS::X11.include.to_s << "#{MacOS::X11.include}/freetype2" if x11?
else
paths << "#{sdk}/System/Library/Frameworks/OpenGL.framework/Versions/Current/Headers"
end
paths.to_path_s paths.to_path_s
end end
def determine_cmake_library_path def determine_cmake_library_path
sdk = MacOS.sdk_path if MacOS::Xcode.without_clt?
paths = [] paths = []
if x11? paths << "#{effective_sysroot}/System/Library/Frameworks/OpenGL.framework/Versions/Current/Libraries"
paths << MacOS::X11.lib paths << MacOS::X11.lib.to_s if x11?
else paths.to_path_s
paths << "#{sdk}/System/Library/Frameworks/OpenGL.framework/Versions/Current/Libraries" end
end
def determine_cmake_frameworks_path
paths = deps.map { |dep| "#{HOMEBREW_PREFIX}/opt/#{dep}/Frameworks" }
paths << "#{effective_sysroot}/System/Library/Frameworks" if MacOS::Xcode.without_clt?
paths.to_path_s paths.to_path_s
end end
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment