Extract runtime configuration from global.rb
This allows global.rb to be safely loaded in the test environment.
This commit is contained in:
parent
ee0a553021
commit
0397d68259
52
Library/Homebrew/config.rb
Normal file
52
Library/Homebrew/config.rb
Normal file
@ -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'))
|
@ -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)
|
||||
|
8
Library/Homebrew/test/lib/config.rb
Normal file
8
Library/Homebrew/test/lib/config.rb
Normal file
@ -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")
|
@ -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)
|
||||
|
Loading…
x
Reference in New Issue
Block a user