diff --git a/Library/Homebrew/config.rb b/Library/Homebrew/config.rb new file mode 100644 index 0000000000..505c49c6ec --- /dev/null +++ b/Library/Homebrew/config.rb @@ -0,0 +1,52 @@ +def cache + if ENV['HOMEBREW_CACHE'] + Pathname.new(ENV['HOMEBREW_CACHE']) + else + # we do this for historic reasons, however the cache *should* be the same + # directory whichever user is used and whatever instance of brew is executed + home_cache = Pathname.new("~/Library/Caches/Homebrew").expand_path + if home_cache.directory? and home_cache.writable_real? + home_cache + else + Pathname.new("/Library/Caches/Homebrew").extend Module.new { + def mkpath + unless exist? + super + chmod 0775 + end + end + } + end + end +end + +HOMEBREW_CACHE = cache +undef cache + +# Where brews installed via URL are cached +HOMEBREW_CACHE_FORMULA = HOMEBREW_CACHE+"Formula" + +if not defined? HOMEBREW_BREW_FILE + HOMEBREW_BREW_FILE = ENV['HOMEBREW_BREW_FILE'] || which('brew').to_s +end + +# Where we link under +HOMEBREW_PREFIX = Pathname.new(HOMEBREW_BREW_FILE).dirname.parent + +# Where .git is found +HOMEBREW_REPOSITORY = Pathname.new(HOMEBREW_BREW_FILE).realpath.dirname.parent + +HOMEBREW_LIBRARY = HOMEBREW_REPOSITORY/"Library" +HOMEBREW_CONTRIB = HOMEBREW_REPOSITORY/"Library/Contributions" + +# Where we store built products; /usr/local/Cellar if it exists, +# otherwise a Cellar relative to the Repository. +HOMEBREW_CELLAR = if (HOMEBREW_PREFIX+"Cellar").exist? + HOMEBREW_PREFIX+"Cellar" +else + HOMEBREW_REPOSITORY+"Cellar" +end + +HOMEBREW_LOGS = Pathname.new(ENV['HOMEBREW_LOGS'] || '~/Library/Logs/Homebrew/').expand_path + +HOMEBREW_TEMP = Pathname.new(ENV.fetch('HOMEBREW_TEMP', '/tmp')) diff --git a/Library/Homebrew/global.rb b/Library/Homebrew/global.rb index 442671518e..7374bd5e83 100644 --- a/Library/Homebrew/global.rb +++ b/Library/Homebrew/global.rb @@ -16,58 +16,7 @@ ARGV.extend(HomebrewArgvExtension) HOMEBREW_VERSION = '0.9.5' HOMEBREW_WWW = 'http://brew.sh' -def cache - if ENV['HOMEBREW_CACHE'] - Pathname.new(ENV['HOMEBREW_CACHE']) - else - # we do this for historic reasons, however the cache *should* be the same - # directory whichever user is used and whatever instance of brew is executed - home_cache = Pathname.new("~/Library/Caches/Homebrew").expand_path - if home_cache.directory? and home_cache.writable_real? - home_cache - else - Pathname.new("/Library/Caches/Homebrew").extend Module.new { - def mkpath - unless exist? - super - chmod 0775 - end - end - } - end - end -end - -HOMEBREW_CACHE = cache -undef cache - -# Where brews installed via URL are cached -HOMEBREW_CACHE_FORMULA = HOMEBREW_CACHE+"Formula" - -if not defined? HOMEBREW_BREW_FILE - HOMEBREW_BREW_FILE = ENV['HOMEBREW_BREW_FILE'] || which('brew').to_s -end - -# Where we link under -HOMEBREW_PREFIX = Pathname.new(HOMEBREW_BREW_FILE).dirname.parent - -# Where .git is found -HOMEBREW_REPOSITORY = Pathname.new(HOMEBREW_BREW_FILE).realpath.dirname.parent - -HOMEBREW_LIBRARY = HOMEBREW_REPOSITORY/"Library" -HOMEBREW_CONTRIB = HOMEBREW_REPOSITORY/"Library/Contributions" - -# Where we store built products; /usr/local/Cellar if it exists, -# otherwise a Cellar relative to the Repository. -HOMEBREW_CELLAR = if (HOMEBREW_PREFIX+"Cellar").exist? - HOMEBREW_PREFIX+"Cellar" -else - HOMEBREW_REPOSITORY+"Cellar" -end - -HOMEBREW_LOGS = Pathname.new(ENV['HOMEBREW_LOGS'] || '~/Library/Logs/Homebrew/').expand_path - -HOMEBREW_TEMP = Pathname.new(ENV.fetch('HOMEBREW_TEMP', '/tmp')) +require "config" if RbConfig.respond_to?(:ruby) RUBY_PATH = Pathname.new(RbConfig.ruby) diff --git a/Library/Homebrew/test/lib/config.rb b/Library/Homebrew/test/lib/config.rb new file mode 100644 index 0000000000..63b3e00640 --- /dev/null +++ b/Library/Homebrew/test/lib/config.rb @@ -0,0 +1,8 @@ +HOMEBREW_PREFIX = Pathname.new(TEST_TMPDIR).join("prefix") +HOMEBREW_REPOSITORY = HOMEBREW_PREFIX +HOMEBREW_LIBRARY = HOMEBREW_REPOSITORY+"Library" +HOMEBREW_CACHE = HOMEBREW_PREFIX.parent+"cache" +HOMEBREW_CACHE_FORMULA = HOMEBREW_PREFIX.parent+"formula_cache" +HOMEBREW_CELLAR = HOMEBREW_PREFIX.parent+"cellar" +HOMEBREW_LOGS = HOMEBREW_PREFIX.parent+"logs" +HOMEBREW_TEMP = Pathname.new(ENV["HOMEBREW_TEMP"] || "/tmp") diff --git a/Library/Homebrew/test/testing_env.rb b/Library/Homebrew/test/testing_env.rb index fc5d80441b..8e907e24a2 100644 --- a/Library/Homebrew/test/testing_env.rb +++ b/Library/Homebrew/test/testing_env.rb @@ -1,51 +1,12 @@ -# Require this file to build a testing environment. +$:.unshift File.expand_path("../..", __FILE__) +$:.unshift File.expand_path("../lib", __FILE__) -$:.push(File.expand_path(__FILE__+'/../..')) - -require 'extend/module' -require 'extend/fileutils' -require 'extend/pathname' -require 'extend/ARGV' -require 'extend/string' -require 'extend/symbol' -require 'extend/enumerable' -require 'exceptions' -require 'utils' -require 'rbconfig' -require 'tmpdir' +require "tmpdir" TEST_TMPDIR = Dir.mktmpdir("homebrew_tests") at_exit { FileUtils.remove_entry(TEST_TMPDIR) } -# Constants normally defined in global.rb -HOMEBREW_PREFIX = Pathname.new(TEST_TMPDIR).join("prefix") -HOMEBREW_REPOSITORY = HOMEBREW_PREFIX -HOMEBREW_LIBRARY = HOMEBREW_REPOSITORY+'Library' -HOMEBREW_CACHE = HOMEBREW_PREFIX.parent+'cache' -HOMEBREW_CACHE_FORMULA = HOMEBREW_PREFIX.parent+'formula_cache' -HOMEBREW_CELLAR = HOMEBREW_PREFIX.parent+'cellar' -HOMEBREW_LOGS = HOMEBREW_PREFIX.parent+'logs' -HOMEBREW_TEMP = Pathname.new(ENV.fetch('HOMEBREW_TEMP', '/tmp')) -HOMEBREW_USER_AGENT = 'Homebrew' -HOMEBREW_WWW = 'http://example.com' -HOMEBREW_CURL_ARGS = '-fsLA' -HOMEBREW_VERSION = '0.9-test' - -require 'tap_constants' - -if RbConfig.respond_to?(:ruby) - RUBY_PATH = Pathname.new(RbConfig.ruby) -else - RUBY_PATH = Pathname.new(RbConfig::CONFIG["bindir"]).join( - RbConfig::CONFIG["ruby_install_name"] + RbConfig::CONFIG["EXEEXT"] - ) -end -RUBY_BIN = RUBY_PATH.dirname - -MACOS_FULL_VERSION = `/usr/bin/sw_vers -productVersion`.chomp -MACOS_VERSION = ENV.fetch('MACOS_VERSION') { MACOS_FULL_VERSION[/10\.\d+/] } - -ORIGINAL_PATHS = ENV['PATH'].split(File::PATH_SEPARATOR).map{ |p| Pathname.new(p).expand_path rescue nil }.compact.freeze +require "global" # Test environment setup %w{ENV Formula}.each { |d| HOMEBREW_LIBRARY.join(d).mkpath } @@ -54,8 +15,6 @@ ORIGINAL_PATHS = ENV['PATH'].split(File::PATH_SEPARATOR).map{ |p| Pathname.new(p # Test fixtures and files can be found relative to this path TEST_DIRECTORY = File.dirname(File.expand_path(__FILE__)) -ARGV.extend(HomebrewArgvExtension) - begin require "rubygems" require "minitest/autorun" @@ -65,9 +24,6 @@ rescue LoadError end module Homebrew - include FileUtils - extend self - module VersionAssertions def version v Version.new(v)