aboutsummaryrefslogtreecommitdiffstats
path: root/Library
diff options
context:
space:
mode:
authorJack Nagel2013-05-25 15:26:55 -0500
committerJack Nagel2013-05-25 15:26:55 -0500
commit67694b8c6064e4424a05e79a7e7907c5f9f744fb (patch)
tree8143bc977d47827aff97ed1d8dd5b138d92abebf /Library
parent439a2f4fae2e5ddae40a808246f28b5b4e7961f6 (diff)
downloadbrew-67694b8c6064e4424a05e79a7e7907c5f9f744fb.tar.bz2
build: move build methods into a class
Diffstat (limited to 'Library')
-rwxr-xr-xLibrary/Homebrew/build.rb174
1 files changed, 91 insertions, 83 deletions
diff --git a/Library/Homebrew/build.rb b/Library/Homebrew/build.rb
index 6c8d60a14..31e6d6f3d 100755
--- a/Library/Homebrew/build.rb
+++ b/Library/Homebrew/build.rb
@@ -40,7 +40,7 @@ def main
# can be inconvenient for the user. But we need to be safe.
system "/usr/bin/sudo", "-k"
- install(Formula.factory($0))
+ Build.new(Formula.factory($0)).install
rescue Exception => e
unless error_pipe.nil?
e.continuation = nil if ARGV.debug?
@@ -54,106 +54,114 @@ rescue Exception => e
end
end
-def post_superenv_hacks f
- # Only allow Homebrew-approved directories into the PATH, unless
- # a formula opts-in to allowing the user's path.
- if f.env.userpaths? or f.recursive_requirements.any? { |rq| rq.env.userpaths? }
- ENV.userpaths!
- end
-end
+class Build
+ attr_reader :f
-def pre_superenv_hacks f
- # Allow a formula to opt-in to the std environment.
- ARGV.unshift '--env=std' if (f.env.std? or
- f.recursive_dependencies.detect{|d| d.name == 'scons' }) and
- not ARGV.include? '--env=super'
-end
+ def initialize(f)
+ @f = f
+ end
-def expand_deps f
- f.recursive_dependencies do |dependent, dep|
- if dep.optional? || dep.recommended?
- Dependency.prune unless dependent.build.with?(dep.name)
- elsif dep.build?
- Dependency.prune unless dependent == f
+ def post_superenv_hacks
+ # Only allow Homebrew-approved directories into the PATH, unless
+ # a formula opts-in to allowing the user's path.
+ if f.env.userpaths? or f.recursive_requirements.any? { |rq| rq.env.userpaths? }
+ ENV.userpaths!
end
- end.map(&:to_formula)
-end
-
-def install f
- deps = expand_deps(f)
- keg_only_deps = deps.select(&:keg_only?)
+ end
- pre_superenv_hacks(f)
- require 'superenv'
+ def pre_superenv_hacks
+ # Allow a formula to opt-in to the std environment.
+ ARGV.unshift '--env=std' if (f.env.std? or
+ f.recursive_dependencies.detect{|d| d.name == 'scons' }) and
+ not ARGV.include? '--env=super'
+ end
- deps.each do |dep|
- opt = HOMEBREW_PREFIX/:opt/dep
- fixopt(dep) unless opt.directory? or ARGV.ignore_deps?
+ def expand_deps
+ f.recursive_dependencies do |dependent, dep|
+ if dep.optional? || dep.recommended?
+ Dependency.prune unless dependent.build.with?(dep.name)
+ elsif dep.build?
+ Dependency.prune unless dependent == f
+ end
+ end.map(&:to_formula)
end
- if superenv?
- ENV.keg_only_deps = keg_only_deps.map(&:to_s)
- ENV.deps = deps.map(&:to_s)
- ENV.x11 = f.recursive_requirements.detect { |rq| rq.kind_of?(X11Dependency) }
- ENV.setup_build_environment
- post_superenv_hacks(f)
- f.recursive_requirements.each(&:modify_build_environment)
- else
- ENV.setup_build_environment
- f.recursive_requirements.each(&:modify_build_environment)
-
- keg_only_deps.each do |dep|
- opt = dep.opt_prefix
- ENV.prepend_path 'PATH', "#{opt}/bin"
- ENV.prepend_path 'PKG_CONFIG_PATH', "#{opt}/lib/pkgconfig"
- ENV.prepend_path 'PKG_CONFIG_PATH', "#{opt}/share/pkgconfig"
- ENV.prepend_path 'ACLOCAL_PATH', "#{opt}/share/aclocal"
- ENV.prepend_path 'CMAKE_PREFIX_PATH', opt
- ENV.prepend 'LDFLAGS', "-L#{opt}/lib" if (opt/:lib).directory?
- ENV.prepend 'CPPFLAGS', "-I#{opt}/include" if (opt/:include).directory?
+ def install
+ deps = expand_deps
+ keg_only_deps = deps.select(&:keg_only?)
+
+ pre_superenv_hacks
+ require 'superenv'
+
+ deps.each do |dep|
+ opt = HOMEBREW_PREFIX/:opt/dep
+ fixopt(dep) unless opt.directory? or ARGV.ignore_deps?
end
- end
- if f.fails_with? ENV.compiler
- begin
- ENV.send CompilerSelector.new(f, ENV.compiler).compiler
- rescue CompilerSelectionError => e
- raise e.message
+ if superenv?
+ ENV.keg_only_deps = keg_only_deps.map(&:to_s)
+ ENV.deps = deps.map(&:to_s)
+ ENV.x11 = f.recursive_requirements.detect { |rq| rq.kind_of?(X11Dependency) }
+ ENV.setup_build_environment
+ post_superenv_hacks
+ f.recursive_requirements.each(&:modify_build_environment)
+ else
+ ENV.setup_build_environment
+ f.recursive_requirements.each(&:modify_build_environment)
+
+ keg_only_deps.each do |dep|
+ opt = dep.opt_prefix
+ ENV.prepend_path 'PATH', "#{opt}/bin"
+ ENV.prepend_path 'PKG_CONFIG_PATH', "#{opt}/lib/pkgconfig"
+ ENV.prepend_path 'PKG_CONFIG_PATH', "#{opt}/share/pkgconfig"
+ ENV.prepend_path 'ACLOCAL_PATH', "#{opt}/share/aclocal"
+ ENV.prepend_path 'CMAKE_PREFIX_PATH', opt
+ ENV.prepend 'LDFLAGS', "-L#{opt}/lib" if (opt/:lib).directory?
+ ENV.prepend 'CPPFLAGS', "-I#{opt}/include" if (opt/:include).directory?
+ end
end
- end
- f.brew do
- if ARGV.flag? '--git'
- system "git init"
- system "git add -A"
+ if f.fails_with? ENV.compiler
+ begin
+ ENV.send CompilerSelector.new(f, ENV.compiler).compiler
+ rescue CompilerSelectionError => e
+ raise e.message
+ end
end
- if ARGV.interactive?
- ohai "Entering interactive mode"
- puts "Type `exit' to return and finalize the installation"
- puts "Install to this prefix: #{f.prefix}"
+ f.brew do
if ARGV.flag? '--git'
- puts "This directory is now a git repo. Make your changes and then use:"
- puts " git diff | pbcopy"
- puts "to copy the diff to the clipboard."
+ system "git init"
+ system "git add -A"
end
+ if ARGV.interactive?
+ ohai "Entering interactive mode"
+ puts "Type `exit' to return and finalize the installation"
+ puts "Install to this prefix: #{f.prefix}"
+
+ if ARGV.flag? '--git'
+ puts "This directory is now a git repo. Make your changes and then use:"
+ puts " git diff | pbcopy"
+ puts "to copy the diff to the clipboard."
+ end
- interactive_shell f
- else
- f.prefix.mkpath
-
- begin
- f.install
- rescue Exception => e
- if ARGV.debug?
- debrew e, f
- else
- raise e
+ interactive_shell f
+ else
+ f.prefix.mkpath
+
+ begin
+ f.install
+ rescue Exception => e
+ if ARGV.debug?
+ debrew e, f
+ else
+ raise e
+ end
end
- end
- # Find and link metafiles
- f.prefix.install_metafiles Pathname.pwd
+ # Find and link metafiles
+ f.prefix.install_metafiles Pathname.pwd
+ end
end
end
end