aboutsummaryrefslogtreecommitdiffstats
path: root/Library
diff options
context:
space:
mode:
Diffstat (limited to 'Library')
-rw-r--r--Library/.rubocop.yml6
-rw-r--r--Library/Homebrew/.rubocop_todo.yml86
-rw-r--r--Library/Homebrew/build_options.rb16
-rw-r--r--Library/Homebrew/cask/Rakefile3
-rwxr-xr-xLibrary/Homebrew/cask/cmd/brew-cask-tests.rb8
-rw-r--r--Library/Homebrew/cask/lib/hbc/caskroom.rb2
-rw-r--r--Library/Homebrew/cask/lib/hbc/cli/doctor.rb16
-rw-r--r--Library/Homebrew/cask/lib/hbc/cli/search.rb15
-rw-r--r--Library/Homebrew/cask/lib/hbc/cli/style.rb2
-rw-r--r--Library/Homebrew/cask/lib/hbc/cli/update.rb4
-rw-r--r--Library/Homebrew/cask/lib/hbc/container/cab.rb2
-rw-r--r--Library/Homebrew/cask/lib/hbc/dsl/caveats.rb2
-rw-r--r--Library/Homebrew/cask/lib/hbc/installer.rb29
-rw-r--r--Library/Homebrew/cask/lib/hbc/locations.rb38
-rw-r--r--Library/Homebrew/cask/lib/hbc/system_command.rb1
-rw-r--r--Library/Homebrew/cask/lib/hbc/utils.rb16
-rw-r--r--Library/Homebrew/cask/spec/spec_helper.rb2
-rw-r--r--Library/Homebrew/cask/test/support/fake_dirs.rb2
-rw-r--r--Library/Homebrew/cask/test/test_helper.rb4
-rw-r--r--Library/Homebrew/cleanup.rb7
-rw-r--r--Library/Homebrew/cmd/gist-logs.rb16
-rw-r--r--Library/Homebrew/cmd/install.rb24
-rw-r--r--Library/Homebrew/cmd/list.rb9
-rw-r--r--Library/Homebrew/cmd/missing.rb12
-rw-r--r--Library/Homebrew/cmd/reinstall.rb1
-rw-r--r--Library/Homebrew/cmd/style.rb2
-rw-r--r--Library/Homebrew/cmd/uninstall.rb85
-rw-r--r--Library/Homebrew/cmd/upgrade.rb1
-rw-r--r--Library/Homebrew/compilers.rb2
-rw-r--r--Library/Homebrew/descriptions.rb45
-rw-r--r--Library/Homebrew/dev-cmd/audit.rb37
-rw-r--r--Library/Homebrew/dev-cmd/boneyard-formula-pr.rb2
-rw-r--r--Library/Homebrew/diagnostic.rb36
-rw-r--r--Library/Homebrew/extend/ARGV.rb32
-rw-r--r--Library/Homebrew/extend/ENV/shared.rb3
-rw-r--r--Library/Homebrew/extend/ENV/std.rb5
-rw-r--r--Library/Homebrew/extend/enumerable.rb11
-rw-r--r--Library/Homebrew/extend/os/mac/diagnostic.rb1
-rw-r--r--Library/Homebrew/extend/pathname.rb30
-rw-r--r--Library/Homebrew/formula.rb27
-rw-r--r--Library/Homebrew/formula_installer.rb16
-rw-r--r--Library/Homebrew/formula_versions.rb15
-rw-r--r--Library/Homebrew/formulary.rb23
-rw-r--r--Library/Homebrew/global.rb1
-rw-r--r--Library/Homebrew/keg.rb59
-rw-r--r--Library/Homebrew/os/mac/xcode.rb34
-rw-r--r--Library/Homebrew/sandbox.rb7
-rwxr-xr-xLibrary/Homebrew/shims/super/cc2
-rw-r--r--Library/Homebrew/test/helper/integration_command_test_case.rb5
-rw-r--r--Library/Homebrew/test/test_ARGV.rb15
-rw-r--r--Library/Homebrew/test/test_build_options.rb15
-rw-r--r--Library/Homebrew/test/test_formula_installer.rb1
-rw-r--r--Library/Homebrew/test/test_hardware.rb10
-rw-r--r--Library/Homebrew/test/test_install.rb6
-rw-r--r--Library/Homebrew/test/test_keg.rb107
-rw-r--r--Library/Homebrew/test/test_missing.rb27
-rw-r--r--Library/Homebrew/test/test_uninstall.rb22
-rw-r--r--Library/Homebrew/test/testing_env.rb3
-rw-r--r--Library/Homebrew/utils/lock.sh15
59 files changed, 665 insertions, 360 deletions
diff --git a/Library/.rubocop.yml b/Library/.rubocop.yml
index c77d55f67..be2fb4a67 100644
--- a/Library/.rubocop.yml
+++ b/Library/.rubocop.yml
@@ -6,6 +6,9 @@ AllCops:
Metrics/AbcSize:
Enabled: false
+Metrics/BlockLength:
+ Enabled: false
+
Metrics/ClassLength:
Enabled: false
@@ -136,6 +139,9 @@ Style/RegexpLiteral:
Style/SpaceAroundOperators:
Enabled: false
+Style/SingleLineBlockParams:
+ Enabled: false
+
# not a problem for typical shell users
Style/SpecialGlobalVars:
Enabled: false
diff --git a/Library/Homebrew/.rubocop_todo.yml b/Library/Homebrew/.rubocop_todo.yml
index 6a31cdecd..867a61966 100644
--- a/Library/Homebrew/.rubocop_todo.yml
+++ b/Library/Homebrew/.rubocop_todo.yml
@@ -1,6 +1,6 @@
# This configuration was generated by
# `rubocop --auto-gen-config --exclude-limit 100`
-# on 2016-09-28 22:26:33 +0200 using RuboCop version 0.43.0.
+# on 2016-10-24 17:14:14 +0200 using RuboCop version 0.44.1.
# The point is for the user to remove these configuration records
# one by one as the offenses are removed from the code base.
# Note that changes in the inspected code, or installation of new
@@ -66,7 +66,7 @@ Metrics/BlockNesting:
# Offense count: 19
# Configuration parameters: CountComments.
Metrics/ModuleLength:
- Max: 400
+ Max: 367
# Offense count: 2
# Configuration parameters: CountKeywordArgs.
@@ -85,89 +85,12 @@ Style/BarePercentLiterals:
- 'test/test_patch.rb'
- 'test/test_string.rb'
-# Offense count: 134
-# Cop supports --auto-correct.
-# Configuration parameters: EnforcedStyle, SupportedStyles, ProceduralMethods, FunctionalMethods, IgnoredMethods.
-# SupportedStyles: line_count_based, semantic, braces_for_chaining
-# ProceduralMethods: benchmark, bm, bmbm, create, each_with_object, measure, new, realtime, tap, with_object
-# FunctionalMethods: let, let!, subject, watch
-# IgnoredMethods: lambda, proc, it
-Style/BlockDelimiters:
- Exclude:
- - 'caveats.rb'
- - 'cleaner.rb'
- - 'cleanup.rb'
- - 'cmd/deps.rb'
- - 'cmd/desc.rb'
- - 'cmd/fetch.rb'
- - 'cmd/help.rb'
- - 'cmd/info.rb'
- - 'cmd/linkapps.rb'
- - 'cmd/list.rb'
- - 'cmd/outdated.rb'
- - 'cmd/reinstall.rb'
- - 'cmd/search.rb'
- - 'cmd/tap-info.rb'
- - 'cmd/unlinkapps.rb'
- - 'cmd/update-report.rb'
- - 'cmd/upgrade.rb'
- - 'cmd/uses.rb'
- - 'compilers.rb'
- - 'debrew.rb'
- - 'descriptions.rb'
- - 'dev-cmd/aspell-dictionaries.rb'
- - 'dev-cmd/audit.rb'
- - 'dev-cmd/bottle.rb'
- - 'dev-cmd/edit.rb'
- - 'dev-cmd/man.rb'
- - 'diagnostic.rb'
- - 'exceptions.rb'
- - 'extend/ARGV.rb'
- - 'extend/ENV/shared.rb'
- - 'extend/ENV/std.rb'
- - 'extend/fileutils.rb'
- - 'extend/os/mac/formula_cellar_checks.rb'
- - 'extend/pathname.rb'
- - 'formula.rb'
- - 'formula_assertions.rb'
- - 'formula_cellar_checks.rb'
- - 'formula_installer.rb'
- - 'formulary.rb'
- - 'global.rb'
- - 'keg.rb'
- - 'language/haskell.rb'
- - 'language/node.rb'
- - 'language/python.rb'
- - 'migrator.rb'
- - 'os/mac/linkage_checker.rb'
- - 'os/mac/xquartz.rb'
- - 'patch.rb'
- - 'readall.rb'
- - 'software_spec.rb'
- - 'tap.rb'
- - 'test/lib/config.rb'
- - 'test/test_ARGV.rb'
- - 'test/test_cleanup.rb'
- - 'test/test_dependency_collector.rb'
- - 'test/test_formula_installer.rb'
- - 'test/test_formula_installer_bottle.rb'
- - 'test/test_formulary.rb'
- - 'test/test_gpg.rb'
- - 'test/test_migrator.rb'
- - 'test/test_pathname.rb'
- - 'test/test_tap.rb'
- - 'test/test_utils.rb'
- - 'test/testing_env.rb'
- - 'utils.rb'
- - 'utils/github.rb'
-
-# Offense count: 7
+# Offense count: 6
Style/ClassVars:
Exclude:
- 'dev-cmd/audit.rb'
- 'formula_installer.rb'
- 'test/testing_env.rb'
- - 'utils.rb'
# Offense count: 13
# Configuration parameters: AllowedVariables.
@@ -176,12 +99,11 @@ Style/GlobalVars:
- 'diagnostic.rb'
- 'utils.rb'
-# Offense count: 2
+# Offense count: 1
# Configuration parameters: EnforcedStyle, SupportedStyles.
# SupportedStyles: module_function, extend_self
Style/ModuleFunction:
Exclude:
- - 'global.rb'
- 'os/mac/xcode.rb'
# Offense count: 8
diff --git a/Library/Homebrew/build_options.rb b/Library/Homebrew/build_options.rb
index e9a06f4e0..44b6440dc 100644
--- a/Library/Homebrew/build_options.rb
+++ b/Library/Homebrew/build_options.rb
@@ -101,6 +101,22 @@ class BuildOptions
@options - @args
end
+ # @private
+ def invalid_options
+ @args - @options - BuildOptions.formula_install_options
+ end
+
+ # @private
+ def invalid_option_names
+ invalid_options.map(&:flag).sort
+ end
+
+ def self.formula_install_options
+ @formula_install_options ||= ARGV.formula_install_option_names.map do |option_name|
+ Option.new option_name[2..-1]
+ end
+ end
+
private
def option_defined?(name)
diff --git a/Library/Homebrew/cask/Rakefile b/Library/Homebrew/cask/Rakefile
index ec6a4a7f6..39398aa19 100644
--- a/Library/Homebrew/cask/Rakefile
+++ b/Library/Homebrew/cask/Rakefile
@@ -1,8 +1,7 @@
require "rake/testtask"
require "rspec/core/rake_task"
-homebrew_repo = `brew --repository`.chomp
-$LOAD_PATH.unshift(File.expand_path("#{homebrew_repo}/Library/Homebrew"))
+$LOAD_PATH.unshift(File.expand_path("#{ENV["HOMEBREW_REPOSITORY"]}/Library/Homebrew"))
$LOAD_PATH.unshift(File.expand_path("../lib", __FILE__))
namespace :test do
diff --git a/Library/Homebrew/cask/cmd/brew-cask-tests.rb b/Library/Homebrew/cask/cmd/brew-cask-tests.rb
index 3126490e3..0bfc4b037 100755
--- a/Library/Homebrew/cask/cmd/brew-cask-tests.rb
+++ b/Library/Homebrew/cask/cmd/brew-cask-tests.rb
@@ -26,6 +26,8 @@ repo_root.cd do
ENV["HOMEBREW_TESTS_COVERAGE"] = "1" if ARGV.flag?("--coverage")
+ failed = false
+
if rspec
run_tests "parallel_rspec", Dir["spec/**/*_spec.rb"], %w[
--color
@@ -34,15 +36,17 @@ repo_root.cd do
--format ParallelTests::RSpec::RuntimeLogger
--out tmp/parallel_runtime_rspec.log
]
+ failed ||= !$CHILD_STATUS.success?
end
if minitest
run_tests "parallel_test", Dir["test/**/*_test.rb"]
+ failed ||= !$CHILD_STATUS.success?
end
+ Homebrew.failed = failed
+
if ENV["CODECOV_TOKEN"]
system "bundle", "exec", "rake", "test:coverage:upload"
end
-
- Homebrew.failed = !$CHILD_STATUS.success?
end
diff --git a/Library/Homebrew/cask/lib/hbc/caskroom.rb b/Library/Homebrew/cask/lib/hbc/caskroom.rb
index 7bc8294e1..644728129 100644
--- a/Library/Homebrew/cask/lib/hbc/caskroom.rb
+++ b/Library/Homebrew/cask/lib/hbc/caskroom.rb
@@ -3,7 +3,7 @@ module Hbc
module_function
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 unless repo_caskroom.directory?
diff --git a/Library/Homebrew/cask/lib/hbc/cli/doctor.rb b/Library/Homebrew/cask/lib/hbc/cli/doctor.rb
index 4c5bf98e6..84d8e1ebc 100644
--- a/Library/Homebrew/cask/lib/hbc/cli/doctor.rb
+++ b/Library/Homebrew/cask/lib/hbc/cli/doctor.rb
@@ -8,9 +8,9 @@ module Hbc
ohai "Ruby Path:", render_with_none_as_error(RbConfig.ruby)
# TODO: consider removing most Homebrew constants from doctor output
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 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-Cask Version:", render_with_none_as_error(Hbc.full_version)
ohai "Homebrew-Cask Install Location:", render_install_location
@@ -47,7 +47,7 @@ module Hbc
def self.homebrew_origin
homebrew_origin = notfound_string
begin
- Dir.chdir(homebrew_repository) do
+ Dir.chdir(HOMEBREW_REPOSITORY) do
homebrew_origin = SystemCommand.run("/usr/bin/git",
args: %w[config --get remote.origin.url],
print_stderr: false).stdout.strip
@@ -63,10 +63,6 @@ module Hbc
homebrew_origin
end
- def self.homebrew_repository
- homebrew_constants("repository")
- end
-
def self.homebrew_cellar
homebrew_constants("cellar")
end
@@ -76,9 +72,7 @@ module Hbc
end
def self.homebrew_taps
- @homebrew_taps ||= if homebrew_repository.respond_to?(:join)
- homebrew_repository.join("Library", "Taps")
- end
+ Tap::TAP_DIRECTORY
end
def self.homebrew_constants(name)
@@ -86,7 +80,7 @@ module Hbc
return @homebrew_constants[name] if @homebrew_constants.key?(name)
@homebrew_constants[name] = notfound_string
begin
- @homebrew_constants[name] = SystemCommand.run!(Hbc.homebrew_executable,
+ @homebrew_constants[name] = SystemCommand.run!(HOMEBREW_BREW_FILE,
args: ["--#{name}"],
print_stderr: false)
.stdout
diff --git a/Library/Homebrew/cask/lib/hbc/cli/search.rb b/Library/Homebrew/cask/lib/hbc/cli/search.rb
index 8e8f8fd75..3f73fcd2e 100644
--- a/Library/Homebrew/cask/lib/hbc/cli/search.rb
+++ b/Library/Homebrew/cask/lib/hbc/cli/search.rb
@@ -41,14 +41,15 @@ module Hbc
ohai "Exact match"
puts exact_match
end
- unless partial_matches.empty?
- if extract_regexp search_term
- ohai "Regexp matches"
- else
- ohai "Partial matches"
- end
- puts Formatter.columns(partial_matches)
+
+ return if partial_matches.empty?
+
+ if extract_regexp search_term
+ ohai "Regexp matches"
+ else
+ ohai "Partial matches"
end
+ puts Formatter.columns(partial_matches)
end
def self.help
diff --git a/Library/Homebrew/cask/lib/hbc/cli/style.rb b/Library/Homebrew/cask/lib/hbc/cli/style.rb
index 01ba39411..e036770ab 100644
--- a/Library/Homebrew/cask/lib/hbc/cli/style.rb
+++ b/Library/Homebrew/cask/lib/hbc/cli/style.rb
@@ -23,7 +23,7 @@ module Hbc
$CHILD_STATUS.success?
end
- RUBOCOP_CASK_VERSION = "~> 0.10.4".freeze
+ RUBOCOP_CASK_VERSION = "~> 0.10.5".freeze
def install_rubocop
Utils.capture_stderr do
diff --git a/Library/Homebrew/cask/lib/hbc/cli/update.rb b/Library/Homebrew/cask/lib/hbc/cli/update.rb
index 1d6ed2af5..86d02bb55 100644
--- a/Library/Homebrew/cask/lib/hbc/cli/update.rb
+++ b/Library/Homebrew/cask/lib/hbc/cli/update.rb
@@ -2,8 +2,8 @@ module Hbc
class CLI
class Update < Base
def self.run(*_ignored)
- result = SystemCommand.run(Hbc.homebrew_executable,
- args: %w[update])
+ result = SystemCommand.run(HOMEBREW_BREW_FILE,
+ args: ["update"])
# TODO: separating stderr/stdout is undesirable here.
# Hbc::SystemCommand should have an option for plain
# unbuffered output.
diff --git a/Library/Homebrew/cask/lib/hbc/container/cab.rb b/Library/Homebrew/cask/lib/hbc/container/cab.rb
index 52c13402c..b3cf01452 100644
--- a/Library/Homebrew/cask/lib/hbc/container/cab.rb
+++ b/Library/Homebrew/cask/lib/hbc/container/cab.rb
@@ -8,7 +8,7 @@ module Hbc
def self.me?(criteria)
cabextract = which("cabextract")
- criteria.magic_number(/^MSCF/n) &&
+ criteria.magic_number(/^(MSCF|MZ)/n) &&
!cabextract.nil? &&
criteria.command.run(cabextract, args: ["-t", "--", criteria.path.to_s]).stderr.empty?
end
diff --git a/Library/Homebrew/cask/lib/hbc/dsl/caveats.rb b/Library/Homebrew/cask/lib/hbc/dsl/caveats.rb
index 9dd9abab1..402574456 100644
--- a/Library/Homebrew/cask/lib/hbc/dsl/caveats.rb
+++ b/Library/Homebrew/cask/lib/hbc/dsl/caveats.rb
@@ -31,7 +31,7 @@ module Hbc
def files_in_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
Cask #{@cask} installs files under "#{localpath}". The presence of such
files can cause warnings when running "brew doctor", which is considered
diff --git a/Library/Homebrew/cask/lib/hbc/installer.rb b/Library/Homebrew/cask/lib/hbc/installer.rb
index 0c50e3757..57efe97e9 100644
--- a/Library/Homebrew/cask/lib/hbc/installer.rb
+++ b/Library/Homebrew/cask/lib/hbc/installer.rb
@@ -28,22 +28,21 @@ module Hbc
def self.print_caveats(cask)
odebug "Printing caveats"
- unless cask.caveats.empty?
- output = capture_output do
- cask.caveats.each do |caveat|
- if caveat.respond_to?(:eval_and_print)
- caveat.eval_and_print(cask)
- else
- puts caveat
- end
+ return if cask.caveats.empty?
+
+ output = capture_output do
+ cask.caveats.each do |caveat|
+ if caveat.respond_to?(:eval_and_print)
+ caveat.eval_and_print(cask)
+ else
+ puts caveat
end
end
-
- unless output.empty?
- ohai "Caveats"
- puts output
- end
end
+
+ return if output.empty?
+ ohai "Caveats"
+ puts output
end
def self.capture_output(&block)
@@ -188,13 +187,13 @@ module Hbc
ohai "Installing Formula dependencies from Homebrew"
@cask.depends_on.formula.each do |dep_name|
print "#{dep_name} ... "
- installed = @command.run(Hbc.homebrew_executable,
+ installed = @command.run(HOMEBREW_BREW_FILE,
args: ["list", "--versions", dep_name],
print_stderr: false).stdout.include?(dep_name)
if installed
puts "already installed"
else
- @command.run!(Hbc.homebrew_executable,
+ @command.run!(HOMEBREW_BREW_FILE,
args: ["install", dep_name])
puts "done"
end
diff --git a/Library/Homebrew/cask/lib/hbc/locations.rb b/Library/Homebrew/cask/lib/hbc/locations.rb
index 8f6c028ec..7a0bde1b0 100644
--- a/Library/Homebrew/cask/lib/hbc/locations.rb
+++ b/Library/Homebrew/cask/lib/hbc/locations.rb
@@ -10,7 +10,7 @@ module Hbc
end
def default_caskroom
- @default_caskroom ||= homebrew_prefix.join("Caskroom")
+ @default_caskroom ||= HOMEBREW_PREFIX.join("Caskroom")
end
def caskroom
@@ -39,11 +39,11 @@ module Hbc
end
def legacy_cache
- @legacy_cache ||= homebrew_cache.join("Casks")
+ @legacy_cache ||= HOMEBREW_CACHE.join("Casks")
end
def cache
- @cache ||= homebrew_cache.join("Cask")
+ @cache ||= HOMEBREW_CACHE.join("Cask")
end
attr_writer :appdir
@@ -91,7 +91,7 @@ module Hbc
attr_writer :binarydir
def binarydir
- @binarydir ||= homebrew_prefix.join("bin")
+ @binarydir ||= HOMEBREW_PREFIX.join("bin")
end
attr_writer :input_methoddir
@@ -179,36 +179,6 @@ module Hbc
def x11_libpng
@x11_libpng ||= [Pathname.new("/opt/X11/lib/libpng.dylib"), Pathname.new("/usr/X11/lib/libpng.dylib")]
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
diff --git a/Library/Homebrew/cask/lib/hbc/system_command.rb b/Library/Homebrew/cask/lib/hbc/system_command.rb
index de544f1b7..638069386 100644
--- a/Library/Homebrew/cask/lib/hbc/system_command.rb
+++ b/Library/Homebrew/cask/lib/hbc/system_command.rb
@@ -50,6 +50,7 @@ module Hbc
options.extend(HashValidator)
.assert_valid_keys :input, :print_stdout, :print_stderr, :args, :must_succeed, :sudo, :bsexec
sudo_prefix = %w[/usr/bin/sudo -E --]
+ sudo_prefix = sudo_prefix.insert(1, "-A") unless ENV["SUDO_ASKPASS"].nil?
bsexec_prefix = ["/bin/launchctl", "bsexec", options[:bsexec] == :startup ? "/" : options[:bsexec]]
@command = [executable]
options[:print_stderr] = true unless options.key?(:print_stderr)
diff --git a/Library/Homebrew/cask/lib/hbc/utils.rb b/Library/Homebrew/cask/lib/hbc/utils.rb
index b442efd2f..ef3e5eda3 100644
--- a/Library/Homebrew/cask/lib/hbc/utils.rb
+++ b/Library/Homebrew/cask/lib/hbc/utils.rb
@@ -137,17 +137,17 @@ module Hbc
def self.nowstamp_metadata_path(container_path)
@timenow ||= Time.now.gmtime
- if container_path.respond_to?(:join)
- precision = 3
- timestamp = @timenow.strftime("%Y%m%d%H%M%S")
- fraction = format("%.#{precision}f", @timenow.to_f - @timenow.to_i)[1..-1]
- timestamp.concat(fraction)
- container_path.join(timestamp)
- end
+ return unless container_path.respond_to?(:join)
+
+ precision = 3
+ timestamp = @timenow.strftime("%Y%m%d%H%M%S")
+ fraction = format("%.#{precision}f", @timenow.to_f - @timenow.to_i)[1..-1]
+ timestamp.concat(fraction)
+ container_path.join(timestamp)
end
def self.size_in_bytes(files)
- Array(files).reduce(0) { |a, e| a + (File.size?(e) || 0) }
+ Array(files).reduce(0) { |acc, elem| acc + (File.size?(elem) || 0) }
end
def self.capture_stderr
diff --git a/Library/Homebrew/cask/spec/spec_helper.rb b/Library/Homebrew/cask/spec/spec_helper.rb
index 1e41e3de4..7e72a2cee 100644
--- a/Library/Homebrew/cask/spec/spec_helper.rb
+++ b/Library/Homebrew/cask/spec/spec_helper.rb
@@ -29,7 +29,7 @@ end
# create and override default directories
Hbc.appdir = Pathname.new(TEST_TMPDIR).join("Applications").tap(&:mkpath)
Hbc.cache.mkpath
-Hbc.caskroom.mkpath
+Hbc.caskroom = Hbc.default_caskroom.tap(&:mkpath)
Hbc.default_tap = Tap.fetch("caskroom", "spec").tap do |tap|
# link test casks
FileUtils.mkdir_p tap.path.dirname
diff --git a/Library/Homebrew/cask/test/support/fake_dirs.rb b/Library/Homebrew/cask/test/support/fake_dirs.rb
index f8e36bbbb..ea7acc685 100644
--- a/Library/Homebrew/cask/test/support/fake_dirs.rb
+++ b/Library/Homebrew/cask/test/support/fake_dirs.rb
@@ -8,7 +8,7 @@ module FakeDirHooks
@canned_dirs = {}
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
Hbc.send("#{dir_name}=", dir)
@canned_dirs[:dir_name] = dir
diff --git a/Library/Homebrew/cask/test/test_helper.rb b/Library/Homebrew/cask/test/test_helper.rb
index 85024aae8..73459cb25 100644
--- a/Library/Homebrew/cask/test/test_helper.rb
+++ b/Library/Homebrew/cask/test/test_helper.rb
@@ -41,8 +41,10 @@ module Hbc
class TestCask < Cask; end
end
+# create and override default directories
+Hbc.appdir = Pathname.new(TEST_TMPDIR).join("Applications").tap(&:mkpath)
Hbc.cache.mkpath
-Hbc.caskroom.mkpath
+Hbc.caskroom = Hbc.default_caskroom.tap(&:mkpath)
Hbc.default_tap = Tap.fetch("caskroom", "test").tap do |tap|
# link test casks
FileUtils.mkdir_p tap.path.dirname
diff --git a/Library/Homebrew/cleanup.rb b/Library/Homebrew/cleanup.rb
index f7db1c11f..615a7ce9e 100644
--- a/Library/Homebrew/cleanup.rb
+++ b/Library/Homebrew/cleanup.rb
@@ -10,10 +10,9 @@ module Homebrew
cleanup_cellar
cleanup_cache
cleanup_logs
- unless ARGV.dry_run?
- cleanup_lockfiles
- rm_ds_store
- end
+ return if ARGV.dry_run?
+ cleanup_lockfiles
+ rm_ds_store
end
def self.update_disk_cleanup_size(path_size)
diff --git a/Library/Homebrew/cmd/gist-logs.rb b/Library/Homebrew/cmd/gist-logs.rb
index 5cacd50b6..fecdc25a0 100644
--- a/Library/Homebrew/cmd/gist-logs.rb
+++ b/Library/Homebrew/cmd/gist-logs.rb
@@ -94,13 +94,15 @@ module Homebrew
def load_logs(dir)
logs = {}
- dir.children.sort.each do |file|
- contents = file.size? ? file.read : "empty log"
- # small enough to avoid GitHub "unicorn" page-load-timeout errors
- max_file_size = 1_000_000
- contents = truncate_text_to_approximate_size(contents, max_file_size, front_weight: 0.2)
- logs[file.basename.to_s] = { content: contents }
- end if dir.exist?
+ if dir.exist?
+ dir.children.sort.each do |file|
+ contents = file.size? ? file.read : "empty log"
+ # small enough to avoid GitHub "unicorn" page-load-timeout errors
+ max_file_size = 1_000_000
+ contents = truncate_text_to_approximate_size(contents, max_file_size, front_weight: 0.2)
+ logs[file.basename.to_s] = { content: contents }
+ end
+ end
raise "No logs." if logs.empty?
logs
end
diff --git a/Library/Homebrew/cmd/install.rb b/Library/Homebrew/cmd/install.rb
index 16639c4aa..c3c3b4bb9 100644
--- a/Library/Homebrew/cmd/install.rb
+++ b/Library/Homebrew/cmd/install.rb
@@ -249,19 +249,21 @@ module Homebrew
def install_formula(f)
f.print_tap_action
+ build_options = f.build
fi = FormulaInstaller.new(f)
- fi.options = f.build.used_options
- fi.ignore_deps = ARGV.ignore_deps?
- fi.only_deps = ARGV.only_deps?
- fi.build_bottle = ARGV.build_bottle?
- fi.build_from_source = ARGV.build_from_source? || ARGV.build_all_from_source?
- fi.force_bottle = ARGV.force_bottle?
- fi.interactive = ARGV.interactive?
- fi.git = ARGV.git?
- fi.verbose = ARGV.verbose?
- fi.quieter = ARGV.quieter?
- fi.debug = ARGV.debug?
+ fi.options = build_options.used_options
+ fi.invalid_option_names = build_options.invalid_option_names
+ fi.ignore_deps = ARGV.ignore_deps?
+ fi.only_deps = ARGV.only_deps?
+ fi.build_bottle = ARGV.build_bottle?
+ fi.build_from_source = ARGV.build_from_source? || ARGV.build_all_from_source?
+ fi.force_bottle = ARGV.force_bottle?
+ fi.interactive = ARGV.interactive?
+ fi.git = ARGV.git?
+ fi.verbose = ARGV.verbose?
+ fi.quieter = ARGV.quieter?
+ fi.debug = ARGV.debug?
fi.prelude
fi.install
fi.finish
diff --git a/Library/Homebrew/cmd/list.rb b/Library/Homebrew/cmd/list.rb
index 3496580f4..7bbcb4799 100644
--- a/Library/Homebrew/cmd/list.rb
+++ b/Library/Homebrew/cmd/list.rb
@@ -146,7 +146,7 @@ class PrettyListing
(pnn.extname == ".dylib" || pnn.extname == ".pc") && !pnn.symlink?
end
when ".brew"
- # Ignore .brew
+ next # Ignore .brew
else
if pn.directory?
if pn.symlink?
@@ -187,12 +187,9 @@ class PrettyListing
end
def print_remaining_files(files, root, other = "")
- case files.length
- when 0
- # noop
- when 1
+ if files.length == 1
puts files
- else
+ elsif files.length > 1
puts "#{root}/ (#{files.length} #{other}files)"
end
end
diff --git a/Library/Homebrew/cmd/missing.rb b/Library/Homebrew/cmd/missing.rb
index 148fe5bef..8a1dc506d 100644
--- a/Library/Homebrew/cmd/missing.rb
+++ b/Library/Homebrew/cmd/missing.rb
@@ -1,6 +1,9 @@
-#: * `missing` [<formulae>]:
+#: * `missing` [`--hide=`<hidden>] [<formulae>]:
#: Check the given <formulae> for missing dependencies. If no <formulae> are
#: given, check all installed brews.
+#:
+#: If `--hide=`<hidden> is passed, act as if none of <hidden> are installed.
+#: <hidden> should be a comma-separated list of formulae.
require "formula"
require "tab"
@@ -18,8 +21,11 @@ module Homebrew
ARGV.resolved_formulae
end
- Diagnostic.missing_deps(ff) do |name, missing|
- print "#{name}: " if ff.size > 1
+ ff.each do |f|
+ missing = f.missing_dependencies(hide: ARGV.values("hide"))
+ next if missing.empty?
+
+ print "#{f}: " if ff.size > 1
puts missing.join(" ")
end
end
diff --git a/Library/Homebrew/cmd/reinstall.rb b/Library/Homebrew/cmd/reinstall.rb
index 618835d74..598286562 100644
--- a/Library/Homebrew/cmd/reinstall.rb
+++ b/Library/Homebrew/cmd/reinstall.rb
@@ -22,6 +22,7 @@ module Homebrew
def reinstall_formula(f)
options = BuildOptions.new(Options.create(ARGV.flags_only), f.options).used_options
options |= f.build.used_options
+ options &= f.options
notice = "Reinstalling #{f.full_name}"
notice += " with #{options * ", "}" unless options.empty?
diff --git a/Library/Homebrew/cmd/style.rb b/Library/Homebrew/cmd/style.rb
index 08eb111a5..8b6793e77 100644
--- a/Library/Homebrew/cmd/style.rb
+++ b/Library/Homebrew/cmd/style.rb
@@ -47,7 +47,7 @@ module Homebrew
def check_style_impl(files, output_type, options = {})
fix = options[:fix]
- Homebrew.install_gem_setup_path! "rubocop", "0.43.0"
+ Homebrew.install_gem_setup_path! "rubocop", "0.45.0"
args = %w[
--force-exclusion
diff --git a/Library/Homebrew/cmd/uninstall.rb b/Library/Homebrew/cmd/uninstall.rb
index 8bcfc31fb..d9e6a7377 100644
--- a/Library/Homebrew/cmd/uninstall.rb
+++ b/Library/Homebrew/cmd/uninstall.rb
@@ -1,11 +1,15 @@
-#: * `uninstall`, `rm`, `remove` [`--force`] <formula>:
+#: * `uninstall`, `rm`, `remove` [`--force`] [`--ignore-dependencies`] <formula>:
#: Uninstall <formula>.
#:
#: If `--force` is passed, and there are multiple versions of <formula>
#: installed, delete all installed versions.
+#:
+#: If `--ignore-dependencies` is passed, uninstalling won't fail, even if
+#: formulae depending on <formula> would still be installed.
require "keg"
require "formula"
+require "diagnostic"
require "migrator"
module Homebrew
@@ -14,38 +18,51 @@ module Homebrew
def uninstall
raise KegUnspecifiedError if ARGV.named.empty?
- if !ARGV.force?
- ARGV.kegs.each do |keg|
- keg.lock do
- puts "Uninstalling #{keg}... (#{keg.abv})"
- keg.unlink
- keg.uninstall
- rack = keg.rack
- rm_pin rack
-
- if rack.directory?
- versions = rack.subdirs.map(&:basename)
- verb = versions.length == 1 ? "is" : "are"
- puts "#{keg.name} #{versions.join(", ")} #{verb} still installed."
- puts "Remove all versions with `brew uninstall --force #{keg.name}`."
- end
- end
- end
- else
- ARGV.named.each do |name|
+ kegs_by_rack = if ARGV.force?
+ Hash[ARGV.named.map do |name|
rack = Formulary.to_rack(name)
+ next unless rack.directory?
+ [rack, rack.subdirs.map { |d| Keg.new(d) }]
+ end]
+ else
+ ARGV.kegs.group_by(&:rack)
+ end
+
+ if should_check_for_dependents?
+ all_kegs = kegs_by_rack.values.flatten(1)
+ return if check_for_dependents all_kegs
+ end
+
+ kegs_by_rack.each do |rack, kegs|
+ if ARGV.force?
name = rack.basename
if rack.directory?
puts "Uninstalling #{name}... (#{rack.abv})"
- rack.subdirs.each do |d|
- keg = Keg.new(d)
+ kegs.each do |keg|
keg.unlink
keg.uninstall
end
end
rm_pin rack
+ else
+ kegs.each do |keg|
+ keg.lock do
+ puts "Uninstalling #{keg}... (#{keg.abv})"
+ keg.unlink
+ keg.uninstall
+ rack = keg.rack
+ rm_pin rack
+
+ if rack.directory?
+ versions = rack.subdirs.map(&:basename)
+ verb = versions.length == 1 ? "is" : "are"
+ puts "#{keg.name} #{versions.join(", ")} #{verb} still installed."
+ puts "Remove all versions with `brew uninstall --force #{keg.name}`."
+ end
+ end
+ end
end
end
rescue MultipleVersionsInstalledError => e
@@ -61,6 +78,30 @@ module Homebrew
end
end
+ def should_check_for_dependents?
+ # --ignore-dependencies, to be consistent with install
+ return false if ARGV.include?("--ignore-dependencies")
+ return false if ARGV.homebrew_developer?
+ true
+ end
+
+ def check_for_dependents(kegs)
+ return false unless result = Keg.find_some_installed_dependents(kegs)
+
+ requireds, dependents = result
+
+ msg = "Refusing to uninstall #{requireds.join(", ")} because "
+ msg << (requireds.count == 1 ? "it is" : "they are")
+ msg << " required by #{dependents.join(", ")}, which "
+ msg << (dependents.count == 1 ? "is" : "are")
+ msg << " currently installed."
+ ofail msg
+ print "You can override this and force removal with "
+ puts "`brew uninstall --ignore-dependencies #{requireds.map(&:name).join(" ")}`."
+
+ true
+ end
+
def rm_pin(rack)
Formulary.from_rack(rack).unpin
rescue
diff --git a/Library/Homebrew/cmd/upgrade.rb b/Library/Homebrew/cmd/upgrade.rb
index 40805b4ca..f92832aa2 100644
--- a/Library/Homebrew/cmd/upgrade.rb
+++ b/Library/Homebrew/cmd/upgrade.rb
@@ -96,6 +96,7 @@ module Homebrew
fi = FormulaInstaller.new(f)
fi.options = f.build.used_options
+ fi.options &= f.options
fi.build_bottle = ARGV.build_bottle? || (!f.bottled? && f.build.build_bottle?)
fi.build_from_source = ARGV.build_from_source? || ARGV.build_all_from_source?
fi.verbose = ARGV.verbose?
diff --git a/Library/Homebrew/compilers.rb b/Library/Homebrew/compilers.rb
index cf614644c..fdfcab817 100644
--- a/Library/Homebrew/compilers.rb
+++ b/Library/Homebrew/compilers.rb
@@ -125,7 +125,7 @@ class CompilerSelector
yield Compiler.new(name, version) unless version.null?
end
when :llvm
- # no-op. DSL supported, compiler is not.
+ next # no-op. DSL supported, compiler is not.
else
version = compiler_version(compiler)
yield Compiler.new(compiler, version) unless version.null?
diff --git a/Library/Homebrew/descriptions.rb b/Library/Homebrew/descriptions.rb
index cc690c050..08860f7cf 100644
--- a/Library/Homebrew/descriptions.rb
+++ b/Library/Homebrew/descriptions.rb
@@ -57,42 +57,41 @@ class Descriptions
# If it does exist, but the Report is empty, just touch the cache file.
# Otherwise, use the report to update the cache.
def self.update_cache(report)
- if CACHE_FILE.exist?
- if report.empty?
- FileUtils.touch CACHE_FILE
- else
- renamings = report.select_formula(:R)
- alterations = report.select_formula(:A) + report.select_formula(:M) +
- renamings.map(&:last)
- cache_formulae(alterations, save: false)
- uncache_formulae(report.select_formula(:D) +
- renamings.map(&:first))
- end
+ return unless CACHE_FILE.exist?
+
+ if report.empty?
+ FileUtils.touch CACHE_FILE
+ else
+ renamings = report.select_formula(:R)
+ alterations = report.select_formula(:A) + report.select_formula(:M) +
+ renamings.map(&:last)
+ cache_formulae(alterations, save: false)
+ uncache_formulae(report.select_formula(:D) +
+ renamings.map(&:first))
end
end
# Given an array of formula names, add them and their descriptions to the
# cache. Save the updated cache to disk, unless explicitly told not to.
def self.cache_formulae(formula_names, options = { save: true })
- if cache
- formula_names.each do |name|
- begin
- desc = Formulary.factory(name).desc
- rescue FormulaUnavailableError, *FormulaVersions::IGNORED_EXCEPTIONS
- end
- @cache[name] = desc
+ return unless cache
+
+ formula_names.each do |name|
+ begin
+ desc = Formulary.factory(name).desc
+ rescue FormulaUnavailableError, *FormulaVersions::IGNORED_EXCEPTIONS
end
- save_cache if options[:save]
+ @cache[name] = desc
end
+ save_cache if options[:save]
end
# Given an array of formula names, remove them and their descriptions from
# the cache. Save the updated cache to disk, unless explicitly told not to.
def self.uncache_formulae(formula_names, options = { save: true })
- if cache
- formula_names.each { |name| @cache.delete(name) }
- save_cache if options[:save]
- end
+ return unless cache
+ formula_names.each { |name| @cache.delete(name) }
+ save_cache if options[:save]
end
# Given a regex, find all formulae whose specified fields contain a match.
diff --git a/Library/Homebrew/dev-cmd/audit.rb b/Library/Homebrew/dev-cmd/audit.rb
index 568051b43..9024cf50c 100644
--- a/Library/Homebrew/dev-cmd/audit.rb
+++ b/Library/Homebrew/dev-cmd/audit.rb
@@ -662,26 +662,39 @@ class FormulaAuditor
return if @new_formula
fv = FormulaVersions.new(formula, max_depth: 10)
- no_decrease_attributes = [:revision, :version_scheme]
- attributes = no_decrease_attributes + [:version]
+ attributes = [:revision, :version_scheme]
+
attributes_map = fv.version_attributes_map(attributes, "origin/master")
- no_decrease_attributes.each do |attribute|
- attributes_for_version = attributes_map[attribute][formula.version]
- next if attributes_for_version.empty?
- if formula.send(attribute) < attributes_for_version.max
- problem "#{attribute} should not decrease"
+ [:stable, :devel].each do |spec|
+ attributes.each do |attribute|
+ spec_attribute_map = attributes_map[attribute][spec]
+ next if spec_attribute_map.nil? || spec_attribute_map.empty?
+
+ attributes_for_version = spec_attribute_map[formula.version]
+ next if attributes_for_version.nil? || attributes_for_version.empty?
+
+ if formula.send(attribute) < attributes_for_version.max
+ problem "#{spec} #{attribute} should not decrease"
+ end
end
- end
- versions = attributes_map[:version].values.flatten
- if !versions.empty? && formula.version < versions.max
- problem "version should not decrease"
+ spec_version_scheme_map = attributes_map[:version_scheme][spec]
+ next if spec_version_scheme_map.nil? || spec_version_scheme_map.empty?
+
+ max_version_scheme = spec_version_scheme_map.values.flatten.max
+ max_version = spec_version_scheme_map.select do |_, version_scheme|
+ version_scheme.first == max_version_scheme
+ end.keys.max
+
+ if max_version && formula.version < max_version
+ problem "#{spec} version should not decrease"
+ end
end
return if formula.revision.zero?
if formula.stable
- revision_map = attributes_map[:revision]
+ revision_map = attributes_map[:revision][:stable]
if revision_map[formula.stable.version].empty? # check stable spec
problem "'revision #{formula.revision}' should be removed"
end
diff --git a/Library/Homebrew/dev-cmd/boneyard-formula-pr.rb b/Library/Homebrew/dev-cmd/boneyard-formula-pr.rb
index 487f0c9db..3d95f14b9 100644
--- a/Library/Homebrew/dev-cmd/boneyard-formula-pr.rb
+++ b/Library/Homebrew/dev-cmd/boneyard-formula-pr.rb
@@ -62,7 +62,7 @@ module Homebrew
end
tap_migrations = Utils::JSON.load(File.read(tap_migrations_path))
tap_migrations[formula.name] = boneyard_tap.name
- tap_migrations = tap_migrations.sort.inject({}) { |a, e| a.merge!(e[0] => e[1]) }
+ tap_migrations = tap_migrations.sort.inject({}) { |acc, elem| acc.merge!(elem[0] => elem[1]) }
tap_migrations_path.atomic_write(JSON.pretty_generate(tap_migrations) + "\n")
end
unless which("hub") || local_only
diff --git a/Library/Homebrew/diagnostic.rb b/Library/Homebrew/diagnostic.rb
index e499c4d3b..19148a6ae 100644
--- a/Library/Homebrew/diagnostic.rb
+++ b/Library/Homebrew/diagnostic.rb
@@ -7,24 +7,14 @@ require "utils/shell"
module Homebrew
module Diagnostic
- def self.missing_deps(ff)
+ def self.missing_deps(ff, hide = nil)
missing = {}
ff.each do |f|
- missing_deps = f.recursive_dependencies do |dependent, dep|
- if dep.optional? || dep.recommended?
- tab = Tab.for_formula(dependent)
- Dependency.prune unless tab.with?(dep)
- elsif dep.build?
- Dependency.prune
- end
- end
-
- missing_deps.map!(&:to_formula)
- missing_deps.reject! { |d| d.installed_prefixes.any? }
+ missing_dependencies = f.missing_dependencies(hide: hide)
- unless missing_deps.empty?
- yield f.full_name, missing_deps if block_given?
- missing[f.full_name] = missing_deps
+ unless missing_dependencies.empty?
+ yield f.full_name, missing_dependencies if block_given?
+ missing[f.full_name] = missing_dependencies
end
end
missing
@@ -79,7 +69,7 @@ module Homebrew
end
def inject_file_list(list, string)
- list.inject(string) { |a, e| a << " #{e}\n" }
+ list.inject(string) { |acc, elem| acc << " #{elem}\n" }
end
############# END HELPERS
@@ -358,6 +348,20 @@ module Homebrew
EOS
end
+ def check_access_lock_dir
+ return unless HOMEBREW_LOCK_DIR.exist?
+ return if HOMEBREW_LOCK_DIR.writable_real?
+
+ <<-EOS.undent
+ #{HOMEBREW_LOCK_DIR} isn't writable.
+ Homebrew writes lock files to this location.
+
+ You should change the ownership and permissions of #{HOMEBREW_LOCK_DIR}
+ back to your user account.
+ sudo chown -R $(whoami) #{HOMEBREW_LOCK_DIR}
+ EOS
+ end
+
def check_access_logs
return unless HOMEBREW_LOGS.exist?
return if HOMEBREW_LOGS.writable_real?
diff --git a/Library/Homebrew/extend/ARGV.rb b/Library/Homebrew/extend/ARGV.rb
index 0adf8d548..3e4e7f5c7 100644
--- a/Library/Homebrew/extend/ARGV.rb
+++ b/Library/Homebrew/extend/ARGV.rb
@@ -1,4 +1,29 @@
module HomebrewArgvExtension
+ def formula_install_option_names
+ %w[
+ --debug
+ --env=
+ --ignore-dependencies
+ --cc=
+ --build-from-source
+ --devel
+ --HEAD
+ --keep-tmp
+ --interactive
+ --git
+ --sandbox
+ --no-sandbox
+ --build-bottle
+ --force-bottle
+ --verbose
+ -i
+ -v
+ -d
+ -g
+ -s
+ ].freeze
+ end
+
def named
@named ||= self - options_only
end
@@ -121,6 +146,13 @@ module HomebrewArgvExtension
flag_with_value.strip_prefix(arg_prefix) if flag_with_value
end
+ # Returns an array of values that were given as a comma-seperated list.
+ # @see value
+ def values(name)
+ return unless val = value(name)
+ val.split(",")
+ end
+
def force?
flag? "--force"
end
diff --git a/Library/Homebrew/extend/ENV/shared.rb b/Library/Homebrew/extend/ENV/shared.rb
index 909dc4f94..a93c1ee1f 100644
--- a/Library/Homebrew/extend/ENV/shared.rb
+++ b/Library/Homebrew/extend/ENV/shared.rb
@@ -98,11 +98,12 @@ module SharedEnvExtension
end
def remove(keys, value)
+ return if value.nil?
Array(keys).each do |key|
next unless self[key]
self[key] = self[key].sub(value, "")
delete(key) if self[key].empty?
- end if value
+ end
end
def cc
diff --git a/Library/Homebrew/extend/ENV/std.rb b/Library/Homebrew/extend/ENV/std.rb
index 27dc95d29..14f9b81b8 100644
--- a/Library/Homebrew/extend/ENV/std.rb
+++ b/Library/Homebrew/extend/ENV/std.rb
@@ -11,9 +11,8 @@ module Stdenv
DEFAULT_FLAGS = "-march=core2 -msse4".freeze
def self.extended(base)
- unless ORIGINAL_PATHS.include? HOMEBREW_PREFIX/"bin"
- base.prepend_path "PATH", "#{HOMEBREW_PREFIX}/bin"
- end
+ return if ORIGINAL_PATHS.include? HOMEBREW_PREFIX/"bin"
+ base.prepend_path "PATH", "#{HOMEBREW_PREFIX}/bin"
end
# @private
diff --git a/Library/Homebrew/extend/enumerable.rb b/Library/Homebrew/extend/enumerable.rb
deleted file mode 100644
index fededbfca..000000000
--- a/Library/Homebrew/extend/enumerable.rb
+++ /dev/null
@@ -1,11 +0,0 @@
-module Enumerable
- def flat_map
- return to_enum(:flat_map) unless block_given?
- r = []
- each do |*args|
- result = yield(*args)
- result.respond_to?(:to_ary) ? r.concat(result) : r.push(result)
- end
- r
- end unless method_defined?(:flat_map)
-end
diff --git a/Library/Homebrew/extend/os/mac/diagnostic.rb b/Library/Homebrew/extend/os/mac/diagnostic.rb
index 9c106acf1..db054ea4c 100644
--- a/Library/Homebrew/extend/os/mac/diagnostic.rb
+++ b/Library/Homebrew/extend/os/mac/diagnostic.rb
@@ -233,6 +233,7 @@ module Homebrew
def check_xcode_select_path
return if MacOS::CLT.installed?
+ return unless MacOS::Xcode.installed?
return if File.file?("#{MacOS.active_developer_dir}/usr/bin/xcodebuild")
path = MacOS::Xcode.bundle_path
diff --git a/Library/Homebrew/extend/pathname.rb b/Library/Homebrew/extend/pathname.rb
index 3f73b6a1c..976ea7dd8 100644
--- a/Library/Homebrew/extend/pathname.rb
+++ b/Library/Homebrew/extend/pathname.rb
@@ -148,13 +148,17 @@ class Pathname
open("a", *open_args) { |f| f.puts(content) }
end
- def binwrite(contents, *open_args)
- open("wb", *open_args) { |f| f.write(contents) }
- end unless method_defined?(:binwrite)
+ unless method_defined?(:binwrite)
+ def binwrite(contents, *open_args)
+ open("wb", *open_args) { |f| f.write(contents) }
+ end
+ end
- def binread(*open_args)
- open("rb", *open_args, &:read)
- end unless method_defined?(:binread)
+ unless method_defined?(:binread)
+ def binread(*open_args)
+ open("rb", *open_args, &:read)
+ end
+ end
# NOTE always overwrites
def atomic_write(content)
@@ -353,13 +357,15 @@ class Pathname
File.symlink(src.relative_path_from(dirname), self)
end
- def /(other)
- unless other.respond_to?(:to_str) || other.respond_to?(:to_path)
- opoo "Pathname#/ called on #{inspect} with #{other.inspect} as an argument"
- puts "This behavior is deprecated, please pass either a String or a Pathname"
+ unless method_defined?(:/)
+ def /(other)
+ unless other.respond_to?(:to_str) || other.respond_to?(:to_path)
+ opoo "Pathname#/ called on #{inspect} with #{other.inspect} as an argument"
+ puts "This behavior is deprecated, please pass either a String or a Pathname"
+ end
+ self + other.to_s
end
- self + other.to_s
- end unless method_defined?(:/)
+ end
# @private
def ensure_writable
diff --git a/Library/Homebrew/formula.rb b/Library/Homebrew/formula.rb
index ab05548a8..5434d87c2 100644
--- a/Library/Homebrew/formula.rb
+++ b/Library/Homebrew/formula.rb
@@ -1337,6 +1337,13 @@ class Formula
end
end
+ # Clear caches of .racks and .installed.
+ # @private
+ def self.clear_cache
+ @racks = nil
+ @installed = nil
+ end
+
# An array of all racks currently installed.
# @private
def self.racks
@@ -1459,6 +1466,26 @@ class Formula
recursive_dependencies.reject(&:build?)
end
+ # Returns a list of formulae depended on by this formula that aren't
+ # installed
+ def missing_dependencies(hide: nil)
+ hide ||= []
+ missing_dependencies = recursive_dependencies do |dependent, dep|
+ if dep.optional? || dep.recommended?
+ tab = Tab.for_formula(dependent)
+ Dependency.prune unless tab.with?(dep)
+ elsif dep.build?
+ Dependency.prune
+ end
+ end
+
+ missing_dependencies.map!(&:to_formula)
+ missing_dependencies.select! do |d|
+ hide.include?(d.name) || d.installed_prefixes.empty?
+ end
+ missing_dependencies
+ end
+
# @private
def to_hash
hsh = {
diff --git a/Library/Homebrew/formula_installer.rb b/Library/Homebrew/formula_installer.rb
index c25702059..c05b0da60 100644
--- a/Library/Homebrew/formula_installer.rb
+++ b/Library/Homebrew/formula_installer.rb
@@ -31,7 +31,7 @@ class FormulaInstaller
end
attr_reader :formula
- attr_accessor :options, :build_bottle
+ attr_accessor :options, :build_bottle, :invalid_option_names
mode_attr_accessor :show_summary_heading, :show_header
mode_attr_accessor :build_from_source, :force_bottle
mode_attr_accessor :ignore_deps, :only_deps, :interactive, :git
@@ -51,6 +51,7 @@ class FormulaInstaller
@quieter = false
@debug = false
@options = Options.new
+ @invalid_option_names = []
@@attempted ||= Set.new
@@ -213,6 +214,10 @@ class FormulaInstaller
opoo "#{formula.full_name}: #{old_flag} was deprecated; using #{new_flag} instead!"
end
+ invalid_option_names.each do |option|
+ opoo "#{formula.full_name}: this formula has no #{option} option so it will be ignored!"
+ end
+
oh1 "Installing #{Formatter.identifier(formula.full_name)}" if show_header?
if formula.tap && !formula.tap.private?
@@ -457,6 +462,7 @@ class FormulaInstaller
fi.options |= tab.used_options
fi.options |= Tab.remap_deprecated_options(df.deprecated_options, dep.options)
fi.options |= inherited_options
+ fi.options &= df.options
fi.build_from_source = ARGV.build_formula_from_source?(df)
fi.verbose = verbose? && !quieter?
fi.debug = debug?
@@ -808,9 +814,11 @@ class FormulaInstaller
def lock
return unless (@@locked ||= []).empty?
- formula.recursive_dependencies.each do |dep|
- @@locked << dep.to_formula
- end unless ignore_deps?
+ unless ignore_deps?
+ formula.recursive_dependencies.each do |dep|
+ @@locked << dep.to_formula
+ end
+ end
@@locked.unshift(formula)
@@locked.uniq!
@@locked.each(&:lock)
diff --git a/Library/Homebrew/formula_versions.rb b/Library/Homebrew/formula_versions.rb
index d9a082399..28c2a3be8 100644
--- a/Library/Homebrew/formula_versions.rb
+++ b/Library/Homebrew/formula_versions.rb
@@ -61,19 +61,28 @@ class FormulaVersions
def version_attributes_map(attributes, branch)
attributes_map = {}
return attributes_map if attributes.empty?
+
attributes.each do |attribute|
- attributes_map[attribute] = Hash.new { |h, k| h[k] = [] }
+ attributes_map[attribute] ||= {}
end
rev_list(branch) do |rev|
formula_at_revision(rev) do |f|
attributes.each do |attribute|
map = attributes_map[attribute]
- map[f.stable.version] << f.send(attribute) if f.stable
- map[f.devel.version] << f.send(attribute) if f.devel
+ if f.stable
+ map[:stable] ||= {}
+ map[:stable][f.stable.version] ||= []
+ map[:stable][f.stable.version] << f.send(attribute)
+ end
+ next unless f.devel
+ map[:devel] ||= {}
+ map[:devel][f.devel.version] ||= []
+ map[:devel][f.devel.version] << f.send(attribute)
end
end
end
+
attributes_map
end
end
diff --git a/Library/Homebrew/formulary.rb b/Library/Homebrew/formulary.rb
index 4d6832e44..772f4c902 100644
--- a/Library/Homebrew/formulary.rb
+++ b/Library/Homebrew/formulary.rb
@@ -158,8 +158,9 @@ class Formulary
class TapLoader < FormulaLoader
attr_reader :tap
- def initialize(tapped_name)
- name, path = formula_name_path(tapped_name)
+ def initialize(tapped_name, from: nil)
+ warn = ![:keg, :rack].include?(from)
+ name, path = formula_name_path(tapped_name, warn: warn)
super name, path
end
@@ -236,8 +237,8 @@ class Formulary
# * a formula pathname
# * a formula URL
# * a local bottle reference
- def self.factory(ref, spec = :stable, alias_path: nil)
- loader_for(ref).get_formula(spec, alias_path: alias_path)
+ def self.factory(ref, spec = :stable, alias_path: nil, from: nil)
+ loader_for(ref, from: from).get_formula(spec, alias_path: alias_path)
end
# Return a Formula instance for the given rack.
@@ -253,7 +254,7 @@ class Formulary
if keg
from_keg(keg, spec, alias_path: alias_path)
else
- factory(rack.basename.to_s, spec || :stable, alias_path: alias_path)
+ factory(rack.basename.to_s, spec || :stable, alias_path: alias_path, from: :rack)
end
end
@@ -265,13 +266,13 @@ class Formulary
spec ||= tab.spec
f = if tap.nil?
- factory(keg.rack.basename.to_s, spec, alias_path: alias_path)
+ factory(keg.rack.basename.to_s, spec, alias_path: alias_path, from: :keg)
else
begin
- factory("#{tap}/#{keg.rack.basename}", spec, alias_path: alias_path)
+ factory("#{tap}/#{keg.rack.basename}", spec, alias_path: alias_path, from: :keg)
rescue FormulaUnavailableError
# formula may be migrated to different tap. Try to search in core and all taps.
- factory(keg.rack.basename.to_s, spec, alias_path: alias_path)
+ factory(keg.rack.basename.to_s, spec, alias_path: alias_path, from: :keg)
end
end
f.build = tab
@@ -309,14 +310,14 @@ class Formulary
loader_for(ref).path
end
- def self.loader_for(ref)
+ def self.loader_for(ref, from: nil)
case ref
when %r{(https?|ftp|file)://}
return FromUrlLoader.new(ref)
when Pathname::BOTTLE_EXTNAME_RX
return BottleLoader.new(ref)
when HOMEBREW_TAP_FORMULA_REGEX
- return TapLoader.new(ref)
+ return TapLoader.new(ref, from: from)
end
return FromPathLoader.new(ref) if File.extname(ref) == ".rb"
@@ -359,7 +360,7 @@ class Formulary
end
unless possible_tap_newname_formulae.empty?
- return TapLoader.new(possible_tap_newname_formulae.first)
+ return TapLoader.new(possible_tap_newname_formulae.first, from: from)
end
possible_cached_formula = Pathname.new("#{HOMEBREW_CACHE_FORMULA}/#{ref}.rb")
diff --git a/Library/Homebrew/global.rb b/Library/Homebrew/global.rb
index bf700b095..eabc4c164 100644
--- a/Library/Homebrew/global.rb
+++ b/Library/Homebrew/global.rb
@@ -4,7 +4,6 @@ require "extend/pathname"
require "extend/git_repository"
require "extend/ARGV"
require "extend/string"
-require "extend/enumerable"
require "os"
require "utils"
require "exceptions"
diff --git a/Library/Homebrew/keg.rb b/Library/Homebrew/keg.rb
index d2c9e12e8..f1275e748 100644
--- a/Library/Homebrew/keg.rb
+++ b/Library/Homebrew/keg.rb
@@ -87,6 +87,48 @@ class Keg
mime-info pixmaps sounds postgresql
].freeze
+ # Will return some kegs, and some dependencies, if they're present.
+ # For efficiency, we don't bother trying to get complete data.
+ def self.find_some_installed_dependents(kegs)
+ # First, check in the tabs of installed Formulae.
+ kegs.each do |keg|
+ dependents = keg.installed_dependents - kegs
+ dependents.map! { |d| "#{d.name} #{d.version}" }
+ return [keg], dependents if dependents.any?
+ end
+
+ # Some kegs won't have modern Tabs with the dependencies listed.
+ # In this case, fall back to Formula#missing_dependencies.
+
+ # Find formulae that didn't have dependencies saved in all of their kegs,
+ # so need them to be calculated now.
+ #
+ # This happens after the initial dependency check because it's sloooow.
+ remaining_formulae = Formula.installed.select do |f|
+ f.installed_kegs.any? { |k| Tab.for_keg(k).runtime_dependencies.nil? }
+ end
+
+ keg_names = kegs.map(&:name)
+ kegs_by_source = kegs.group_by { |k| [k.name, Tab.for_keg(k).tap] }
+
+ remaining_formulae.each do |dependent|
+ required = dependent.missing_dependencies(hide: keg_names)
+
+ required_kegs = required.map do |f|
+ f_kegs = kegs_by_source[[f.name, f.tap]]
+ next unless f_kegs
+
+ f_kegs.sort_by(&:version).last
+ end
+
+ next unless required_kegs.any?
+
+ return required_kegs, [dependent.to_s]
+ end
+
+ nil
+ end
+
# if path is a file in a keg then this will return the containing Keg object
def self.for(path)
path = path.realpath
@@ -292,6 +334,23 @@ class Keg
PkgVersion.parse(path.basename.to_s)
end
+ def to_formula
+ Formulary.from_keg(self)
+ end
+
+ def installed_dependents
+ Formula.installed.flat_map(&:installed_kegs).select do |keg|
+ tab = Tab.for_keg(keg)
+ next if tab.runtime_dependencies.nil? # no dependency information saved.
+ tab.runtime_dependencies.any? do |dep|
+ # Resolve formula rather than directly comparing names
+ # in case of conflicts between formulae from different taps.
+ dep_formula = Formulary.factory(dep["full_name"])
+ dep_formula == to_formula && dep["version"] == version.to_s
+ end
+ end
+ end
+
def find(*args, &block)
path.find(*args, &block)
end
diff --git a/Library/Homebrew/os/mac/xcode.rb b/Library/Homebrew/os/mac/xcode.rb
index f081d4382..67cd8f54d 100644
--- a/Library/Homebrew/os/mac/xcode.rb
+++ b/Library/Homebrew/os/mac/xcode.rb
@@ -38,15 +38,15 @@ module OS
def prerelease?
# TODO: bump to version >= "8.3" after Xcode 8.2 is stable.
- version >= "8.2"
+ Version.new(version) >= "8.2"
end
def outdated?
- version < latest_version
+ Version.new(version) < latest_version
end
def without_clt?
- installed? && version >= "4.3" && !MacOS::CLT.installed?
+ installed? && Version.new(version) >= "4.3" && !MacOS::CLT.installed?
end
# Returns a Pathname object corresponding to Xcode.app's Developer
@@ -67,7 +67,7 @@ module OS
end
def toolchain_path
- Pathname.new("#{prefix}/Toolchains/XcodeDefault.xctoolchain") if installed? && version >= "4.3"
+ Pathname.new("#{prefix}/Toolchains/XcodeDefault.xctoolchain") if installed? && Version.new(version) >= "4.3"
end
# Ask Spotlight where Xcode is. If the user didn't install the
@@ -82,7 +82,7 @@ module OS
end
def update_instructions
- if MacOS.version >= "10.9" && !OS::Mac.prerelease?
+ if Version.new(MacOS.version) >= "10.9" && !OS::Mac.prerelease?
<<-EOS.undent
Xcode can be updated from the App Store.
EOS
@@ -156,20 +156,26 @@ module OS
end
def provides_gcc?
- installed? && version < "4.3"
+ installed? && Version.new(version) < "4.3"
end
def provides_cvs?
- installed? && version < "5.0"
+ installed? && Version.new(version) < "5.0"
end
def default_prefix?
- if version < "4.3"
+ if Version.new(version) < "4.3"
prefix.to_s.start_with? "/Developer"
else
prefix.to_s == "/Applications/Xcode.app/Contents/Developer"
end
end
+
+ class Version < ::Version
+ def <=>(other)
+ super(Version.new(other))
+ end
+ end
end
module CLT
@@ -188,7 +194,7 @@ module OS
end
def update_instructions
- if MacOS.version >= "10.9"
+ if Xcode::Version.new(MacOS.version) >= "10.9"
<<-EOS.undent
Update them from Software Update in the App Store.
EOS
@@ -206,7 +212,7 @@ module OS
# on the older supported platform for that Xcode release, i.e there's no
# CLT package for 10.11 that contains the Clang version from Xcode 8.
case MacOS.version
- when "10.12" then "800.0.38"
+ when "10.12" then "800.0.42.1"
when "10.11" then "703.0.31"
when "10.10" then "700.1.81"
when "10.9" then "600.0.57"
@@ -228,13 +234,13 @@ module OS
end
def outdated?
- if MacOS.version >= :mavericks
+ if Xcode::Version.new(MacOS.version) >= :mavericks.to_s
version = Utils.popen_read("#{MAVERICKS_PKG_PATH}/usr/bin/clang --version")
else
version = Utils.popen_read("/usr/bin/clang --version")
end
version = version[/clang-(\d+\.\d+\.\d+(\.\d+)?)/, 1] || "0"
- version < latest_version
+ Xcode::Version.new(version) < latest_version
end
# Version string (a pretty long one) of the CLT package.
@@ -247,10 +253,10 @@ module OS
def detect_version
# CLT isn't a distinct entity pre-4.3, and pkgutil doesn't exist
# at all on Tiger, so just count it as installed if Xcode is installed
- return MacOS::Xcode.version if MacOS::Xcode.installed? && MacOS::Xcode.version < "3.0"
+ return MacOS::Xcode.version if MacOS::Xcode.installed? && Xcode::Version.new(MacOS::Xcode.version) < "3.0"
[MAVERICKS_PKG_ID, MAVERICKS_NEW_PKG_ID, STANDALONE_PKG_ID, FROM_XCODE_PKG_ID].find do |id|
- if MacOS.version >= :mavericks
+ if Xcode::Version.new(MacOS.version) >= :mavericks.to_s
next unless File.exist?("#{MAVERICKS_PKG_PATH}/usr/bin/clang")
end
version = MacOS.pkgutil_info(id)[/version: (.+)$/, 1]
diff --git a/Library/Homebrew/sandbox.rb b/Library/Homebrew/sandbox.rb
index 4d0709cb4..9597dafa8 100644
--- a/Library/Homebrew/sandbox.rb
+++ b/Library/Homebrew/sandbox.rb
@@ -27,10 +27,9 @@ class Sandbox
end
def self.print_sandbox_message
- unless @printed_sandbox_message
- ohai "Using the sandbox"
- @printed_sandbox_message = true
- end
+ return if @printed_sandbox_message
+ ohai "Using the sandbox"
+ @printed_sandbox_message = true
end
def initialize
diff --git a/Library/Homebrew/shims/super/cc b/Library/Homebrew/shims/super/cc
index db6361f04..1552f412d 100755
--- a/Library/Homebrew/shims/super/cc
+++ b/Library/Homebrew/shims/super/cc
@@ -160,7 +160,7 @@ class Cmd
"-fcaller-saves", "-fthread-jumps", "-fno-reorder-blocks", "-fcse-skip-blocks",
"-frerun-cse-after-loop", "-frerun-loop-opt", "-fcse-follow-jumps",
"-fno-regmove", "-fno-for-scope", "-fno-tree-pre", "-fno-tree-dominator-opts",
- "-fuse-linker-plugin"
+ "-fuse-linker-plugin", "-frounding-math"
# clang doesn't support these flags
args << arg unless tool =~ /^clang/
when "--fast-math"
diff --git a/Library/Homebrew/test/helper/integration_command_test_case.rb b/Library/Homebrew/test/helper/integration_command_test_case.rb
index 20c0fc48e..2f137e14a 100644
--- a/Library/Homebrew/test/helper/integration_command_test_case.rb
+++ b/Library/Homebrew/test/helper/integration_command_test_case.rb
@@ -73,10 +73,12 @@ class IntegrationCommandTestCase < Homebrew::TestCase
cmd_args << "-rintegration_mocks"
cmd_args << (HOMEBREW_LIBRARY_PATH/"brew.rb").resolved_path.to_s
cmd_args += args
+ developer = ENV["HOMEBREW_DEVELOPER"]
Bundler.with_original_env do
ENV["HOMEBREW_BREW_FILE"] = HOMEBREW_PREFIX/"bin/brew"
ENV["HOMEBREW_INTEGRATION_TEST"] = cmd_id_from_args(args)
ENV["HOMEBREW_TEST_TMPDIR"] = TEST_TMPDIR
+ ENV["HOMEBREW_DEVELOPER"] = developer
env.each_pair do |k, v|
ENV[k] = v
end
@@ -127,7 +129,6 @@ class IntegrationCommandTestCase < Homebrew::TestCase
sha256 "#{TESTBALL_SHA256}"
option "with-foo", "Build with foo"
- #{content}
def install
(prefix/"foo"/"test").write("test") if build.with? "foo"
@@ -138,6 +139,8 @@ class IntegrationCommandTestCase < Homebrew::TestCase
system ENV.cc, "test.c", "-o", bin/"test"
end
+ #{content}
+
# something here
EOS
when "foo"
diff --git a/Library/Homebrew/test/test_ARGV.rb b/Library/Homebrew/test/test_ARGV.rb
index 39f32f452..6805e0c62 100644
--- a/Library/Homebrew/test/test_ARGV.rb
+++ b/Library/Homebrew/test/test_ARGV.rb
@@ -62,4 +62,19 @@ class ArgvExtensionTests < Homebrew::TestCase
assert !@argv.flag?("--frotz")
assert !@argv.flag?("--debug")
end
+
+ def test_value
+ @argv << "--foo=" << "--bar=ab"
+ assert_equal "", @argv.value("foo")
+ assert_equal "ab", @argv.value("bar")
+ assert_nil @argv.value("baz")
+ end
+
+ def test_values
+ @argv << "--foo=" << "--bar=a" << "--baz=b,c"
+ assert_equal [], @argv.values("foo")
+ assert_equal ["a"], @argv.values("bar")
+ assert_equal ["b", "c"], @argv.values("baz")
+ assert_nil @argv.values("qux")
+ end
end
diff --git a/Library/Homebrew/test/test_build_options.rb b/Library/Homebrew/test/test_build_options.rb
index dab418792..e460d25cc 100644
--- a/Library/Homebrew/test/test_build_options.rb
+++ b/Library/Homebrew/test/test_build_options.rb
@@ -7,6 +7,8 @@ class BuildOptionsTests < Homebrew::TestCase
args = Options.create(%w[--with-foo --with-bar --without-qux])
opts = Options.create(%w[--with-foo --with-bar --without-baz --without-qux])
@build = BuildOptions.new(args, opts)
+ bad_args = Options.create(%w[--with-foo --with-bar --without-bas --without-qux --without-abc])
+ @bad_build = BuildOptions.new(bad_args, opts)
end
def test_include
@@ -31,4 +33,17 @@ class BuildOptionsTests < Homebrew::TestCase
def test_unused_options
assert_includes @build.unused_options, "--without-baz"
end
+
+ def test_invalid_options
+ assert_empty @build.invalid_options
+ assert_includes @bad_build.invalid_options, "--without-bas"
+ assert_includes @bad_build.invalid_options, "--without-abc"
+ refute_includes @bad_build.invalid_options, "--with-foo"
+ refute_includes @bad_build.invalid_options, "--with-baz"
+ end
+
+ def test_invalid_option_names
+ assert_empty @build.invalid_option_names
+ assert_equal @bad_build.invalid_option_names, %w[--without-abc --without-bas]
+ end
end
diff --git a/Library/Homebrew/test/test_formula_installer.rb b/Library/Homebrew/test/test_formula_installer.rb
index 5b937d1df..18bd910a6 100644
--- a/Library/Homebrew/test/test_formula_installer.rb
+++ b/Library/Homebrew/test/test_formula_installer.rb
@@ -37,6 +37,7 @@ class InstallTests < Homebrew::TestCase
end
def test_a_basic_install
+ ARGV << "--with-invalid_flag" # added to ensure it doesn't fail install
temporary_install(Testball.new) do |f|
# Test that things made it into the Keg
assert_predicate f.prefix+"readme", :exist?
diff --git a/Library/Homebrew/test/test_hardware.rb b/Library/Homebrew/test/test_hardware.rb
index 56d0980fa..2bea5387d 100644
--- a/Library/Homebrew/test/test_hardware.rb
+++ b/Library/Homebrew/test/test_hardware.rb
@@ -6,8 +6,10 @@ class HardwareTests < Homebrew::TestCase
assert_includes [:intel, :ppc, :dunno], Hardware::CPU.type
end
- def test_hardware_intel_family
- families = [:core, :core2, :penryn, :nehalem, :arrandale, :sandybridge, :ivybridge, :haswell, :broadwell, :skylake, :dunno]
- assert_includes families, Hardware::CPU.family
- end if Hardware::CPU.intel?
+ if Hardware::CPU.intel?
+ def test_hardware_intel_family
+ families = [:core, :core2, :penryn, :nehalem, :arrandale, :sandybridge, :ivybridge, :haswell, :broadwell, :skylake, :dunno]
+ assert_includes families, Hardware::CPU.family
+ end
+ end
end
diff --git a/Library/Homebrew/test/test_install.rb b/Library/Homebrew/test/test_install.rb
index 5d27d978b..7135dddb2 100644
--- a/Library/Homebrew/test/test_install.rb
+++ b/Library/Homebrew/test/test_install.rb
@@ -21,4 +21,10 @@ class IntegrationCommandTestInstall < IntegrationCommandTestCase
assert_match "testball1 already installed, it's just not migrated",
cmd("install", "testball2")
end
+
+ def test_install_with_invalid_option
+ setup_test_formula "testball1"
+ assert_match "testball1: this formula has no --with-fo option so it will be ignored!",
+ cmd("install", "testball1", "--with-fo")
+ end
end
diff --git a/Library/Homebrew/test/test_keg.rb b/Library/Homebrew/test/test_keg.rb
index 3abf3fc27..fdc739c9d 100644
--- a/Library/Homebrew/test/test_keg.rb
+++ b/Library/Homebrew/test/test_keg.rb
@@ -5,15 +5,22 @@ require "stringio"
class LinkTests < Homebrew::TestCase
include FileUtils
- def setup
- keg = HOMEBREW_CELLAR.join("foo", "1.0")
- keg.join("bin").mkpath
+ def setup_test_keg(name, version)
+ path = HOMEBREW_CELLAR.join(name, version)
+ path.join("bin").mkpath
%w[hiworld helloworld goodbye_cruel_world].each do |file|
- touch keg.join("bin", file)
+ touch path.join("bin", file)
end
- @keg = Keg.new(keg)
+ keg = Keg.new(path)
+ @kegs ||= []
+ @kegs << keg
+ keg
+ end
+
+ def setup
+ @keg = setup_test_keg("foo", "1.0")
@dst = HOMEBREW_PREFIX.join("bin", "helloworld")
@nonexistent = Pathname.new("/some/nonexistent/path")
@@ -27,8 +34,10 @@ class LinkTests < Homebrew::TestCase
end
def teardown
- @keg.unlink
- @keg.uninstall
+ @kegs.each do |keg|
+ keg.unlink
+ keg.uninstall
+ end
$stdout = @old_stdout
@@ -305,3 +314,87 @@ class LinkTests < Homebrew::TestCase
keg.uninstall
end
end
+
+class InstalledDependantsTests < LinkTests
+ def stub_formula_name(name)
+ f = formula(name) { url "foo-1.0" }
+ stub_formula_loader f
+ stub_formula_loader f, "homebrew/core/#{f}"
+ f
+ end
+
+ def setup_test_keg(name, version)
+ f = stub_formula_name(name)
+ keg = super
+ Tab.create(f, DevelopmentTools.default_compiler, :libcxx).write
+ Formula.clear_cache
+ keg
+ end
+
+ def setup
+ super
+ @dependent = setup_test_keg("bar", "1.0")
+ end
+
+ def alter_tab(keg = @dependent)
+ tab = Tab.for_keg(keg)
+ yield tab
+ tab.write
+ end
+
+ def dependencies(deps)
+ alter_tab do |tab|
+ tab.tabfile = @dependent.join("INSTALL_RECEIPT.json")
+ tab.runtime_dependencies = deps
+ end
+ end
+
+ # Test with a keg whose formula isn't known.
+ # This can happen if e.g. a formula is installed
+ # from a file path or URL.
+ def test_unknown_formula
+ Formulary.unstub(:loader_for)
+ dependencies []
+ alter_tab { |t| t.source["path"] = nil }
+ assert_empty @keg.installed_dependents
+ assert_nil Keg.find_some_installed_dependents([@keg])
+ end
+
+ def test_no_dependencies_anywhere
+ dependencies nil
+ assert_empty @keg.installed_dependents
+ assert_nil Keg.find_some_installed_dependents([@keg])
+ end
+
+ def test_missing_formula_dependency
+ dependencies nil
+ Formula["bar"].class.depends_on "foo"
+ assert_empty @keg.installed_dependents
+ assert_equal [[@keg], ["bar"]], Keg.find_some_installed_dependents([@keg])
+ end
+
+ def test_empty_dependencies_in_tab
+ dependencies []
+ assert_empty @keg.installed_dependents
+ assert_nil Keg.find_some_installed_dependents([@keg])
+ end
+
+ def test_same_name_different_version_in_tab
+ dependencies [{ "full_name" => "foo", "version" => "1.1" }]
+ assert_empty @keg.installed_dependents
+ assert_nil Keg.find_some_installed_dependents([@keg])
+ end
+
+ def test_different_name_same_version_in_tab
+ stub_formula_name("baz")
+ dependencies [{ "full_name" => "baz", "version" => @keg.version.to_s }]
+ assert_empty @keg.installed_dependents
+ assert_nil Keg.find_some_installed_dependents([@keg])
+ end
+
+ def test_same_name_and_version_in_tab
+ dependencies [{ "full_name" => "foo", "version" => "1.0" }]
+ assert_equal [@dependent], @keg.installed_dependents
+ assert_equal [[@keg], ["bar 1.0"]], Keg.find_some_installed_dependents([@keg])
+ end
+end
diff --git a/Library/Homebrew/test/test_missing.rb b/Library/Homebrew/test/test_missing.rb
index 3a5fd3df0..565f413da 100644
--- a/Library/Homebrew/test/test_missing.rb
+++ b/Library/Homebrew/test/test_missing.rb
@@ -1,11 +1,34 @@
require "helper/integration_command_test_case"
class IntegrationCommandTestMissing < IntegrationCommandTestCase
- def test_missing
+ def setup
+ super
+
setup_test_formula "foo"
setup_test_formula "bar"
+ end
+
+ def make_prefix(name)
+ (HOMEBREW_CELLAR/name/"1.0").mkpath
+ end
+
+ def test_missing_missing
+ make_prefix "bar"
- (HOMEBREW_CELLAR/"bar/1.0").mkpath
assert_match "foo", cmd("missing")
end
+
+ def test_missing_not_missing
+ make_prefix "foo"
+ make_prefix "bar"
+
+ assert_empty cmd("missing")
+ end
+
+ def test_missing_hide
+ make_prefix "foo"
+ make_prefix "bar"
+
+ assert_match "foo", cmd("missing", "--hide=foo")
+ end
end
diff --git a/Library/Homebrew/test/test_uninstall.rb b/Library/Homebrew/test/test_uninstall.rb
index 050934238..a7859b7ad 100644
--- a/Library/Homebrew/test/test_uninstall.rb
+++ b/Library/Homebrew/test/test_uninstall.rb
@@ -1,4 +1,26 @@
require "helper/integration_command_test_case"
+require "cmd/uninstall"
+
+class UninstallTests < Homebrew::TestCase
+ def test_check_for_testball_f2s_when_developer
+ refute_predicate Homebrew, :should_check_for_dependents?
+ end
+
+ def test_check_for_dependents_when_not_developer
+ run_as_not_developer do
+ assert_predicate Homebrew, :should_check_for_dependents?
+ end
+ end
+
+ def test_check_for_dependents_when_ignore_dependencies
+ ARGV << "--ignore-dependencies"
+ run_as_not_developer do
+ refute_predicate Homebrew, :should_check_for_dependents?
+ end
+ ensure
+ ARGV.delete("--ignore-dependencies")
+ end
+end
class IntegrationCommandTestUninstall < IntegrationCommandTestCase
def test_uninstall
diff --git a/Library/Homebrew/test/testing_env.rb b/Library/Homebrew/test/testing_env.rb
index 4f2619464..3fbf3e4b5 100644
--- a/Library/Homebrew/test/testing_env.rb
+++ b/Library/Homebrew/test/testing_env.rb
@@ -119,7 +119,8 @@ module Homebrew
def stub_formula_loader(formula, ref = formula.full_name)
loader = mock
loader.stubs(:get_formula).returns(formula)
- Formulary.stubs(:loader_for).with(ref).returns(loader)
+ Formulary.stubs(:loader_for).with(ref, from: :keg).returns(loader)
+ Formulary.stubs(:loader_for).with(ref, from: nil).returns(loader)
end
end
end
diff --git a/Library/Homebrew/utils/lock.sh b/Library/Homebrew/utils/lock.sh
index cc041fa74..7f0638c1a 100644
--- a/Library/Homebrew/utils/lock.sh
+++ b/Library/Homebrew/utils/lock.sh
@@ -6,6 +6,14 @@ lock() {
local lock_dir="$HOMEBREW_PREFIX/var/homebrew/locks"
local lock_file="$lock_dir/$name"
[[ -d "$lock_dir" ]] || mkdir -p "$lock_dir"
+ if ! [[ -w "$lock_dir" ]]
+ then
+ odie <<EOS
+Can't create $name lock in $lock_dir!
+Fix permissions by running:
+ sudo chown -R \$(whoami) $HOMEBREW_PREFIX/var/homebrew
+EOS
+ fi
# 200 is the file descriptor used in the lock.
# This FD should be used exclusively for lock purpose.
# Any value except 0(stdin), 1(stdout) and 2(stderr) can do the job.
@@ -17,10 +25,10 @@ lock() {
exec 200>&-
# open the lock file to FD, so the shell process can hold the lock.
exec 200>"$lock_file"
- if ! _create_lock 200
+ if ! _create_lock 200 "$name"
then
odie <<EOS
-Another active Homebrew process is already in progress.
+Another active Homebrew $name process is already in progress.
Please wait for it to finish or terminate it to continue.
EOS
fi
@@ -28,6 +36,7 @@ EOS
_create_lock() {
local lock_fd="$1"
+ local name="$2"
local ruby="/usr/bin/ruby"
[[ -x "$ruby" ]] || ruby="$(which ruby 2>/dev/null)"
@@ -38,6 +47,6 @@ _create_lock() {
then
flock -n "$lock_fd"
else
- onoe "Cannot create lock, please avoid running brew in parallel."
+ onoe "Cannot create $name lock, please avoid running Homebrew in parallel."
fi
}