aboutsummaryrefslogtreecommitdiffstats
path: root/Library
diff options
context:
space:
mode:
authorJack Nagel2015-04-28 22:37:26 -0400
committerJack Nagel2015-04-29 19:15:11 -0400
commit0397d68259b53b4c73e274d4047fe0e7529ade49 (patch)
treea08ddd95a355ef65f089b0c12f2f127ecf2a496a /Library
parentee0a553021e044929656de102fbb16c47fcdba3d (diff)
downloadbrew-0397d68259b53b4c73e274d4047fe0e7529ade49.tar.bz2
Extract runtime configuration from global.rb
This allows global.rb to be safely loaded in the test environment.
Diffstat (limited to 'Library')
-rw-r--r--Library/Homebrew/config.rb52
-rw-r--r--Library/Homebrew/global.rb53
-rw-r--r--Library/Homebrew/test/lib/config.rb8
-rw-r--r--Library/Homebrew/test/testing_env.rb54
4 files changed, 66 insertions, 101 deletions
diff --git a/Library/Homebrew/config.rb b/Library/Homebrew/config.rb
new file mode 100644
index 000000000..505c49c6e
--- /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 442671518..7374bd5e8 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 000000000..63b3e0064
--- /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 fc5d80441..8e907e24a 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.
-
-$:.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'
+$:.unshift File.expand_path("../..", __FILE__)
+$:.unshift File.expand_path("../lib", __FILE__)
+
+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)