From 2b22c47ee1e4c69a2feda191c5d33ff68e4d34b8 Mon Sep 17 00:00:00 2001 From: Max Howell Date: Fri, 4 Sep 2009 15:28:18 +0100 Subject: Allow formulae to use __END__ For this to work the "running script" must be the formulae file. Making this so wasn't so hard, there is now an install.rb script which is included with the -r flag to the ruby executable. An at_exit handler calls the install function. Having the install logic in its own file made it feel like there was so much space that I added extra error handling. So there is something to be said for separating functionality out into its own files. Still the error handling sucks, we'll need to marshall the exception back to the bin/brew command. Which is another PITA. Still overall I think this will prove worthwhile. But if it doesn't we'll revert. As a first usage, you can put a diff after __END__ and return DATA from Formula::patches to make Homebrew aware of it. --- bin/brew | 64 +++++++++------------------------------------------------------- 1 file changed, 9 insertions(+), 55 deletions(-) (limited to 'bin') diff --git a/bin/brew b/bin/brew index ba7080290..bd57b7103 100755 --- a/bin/brew +++ b/bin/brew @@ -1,26 +1,10 @@ #!/usr/bin/ruby # -*- coding: utf-8 -*- -$:.unshift ENV['RUBYLIB']=File.expand_path(__FILE__+'/../../Library/Homebrew') -require 'pathname+yeast' -require 'ARGV+yeast' -require 'utils' -require 'hardware' +ENV['RUBYLIB']=HOMEBREW_RUBYLIB=File.expand_path(__FILE__+'/../../Library/Homebrew') +$:.unshift HOMEBREW_RUBYLIB +require 'global' require 'brew.h' -if Process.uid == 0 - # technically this is not the correct place, this cache is for *all users* - # so in that case, maybe we should always use it, root or not? - HOMEBREW_CACHE=Pathname.new("/Library/Caches/Homebrew") -else - HOMEBREW_CACHE=Pathname.new("~/Library/Caches/Homebrew").expand_path -end - -HOMEBREW_PREFIX=(Pathname.getwd+__FILE__).dirname.parent.cleanpath -HOMEBREW_CELLAR=HOMEBREW_PREFIX+'Cellar' -HOMEBREW_VERSION='0.4' -HOMEBREW_WWW='http://bit.ly/Homebrew' -HOMEBREW_USER_AGENT="Homebrew #{HOMEBREW_VERSION} (Ruby #{VERSION}; Mac OS X 10.5 Leopard)" - if %w[/ /usr].include? HOMEBREW_PREFIX.to_s then abort <<-EOS You have placed Homebrew at the prefix: #{HOMEBREW_PREFIX} This is not currently supported. Voice your support for this feature at: @@ -109,11 +93,14 @@ begin next end - # we need to ensure a pristine ENV for each process or the formula - # will start with the ENV from the previous build + # 1. formulae can modify ENV, so we must ensure that each + # installation has a pristine ENV when it starts, forking now is + # the easiest way to do this + # 2. formulae have access to __END__ the only way to allow this is + # to make the formula script the executed script pid=fork if pid.nil? - exec __FILE__, "install-just-one", f.name, *ARGV.options + exec 'ruby', '-r', "#{HOMEBREW_RUBYLIB}/install", f.path, '--', *ARGV.options else Process.wait pid end @@ -122,39 +109,6 @@ begin end end - # this is an internal option, don't expose it to the user - when 'install-just-one' - require 'keg' - - f=ARGV.formulae.shift - - begin - build_time=install f - ohai "Caveats", f.caveats, '' - ohai 'Finishing up' if ARGV.verbose? - clean f - raise "Nothing was installed to #{f.prefix}" unless f.installed? - rescue Exception - if f.prefix.directory? - f.prefix.rmtree - f.prefix.parent.rmdir_if_possible - end - raise - end - - begin - Keg.new(f.prefix).link - rescue Exception - onoe "The linking step did not complete successfully" - puts "The package built, but is not symlinked into #{HOMEBREW_PREFIX}" - puts "You can try again using `brew link #{f.name}'" - ohai "Summary" unless ARGV.verbose? - end - - ohai "Summary" if ARGV.verbose? - print "#{f.prefix}: #{f.prefix.abv}" - print ", built in #{pretty_duration build_time}" if build_time - puts when 'ln', 'link' ARGV.kegs.each {|keg| puts "#{keg.link} links created for #{keg}"} -- cgit v1.2.3