From 88ad4c061d8d2bf7fe1bce29cf474b0bd854df2a Mon Sep 17 00:00:00 2001 From: Adam Vandenberg Date: Fri, 14 Sep 2012 07:54:14 -0700 Subject: [PATCH] Support env :std, :userpaths Closes Homebrew/homebrew#14654. --- Library/Homebrew/build.rb | 25 +++++-------------------- Library/Homebrew/build_environment.rb | 15 +++++++++++++++ Library/Homebrew/formula.rb | 13 +++++++++++++ 3 files changed, 33 insertions(+), 20 deletions(-) create mode 100644 Library/Homebrew/build_environment.rb diff --git a/Library/Homebrew/build.rb b/Library/Homebrew/build.rb index f40a7ef340..d3892819b0 100755 --- a/Library/Homebrew/build.rb +++ b/Library/Homebrew/build.rb @@ -53,32 +53,17 @@ rescue Exception => e end def post_superenv_hacks f - # TODO replace with Formula DSL - # Python etc. build but then pip can't build stuff. - # Scons resets ENV and then can't find superenv's build-tools. - # In some cases we should only apply in the case of an option I suggest the - # following: - # - # option 'with-passenger' do - # env :userpaths # for superenv - # end - # option 'without-foo' do - # env :std, :x11 - # end - # - # NOTE I think all ENV stuff should be specified with a DSL like this now. - case f.name.to_sym - when :lilypond, :nginx, :auctex + # Only allow Homebrew-approved directories into the PATH, unless + # a formula opts-in to allowing the user's path. + if f.env.userpaths? paths = ORIGINAL_PATHS.map{|pn| pn.realpath.to_s rescue nil } - %w{/usr/X11/bin /opt/X11/bin} ENV['PATH'] = "#{ENV['PATH']}:#{paths.join(':')}" end end def pre_superenv_hacks f - # fontforge needs 10.7 SDK, wine 32 bit, graphviz has mysteriously missing symbols - # and ruby/python/ghc etc. create gem/pip that then won't work - stdenvs = %w{fontforge python python3 ruby ruby-enterprise-edition jruby wine graphviz ghc} - ARGV.unshift '--env=std' if (stdenvs.include?(f.name) or + # Allow a formula to opt-in to the std environment. + ARGV.unshift '--env=std' if (f.env.std? or f.recursive_deps.detect{|d| d.name == 'scons' }) and not ARGV.include? '--env=super' end diff --git a/Library/Homebrew/build_environment.rb b/Library/Homebrew/build_environment.rb new file mode 100644 index 0000000000..0beee6c254 --- /dev/null +++ b/Library/Homebrew/build_environment.rb @@ -0,0 +1,15 @@ +require 'set' + +class BuildEnvironment + def initialize settings + @settings = Set.new(settings) + end + + def std? + @settings.include? :std + end + + def userpaths? + @settings.include? :userpaths + end +end diff --git a/Library/Homebrew/formula.rb b/Library/Homebrew/formula.rb index 2fbfbe2018..1847758353 100644 --- a/Library/Homebrew/formula.rb +++ b/Library/Homebrew/formula.rb @@ -6,6 +6,7 @@ require 'bottles' require 'extend/fileutils' require 'patches' require 'compilers' +require 'build_environment' class Formula @@ -436,6 +437,10 @@ class Formula def deps; self.class.dependencies.deps; end def requirements; self.class.dependencies.requirements; end + def env + @env ||= BuildEnvironment.new(self.class.environments) + end + def conflicts requirements.select { |r| r.is_a? ConflictRequirement } end @@ -646,6 +651,14 @@ private @stable.mirror(val) end + def environments + @environments ||= [] + end + + def env *settings + environments.concat [settings].flatten + end + def dependencies @dependencies ||= DependencyCollector.new end