Remove unnecessary Hbc::Locations aliases.

This commit is contained in:
Markus Reiter 2016-11-10 14:48:53 +01:00
parent 0f673cc27f
commit 8dd8273d5e
8 changed files with 17 additions and 54 deletions

View File

@ -1,8 +1,7 @@
require "rake/testtask" require "rake/testtask"
require "rspec/core/rake_task" require "rspec/core/rake_task"
homebrew_repo = `brew --repository`.chomp $LOAD_PATH.unshift(File.expand_path("#{ENV["HOMEBREW_REPOSITORY"]}/Library/Homebrew"))
$LOAD_PATH.unshift(File.expand_path("#{homebrew_repo}/Library/Homebrew"))
$LOAD_PATH.unshift(File.expand_path("../lib", __FILE__)) $LOAD_PATH.unshift(File.expand_path("../lib", __FILE__))
namespace :test do namespace :test do

View File

@ -3,7 +3,7 @@ module Hbc
module_function module_function
def migrate_caskroom_from_repo_to_prefix def migrate_caskroom_from_repo_to_prefix
repo_caskroom = Hbc.homebrew_repository.join("Caskroom") repo_caskroom = HOMEBREW_REPOSITORY.join("Caskroom")
return if Hbc.caskroom.exist? return if Hbc.caskroom.exist?
return unless repo_caskroom.directory? return unless repo_caskroom.directory?

View File

@ -8,9 +8,9 @@ module Hbc
ohai "Ruby Path:", render_with_none_as_error(RbConfig.ruby) ohai "Ruby Path:", render_with_none_as_error(RbConfig.ruby)
# TODO: consider removing most Homebrew constants from doctor output # TODO: consider removing most Homebrew constants from doctor output
ohai "Homebrew Version:", render_with_none_as_error(homebrew_version) ohai "Homebrew Version:", render_with_none_as_error(homebrew_version)
ohai "Homebrew Executable Path:", render_with_none_as_error(Hbc.homebrew_executable) ohai "Homebrew Executable Path:", render_with_none_as_error(HOMEBREW_BREW_FILE)
ohai "Homebrew Cellar Path:", render_with_none_as_error(homebrew_cellar) ohai "Homebrew Cellar Path:", render_with_none_as_error(homebrew_cellar)
ohai "Homebrew Repository Path:", render_with_none_as_error(homebrew_repository) ohai "Homebrew Repository Path:", render_with_none_as_error(HOMEBREW_REPOSITORY)
ohai "Homebrew Origin:", render_with_none_as_error(homebrew_origin) ohai "Homebrew Origin:", render_with_none_as_error(homebrew_origin)
ohai "Homebrew-Cask Version:", render_with_none_as_error(Hbc.full_version) ohai "Homebrew-Cask Version:", render_with_none_as_error(Hbc.full_version)
ohai "Homebrew-Cask Install Location:", render_install_location ohai "Homebrew-Cask Install Location:", render_install_location
@ -48,7 +48,7 @@ module Hbc
def self.homebrew_origin def self.homebrew_origin
homebrew_origin = notfound_string homebrew_origin = notfound_string
begin begin
Dir.chdir(homebrew_repository) do Dir.chdir(HOMEBREW_REPOSITORY) do
homebrew_origin = SystemCommand.run("/usr/bin/git", homebrew_origin = SystemCommand.run("/usr/bin/git",
args: %w[config --get remote.origin.url], args: %w[config --get remote.origin.url],
print_stderr: false).stdout.strip print_stderr: false).stdout.strip
@ -64,10 +64,6 @@ module Hbc
homebrew_origin homebrew_origin
end end
def self.homebrew_repository
homebrew_constants("repository")
end
def self.homebrew_cellar def self.homebrew_cellar
homebrew_constants("cellar") homebrew_constants("cellar")
end end
@ -77,9 +73,7 @@ module Hbc
end end
def self.homebrew_taps def self.homebrew_taps
@homebrew_taps ||= if homebrew_repository.respond_to?(:join) Tap::TAP_DIRECTORY
homebrew_repository.join("Library", "Taps")
end
end end
def self.homebrew_constants(name) def self.homebrew_constants(name)
@ -87,7 +81,7 @@ module Hbc
return @homebrew_constants[name] if @homebrew_constants.key?(name) return @homebrew_constants[name] if @homebrew_constants.key?(name)
@homebrew_constants[name] = notfound_string @homebrew_constants[name] = notfound_string
begin begin
@homebrew_constants[name] = SystemCommand.run!(Hbc.homebrew_executable, @homebrew_constants[name] = SystemCommand.run!(HOMEBREW_BREW_FILE,
args: ["--#{name}"], args: ["--#{name}"],
print_stderr: false) print_stderr: false)
.stdout .stdout

View File

@ -2,8 +2,8 @@ module Hbc
class CLI class CLI
class Update < Base class Update < Base
def self.run(*_ignored) def self.run(*_ignored)
result = SystemCommand.run(Hbc.homebrew_executable, result = SystemCommand.run(HOMEBREW_BREW_FILE,
args: %w[update]) args: ["update"])
# TODO: separating stderr/stdout is undesirable here. # TODO: separating stderr/stdout is undesirable here.
# Hbc::SystemCommand should have an option for plain # Hbc::SystemCommand should have an option for plain
# unbuffered output. # unbuffered output.

View File

@ -31,7 +31,7 @@ module Hbc
def files_in_usr_local def files_in_usr_local
localpath = "/usr/local" localpath = "/usr/local"
return unless Hbc.homebrew_prefix.to_s.downcase.start_with?(localpath) return unless HOMEBREW_PREFIX.to_s.downcase.start_with?(localpath)
puts <<-EOS.undent puts <<-EOS.undent
Cask #{@cask} installs files under "#{localpath}". The presence of such Cask #{@cask} installs files under "#{localpath}". The presence of such
files can cause warnings when running "brew doctor", which is considered files can cause warnings when running "brew doctor", which is considered

View File

@ -188,13 +188,13 @@ module Hbc
ohai "Installing Formula dependencies from Homebrew" ohai "Installing Formula dependencies from Homebrew"
@cask.depends_on.formula.each do |dep_name| @cask.depends_on.formula.each do |dep_name|
print "#{dep_name} ... " print "#{dep_name} ... "
installed = @command.run(Hbc.homebrew_executable, installed = @command.run(HOMEBREW_BREW_FILE,
args: ["list", "--versions", dep_name], args: ["list", "--versions", dep_name],
print_stderr: false).stdout.include?(dep_name) print_stderr: false).stdout.include?(dep_name)
if installed if installed
puts "already installed" puts "already installed"
else else
@command.run!(Hbc.homebrew_executable, @command.run!(HOMEBREW_BREW_FILE,
args: ["install", dep_name]) args: ["install", dep_name])
puts "done" puts "done"
end end

View File

@ -10,7 +10,7 @@ module Hbc
end end
def default_caskroom def default_caskroom
@default_caskroom ||= homebrew_prefix.join("Caskroom") @default_caskroom ||= HOMEBREW_PREFIX.join("Caskroom")
end end
def caskroom def caskroom
@ -39,11 +39,11 @@ module Hbc
end end
def legacy_cache def legacy_cache
@legacy_cache ||= homebrew_cache.join("Casks") @legacy_cache ||= HOMEBREW_CACHE.join("Casks")
end end
def cache def cache
@cache ||= homebrew_cache.join("Cask") @cache ||= HOMEBREW_CACHE.join("Cask")
end end
attr_writer :appdir attr_writer :appdir
@ -91,7 +91,7 @@ module Hbc
attr_writer :binarydir attr_writer :binarydir
def binarydir def binarydir
@binarydir ||= homebrew_prefix.join("bin") @binarydir ||= HOMEBREW_PREFIX.join("bin")
end end
attr_writer :input_methoddir attr_writer :input_methoddir
@ -179,36 +179,6 @@ module Hbc
def x11_libpng def x11_libpng
@x11_libpng ||= [Pathname.new("/opt/X11/lib/libpng.dylib"), Pathname.new("/usr/X11/lib/libpng.dylib")] @x11_libpng ||= [Pathname.new("/opt/X11/lib/libpng.dylib"), Pathname.new("/usr/X11/lib/libpng.dylib")]
end end
def homebrew_cache
@homebrew_cache ||= HOMEBREW_CACHE
end
def homebrew_cache=(path)
@homebrew_cache = path ? Pathname.new(path) : path
end
def homebrew_executable
@homebrew_executable ||= HOMEBREW_BREW_FILE
end
def homebrew_prefix
# where Homebrew links
@homebrew_prefix ||= HOMEBREW_PREFIX
end
def homebrew_prefix=(path)
@homebrew_prefix = path ? Pathname.new(path) : path
end
def homebrew_repository
# where Homebrew's .git dir is found
@homebrew_repository ||= HOMEBREW_REPOSITORY
end
def homebrew_repository=(path)
@homebrew_repository = path ? Pathname.new(path) : path
end
end end
end end
end end

View File

@ -8,7 +8,7 @@ module FakeDirHooks
@canned_dirs = {} @canned_dirs = {}
DIRS.each do |dir_name| DIRS.each do |dir_name|
dir = Hbc.homebrew_prefix.join("#{dir_name}-#{Time.now.to_i}-#{rand(1024)}") dir = HOMEBREW_PREFIX.join("#{dir_name}-#{Time.now.to_i}-#{rand(1024)}")
dir.mkpath dir.mkpath
Hbc.send("#{dir_name}=", dir) Hbc.send("#{dir_name}=", dir)
@canned_dirs[:dir_name] = dir @canned_dirs[:dir_name] = dir