Move CompilerSelector logic into build env setup
This moves the CompilerSelector fails_with logic into the build environment setup, making the compiler selection available before performing actions that depends on knowing what the compiler is, e.g. setting up PATH. ENV.setup_build_environment now optionally takes a Formula argument to provide the information necessary to do the fails_with, and the new ENV.validate_cc! extracts the fails_with logic from Build.install.
This commit is contained in:
parent
91e6c993f8
commit
1ae81f0bf7
@ -120,12 +120,12 @@ class Build
|
|||||||
ENV.keg_only_deps = keg_only_deps.map(&:to_s)
|
ENV.keg_only_deps = keg_only_deps.map(&:to_s)
|
||||||
ENV.deps = deps.map { |d| d.to_formula.to_s }
|
ENV.deps = deps.map { |d| d.to_formula.to_s }
|
||||||
ENV.x11 = reqs.any? { |rq| rq.kind_of?(X11Dependency) }
|
ENV.x11 = reqs.any? { |rq| rq.kind_of?(X11Dependency) }
|
||||||
ENV.setup_build_environment
|
ENV.setup_build_environment(f)
|
||||||
post_superenv_hacks
|
post_superenv_hacks
|
||||||
reqs.each(&:modify_build_environment)
|
reqs.each(&:modify_build_environment)
|
||||||
deps.each(&:modify_build_environment)
|
deps.each(&:modify_build_environment)
|
||||||
else
|
else
|
||||||
ENV.setup_build_environment
|
ENV.setup_build_environment(f)
|
||||||
reqs.each(&:modify_build_environment)
|
reqs.each(&:modify_build_environment)
|
||||||
deps.each(&:modify_build_environment)
|
deps.each(&:modify_build_environment)
|
||||||
|
|
||||||
@ -141,14 +141,6 @@ class Build
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
if f.fails_with? ENV.compiler
|
|
||||||
begin
|
|
||||||
ENV.send CompilerSelector.new(f).compiler
|
|
||||||
rescue CompilerSelectionError => e
|
|
||||||
raise e.message
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
# We only support libstdc++ right now
|
# We only support libstdc++ right now
|
||||||
stdlib_in_use = CxxStdlib.new(:libstdcxx, ENV.compiler)
|
stdlib_in_use = CxxStdlib.new(:libstdcxx, ENV.compiler)
|
||||||
|
|
||||||
|
@ -111,6 +111,19 @@ module SharedEnvExtension
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# If the given compiler isn't compatible, will try to select
|
||||||
|
# an alternate compiler, altering the value of environment variables.
|
||||||
|
# If no valid compiler is found, raises an exception.
|
||||||
|
def validate_cc!(formula)
|
||||||
|
if formula.fails_with? ENV.compiler
|
||||||
|
begin
|
||||||
|
send CompilerSelector.new(formula).compiler
|
||||||
|
rescue CompilerSelectionError => e
|
||||||
|
raise e.message
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
# Snow Leopard defines an NCURSES value the opposite of most distros
|
# Snow Leopard defines an NCURSES value the opposite of most distros
|
||||||
# See: http://bugs.python.org/issue6848
|
# See: http://bugs.python.org/issue6848
|
||||||
# Currently only used by aalib in core
|
# Currently only used by aalib in core
|
||||||
@ -162,7 +175,7 @@ module SharedEnvExtension
|
|||||||
|
|
||||||
begin
|
begin
|
||||||
gcc_name = 'gcc' + gcc.delete('.')
|
gcc_name = 'gcc' + gcc.delete('.')
|
||||||
gcc = Formula.factory(gcc_name)
|
gcc = Formulary.factory(gcc_name)
|
||||||
if !gcc.installed?
|
if !gcc.installed?
|
||||||
raise <<-EOS.undent
|
raise <<-EOS.undent
|
||||||
The requested Homebrew GCC, #{gcc_name}, was not installed.
|
The requested Homebrew GCC, #{gcc_name}, was not installed.
|
||||||
@ -171,8 +184,6 @@ module SharedEnvExtension
|
|||||||
brew install #{gcc_name}
|
brew install #{gcc_name}
|
||||||
EOS
|
EOS
|
||||||
end
|
end
|
||||||
|
|
||||||
ENV.append('PATH', gcc.opt_prefix/'bin', ':')
|
|
||||||
rescue FormulaUnavailableError
|
rescue FormulaUnavailableError
|
||||||
raise <<-EOS.undent
|
raise <<-EOS.undent
|
||||||
Homebrew GCC requested, but formula #{gcc_name} not found!
|
Homebrew GCC requested, but formula #{gcc_name} not found!
|
||||||
|
@ -14,7 +14,7 @@ module Stdenv
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def setup_build_environment
|
def setup_build_environment(formula=nil)
|
||||||
# Clear CDPATH to avoid make issues that depend on changing directories
|
# Clear CDPATH to avoid make issues that depend on changing directories
|
||||||
delete('CDPATH')
|
delete('CDPATH')
|
||||||
delete('GREP_OPTIONS') # can break CMake (lol)
|
delete('GREP_OPTIONS') # can break CMake (lol)
|
||||||
@ -68,8 +68,13 @@ module Stdenv
|
|||||||
self.cxx = MacOS.locate("c++")
|
self.cxx = MacOS.locate("c++")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
validate_cc!(formula) unless formula.nil?
|
||||||
|
|
||||||
if cc =~ GNU_GCC_REGEXP
|
if cc =~ GNU_GCC_REGEXP
|
||||||
warn_about_non_apple_gcc($1)
|
warn_about_non_apple_gcc($1)
|
||||||
|
gcc_name = 'gcc' + $1.delete('.')
|
||||||
|
gcc = Formulary.factory(gcc_name)
|
||||||
|
self.append_path('PATH', gcc.opt_prefix/'bin')
|
||||||
end
|
end
|
||||||
|
|
||||||
# Add lib and include etc. from the current macosxsdk to compiler flags:
|
# Add lib and include etc. from the current macosxsdk to compiler flags:
|
||||||
|
@ -54,16 +54,18 @@ module Superenv
|
|||||||
delete('CLICOLOR_FORCE') # autotools doesn't like this
|
delete('CLICOLOR_FORCE') # autotools doesn't like this
|
||||||
end
|
end
|
||||||
|
|
||||||
def setup_build_environment
|
def setup_build_environment(formula=nil)
|
||||||
reset
|
reset
|
||||||
|
|
||||||
self.cc = 'cc'
|
self.cc = 'cc'
|
||||||
self.cxx = 'c++'
|
self.cxx = 'c++'
|
||||||
|
self['HOMEBREW_CC'] = determine_cc
|
||||||
|
validate_cc!(formula) unless formula.nil?
|
||||||
self['DEVELOPER_DIR'] = determine_developer_dir
|
self['DEVELOPER_DIR'] = determine_developer_dir
|
||||||
self['MAKEFLAGS'] ||= "-j#{determine_make_jobs}"
|
self['MAKEFLAGS'] ||= "-j#{determine_make_jobs}"
|
||||||
self['PATH'] = determine_path
|
self['PATH'] = determine_path
|
||||||
self['PKG_CONFIG_PATH'] = determine_pkg_config_path
|
self['PKG_CONFIG_PATH'] = determine_pkg_config_path
|
||||||
self['PKG_CONFIG_LIBDIR'] = determine_pkg_config_libdir
|
self['PKG_CONFIG_LIBDIR'] = determine_pkg_config_libdir
|
||||||
self['HOMEBREW_CC'] = determine_cc
|
|
||||||
self['HOMEBREW_CCCFG'] = determine_cccfg
|
self['HOMEBREW_CCCFG'] = determine_cccfg
|
||||||
self['HOMEBREW_BREW_FILE'] = HOMEBREW_BREW_FILE
|
self['HOMEBREW_BREW_FILE'] = HOMEBREW_BREW_FILE
|
||||||
self['HOMEBREW_SDKROOT'] = "#{MacOS.sdk_path}" if MacOS::Xcode.without_clt?
|
self['HOMEBREW_SDKROOT'] = "#{MacOS.sdk_path}" if MacOS::Xcode.without_clt?
|
||||||
@ -99,20 +101,7 @@ module Superenv
|
|||||||
# s - apply fix for sed's Unicode support
|
# s - apply fix for sed's Unicode support
|
||||||
# a - apply fix for apr-1-config path
|
# a - apply fix for apr-1-config path
|
||||||
|
|
||||||
# Homebrew's apple-gcc42 will be outside the PATH in superenv,
|
warn_about_non_apple_gcc($1) if ENV['HOMEBREW_CC'] =~ GNU_GCC_REGEXP
|
||||||
# so xcrun may not be able to find it
|
|
||||||
if self['HOMEBREW_CC'] == 'gcc-4.2'
|
|
||||||
apple_gcc42 = begin
|
|
||||||
Formulary.factory('apple-gcc42')
|
|
||||||
rescue Exception # in --debug, catch bare exceptions too
|
|
||||||
nil
|
|
||||||
end
|
|
||||||
append_path('PATH', apple_gcc42.opt_prefix/'bin') if apple_gcc42
|
|
||||||
end
|
|
||||||
|
|
||||||
if ENV['HOMEBREW_CC'] =~ GNU_GCC_REGEXP
|
|
||||||
warn_about_non_apple_gcc($1)
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def universal_binary
|
def universal_binary
|
||||||
@ -141,6 +130,24 @@ module Superenv
|
|||||||
paths += deps.map{|dep| "#{HOMEBREW_PREFIX}/opt/#{dep}/bin" }
|
paths += deps.map{|dep| "#{HOMEBREW_PREFIX}/opt/#{dep}/bin" }
|
||||||
paths << MacOS::X11.bin if x11?
|
paths << MacOS::X11.bin if x11?
|
||||||
paths += %w{/usr/bin /bin /usr/sbin /sbin}
|
paths += %w{/usr/bin /bin /usr/sbin /sbin}
|
||||||
|
|
||||||
|
# Homebrew's apple-gcc42 will be outside the PATH in superenv,
|
||||||
|
# so xcrun may not be able to find it
|
||||||
|
if self['HOMEBREW_CC'] == 'gcc-4.2'
|
||||||
|
apple_gcc42 = begin
|
||||||
|
Formulary.factory('apple-gcc42')
|
||||||
|
rescue Exception # in --debug, catch bare exceptions too
|
||||||
|
nil
|
||||||
|
end
|
||||||
|
paths << apple_gcc42.opt_prefix/'bin' if apple_gcc42
|
||||||
|
end
|
||||||
|
|
||||||
|
if self['HOMEBREW_CC'] =~ GNU_GCC_REGEXP
|
||||||
|
gcc_name = 'gcc' + $1.delete('.')
|
||||||
|
gcc = Formulary.factory(gcc_name)
|
||||||
|
paths << gcc.opt_prefix/'bin'
|
||||||
|
end
|
||||||
|
|
||||||
paths.to_path_s
|
paths.to_path_s
|
||||||
end
|
end
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user