diff options
| author | Adam Vandenberg | 2009-10-05 11:52:05 -0700 |
|---|---|---|
| committer | Max Howell | 2009-11-04 16:27:34 +0000 |
| commit | ce01313bbc9386aed4fec68940fbdff35868feb5 (patch) | |
| tree | 9d4c4416e482027e9a670503d02b5e01046d82c3 /bin | |
| parent | 0221ee2ddfbc59d22bd50f1f045fe6de3dde2692 (diff) | |
| download | homebrew-ce01313bbc9386aed4fec68940fbdff35868feb5.tar.bz2 | |
Rewrite of HOMEBREW_ folder locations
This rewrite attempts to sort out where the Prefix, Cellar, and
Repository are relative to the real and symlinked 'brew' command.
Also included is a --config option which dumps all of these variables.
Any top-level script must define a "BREW_FILE" that gives the path
to brew as it exists in the path. 'brew' itself just uses __FILE__ and
install.rb does a `which brew` (there may be a better way?)
The Prefix is always relative to the location of brew as it exists in
the path. Thus, whether or not /usr/local/bin/brew is a symlink or real
file, the Prefix is always /usr/local. If you have brew in some other
prefix, such as /nonstandard/bin/brew, then '/nonstandard/ will be
managed by brew instead.
The Repository, Cellar, and "Library/Homebrew" required code is always
found relative to the "real" path or brew. If brew is a real file in
/usr/local/bin/brew, then everything else will be found in /usr/local
and we'll expect a /usr/local/.git
Otherwise, we dereference brew's symlink and look for everything else
relative to that path instead.
Diffstat (limited to 'bin')
| -rwxr-xr-x | bin/brew | 49 |
1 files changed, 37 insertions, 12 deletions
@@ -5,16 +5,14 @@ # odd exceptions. Reduce our support burden by showing a user-friendly error. Dir.getwd rescue abort "The current working directory doesn't exist, cannot proceed." +BREW_FILE = __FILE__ + def homebrew_rubylib_path lib_path = "/../../Library/Homebrew" - # we resolve off of Dir.getwd as otherwise the symlink gets resolved! - brew_path = if not File.symlink? __FILE__ or File.exist? Dir.getwd+'/'+__FILE__+lib_path - # standard 100% symlinked or non-symlinked installation - __FILE__ - else - # non-standard installation -- just this script is symlinked - File.readlink(__FILE__) - end + + # Library/Homebrew is relative to the real path of brew + brew_path = __FILE__ + brew_path = File.readlink(brew_path) if File.symlink? brew_path return File.expand_path(brew_path+lib_path) end @@ -53,12 +51,36 @@ case Hardware.cpu_type when :ppc, :dunno abort "Sorry, Homebrew does not support your computer's CPU architecture." end +def dump_config + puts <<-EOS +HOMEBREW_VERSION: #{HOMEBREW_VERSION} + +HOMEBREW_PREFIX: #{HOMEBREW_PREFIX} +\tWhere do we symlink installs to? + +HOMEBREW_CELLAR: #{HOMEBREW_CELLAR} +\tWhere do we store our built products? + +HOMEBREW_CACHE: #{HOMEBREW_CACHE} +\tWhere do we cache our downloads? + +HOMEBREW_REPOSITORY: #{HOMEBREW_REPOSITORY} +\tWhere is our .git? + +library path: #{homebrew_rubylib_path} +\tWhat do we put on the ruby path? +EOS +end + + begin require 'brew.h' case ARGV.shift when '--prefix' puts HOMEBREW_PREFIX + when '--config' + dump_config when 'home', 'homepage' if ARGV.named_empty? @@ -83,7 +105,7 @@ begin end when 'search', '-S' - formulae = (HOMEBREW_PREFIX+'Library'+'Formula').children.sort.map{|f| f.basename('.rb') } + formulae = (HOMEBREW_REPOSITORY+'Library/Formula').children.sort.map{|f| f.basename('.rb') } if ARGV.first =~ /^\/(.*)\/$/ puts_columns formulae.grep(Regexp.new($1)) else @@ -95,9 +117,9 @@ begin # EDITOR isn't a good fit here, we need a GUI client that actually has # a UI for projects, so apologies if this wasn't what you expected, # please improve it! :) - exec 'mate', *Dir["#{HOMEBREW_PREFIX}/Library/*"]<< - "#{HOMEBREW_PREFIX}/bin/brew"<< - "#{HOMEBREW_PREFIX}/README.md" + exec 'mate', *Dir["#{HOMEBREW_REPOSITORY}/Library/*"]<< + "#{HOMEBREW_REPOSITORY}/bin/brew"<< + "#{HOMEBREW_REPOSITORY}/README.md" else exec_editor *ARGV.formulae.collect {|f| f.path} end @@ -108,6 +130,9 @@ begin exit 0 end + # The Cellar lives under the repository + raise "Cannot write to #{HOMEBREW_REPOSITORY}" unless HOMEBREW_REPOSITORY.writable? + # The Prefix is where we symlink under raise "Cannot write to #{HOMEBREW_PREFIX}" unless HOMEBREW_PREFIX.writable? if ARGV.interactive? and ARGV.formulae.length > 1 |
