aboutsummaryrefslogtreecommitdiffstats
path: root/Library
diff options
context:
space:
mode:
authorMisty De Meo2013-09-10 23:08:17 -0700
committerMisty De Meo2013-09-17 12:43:38 -0700
commit045aadb8608c5d56a4e71e2859c56f3ed3a7cbbb (patch)
treece077b985ba98650f64eb654c0ba0861e9a23f22 /Library
parenta9562366d26b92d5c54158665c109906e4e2caa3 (diff)
downloadhomebrew-045aadb8608c5d56a4e71e2859c56f3ed3a7cbbb.tar.bz2
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.
Diffstat (limited to 'Library')
-rwxr-xr-xLibrary/Homebrew/build.rb12
-rw-r--r--Library/Homebrew/extend/ENV/shared.rb17
-rw-r--r--Library/Homebrew/extend/ENV/std.rb7
-rw-r--r--Library/Homebrew/extend/ENV/super.rb39
4 files changed, 45 insertions, 30 deletions
diff --git a/Library/Homebrew/build.rb b/Library/Homebrew/build.rb
index 69ef1a6de..de9d503f3 100755
--- a/Library/Homebrew/build.rb
+++ b/Library/Homebrew/build.rb
@@ -120,12 +120,12 @@ class Build
ENV.keg_only_deps = keg_only_deps.map(&:to_s)
ENV.deps = deps.map { |d| d.to_formula.to_s }
ENV.x11 = reqs.any? { |rq| rq.kind_of?(X11Dependency) }
- ENV.setup_build_environment
+ ENV.setup_build_environment(f)
post_superenv_hacks
reqs.each(&:modify_build_environment)
deps.each(&:modify_build_environment)
else
- ENV.setup_build_environment
+ ENV.setup_build_environment(f)
reqs.each(&:modify_build_environment)
deps.each(&:modify_build_environment)
@@ -141,14 +141,6 @@ class Build
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
stdlib_in_use = CxxStdlib.new(:libstdcxx, ENV.compiler)
diff --git a/Library/Homebrew/extend/ENV/shared.rb b/Library/Homebrew/extend/ENV/shared.rb
index 03e636403..de5c14384 100644
--- a/Library/Homebrew/extend/ENV/shared.rb
+++ b/Library/Homebrew/extend/ENV/shared.rb
@@ -111,6 +111,19 @@ module SharedEnvExtension
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
# See: http://bugs.python.org/issue6848
# Currently only used by aalib in core
@@ -162,7 +175,7 @@ module SharedEnvExtension
begin
gcc_name = 'gcc' + gcc.delete('.')
- gcc = Formula.factory(gcc_name)
+ gcc = Formulary.factory(gcc_name)
if !gcc.installed?
raise <<-EOS.undent
The requested Homebrew GCC, #{gcc_name}, was not installed.
@@ -171,8 +184,6 @@ module SharedEnvExtension
brew install #{gcc_name}
EOS
end
-
- ENV.append('PATH', gcc.opt_prefix/'bin', ':')
rescue FormulaUnavailableError
raise <<-EOS.undent
Homebrew GCC requested, but formula #{gcc_name} not found!
diff --git a/Library/Homebrew/extend/ENV/std.rb b/Library/Homebrew/extend/ENV/std.rb
index b45e34ccc..3a20b5d30 100644
--- a/Library/Homebrew/extend/ENV/std.rb
+++ b/Library/Homebrew/extend/ENV/std.rb
@@ -14,7 +14,7 @@ module Stdenv
end
end
- def setup_build_environment
+ def setup_build_environment(formula=nil)
# Clear CDPATH to avoid make issues that depend on changing directories
delete('CDPATH')
delete('GREP_OPTIONS') # can break CMake (lol)
@@ -68,8 +68,13 @@ module Stdenv
self.cxx = MacOS.locate("c++")
end
+ validate_cc!(formula) unless formula.nil?
+
if cc =~ GNU_GCC_REGEXP
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
# Add lib and include etc. from the current macosxsdk to compiler flags:
diff --git a/Library/Homebrew/extend/ENV/super.rb b/Library/Homebrew/extend/ENV/super.rb
index 63bae6e9f..563f8955d 100644
--- a/Library/Homebrew/extend/ENV/super.rb
+++ b/Library/Homebrew/extend/ENV/super.rb
@@ -54,16 +54,18 @@ module Superenv
delete('CLICOLOR_FORCE') # autotools doesn't like this
end
- def setup_build_environment
+ def setup_build_environment(formula=nil)
reset
+
self.cc = 'cc'
self.cxx = 'c++'
+ self['HOMEBREW_CC'] = determine_cc
+ validate_cc!(formula) unless formula.nil?
self['DEVELOPER_DIR'] = determine_developer_dir
self['MAKEFLAGS'] ||= "-j#{determine_make_jobs}"
self['PATH'] = determine_path
self['PKG_CONFIG_PATH'] = determine_pkg_config_path
self['PKG_CONFIG_LIBDIR'] = determine_pkg_config_libdir
- self['HOMEBREW_CC'] = determine_cc
self['HOMEBREW_CCCFG'] = determine_cccfg
self['HOMEBREW_BREW_FILE'] = HOMEBREW_BREW_FILE
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
# a - apply fix for apr-1-config path
- # 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
- 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
+ warn_about_non_apple_gcc($1) if ENV['HOMEBREW_CC'] =~ GNU_GCC_REGEXP
end
def universal_binary
@@ -141,6 +130,24 @@ module Superenv
paths += deps.map{|dep| "#{HOMEBREW_PREFIX}/opt/#{dep}/bin" }
paths << MacOS::X11.bin if x11?
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
end