diff options
Diffstat (limited to 'Library/Homebrew')
105 files changed, 686 insertions, 792 deletions
diff --git a/Library/Homebrew/brew.rb b/Library/Homebrew/brew.rb index 7222f7e87..11ea8df67 100644 --- a/Library/Homebrew/brew.rb +++ b/Library/Homebrew/brew.rb @@ -10,7 +10,8 @@ raise "Homebrew must be run under Ruby 2!" unless RUBY_TWO require "pathname" HOMEBREW_LIBRARY_PATH = Pathname.new(__FILE__).realpath.parent -$:.unshift(HOMEBREW_LIBRARY_PATH.to_s) +require "English" +$LOAD_PATH.unshift(HOMEBREW_LIBRARY_PATH.to_s) require "global" require "tap" @@ -20,14 +21,6 @@ if ARGV == %w[--version] || ARGV == %w[-v] exit 0 end -def require?(path) - return false if path.nil? - require path -rescue LoadError => e - # we should raise on syntax errors but not if the file doesn't exist. - raise unless e.message.include?(path) -end - begin trap("INT", std_trap) # restore default CTRL-C handler @@ -134,17 +127,15 @@ rescue Interrupt $stderr.puts # seemingly a newline is typical exit 130 rescue BuildError => e - Utils::Analytics.report_exception(e) + Utils::Analytics.report_build_error(e) e.dump exit 1 rescue RuntimeError, SystemCallError => e - Utils::Analytics.report_exception(e) raise if e.message.empty? onoe e $stderr.puts e.backtrace if ARGV.debug? exit 1 rescue MethodDeprecatedError => e - Utils::Analytics.report_exception(e) onoe e if e.issues_url $stderr.puts "If reporting this issue please do so at (not Homebrew/brew or Homebrew/core):" @@ -152,9 +143,9 @@ rescue MethodDeprecatedError => e end exit 1 rescue Exception => e - Utils::Analytics.report_exception(e) onoe e - if internal_cmd && defined?(OS::ISSUES_URL) + if internal_cmd && defined?(OS::ISSUES_URL) && + !ENV["HOMEBREW_NO_AUTO_UPDATE"] $stderr.puts "#{Tty.bold}Please report this bug:#{Tty.reset}" $stderr.puts " #{Formatter.url(OS::ISSUES_URL)}" end diff --git a/Library/Homebrew/brew.sh b/Library/Homebrew/brew.sh index b76280099..97c3b7f86 100644 --- a/Library/Homebrew/brew.sh +++ b/Library/Homebrew/brew.sh @@ -278,7 +278,6 @@ fi # shellcheck source=/dev/null source "$HOMEBREW_LIBRARY/Homebrew/utils/analytics.sh" setup-analytics -report-analytics-screenview-command # Let user know we're still updating Homebrew if brew update --preinstall # exceeds 3 seconds. diff --git a/Library/Homebrew/cask/lib/hbc/cask_loader.rb b/Library/Homebrew/cask/lib/hbc/cask_loader.rb index a0c44d9b4..43fd9080d 100644 --- a/Library/Homebrew/cask/lib/hbc/cask_loader.rb +++ b/Library/Homebrew/cask/lib/hbc/cask_loader.rb @@ -32,9 +32,9 @@ module Hbc end def load - raise CaskError, "'#{@path}' does not exist." unless @path.exist? - raise CaskError, "'#{@path}' is not readable." unless @path.readable? - raise CaskError, "'#{@path}' is not a file." unless @path.file? + raise CaskUnavailableError.new(@token, "'#{@path}' does not exist.") unless @path.exist? + raise CaskUnavailableError.new(@token, "'#{@path}' is not readable.") unless @path.readable? + raise CaskUnavailableError.new(@token, "'#{@path}' is not a file.") unless @path.file? @content = IO.read(@path) @@ -45,7 +45,7 @@ module Hbc def cask(header_token, &block) if @token != header_token - raise CaskTokenDoesNotMatchError.new(@token, header_token) + raise CaskTokenMismatchError.new(@token, header_token) end Cask.new(header_token, sourcefile_path: @path, &block) @@ -57,10 +57,11 @@ module Hbc ref.to_s.match?(::URI.regexp) end + attr_reader :url + def initialize(url) - @url = url - uri = URI(url) - super Hbc.cache/File.basename(uri.path) + @url = URI(url) + super Hbc.cache/File.basename(@url.path) end def load @@ -71,7 +72,7 @@ module Hbc ohai "Downloading #{@url}." curl @url, "-o", @path rescue ErrorDuringExecution - raise CaskUnavailableError, @url + raise CaskUnavailableError.new(@token, "Failed to download #{Formatter.url(@url)}.") end super @@ -108,7 +109,7 @@ module Hbc end def load - raise CaskUnavailableError, @token + raise CaskUnavailableError.new(@token, "No Cask with this name exists.") end end diff --git a/Library/Homebrew/cask/lib/hbc/cli.rb b/Library/Homebrew/cask/lib/hbc/cli.rb index 99980b88d..0108c1621 100644 --- a/Library/Homebrew/cask/lib/hbc/cli.rb +++ b/Library/Homebrew/cask/lib/hbc/cli.rb @@ -66,7 +66,7 @@ module Hbc option "--help", :help, false # handled in OS::Mac - option "--language a,b,c", ->(*) { raise OptionParser::InvalidOption } + option "--language a,b,c", ->(*) {} # override default handling of --version option "--version", ->(*) { raise OptionParser::InvalidOption } @@ -92,10 +92,10 @@ module Hbc command.is_a?(Class) && !command.abstract? && command.needs_init? end - def self.run_command(command, *rest) + def self.run_command(command, *args) if command.respond_to?(:run) # usual case: built-in command verb - command.run(*rest) + command.run(*args) elsif require?(which("brewcask-#{command}.rb")) # external command as Ruby library on PATH, Homebrew-style elsif command.to_s.include?("/") && require?(command.to_s) @@ -111,7 +111,7 @@ module Hbc if klass.respond_to?(:run) # invoke "run" on a Ruby library which follows our coding conventions # other Ruby libraries must do everything via "require" - klass.run(*rest) + klass.run(*args) end elsif which("brewcask-#{command}") # arbitrary external executable on PATH, Homebrew-style @@ -124,7 +124,7 @@ module Hbc exec command, *ARGV[1..-1] else # failure - NullCommand.new(command).run + NullCommand.new(command, *args).run end end @@ -136,18 +136,39 @@ module Hbc @args = process_options(*args) end + def detect_command_and_arguments(*args) + command = args.detect do |arg| + if self.class.commands.include?(arg) + true + else + break unless arg.start_with?("-") + end + end + + if index = args.index(command) + args.delete_at(index) + end + + [*command, *args] + end + def run - command_name, *args = *@args - command = help? ? "help" : self.class.lookup_command(command_name) + command_name, *args = detect_command_and_arguments(*@args) + command = if help? + args.unshift(command_name) + "help" + else + self.class.lookup_command(command_name) + end MacOS.full_version = ENV["MACOS_VERSION"] unless ENV["MACOS_VERSION"].nil? Hbc.default_tap.install unless Hbc.default_tap.installed? Hbc.init if self.class.should_init?(command) self.class.run_command(command, *args) - rescue CaskError, CaskSha256MismatchError, ArgumentError, OptionParser::InvalidOption => e + rescue CaskError, ArgumentError, OptionParser::InvalidOption => e msg = e.message - msg << e.backtrace.join("\n") if ARGV.debug? + msg << e.backtrace.join("\n").prepend("\n") if ARGV.debug? onoe msg exit 1 rescue StandardError, ScriptError, NoMemoryError => e @@ -199,18 +220,19 @@ module Hbc end class NullCommand - def initialize(attempted_verb) - @attempted_verb = attempted_verb + def initialize(command, *args) + @command = command + @args = args end def run(*_args) purpose usage - return if @attempted_verb.to_s.strip.empty? - return if @attempted_verb == "help" + return if @command == "help" && @args.empty? - raise ArgumentError, "Unknown command: #{@attempted_verb}" + unknown_command = @args.empty? ? @command : @args.first + raise ArgumentError, "Unknown command: #{unknown_command}" end def purpose diff --git a/Library/Homebrew/cask/lib/hbc/cli/abstract_command.rb b/Library/Homebrew/cask/lib/hbc/cli/abstract_command.rb index cdb7f5ec8..77f85301e 100644 --- a/Library/Homebrew/cask/lib/hbc/cli/abstract_command.rb +++ b/Library/Homebrew/cask/lib/hbc/cli/abstract_command.rb @@ -9,6 +9,7 @@ module Hbc option "--debug", :debug, false option "--verbose", :verbose, false option "--outdated", :outdated_only, false + option "--require-sha", :require_sha, false def self.command_name @command_name ||= name.sub(/^.*:/, "").gsub(/(.)([A-Z])/, '\1_\2').downcase @@ -40,6 +41,43 @@ module Hbc def initialize(*args) @args = process_arguments(*args) end + + def self.warn_unavailable_with_suggestion(cask_token, e) + exact_match, partial_matches = Search.search(cask_token) + error_message = e.message + if exact_match + error_message.concat(" Did you mean:\n#{exact_match}") + elsif !partial_matches.empty? + error_message.concat(" Did you mean one of:\n") + .concat(Formatter.columns(partial_matches.take(20))) + end + onoe error_message + end + + private + + def casks(alternative: -> { [] }) + return to_enum(:casks, alternative: alternative) unless block_given? + + count = 0 + + casks = args.empty? ? alternative.call : args + + casks.each do |cask_or_token| + begin + yield cask_or_token.respond_to?(:token) ? cask_or_token : CaskLoader.load(cask_or_token) + count += 1 + rescue CaskUnavailableError => e + cask_token = cask_or_token + self.class.warn_unavailable_with_suggestion cask_token, e + rescue CaskError => e + onoe e.message + end + end + + return :empty if casks.length.zero? + (count == casks.length) ? :complete : :incomplete + end end end end diff --git a/Library/Homebrew/cask/lib/hbc/cli/audit.rb b/Library/Homebrew/cask/lib/hbc/cli/audit.rb index 74d1ebfa7..35d82800c 100644 --- a/Library/Homebrew/cask/lib/hbc/cli/audit.rb +++ b/Library/Homebrew/cask/lib/hbc/cli/audit.rb @@ -9,11 +9,8 @@ module Hbc end def run - casks_to_audit = args.empty? ? Hbc.all : args.map(&CaskLoader.public_method(:load)) - - failed_casks = casks_to_audit.reject do |cask| - audit(cask) - end + failed_casks = casks(alternative: -> { Hbc.all }) + .reject { |cask| audit(cask) } return if failed_casks.empty? raise CaskError, "audit failed for casks: #{failed_casks.join(" ")}" diff --git a/Library/Homebrew/cask/lib/hbc/cli/cat.rb b/Library/Homebrew/cask/lib/hbc/cli/cat.rb index e68481b46..d08c87bea 100644 --- a/Library/Homebrew/cask/lib/hbc/cli/cat.rb +++ b/Library/Homebrew/cask/lib/hbc/cli/cat.rb @@ -7,10 +7,12 @@ module Hbc end def run - args.each do |cask_token| - cask_path = CaskLoader.path(cask_token) - raise CaskUnavailableError, cask_token.to_s unless cask_path.exist? - puts File.open(cask_path, &:read) + raise CaskError, "Cat incomplete." if cat_casks == :incomplete + end + + def cat_casks + casks.each do |cask| + puts File.open(cask.sourcefile_path, &:read) end end diff --git a/Library/Homebrew/cask/lib/hbc/cli/cleanup.rb b/Library/Homebrew/cask/lib/hbc/cli/cleanup.rb index 40b37dd5d..356162db5 100644 --- a/Library/Homebrew/cask/lib/hbc/cli/cleanup.rb +++ b/Library/Homebrew/cask/lib/hbc/cli/cleanup.rb @@ -20,7 +20,7 @@ module Hbc end def run - remove_cache_files(*@args) + remove_cache_files(*args) end def cache_files diff --git a/Library/Homebrew/cask/lib/hbc/cli/edit.rb b/Library/Homebrew/cask/lib/hbc/cli/edit.rb index dec0fe36b..b9485886c 100644 --- a/Library/Homebrew/cask/lib/hbc/cli/edit.rb +++ b/Library/Homebrew/cask/lib/hbc/cli/edit.rb @@ -9,10 +9,12 @@ module Hbc def run cask_token = args.first - cask_path = CaskLoader.path(cask_token) - - unless cask_path.exist? - raise CaskUnavailableError, %Q(#{cask_token}, run "brew cask create #{cask_token}" to create a new Cask) + cask_path = begin + CaskLoader.load(cask_token).sourcefile_path + rescue CaskUnavailableError => e + reason = e.reason.empty? ? "" : "#{e.reason} " + reason.concat("Run #{Formatter.identifier("brew cask create #{e.token}")} to create a new Cask.") + raise e.class.new(e.token, reason) end odebug "Opening editor for Cask #{cask_token}" diff --git a/Library/Homebrew/cask/lib/hbc/cli/fetch.rb b/Library/Homebrew/cask/lib/hbc/cli/fetch.rb index 2c1cc5f66..e31b1a17c 100644 --- a/Library/Homebrew/cask/lib/hbc/cli/fetch.rb +++ b/Library/Homebrew/cask/lib/hbc/cli/fetch.rb @@ -9,9 +9,12 @@ module Hbc end def run - args.each do |cask_token| - ohai "Downloading external files for Cask #{cask_token}" - cask = CaskLoader.load(cask_token) + raise CaskError, "Fetch incomplete." if fetch_casks == :incomplete + end + + def fetch_casks + casks.each do |cask| + ohai "Downloading external files for Cask #{cask}" downloaded_path = Download.new(cask, force: force?).perform Verify.all(cask, downloaded_path) ohai "Success! Downloaded to -> #{downloaded_path}" diff --git a/Library/Homebrew/cask/lib/hbc/cli/home.rb b/Library/Homebrew/cask/lib/hbc/cli/home.rb index 009bc1e3e..d496e309e 100644 --- a/Library/Homebrew/cask/lib/hbc/cli/home.rb +++ b/Library/Homebrew/cask/lib/hbc/cli/home.rb @@ -2,9 +2,7 @@ module Hbc class CLI class Home < AbstractCommand def run - casks = args.map(&CaskLoader.public_method(:load)) - - if casks.empty? + if casks.none? odebug "Opening project homepage" self.class.open_url "https://caskroom.github.io/" else diff --git a/Library/Homebrew/cask/lib/hbc/cli/info.rb b/Library/Homebrew/cask/lib/hbc/cli/info.rb index 623c4b737..d26747e17 100644 --- a/Library/Homebrew/cask/lib/hbc/cli/info.rb +++ b/Library/Homebrew/cask/lib/hbc/cli/info.rb @@ -7,10 +7,8 @@ module Hbc end def run - args.each do |cask_token| - odebug "Getting info for Cask #{cask_token}" - cask = CaskLoader.load(cask_token) - + casks.each do |cask| + odebug "Getting info for Cask #{cask}" self.class.info(cask) end end diff --git a/Library/Homebrew/cask/lib/hbc/cli/install.rb b/Library/Homebrew/cask/lib/hbc/cli/install.rb index 72f85fc69..0f1a5dd34 100644 --- a/Library/Homebrew/cask/lib/hbc/cli/install.rb +++ b/Library/Homebrew/cask/lib/hbc/cli/install.rb @@ -3,7 +3,6 @@ module Hbc class Install < AbstractCommand option "--force", :force, false option "--skip-cask-deps", :skip_cask_deps, false - option "--require-sha", :require_sha, false def initialize(*) super @@ -11,53 +10,21 @@ module Hbc end def run - retval = install_casks - # retval is ternary: true/false/nil - - raise CaskError, "nothing to install" if retval.nil? - raise CaskError, "install incomplete" unless retval + raise CaskError, "Install incomplete." if install_casks == :incomplete end def install_casks - count = 0 - args.each do |cask_token| + casks.each do |cask| begin - cask = CaskLoader.load(cask_token) Installer.new(cask, binaries: binaries?, - verbose: verbose?, + verbose: verbose?, force: force?, skip_cask_deps: skip_cask_deps?, require_sha: require_sha?).install - count += 1 rescue CaskAlreadyInstalledError => e opoo e.message - count += 1 - rescue CaskAlreadyInstalledAutoUpdatesError => e - opoo e.message - count += 1 - rescue CaskUnavailableError => e - self.class.warn_unavailable_with_suggestion cask_token, e - rescue CaskNoShasumError => e - opoo e.message - count += 1 - rescue CaskError => e - onoe e.message end end - - count.zero? ? nil : count == args.length - end - - def self.warn_unavailable_with_suggestion(cask_token, e) - exact_match, partial_matches = Search.search(cask_token) - error_message = e.message - if exact_match - error_message.concat(". Did you mean:\n#{exact_match}") - elsif !partial_matches.empty? - error_message.concat(". Did you mean one of:\n") - .concat(Formatter.columns(partial_matches.take(20))) - end - onoe error_message end def self.help diff --git a/Library/Homebrew/cask/lib/hbc/cli/internal_dump.rb b/Library/Homebrew/cask/lib/hbc/cli/internal_dump.rb index 78dbf1622..e21ce86b6 100644 --- a/Library/Homebrew/cask/lib/hbc/cli/internal_dump.rb +++ b/Library/Homebrew/cask/lib/hbc/cli/internal_dump.rb @@ -7,25 +7,11 @@ module Hbc end def run - retval = dump_casks - # retval is ternary: true/false/nil - - raise CaskError, "nothing to dump" if retval.nil? - raise CaskError, "dump incomplete" unless retval + raise CaskError, "Dump incomplete." if dump_casks == :incomplet end def dump_casks - count = 0 - args.each do |cask_token| - begin - cask = CaskLoader.load(cask_token) - count += 1 - cask.dumpcask - rescue StandardError => e - opoo "#{cask_token} was not found or would not load: #{e}" - end - end - count.zero? ? nil : count == args.length + casks.each(&:dumpcask) end def self.help diff --git a/Library/Homebrew/cask/lib/hbc/cli/internal_stanza.rb b/Library/Homebrew/cask/lib/hbc/cli/internal_stanza.rb index 86dee7c9c..4515fe931 100644 --- a/Library/Homebrew/cask/lib/hbc/cli/internal_stanza.rb +++ b/Library/Homebrew/cask/lib/hbc/cli/internal_stanza.rb @@ -72,38 +72,22 @@ module Hbc end def run - retval = print_stanzas - # retval is ternary: true/false/nil - if retval.nil? - exit 1 if quiet? - raise CaskError, "nothing to print" - elsif !retval - exit 1 if quiet? - raise CaskError, "print incomplete" - end + return unless print_stanzas == :incomplete + exit 1 if quiet? + raise CaskError, "Print incomplete." end def print_stanzas - count = 0 if ARTIFACTS.include?(stanza) artifact_name = stanza @stanza = :artifacts end - cask_tokens = args.empty? ? Hbc.all_tokens : args - cask_tokens.each do |cask_token| - print "#{cask_token}\t" if table? - - begin - cask = CaskLoader.load(cask_token) - rescue StandardError - opoo "Cask '#{cask_token}' was not found" unless quiet? - puts "" - next - end + casks(alternative: -> { Hbc.all }).each do |cask| + print "#{cask}\t" if table? unless cask.respond_to?(stanza) - opoo "no such stanza '#{stanza}' on Cask '#{cask_token}'" unless quiet? + opoo "no such stanza '#{stanza}' on Cask '#{cask}'" unless quiet? puts "" next end @@ -111,13 +95,13 @@ module Hbc begin value = cask.send(@stanza) rescue StandardError - opoo "failure calling '#{stanza}' on Cask '#{cask_token}'" unless quiet? + opoo "failure calling '#{stanza}' on Cask '#{cask}'" unless quiet? puts "" next end if artifact_name && !value.key?(artifact_name) - opoo "no such stanza '#{artifact_name}' on Cask '#{cask_token}'" unless quiet? + opoo "no such stanza '#{artifact_name}' on Cask '#{cask}'" unless quiet? puts "" next end @@ -131,10 +115,7 @@ module Hbc else puts value.to_s end - - count += 1 end - count.zero? ? nil : count == cask_tokens.length end def self.help diff --git a/Library/Homebrew/cask/lib/hbc/cli/list.rb b/Library/Homebrew/cask/lib/hbc/cli/list.rb index 9d2ded4be..9d978360e 100644 --- a/Library/Homebrew/cask/lib/hbc/cli/list.rb +++ b/Library/Homebrew/cask/lib/hbc/cli/list.rb @@ -11,44 +11,22 @@ module Hbc def run retval = args.any? ? list : list_installed - # retval is ternary: true/false/nil - if retval.nil? && args.none? - opoo "nothing to list" # special case: avoid exit code - elsif retval.nil? - raise CaskError, "nothing to list" - elsif !retval - raise CaskError, "listing incomplete" - end + raise CaskError, "Listing incomplete." if retval == :incomplete end def list - count = 0 - - args.each do |cask_token| - odebug "Listing files for Cask #{cask_token}" - begin - cask = CaskLoader.load(cask_token) + casks.each do |cask| + raise CaskNotInstalledError, cask unless cask.installed? - if cask.installed? - if one? - puts cask.token - elsif versions? - puts self.class.format_versioned(cask) - else - cask = CaskLoader.load_from_file(cask.installed_caskfile) - self.class.list_artifacts(cask) - end - - count += 1 - else - opoo "#{cask} is not installed" - end - rescue CaskUnavailableError => e - onoe e + if one? + puts cask.token + elsif versions? + puts self.class.format_versioned(cask) + else + cask = CaskLoader.load_from_file(cask.installed_caskfile) + self.class.list_artifacts(cask) end end - - count.zero? ? nil : count == args.length end def self.list_artifacts(cask) @@ -69,7 +47,7 @@ module Hbc puts Formatter.columns(installed_casks.map(&:to_s)) end - installed_casks.empty? ? nil : true + installed_casks.empty? ? :empty : :complete end def self.format_versioned(cask) diff --git a/Library/Homebrew/cask/lib/hbc/cli/outdated.rb b/Library/Homebrew/cask/lib/hbc/cli/outdated.rb index 7877ead05..b0a84e8d2 100644 --- a/Library/Homebrew/cask/lib/hbc/cli/outdated.rb +++ b/Library/Homebrew/cask/lib/hbc/cli/outdated.rb @@ -10,9 +10,7 @@ module Hbc end def run - casks_to_check = args.empty? ? Hbc.installed : args.map(&CaskLoader.public_method(:load)) - - casks_to_check.each do |cask| + casks(alternative: -> { Hbc.installed }).each do |cask| odebug "Checking update info of Cask #{cask}" self.class.list_if_outdated(cask, greedy?, verbose?) end diff --git a/Library/Homebrew/cask/lib/hbc/cli/reinstall.rb b/Library/Homebrew/cask/lib/hbc/cli/reinstall.rb index eb5f45c90..337a2eb9d 100644 --- a/Library/Homebrew/cask/lib/hbc/cli/reinstall.rb +++ b/Library/Homebrew/cask/lib/hbc/cli/reinstall.rb @@ -2,28 +2,13 @@ module Hbc class CLI class Reinstall < Install def install_casks - count = 0 - args.each do |cask_token| - begin - cask = CaskLoader.load(cask_token) - - Installer.new(cask, - binaries: binaries?, - verbose: verbose?, - force: force?, - skip_cask_deps: skip_cask_deps?, - require_sha: require_sha?).reinstall - - count += 1 - rescue CaskUnavailableError => e - self.class.warn_unavailable_with_suggestion cask_token, e - rescue CaskNoShasumError => e - opoo e.message - count += 1 - end + casks.each do |cask| + Installer.new(cask, binaries: binaries?, + verbose: verbose?, + force: force?, + skip_cask_deps: skip_cask_deps?, + require_sha: require_sha?).reinstall end - - count.zero? ? nil : count == args.length end def self.help diff --git a/Library/Homebrew/cask/lib/hbc/cli/search.rb b/Library/Homebrew/cask/lib/hbc/cli/search.rb index b24091aef..9d1a16f15 100644 --- a/Library/Homebrew/cask/lib/hbc/cli/search.rb +++ b/Library/Homebrew/cask/lib/hbc/cli/search.rb @@ -1,10 +1,6 @@ module Hbc class CLI class Search < AbstractCommand - def initialize(*args) - @args = args - end - def run results = self.class.search(*args) self.class.render_results(*results) diff --git a/Library/Homebrew/cask/lib/hbc/cli/style.rb b/Library/Homebrew/cask/lib/hbc/cli/style.rb index 97208232b..86fc98eaa 100644 --- a/Library/Homebrew/cask/lib/hbc/cli/style.rb +++ b/Library/Homebrew/cask/lib/hbc/cli/style.rb @@ -1,5 +1,3 @@ -require "English" - module Hbc class CLI class Style < AbstractCommand @@ -33,7 +31,7 @@ module Hbc elsif args.any? { |file| File.exist?(file) } args else - args.map { |token| CaskLoader.path(token) } + casks.map(&:sourcefile_path) end end diff --git a/Library/Homebrew/cask/lib/hbc/cli/uninstall.rb b/Library/Homebrew/cask/lib/hbc/cli/uninstall.rb index 33ee5afa9..c0697c808 100644 --- a/Library/Homebrew/cask/lib/hbc/cli/uninstall.rb +++ b/Library/Homebrew/cask/lib/hbc/cli/uninstall.rb @@ -9,9 +9,12 @@ module Hbc end def run - args.each do |cask_token| - odebug "Uninstalling Cask #{cask_token}" - cask = CaskLoader.load(cask_token) + raise CaskError, "Uninstall incomplete." if uninstall_casks == :incomplete + end + + def uninstall_casks + casks.each do |cask| + odebug "Uninstalling Cask #{cask}" raise CaskNotInstalledError, cask unless cask.installed? || force? @@ -27,8 +30,8 @@ module Hbc single = versions.count == 1 puts <<-EOS.undent - #{cask_token} #{versions.join(", ")} #{single ? "is" : "are"} still installed. - Remove #{single ? "it" : "them all"} with `brew cask uninstall --force #{cask_token}`. + #{cask} #{versions.join(", ")} #{single ? "is" : "are"} still installed. + Remove #{single ? "it" : "them all"} with `brew cask uninstall --force #{cask}`. EOS end end diff --git a/Library/Homebrew/cask/lib/hbc/cli/zap.rb b/Library/Homebrew/cask/lib/hbc/cli/zap.rb index 3c07ff9e8..d12943106 100644 --- a/Library/Homebrew/cask/lib/hbc/cli/zap.rb +++ b/Library/Homebrew/cask/lib/hbc/cli/zap.rb @@ -7,9 +7,12 @@ module Hbc end def run - args.each do |cask_token| - odebug "Zapping Cask #{cask_token}" - cask = CaskLoader.load(cask_token) + raise CaskError, "Zap incomplete." if zap_casks == :incomplete + end + + def zap_casks + casks.each do |cask| + odebug "Zapping Cask #{cask}" Installer.new(cask, verbose: verbose?).zap end end diff --git a/Library/Homebrew/cask/lib/hbc/exceptions.rb b/Library/Homebrew/cask/lib/hbc/exceptions.rb index b9d305a9b..d9e1b07db 100644 --- a/Library/Homebrew/cask/lib/hbc/exceptions.rb +++ b/Library/Homebrew/cask/lib/hbc/exceptions.rb @@ -3,56 +3,40 @@ module Hbc class AbstractCaskErrorWithToken < CaskError attr_reader :token + attr_reader :reason - def initialize(token) + def initialize(token, reason = nil) @token = token + @reason = reason.to_s end end class CaskNotInstalledError < AbstractCaskErrorWithToken def to_s - "#{token} is not installed" + "Cask '#{token}' is not installed." end end class CaskUnavailableError < AbstractCaskErrorWithToken def to_s - "No available Cask for #{token}" + "Cask '#{token}' is unavailable" << (reason.empty? ? "." : ": #{reason}") end end class CaskAlreadyCreatedError < AbstractCaskErrorWithToken def to_s - %Q(A Cask for #{token} already exists. Run "brew cask cat #{token}" to see it.) + %Q(Cask '#{token}' already exists. Run #{Formatter.identifier("brew cask cat #{token}")} to edit it.) end end class CaskAlreadyInstalledError < AbstractCaskErrorWithToken def to_s - s = <<-EOS.undent - A Cask for #{token} is already installed. - EOS - - s.concat("\n").concat(reinstall_message) - end - - private - - def reinstall_message <<-EOS.undent - To re-install #{token}, run: - brew cask reinstall #{token} - EOS - end - end + Cask '#{token}' is already installed. - class CaskAlreadyInstalledAutoUpdatesError < CaskAlreadyInstalledError - def to_s - s = <<-EOS.undent - A Cask for #{token} is already installed and using auto-updates. + To re-install #{token}, run: + #{Formatter.identifier("brew cask reinstall #{token}")} EOS - - s.concat("\n").concat(reinstall_message) end end @@ -84,8 +68,8 @@ module Hbc class CaskX11DependencyError < AbstractCaskErrorWithToken def to_s <<-EOS.undent - #{token} requires XQuartz/X11, which can be installed using Homebrew-Cask by running - brew cask install xquartz + Cask '#{token}' requires XQuartz/X11, which can be installed using Homebrew-Cask by running + #{Formatter.identifier("brew cask install xquartz")} or manually, by downloading the package from #{Formatter.url("https://www.xquartz.org/")} @@ -101,60 +85,67 @@ module Hbc class CaskUnspecifiedError < CaskError def to_s - "This command requires a Cask token" + "This command requires a Cask token." end end class CaskInvalidError < AbstractCaskErrorWithToken - attr_reader :submsg - def initialize(token, *submsg) - super(token) - @submsg = submsg.join(" ") - end - def to_s - "Cask '#{token}' definition is invalid#{": #{submsg}" unless submsg.empty?}" + "Cask '#{token}' definition is invalid" << (reason.empty? ? ".": ": #{reason}") end end - class CaskTokenDoesNotMatchError < CaskInvalidError + class CaskTokenMismatchError < CaskInvalidError def initialize(token, header_token) - super(token, "Bad header line: '#{header_token}' does not match file name") + super(token, "Token '#{header_token}' in header line does not match the file name.") end end - class CaskSha256MissingError < ArgumentError - end + class CaskSha256Error < AbstractCaskErrorWithToken + attr_reader :expected, :actual - class CaskSha256MismatchError < RuntimeError - attr_reader :path, :expected, :actual - def initialize(path, expected, actual) - @path = path + def initialize(token, expected = nil, actual = nil) + super(token) @expected = expected @actual = actual end + end + class CaskSha256MissingError < CaskSha256Error def to_s <<-EOS.undent - sha256 mismatch - Expected: #{expected} - Actual: #{actual} - File: #{path} - To retry an incomplete download, remove the file above. + Cask '#{token}' requires a checksum: + #{Formatter.identifier("sha256 '#{actual}'")} EOS end end - class CaskNoShasumError < CaskError - attr_reader :token - def initialize(token) - @token = token + class CaskSha256MismatchError < CaskSha256Error + attr_reader :path + + def initialize(token, expected, actual, path) + super(token, expected, actual) + @path = path + end + + def to_s + <<-EOS.undent + Checksum for Cask '#{token}' does not match. + + Expected: #{Formatter.success(expected.to_s)} + Actual: #{Formatter.error(actual.to_s)} + File: #{path} + + To retry an incomplete download, remove the file above. + EOS end + end + class CaskNoShasumError < CaskSha256Error def to_s <<-EOS.undent Cask '#{token}' does not have a sha256 checksum defined and was not installed. - This means you have the "--require-sha" option set, perhaps in your HOMEBREW_CASK_OPTS. + This means you have the #{Formatter.identifier("--require-sha")} option set, perhaps in your HOMEBREW_CASK_OPTS. EOS end end diff --git a/Library/Homebrew/cask/lib/hbc/installer.rb b/Library/Homebrew/cask/lib/hbc/installer.rb index 7da9731e5..aa6d600f7 100644 --- a/Library/Homebrew/cask/lib/hbc/installer.rb +++ b/Library/Homebrew/cask/lib/hbc/installer.rb @@ -94,7 +94,6 @@ module Hbc odebug "Hbc::Installer#install" if @cask.installed? && !force? && !@reinstall - raise CaskAlreadyInstalledAutoUpdatesError, @cask if @cask.auto_updates raise CaskAlreadyInstalledError, @cask end @@ -143,7 +142,7 @@ module Hbc def verify_has_sha odebug "Checking cask has checksum" return unless @cask.sha256 == :no_check - raise CaskNoShasumError, @cask + raise CaskNoShasumError, @cask.token end def verify diff --git a/Library/Homebrew/cask/lib/hbc/scopes.rb b/Library/Homebrew/cask/lib/hbc/scopes.rb index 149c2c343..a469ae0fa 100644 --- a/Library/Homebrew/cask/lib/hbc/scopes.rb +++ b/Library/Homebrew/cask/lib/hbc/scopes.rb @@ -27,6 +27,7 @@ module Hbc # TODO: speed up Hbc::Source::Tapped (main perf drag is calling Hbc.all_tokens repeatedly) # TODO: ability to specify expected source when calling CaskLoader.load (minor perf benefit) Pathname.glob(caskroom.join("*")) + .sort .map do |caskroom_path| token = caskroom_path.basename.to_s diff --git a/Library/Homebrew/cask/lib/hbc/verify/checksum.rb b/Library/Homebrew/cask/lib/hbc/verify/checksum.rb index d079a4446..620703d31 100644 --- a/Library/Homebrew/cask/lib/hbc/verify/checksum.rb +++ b/Library/Homebrew/cask/lib/hbc/verify/checksum.rb @@ -33,13 +33,13 @@ module Hbc end def verify_checksum - raise CaskSha256MissingError, "sha256 required: sha256 '#{computed}'" if expected.nil? || expected.empty? + raise CaskSha256MissingError.new(cask.token, expected, computed) if expected.nil? || expected.empty? if expected == computed odebug "SHA256 checksums match" else ohai 'Note: running "brew update" may fix sha256 checksum errors' - raise CaskSha256MismatchError.new(downloaded_path, expected, computed) + raise CaskSha256MismatchError.new(cask.token, expected, computed, downloaded_path) end end end diff --git a/Library/Homebrew/cmd/--repository.rb b/Library/Homebrew/cmd/--repository.rb index 7a25aba1c..006d4cd5d 100644 --- a/Library/Homebrew/cmd/--repository.rb +++ b/Library/Homebrew/cmd/--repository.rb @@ -1,6 +1,5 @@ #: * `--repository`: -#: Display where Homebrew's `.git` directory is located. For standard installs, -#: the `prefix` and `repository` are the same directory. +#: Display where Homebrew's `.git` directory is located. #: #: * `--repository` <user>`/`<repo>: #: Display where tap <user>`/`<repo>'s directory is located. diff --git a/Library/Homebrew/cmd/info.rb b/Library/Homebrew/cmd/info.rb index 826f31bbd..98200a0b4 100644 --- a/Library/Homebrew/cmd/info.rb +++ b/Library/Homebrew/cmd/info.rb @@ -79,7 +79,7 @@ module Homebrew def github_remote_path(remote, path) if remote =~ %r{^(?:https?://|git(?:@|://))github\.com[:/](.+)/(.+?)(?:\.git)?$} - "https://github.com/#{$1}/#{$2}/blob/master/#{path}" + "https://github.com/#{Regexp.last_match(1)}/#{Regexp.last_match(2)}/blob/master/#{path}" else "#{remote}/#{path}" end diff --git a/Library/Homebrew/cmd/install.rb b/Library/Homebrew/cmd/install.rb index 423b47884..e413bac6f 100644 --- a/Library/Homebrew/cmd/install.rb +++ b/Library/Homebrew/cmd/install.rb @@ -80,7 +80,7 @@ module Homebrew if name !~ HOMEBREW_TAP_FORMULA_REGEX && name !~ HOMEBREW_CASK_TAP_CASK_REGEX next end - tap = Tap.fetch($1, $2) + tap = Tap.fetch(Regexp.last_match(1), Regexp.last_match(2)) tap.install unless tap.installed? end end diff --git a/Library/Homebrew/cmd/reinstall.rb b/Library/Homebrew/cmd/reinstall.rb index c625d2d97..f5d6437bd 100644 --- a/Library/Homebrew/cmd/reinstall.rb +++ b/Library/Homebrew/cmd/reinstall.rb @@ -34,7 +34,7 @@ module Homebrew fi = FormulaInstaller.new(f) fi.options = options fi.invalid_option_names = build_options.invalid_option_names - fi.build_bottle = ARGV.build_bottle? || (!f.bottled? && f.build.build_bottle?) + fi.build_bottle = ARGV.build_bottle? || (!f.bottled? && f.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? @@ -66,6 +66,8 @@ module Homebrew return unless path.directory? + Pathname.new(keg).rmtree if keg.exist? + path.rename keg keg.link unless formula.keg_only? end diff --git a/Library/Homebrew/cmd/search.rb b/Library/Homebrew/cmd/search.rb index 2b35dfc36..b2d069744 100644 --- a/Library/Homebrew/cmd/search.rb +++ b/Library/Homebrew/cmd/search.rb @@ -93,7 +93,7 @@ module Homebrew def query_regexp(query) case query - when %r{^/(.*)/$} then Regexp.new($1) + when %r{^/(.*)/$} then Regexp.new(Regexp.last_match(1)) else /.*#{Regexp.escape(query)}.*/i end rescue RegexpError diff --git a/Library/Homebrew/cmd/style.rb b/Library/Homebrew/cmd/style.rb index 7da71749c..c6201e371 100644 --- a/Library/Homebrew/cmd/style.rb +++ b/Library/Homebrew/cmd/style.rb @@ -112,7 +112,7 @@ module Homebrew args << "--display-cop-names" if ARGV.include? "--display-cop-names" args << "--format" << "simple" if files system(cache_env, "rubocop", *args) - !$?.success? + !$CHILD_STATUS.success? when :json json, _, status = Open3.capture3(cache_env, "rubocop", "--format", "json", *args) # exit status of 1 just means violations were found; other numbers mean diff --git a/Library/Homebrew/dev-cmd/audit.rb b/Library/Homebrew/dev-cmd/audit.rb index aaac9c96b..0d9a630fd 100644 --- a/Library/Homebrew/dev-cmd/audit.rb +++ b/Library/Homebrew/dev-cmd/audit.rb @@ -195,12 +195,12 @@ class FormulaAuditor @specs = %w[stable devel head].map { |s| formula.send(s) }.compact end - def self.check_http_content(url, user_agents: [:default]) + def self.check_http_content(url, name, user_agents: [:default]) return unless url.start_with? "http" details = nil user_agent = nil - hash_needed = url.start_with?("http:") + hash_needed = url.start_with?("http:") && name != "curl" user_agents.each do |ua| details = http_content_headers_and_checksum(url, hash_needed: hash_needed, user_agent: ua) user_agent = ua @@ -578,7 +578,7 @@ class FormulaAuditor next unless o.name =~ /^with(out)?-(?:checks?|tests)$/ unless formula.deps.any? { |d| d.name == "check" && (d.optional? || d.recommended?) } - problem "Use '--with#{$1}-test' instead of '--#{o.name}'. Migrate '--#{o.name}' with `deprecated_option`." + problem "Use '--with#{Regexp.last_match(1)}-test' instead of '--#{o.name}'. Migrate '--#{o.name}' with `deprecated_option`." end end @@ -597,7 +597,8 @@ class FormulaAuditor return unless DevelopmentTools.curl_handles_most_https_homepages? if http_content_problem = FormulaAuditor.check_http_content(homepage, - user_agents: [:browser, :default]) + formula.name, + user_agents: [:browser, :default]) problem http_content_problem end end @@ -721,7 +722,7 @@ class FormulaAuditor stable = formula.stable case stable && stable.url when /[\d\._-](alpha|beta|rc\d)/ - matched = $1 + matched = Regexp.last_match(1) version_prefix = stable.version.to_s.sub(/\d+$/, "") return if unstable_whitelist.include?([formula.name, version_prefix]) problem "Stable version URLs should not contain #{matched}" @@ -836,7 +837,7 @@ class FormulaAuditor when %r{https?://patch-diff\.githubusercontent\.com/raw/(.+)/(.+)/pull/(.+)\.(?:diff|patch)} problem <<-EOS.undent use GitHub pull request URLs: - https://github.com/#{$1}/#{$2}/pull/#{$3}.patch + https://github.com/#{Regexp.last_match(1)}/#{Regexp.last_match(2)}/pull/#{Regexp.last_match(3)}.patch Rather than patch-diff: #{patch.url} EOS @@ -874,7 +875,7 @@ class FormulaAuditor def line_problems(line, _lineno) if line =~ /<(Formula|AmazonWebServicesFormula|ScriptFileFormula|GithubGistFormula)/ - problem "Use a space in class inheritance: class Foo < #{$1}" + problem "Use a space in class inheritance: class Foo < #{Regexp.last_match(1)}" end # Commented-out cmake support from default template @@ -898,52 +899,52 @@ class FormulaAuditor # FileUtils is included in Formula # encfs modifies a file with this name, so check for some leading characters if line =~ %r{[^'"/]FileUtils\.(\w+)} - problem "Don't need 'FileUtils.' before #{$1}." + problem "Don't need 'FileUtils.' before #{Regexp.last_match(1)}." end # Check for long inreplace block vars if line =~ /inreplace .* do \|(.{2,})\|/ - problem "\"inreplace <filenames> do |s|\" is preferred over \"|#{$1}|\"." + problem "\"inreplace <filenames> do |s|\" is preferred over \"|#{Regexp.last_match(1)}|\"." end # Check for string interpolation of single values. if line =~ /(system|inreplace|gsub!|change_make_var!).*[ ,]"#\{([\w.]+)\}"/ - problem "Don't need to interpolate \"#{$2}\" with #{$1}" + problem "Don't need to interpolate \"#{Regexp.last_match(2)}\" with #{Regexp.last_match(1)}" end # Check for string concatenation; prefer interpolation if line =~ /(#\{\w+\s*\+\s*['"][^}]+\})/ - problem "Try not to concatenate paths in string interpolation:\n #{$1}" + problem "Try not to concatenate paths in string interpolation:\n #{Regexp.last_match(1)}" end # Prefer formula path shortcuts in Pathname+ if line =~ %r{\(\s*(prefix\s*\+\s*(['"])(bin|include|libexec|lib|sbin|share|Frameworks)[/'"])} - problem "\"(#{$1}...#{$2})\" should be \"(#{$3.downcase}+...)\"" + problem "\"(#{Regexp.last_match(1)}...#{Regexp.last_match(2)})\" should be \"(#{Regexp.last_match(3).downcase}+...)\"" end if line =~ /((man)\s*\+\s*(['"])(man[1-8])(['"]))/ - problem "\"#{$1}\" should be \"#{$4}\"" + problem "\"#{Regexp.last_match(1)}\" should be \"#{Regexp.last_match(4)}\"" end # Prefer formula path shortcuts in strings if line =~ %r[(\#\{prefix\}/(bin|include|libexec|lib|sbin|share|Frameworks))] - problem "\"#{$1}\" should be \"\#{#{$2.downcase}}\"" + problem "\"#{Regexp.last_match(1)}\" should be \"\#{#{Regexp.last_match(2).downcase}}\"" end if line =~ %r[((\#\{prefix\}/share/man/|\#\{man\}/)(man[1-8]))] - problem "\"#{$1}\" should be \"\#{#{$3}}\"" + problem "\"#{Regexp.last_match(1)}\" should be \"\#{#{Regexp.last_match(3)}}\"" end if line =~ %r[((\#\{share\}/(man)))[/'"]] - problem "\"#{$1}\" should be \"\#{#{$3}}\"" + problem "\"#{Regexp.last_match(1)}\" should be \"\#{#{Regexp.last_match(3)}}\"" end if line =~ %r[(\#\{prefix\}/share/(info|man))] - problem "\"#{$1}\" should be \"\#{#{$2}}\"" + problem "\"#{Regexp.last_match(1)}\" should be \"\#{#{Regexp.last_match(2)}}\"" end if line =~ /depends_on :(automake|autoconf|libtool)/ - problem ":#{$1} is deprecated. Usage should be \"#{$1}\"" + problem ":#{Regexp.last_match(1)} is deprecated. Usage should be \"#{Regexp.last_match(1)}\"" end if line =~ /depends_on :apr/ @@ -953,23 +954,23 @@ class FormulaAuditor problem ":tex is deprecated" if line =~ /depends_on :tex/ if line =~ /depends_on\s+['"](.+)['"]\s+=>\s+:(lua|perl|python|ruby)(\d*)/ - problem "#{$2} modules should be vendored rather than use deprecated `depends_on \"#{$1}\" => :#{$2}#{$3}`" + problem "#{Regexp.last_match(2)} modules should be vendored rather than use deprecated `depends_on \"#{Regexp.last_match(1)}\" => :#{Regexp.last_match(2)}#{Regexp.last_match(3)}`" end if line =~ /depends_on\s+['"](.+)['"]\s+=>\s+(.*)/ - dep = $1 - $2.split(" ").map do |o| + dep = Regexp.last_match(1) + Regexp.last_match(2).split(" ").map do |o| break if ["if", "unless"].include?(o) next unless o =~ /^\[?['"](.*)['"]/ - problem "Dependency #{dep} should not use option #{$1}" + problem "Dependency #{dep} should not use option #{Regexp.last_match(1)}" end end # Commented-out depends_on - problem "Commented-out dep #{$1}" if line =~ /#\s*depends_on\s+(.+)\s*$/ + problem "Commented-out dep #{Regexp.last_match(1)}" if line =~ /#\s*depends_on\s+(.+)\s*$/ if line =~ /if\s+ARGV\.include\?\s+'--(HEAD|devel)'/ - problem "Use \"if build.#{$1.downcase}?\" instead" + problem "Use \"if build.#{Regexp.last_match(1).downcase}?\" instead" end problem "Use separate make calls" if line.include?("make && make") @@ -982,15 +983,15 @@ class FormulaAuditor # Avoid hard-coding compilers if line =~ %r{(system|ENV\[.+\]\s?=)\s?['"](/usr/bin/)?(gcc|llvm-gcc|clang)['" ]} - problem "Use \"\#{ENV.cc}\" instead of hard-coding \"#{$3}\"" + problem "Use \"\#{ENV.cc}\" instead of hard-coding \"#{Regexp.last_match(3)}\"" end if line =~ %r{(system|ENV\[.+\]\s?=)\s?['"](/usr/bin/)?((g|llvm-g|clang)\+\+)['" ]} - problem "Use \"\#{ENV.cxx}\" instead of hard-coding \"#{$3}\"" + problem "Use \"\#{ENV.cxx}\" instead of hard-coding \"#{Regexp.last_match(3)}\"" end if line =~ /system\s+['"](env|export)(\s+|['"])/ - problem "Use ENV instead of invoking '#{$1}' to modify the environment" + problem "Use ENV instead of invoking '#{Regexp.last_match(1)}' to modify the environment" end if formula.name != "wine" && line =~ /ENV\.universal_binary/ @@ -1006,27 +1007,27 @@ class FormulaAuditor end if line =~ /build\.include\?[\s\(]+['"]\-\-(.*)['"]/ - problem "Reference '#{$1}' without dashes" + problem "Reference '#{Regexp.last_match(1)}' without dashes" end if line =~ /build\.include\?[\s\(]+['"]with(out)?-(.*)['"]/ - problem "Use build.with#{$1}? \"#{$2}\" instead of build.include? 'with#{$1}-#{$2}'" + problem "Use build.with#{Regexp.last_match(1)}? \"#{Regexp.last_match(2)}\" instead of build.include? 'with#{Regexp.last_match(1)}-#{Regexp.last_match(2)}'" end if line =~ /build\.with\?[\s\(]+['"]-?-?with-(.*)['"]/ - problem "Don't duplicate 'with': Use `build.with? \"#{$1}\"` to check for \"--with-#{$1}\"" + problem "Don't duplicate 'with': Use `build.with? \"#{Regexp.last_match(1)}\"` to check for \"--with-#{Regexp.last_match(1)}\"" end if line =~ /build\.without\?[\s\(]+['"]-?-?without-(.*)['"]/ - problem "Don't duplicate 'without': Use `build.without? \"#{$1}\"` to check for \"--without-#{$1}\"" + problem "Don't duplicate 'without': Use `build.without? \"#{Regexp.last_match(1)}\"` to check for \"--without-#{Regexp.last_match(1)}\"" end if line =~ /unless build\.with\?(.*)/ - problem "Use if build.without?#{$1} instead of unless build.with?#{$1}" + problem "Use if build.without?#{Regexp.last_match(1)} instead of unless build.with?#{Regexp.last_match(1)}" end if line =~ /unless build\.without\?(.*)/ - problem "Use if build.with?#{$1} instead of unless build.without?#{$1}" + problem "Use if build.with?#{Regexp.last_match(1)} instead of unless build.without?#{Regexp.last_match(1)}" end if line =~ /(not\s|!)\s*build\.with?\?/ @@ -1070,7 +1071,7 @@ class FormulaAuditor end if line =~ /^def (\w+).*$/ - problem "Define method #{$1.inspect} in the class body, not at the top-level" + problem "Define method #{Regexp.last_match(1).inspect} in the class body, not at the top-level" end if line.include?("ENV.fortran") && !formula.requirements.map(&:class).include?(FortranRequirement) @@ -1082,20 +1083,20 @@ class FormulaAuditor end if line =~ /depends_on :(.+) (if.+|unless.+)$/ - conditional_dep_problems($1.to_sym, $2, $&) + conditional_dep_problems(Regexp.last_match(1).to_sym, Regexp.last_match(2), $&) end if line =~ /depends_on ['"](.+)['"] (if.+|unless.+)$/ - conditional_dep_problems($1, $2, $&) + conditional_dep_problems(Regexp.last_match(1), Regexp.last_match(2), $&) end if line =~ /(Dir\[("[^\*{},]+")\])/ - problem "#{$1} is unnecessary; just use #{$2}" + problem "#{Regexp.last_match(1)} is unnecessary; just use #{Regexp.last_match(2)}" end if line =~ /system (["'](#{FILEUTILS_METHODS})["' ])/o - system = $1 - method = $2 + system = Regexp.last_match(1) + method = Regexp.last_match(2) problem "Use the `#{method}` Ruby method instead of `system #{system}`" end @@ -1113,7 +1114,7 @@ class FormulaAuditor end if line =~ /system\s+['"](otool|install_name_tool|lipo)/ && formula.name != "cctools" - problem "Use ruby-macho instead of calling #{$1}" + problem "Use ruby-macho instead of calling #{Regexp.last_match(1)}" end if formula.tap.to_s == "homebrew/core" @@ -1124,29 +1125,29 @@ class FormulaAuditor end if line =~ /((revision|version_scheme)\s+0)/ - problem "'#{$1}' should be removed" + problem "'#{Regexp.last_match(1)}' should be removed" end return unless @strict - problem "`#{$1}` in formulae is deprecated" if line =~ /(env :(std|userpaths))/ + problem "`#{Regexp.last_match(1)}` in formulae is deprecated" if line =~ /(env :(std|userpaths))/ if line =~ /system ((["'])[^"' ]*(?:\s[^"' ]*)+\2)/ - bad_system = $1 + bad_system = Regexp.last_match(1) unless %w[| < > & ; *].any? { |c| bad_system.include? c } good_system = bad_system.gsub(" ", "\", \"") problem "Use `system #{good_system}` instead of `system #{bad_system}` " end end - problem "`#{$1}` is now unnecessary" if line =~ /(require ["']formula["'])/ + problem "`#{Regexp.last_match(1)}` is now unnecessary" if line =~ /(require ["']formula["'])/ if line =~ %r{#\{share\}/#{Regexp.escape(formula.name)}[/'"]} problem "Use \#{pkgshare} instead of \#{share}/#{formula.name}" end return unless line =~ %r{share(\s*[/+]\s*)(['"])#{Regexp.escape(formula.name)}(?:\2|/)} - problem "Use pkgshare instead of (share#{$1}\"#{formula.name}\")" + problem "Use pkgshare instead of (share#{Regexp.last_match(1)}\"#{formula.name}\")" end def audit_reverse_migration @@ -1296,7 +1297,7 @@ class ResourceAuditor def audit_download_strategy if url =~ %r{^(cvs|bzr|hg|fossil)://} || url =~ %r{^(svn)\+http://} - problem "Use of the #{$&} scheme is deprecated, pass `:using => :#{$1}` instead" + problem "Use of the #{$&} scheme is deprecated, pass `:using => :#{Regexp.last_match(1)}` instead" end url_strategy = DownloadStrategyDetector.detect(url) @@ -1340,7 +1341,7 @@ class ResourceAuditor def audit_urls # Check GNU urls; doesn't apply to mirrors if url =~ %r{^(?:https?|ftp)://ftpmirror.gnu.org/(.*)} - problem "Please use \"https://ftp.gnu.org/gnu/#{$1}\" instead of #{url}." + problem "Please use \"https://ftp.gnu.org/gnu/#{Regexp.last_match(1)}\" instead of #{url}." end if mirrors.include?(url) @@ -1374,11 +1375,11 @@ class ResourceAuditor %r{^http://(?:[^/]*\.)?mirrorservice\.org/} problem "Please use https:// for #{p}" when %r{^http://search\.mcpan\.org/CPAN/(.*)}i - problem "#{p} should be `https://cpan.metacpan.org/#{$1}`" + problem "#{p} should be `https://cpan.metacpan.org/#{Regexp.last_match(1)}`" when %r{^(http|ftp)://ftp\.gnome\.org/pub/gnome/(.*)}i - problem "#{p} should be `https://download.gnome.org/#{$2}`" + problem "#{p} should be `https://download.gnome.org/#{Regexp.last_match(2)}`" when %r{^git://anonscm\.debian\.org/users/(.*)}i - problem "#{p} should be `https://anonscm.debian.org/git/users/#{$1}`" + problem "#{p} should be `https://anonscm.debian.org/git/users/#{Regexp.last_match(1)}`" end end @@ -1388,7 +1389,7 @@ class ResourceAuditor when %r{^ftp://ftp\.mirrorservice\.org} problem "Please use https:// for #{p}" when %r{^ftp://ftp\.cpan\.org/pub/CPAN(.*)}i - problem "#{p} should be `http://search.cpan.org/CPAN#{$1}`" + problem "#{p} should be `http://search.cpan.org/CPAN#{Regexp.last_match(1)}`" end end @@ -1402,7 +1403,7 @@ class ResourceAuditor next unless p =~ %r{^https?://.*\b(sourceforge|sf)\.(com|net)} if p =~ /(\?|&)use_mirror=/ - problem "Don't use #{$1}use_mirror in SourceForge urls (url is #{p})." + problem "Don't use #{Regexp.last_match(1)}use_mirror in SourceForge urls (url is #{p})." end if p.end_with?("/download") @@ -1432,7 +1433,7 @@ class ResourceAuditor problem <<-EOS.undent Please use a secure mirror for Debian URLs. We recommend: - https://mirrors.ocf.berkeley.edu/debian/#{$1} + https://mirrors.ocf.berkeley.edu/debian/#{Regexp.last_match(1)} EOS end @@ -1485,7 +1486,7 @@ class ResourceAuditor next unless u =~ %r{https?://codeload\.github\.com/(.+)/(.+)/(?:tar\.gz|zip)/(.+)} problem <<-EOS.undent use GitHub archive URLs: - https://github.com/#{$1}/#{$2}/archive/#{$3}.tar.gz + https://github.com/#{Regexp.last_match(1)}/#{Regexp.last_match(2)}/archive/#{Regexp.last_match(3)}.tar.gz Rather than codeload: #{u} EOS @@ -1494,14 +1495,18 @@ class ResourceAuditor # Check for Maven Central urls, prefer HTTPS redirector over specific host urls.each do |u| next unless u =~ %r{https?://(?:central|repo\d+)\.maven\.org/maven2/(.+)$} - problem "#{u} should be `https://search.maven.org/remotecontent?filepath=#{$1}`" + problem "#{u} should be `https://search.maven.org/remotecontent?filepath=#{Regexp.last_match(1)}`" + end + + if name == "curl" && !urls.find { |u| u.start_with?("http://") } + problem "should always include at least one HTTP url" end # Check pypi urls if @strict urls.each do |p| next unless p =~ %r{^https?://pypi.python.org/(.*)} - problem "#{p} should be `https://files.pythonhosted.org/#{$1}`" + problem "#{p} should be `https://files.pythonhosted.org/#{Regexp.last_match(1)}`" end end @@ -1514,7 +1519,7 @@ class ResourceAuditor # A `brew mirror`'ed URL is usually not yet reachable at the time of # pull request. next if url =~ %r{^https://dl.bintray.com/homebrew/mirror/} - if http_content_problem = FormulaAuditor.check_http_content(url) + if http_content_problem = FormulaAuditor.check_http_content(url, name) problem http_content_problem end elsif strategy <= GitDownloadStrategy diff --git a/Library/Homebrew/dev-cmd/bump-formula-pr.rb b/Library/Homebrew/dev-cmd/bump-formula-pr.rb index 684843d0d..586eec47c 100644 --- a/Library/Homebrew/dev-cmd/bump-formula-pr.rb +++ b/Library/Homebrew/dev-cmd/bump-formula-pr.rb @@ -265,10 +265,10 @@ module Homebrew failed_audit = false if ARGV.include? "--strict" system HOMEBREW_BREW_FILE, "audit", "--strict", formula.path - failed_audit = !$?.success? + failed_audit = !$CHILD_STATUS.success? elsif ARGV.include? "--audit" system HOMEBREW_BREW_FILE, "audit", formula.path - failed_audit = !$?.success? + failed_audit = !$CHILD_STATUS.success? end if failed_audit formula.path.atomic_write(backup_file) diff --git a/Library/Homebrew/dev-cmd/create.rb b/Library/Homebrew/dev-cmd/create.rb index 908f65f8f..802e7b900 100644 --- a/Library/Homebrew/dev-cmd/create.rb +++ b/Library/Homebrew/dev-cmd/create.rb @@ -101,13 +101,13 @@ class FormulaCreator if @name.nil? case url when %r{github\.com/(\S+)/(\S+)\.git} - @user = $1 - @name = $2 + @user = Regexp.last_match(1) + @name = Regexp.last_match(2) @head = true @github = true when %r{github\.com/(\S+)/(\S+)/(archive|releases)/} - @user = $1 - @name = $2 + @user = Regexp.last_match(1) + @name = Regexp.last_match(2) @github = true else @name = path.basename.to_s[/(.*?)[-_.]?#{Regexp.escape(path.version.to_s)}/, 1] @@ -226,9 +226,9 @@ class FormulaCreator test do # `test do` will create, run in and delete a temporary directory. # - # This test will fail and we won't accept that! It's enough to just replace - # "false" with the main program this formula installs, but it'd be nice if you - # were more thorough. Run the test with `brew test #{name}`. Options passed + # This test will fail and we won't accept that! For Homebrew/homebrew-core + # this will need to be a test that verifies the functionality of the + # software. Run the test with `brew test #{name}`. Options passed # to `brew install` such as `--HEAD` also need to be provided to `brew test`. # # The installed folder is not in the path, so use the entire path to any diff --git a/Library/Homebrew/dev-cmd/edit.rb b/Library/Homebrew/dev-cmd/edit.rb index b3a319088..b1e485fe2 100644 --- a/Library/Homebrew/dev-cmd/edit.rb +++ b/Library/Homebrew/dev-cmd/edit.rb @@ -21,8 +21,8 @@ module Homebrew # If no brews are listed, open the project root in an editor. if ARGV.named.empty? editor = File.basename which_editor - if ["mate", "subl"].include?(editor) - # If the user is using TextMate or Sublime Text, + if ["atom", "subl", "mate"].include?(editor) + # If the user is using Atom, Sublime Text or TextMate # give a nice project view instead. exec_editor HOMEBREW_REPOSITORY/"bin/brew", HOMEBREW_REPOSITORY/"README.md", diff --git a/Library/Homebrew/dev-cmd/man.rb b/Library/Homebrew/dev-cmd/man.rb index 4e5103910..7ca22575f 100644 --- a/Library/Homebrew/dev-cmd/man.rb +++ b/Library/Homebrew/dev-cmd/man.rb @@ -87,7 +87,7 @@ module Homebrew date = if ARGV.include?("--fail-if-changed") && target.extname == ".1" && target.exist? /"(\d{1,2})" "([A-Z][a-z]+) (\d{4})" "#{organisation}" "#{manual}"/ =~ target.read - Date.parse("#{$1} #{$2} #{$3}") + Date.parse("#{Regexp.last_match(1)} #{Regexp.last_match(2)} #{Regexp.last_match(3)}") else Date.today end diff --git a/Library/Homebrew/dev-cmd/pull.rb b/Library/Homebrew/dev-cmd/pull.rb index 492898a47..9681bb2bc 100644 --- a/Library/Homebrew/dev-cmd/pull.rb +++ b/Library/Homebrew/dev-cmd/pull.rb @@ -347,7 +347,7 @@ module Homebrew formulae = [] others = [] File.foreach(patchfile) do |line| - files << $1 if line =~ %r{^\+\+\+ b/(.*)} + files << Regexp.last_match(1) if line =~ %r{^\+\+\+ b/(.*)} end files.each do |file| if tap && tap.formula_file?(file) @@ -459,7 +459,7 @@ module Homebrew def self.lookup(name) json = Utils.popen_read(HOMEBREW_BREW_FILE, "info", "--json=v1", name) - return nil unless $?.success? + return nil unless $CHILD_STATUS.success? Homebrew.force_utf8!(json) FormulaInfoFromJson.new(JSON.parse(json)[0]) diff --git a/Library/Homebrew/dev-cmd/release-notes.rb b/Library/Homebrew/dev-cmd/release-notes.rb index bd6363865..e578869bf 100644 --- a/Library/Homebrew/dev-cmd/release-notes.rb +++ b/Library/Homebrew/dev-cmd/release-notes.rb @@ -33,7 +33,7 @@ module Homebrew if ARGV.include?("--markdown") output.map! do |s| /(.*\d)+ \(@(.+)\) - (.*)/ =~ s - "- [#{$3}](#{$1}) (@#{$2})" + "- [#{Regexp.last_match(3)}](#{Regexp.last_match(1)}) (@#{Regexp.last_match(2)})" end end diff --git a/Library/Homebrew/dev-cmd/tests.rb b/Library/Homebrew/dev-cmd/tests.rb index 13f4d7b1e..658f2e2f3 100644 --- a/Library/Homebrew/dev-cmd/tests.rb +++ b/Library/Homebrew/dev-cmd/tests.rb @@ -12,10 +12,8 @@ #: If `--no-compat` is passed, do not load the compatibility layer when #: running tests. #: -#: If `--online` is passed, include tests that use the GitHub API. -#: -#: If `--official-cmd-taps` is passed, include tests that use any of the -#: taps for official external commands. +#: If `--online` is passed, include tests that use the GitHub API and tests +#: that use any of the taps for official external commands. require "fileutils" require "tap" @@ -40,10 +38,6 @@ module Homebrew ENV["HOMEBREW_NO_GITHUB_API"] = "1" end - if ARGV.include? "--official-cmd-taps" - ENV["HOMEBREW_TEST_OFFICIAL_CMD_TAPS"] = "1" - end - if ARGV.include? "--coverage" ENV["HOMEBREW_TESTS_COVERAGE"] = "1" FileUtils.rm_f "test/coverage/.resultset.json" @@ -117,7 +111,7 @@ module Homebrew system "bundle", "exec", "rspec", *args, "--", *files end - return if $?.success? + return if $CHILD_STATUS.success? Homebrew.failed = true end end diff --git a/Library/Homebrew/diagnostic.rb b/Library/Homebrew/diagnostic.rb index 2741184cc..05e48da21 100644 --- a/Library/Homebrew/diagnostic.rb +++ b/Library/Homebrew/diagnostic.rb @@ -49,7 +49,7 @@ module Homebrew case line.chomp # regex matches: /dev/disk0s2 489562928 440803616 48247312 91% / when /^.+\s+[0-9]+\s+[0-9]+\s+[0-9]+\s+[0-9]{1,3}%\s+(.+)/ - vols << $1 + vols << Regexp.last_match(1) end end end @@ -740,7 +740,7 @@ module Homebrew Unless you have compelling reasons, consider setting the origin remote to point at the main repository by running: - git -C "#{HOMEBREW_REPOSITORY}" remote add origin #{Formatter.url("https://github.com/Homebrew/brew.git")} + git -C "#{HOMEBREW_REPOSITORY}" remote set-url origin #{Formatter.url("https://github.com/Homebrew/brew.git")} EOS end end @@ -769,7 +769,7 @@ module Homebrew Unless you have compelling reasons, consider setting the origin remote to point at the main repository by running: - git -C "#{coretap_path}" remote add origin #{Formatter.url("https://github.com/Homebrew/homebrew-core.git")} + git -C "#{coretap_path}" remote set-url origin #{Formatter.url("https://github.com/Homebrew/homebrew-core.git")} EOS end end @@ -919,11 +919,11 @@ module Homebrew return unless which "python" `python -V 2>&1` =~ /Python (\d+)\./ # This won't be the right warning if we matched nothing at all - return if $1.nil? - return if $1 == "2" + return if Regexp.last_match(1).nil? + return if Regexp.last_match(1) == "2" <<-EOS.undent - python is symlinked to python#{$1} + python is symlinked to python#{Regexp.last_match(1)} This will confuse build scripts and in general lead to subtle breakage. EOS end diff --git a/Library/Homebrew/download_strategy.rb b/Library/Homebrew/download_strategy.rb index 9ca30bb9c..78f6c1e28 100644 --- a/Library/Homebrew/download_strategy.rb +++ b/Library/Homebrew/download_strategy.rb @@ -338,7 +338,7 @@ class CurlDownloadStrategy < AbstractFileDownloadStrategy rescue ErrorDuringExecution # 33 == range not supported # try wiping the incomplete download and retrying once - unless $?.exitstatus == 33 && had_incomplete_download + unless $CHILD_STATUS.exitstatus == 33 && had_incomplete_download raise CurlDownloadStrategyError, @url end @@ -517,8 +517,8 @@ class S3DownloadStrategy < CurlDownloadStrategy if @url !~ %r{^https?://([^.].*)\.s3\.amazonaws\.com/(.+)$} raise "Bad S3 URL: " + @url end - bucket = $1 - key = $2 + bucket = Regexp.last_match(1) + key = Regexp.last_match(2) ENV["AWS_ACCESS_KEY_ID"] = ENV["HOMEBREW_AWS_ACCESS_KEY_ID"] ENV["AWS_SECRET_ACCESS_KEY"] = ENV["HOMEBREW_AWS_SECRET_ACCESS_KEY"] diff --git a/Library/Homebrew/exceptions.rb b/Library/Homebrew/exceptions.rb index 488ef7064..23a123c44 100644 --- a/Library/Homebrew/exceptions.rb +++ b/Library/Homebrew/exceptions.rb @@ -182,7 +182,7 @@ class TapFormulaAmbiguityError < RuntimeError @paths = paths @formulae = paths.map do |path| path.to_s =~ HOMEBREW_TAP_PATH_REGEX - "#{Tap.fetch($1, $2)}/#{path.basename(".rb")}" + "#{Tap.fetch(Regexp.last_match(1), Regexp.last_match(2))}/#{path.basename(".rb")}" end super <<-EOS.undent @@ -202,7 +202,7 @@ class TapFormulaWithOldnameAmbiguityError < RuntimeError @taps = possible_tap_newname_formulae.map do |newname| newname =~ HOMEBREW_TAP_FORMULA_REGEX - "#{$1}/#{$2}" + "#{Regexp.last_match(1)}/#{Regexp.last_match(2)}" end super <<-EOS.undent @@ -352,6 +352,7 @@ end class BuildError < RuntimeError attr_reader :formula, :env + attr_accessor :options def initialize(formula, cmd, args, env) @formula = formula @@ -503,7 +504,7 @@ class CurlDownloadStrategyError < RuntimeError def initialize(url) case url when %r{^file://(.+)} - super "File does not exist: #{$1}" + super "File does not exist: #{Regexp.last_match(1)}" else super "Download failed: #{url}" end diff --git a/Library/Homebrew/extend/ENV/std.rb b/Library/Homebrew/extend/ENV/std.rb index 4a871f9bb..a2e800803 100644 --- a/Library/Homebrew/extend/ENV/std.rb +++ b/Library/Homebrew/extend/ENV/std.rb @@ -200,7 +200,7 @@ module Stdenv # @private def set_cpu_flags(flags, default = DEFAULT_FLAGS, map = Hardware::CPU.optimization_flags) cflags =~ /(-Xarch_#{Hardware::CPU.arch_32_bit} )-march=/ - xarch = $1.to_s + xarch = Regexp.last_match(1).to_s remove flags, /(-Xarch_#{Hardware::CPU.arch_32_bit} )?-march=\S*/ remove flags, /( -Xclang \S+)+/ remove flags, /-mssse3/ diff --git a/Library/Homebrew/extend/ENV/super.rb b/Library/Homebrew/extend/ENV/super.rb index ef41161af..692fd3623 100644 --- a/Library/Homebrew/extend/ENV/super.rb +++ b/Library/Homebrew/extend/ENV/super.rb @@ -266,7 +266,7 @@ module Superenv def make_jobs self["MAKEFLAGS"] =~ /-\w*j(\d+)/ - [$1.to_i, 1].max + [Regexp.last_match(1).to_i, 1].max end def universal_binary diff --git a/Library/Homebrew/extend/os/mac/diagnostic.rb b/Library/Homebrew/extend/os/mac/diagnostic.rb index 58d8c633d..0cdd7b115 100644 --- a/Library/Homebrew/extend/os/mac/diagnostic.rb +++ b/Library/Homebrew/extend/os/mac/diagnostic.rb @@ -195,7 +195,8 @@ module Homebrew end def check_ruby_version - return if RUBY_VERSION[/\d\.\d/] == "2.0" + ruby_version = "2.0" + return if RUBY_VERSION[/\d\.\d/] == ruby_version <<-EOS.undent Ruby version #{RUBY_VERSION} is unsupported on #{MacOS.version}. Homebrew @@ -270,7 +271,7 @@ module Homebrew def check_xcode_license_approved # If the user installs Xcode-only, they have to approve the # license or no "xc*" tool will work. - return unless `/usr/bin/xcrun clang 2>&1` =~ /license/ && !$?.success? + return unless `/usr/bin/xcrun clang 2>&1` =~ /license/ && !$CHILD_STATUS.success? <<-EOS.undent You have not agreed to the Xcode license. diff --git a/Library/Homebrew/extend/os/mac/requirements/java_requirement.rb b/Library/Homebrew/extend/os/mac/requirements/java_requirement.rb index da2dffba0..2f132d740 100644 --- a/Library/Homebrew/extend/os/mac/requirements/java_requirement.rb +++ b/Library/Homebrew/extend/os/mac/requirements/java_requirement.rb @@ -23,7 +23,7 @@ class JavaRequirement < Requirement args = %w[--failfast] args << "--version" << @version.to_s if @version java_home = Utils.popen_read("/usr/libexec/java_home", *args).chomp - return nil unless $?.success? + return nil unless $CHILD_STATUS.success? Pathname.new(java_home)/"bin/java" end diff --git a/Library/Homebrew/extend/os/mac/utils/bottles.rb b/Library/Homebrew/extend/os/mac/utils/bottles.rb index c54e4e5b7..03980aab0 100644 --- a/Library/Homebrew/extend/os/mac/utils/bottles.rb +++ b/Library/Homebrew/extend/os/mac/utils/bottles.rb @@ -32,7 +32,7 @@ module Utils # :tiger_g4, :tiger_g5, etc. def find_altivec_tag(tag) return unless tag.to_s =~ /(\w+)_(g4|g4e|g5)$/ - altivec_tag = "#{$1}_altivec".to_sym + altivec_tag = "#{Regexp.last_match(1)}_altivec".to_sym altivec_tag if key?(altivec_tag) end diff --git a/Library/Homebrew/formula.rb b/Library/Homebrew/formula.rb index d9254d23d..d64191b66 100644 --- a/Library/Homebrew/formula.rb +++ b/Library/Homebrew/formula.rb @@ -177,7 +177,7 @@ class Formula @tap = if path == Formulary.core_path(name) CoreTap.instance elsif path.to_s =~ HOMEBREW_TAP_PATH_REGEX - Tap.fetch($1, $2) + Tap.fetch(Regexp.last_match(1), Regexp.last_match(2)) end @full_name = full_name_with_optional_tap(name) @@ -1836,7 +1836,7 @@ class Formula $stdout.flush - unless $?.success? + unless $CHILD_STATUS.success? log_lines = ENV["HOMEBREW_FAIL_LOG_LINES"] log_lines ||= "15" diff --git a/Library/Homebrew/formula_assertions.rb b/Library/Homebrew/formula_assertions.rb index 477782e53..047b40abc 100644 --- a/Library/Homebrew/formula_assertions.rb +++ b/Library/Homebrew/formula_assertions.rb @@ -27,7 +27,7 @@ module Homebrew def shell_output(cmd, result = 0) ohai cmd output = `#{cmd}` - assert_equal result, $?.exitstatus + assert_equal result, $CHILD_STATUS.exitstatus output end @@ -40,7 +40,7 @@ module Homebrew pipe.close_write pipe.read end - assert_equal result, $?.exitstatus unless result.nil? + assert_equal result, $CHILD_STATUS.exitstatus unless result.nil? output end end diff --git a/Library/Homebrew/formula_installer.rb b/Library/Homebrew/formula_installer.rb index fa3096542..2a5120342 100644 --- a/Library/Homebrew/formula_installer.rb +++ b/Library/Homebrew/formula_installer.rb @@ -261,24 +261,17 @@ class FormulaInstaller opoo "#{formula.full_name}: this formula has no #{option} option so it will be ignored!" end - options = [] - if formula.head? - options << "--HEAD" - elsif formula.devel? - options << "--devel" + options = display_options(formula) + if show_header? + oh1 "Installing #{Formatter.identifier(formula.full_name)} #{options}".strip end - options += effective_build_options_for(formula).used_options.to_a - oh1 "Installing #{Formatter.identifier(formula.full_name)} #{options.join " "}" if show_header? if formula.tap && !formula.tap.private? - category = "install" - action = ([formula.full_name] + options).join(" ") - Utils::Analytics.report_event(category, action) + action = "#{formula.full_name} #{options}".strip + Utils::Analytics.report_event("install", action) if installed_on_request - category = "install_on_request" - action = ([formula.full_name] + options).join(" ") - Utils::Analytics.report_event(category, action) + Utils::Analytics.report_event("install_on_request", action) end end @@ -478,6 +471,18 @@ class FormulaInstaller BuildOptions.new(args, dependent.options) end + def display_options(formula) + options = [] + if formula.head? + options << "--HEAD" + elsif formula.devel? + options << "--devel" + end + options += effective_build_options_for(formula).used_options.to_a + return if options.empty? + options.join(" ") + end + def inherited_options_for(dep) inherited_options = Options.new u = Option.new("universal") @@ -680,7 +685,8 @@ class FormulaInstaller if !formula.prefix.directory? || Keg.new(formula.prefix).empty_installation? raise "Empty installation" end - rescue Exception + rescue Exception => e + e.options = display_options(formula) if e.is_a?(BuildError) ignore_interrupts do # any exceptions must leave us with nothing installed formula.update_head_version diff --git a/Library/Homebrew/formulary.rb b/Library/Homebrew/formulary.rb index 446d5dc10..a0ccb9ba0 100644 --- a/Library/Homebrew/formulary.rb +++ b/Library/Homebrew/formulary.rb @@ -59,7 +59,7 @@ module Formulary def self.class_s(name) class_name = name.capitalize - class_name.gsub!(/[-_.\s]([a-zA-Z0-9])/) { $1.upcase } + class_name.gsub!(/[-_.\s]([a-zA-Z0-9])/) { Regexp.last_match(1).upcase } class_name.tr!("+", "x") class_name.sub!(/(.)@(\d)/, "\\1AT\\2") class_name @@ -96,7 +96,7 @@ module Formulary private def load_file - $stderr.puts "#{$0} (#{self.class.name}): loading #{path}" if ARGV.debug? + $stderr.puts "#{$PROGRAM_NAME} (#{self.class.name}): loading #{path}" if ARGV.debug? raise FormulaUnavailableError, name unless path.file? Formulary.load_formula_from_path(name, path) end @@ -168,7 +168,7 @@ module Formulary super rescue MethodDeprecatedError => e if url =~ %r{github.com/([\w-]+)/homebrew-([\w-]+)/} - e.issues_url = "https://github.com/#{$1}/homebrew-#{$2}/issues/new" + e.issues_url = "https://github.com/#{Regexp.last_match(1)}/homebrew-#{Regexp.last_match(2)}/issues/new" end raise end @@ -258,7 +258,7 @@ module Formulary end def klass - $stderr.puts "#{$0} (#{self.class.name}): loading #{path}" if ARGV.debug? + $stderr.puts "#{$PROGRAM_NAME} (#{self.class.name}): loading #{path}" if ARGV.debug? namespace = "FormulaNamespace#{Digest::MD5.hexdigest(contents)}" Formulary.load_formula(name, path, contents, namespace) end diff --git a/Library/Homebrew/global.rb b/Library/Homebrew/global.rb index 877253072..f36b01874 100644 --- a/Library/Homebrew/global.rb +++ b/Library/Homebrew/global.rb @@ -12,6 +12,7 @@ require "set" require "rbconfig" require "official_taps" require "pp" +require "English" ARGV.extend(HomebrewArgvExtension) diff --git a/Library/Homebrew/language/node.rb b/Library/Homebrew/language/node.rb index b9abaea54..47431e8e5 100644 --- a/Library/Homebrew/language/node.rb +++ b/Library/Homebrew/language/node.rb @@ -11,7 +11,7 @@ module Language # directory, consequently breaking that assumption. We require a tarball # because npm install creates a "real" installation when fed a tarball. output = Utils.popen_read("npm pack").chomp - raise "npm failed to pack #{Dir.pwd}" unless $?.exitstatus.zero? + raise "npm failed to pack #{Dir.pwd}" unless $CHILD_STATUS.exitstatus.zero? output end diff --git a/Library/Homebrew/os/mac.rb b/Library/Homebrew/os/mac.rb index bc384da30..5074665fc 100644 --- a/Library/Homebrew/os/mac.rb +++ b/Library/Homebrew/os/mac.rb @@ -207,6 +207,8 @@ module OS "8.3" => { clang: "8.1", clang_build: 802 }, "8.3.1" => { clang: "8.1", clang_build: 802 }, "8.3.2" => { clang: "8.1", clang_build: 802 }, + "8.3.3" => { clang: "8.1", clang_build: 802 }, + "9.0" => { clang: "9.0", clang_build: 900 }, }.freeze def compilers_standard? diff --git a/Library/Homebrew/os/mac/pkgconfig/10.13/libcurl.pc b/Library/Homebrew/os/mac/pkgconfig/10.13/libcurl.pc new file mode 100644 index 000000000..91c69df6e --- /dev/null +++ b/Library/Homebrew/os/mac/pkgconfig/10.13/libcurl.pc @@ -0,0 +1,39 @@ +#*************************************************************************** +# _ _ ____ _ +# Project ___| | | | _ \| | +# / __| | | | |_) | | +# | (__| |_| | _ <| |___ +# \___|\___/|_| \_\_____| +# +# Copyright (C) 2004 - 2012, Daniel Stenberg, <daniel@haxx.se>, et al. +# +# This software is licensed as described in the file COPYING, which +# you should have received as part of this distribution. The terms +# are also available at http://curl.haxx.se/docs/copyright.html. +# +# You may opt to use, copy, modify, merge, publish, distribute and/or sell +# copies of the Software, and permit persons to whom the Software is +# furnished to do so, under the terms of the COPYING file. +# +# This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY +# KIND, either express or implied. +# +########################################################################### + +# This should most probably benefit from getting a "Requires:" field added +# dynamically by configure. +# +prefix=/usr +exec_prefix=${prefix} +libdir=${exec_prefix}/lib +includedir=${prefix}/include +supported_protocols="DICT FILE FTP FTPS GOPHER HTTP HTTPS IMAP IMAPS LDAP LDAPS POP3 POP3S RTSP SMB SMBS SMTP SMTPS TELNET TFTP" +supported_features="AsynchDNS IPv6 Largefile GSS-API Kerberos SPNEGO NTLM NTLM_WB SSL libz UnixSockets" + +Name: libcurl +URL: https://curl.haxx.se/ +Description: Library to transfer files with ftp, http, etc. +Version: 7.51.0 +Libs: -L${libdir} -lcurl +Libs.private: -lldap -lz +Cflags: -I${includedir} diff --git a/Library/Homebrew/os/mac/pkgconfig/10.13/libexslt.pc b/Library/Homebrew/os/mac/pkgconfig/10.13/libexslt.pc new file mode 100644 index 000000000..16276f715 --- /dev/null +++ b/Library/Homebrew/os/mac/pkgconfig/10.13/libexslt.pc @@ -0,0 +1,12 @@ +prefix=/usr +exec_prefix=${prefix} +libdir=${exec_prefix}/lib +includedir=${prefix}/include + + +Name: libexslt +Version: 0.8.17 +Description: EXSLT Extension library +Requires: libxml-2.0 +Libs: -L${libdir} -lexslt -lxslt -lxml2 -lz -lpthread -licucore -lm +Cflags: -I${includedir} diff --git a/Library/Homebrew/os/mac/pkgconfig/10.13/libxml-2.0.pc b/Library/Homebrew/os/mac/pkgconfig/10.13/libxml-2.0.pc new file mode 100644 index 000000000..c297c6b45 --- /dev/null +++ b/Library/Homebrew/os/mac/pkgconfig/10.13/libxml-2.0.pc @@ -0,0 +1,13 @@ +prefix=/usr +exec_prefix=${prefix} +libdir=${exec_prefix}/lib +includedir=${prefix}/include +modules=1 + +Name: libXML +Version: 2.9.4 +Description: libXML library version2. +Requires: +Libs: -L${libdir} -lxml2 +Libs.private: -lz -lpthread -licucore -lm +Cflags: -I${includedir}/libxml2 diff --git a/Library/Homebrew/os/mac/pkgconfig/10.13/libxslt.pc b/Library/Homebrew/os/mac/pkgconfig/10.13/libxslt.pc new file mode 100644 index 000000000..92d07a988 --- /dev/null +++ b/Library/Homebrew/os/mac/pkgconfig/10.13/libxslt.pc @@ -0,0 +1,12 @@ +prefix=/usr +exec_prefix=${prefix} +libdir=${exec_prefix}/lib +includedir=${prefix}/include + + +Name: libxslt +Version: 1.1.29 +Description: XSLT library version 2. +Requires: libxml-2.0 +Libs: -L${libdir} -lxslt -lxml2 -lz -lpthread -licucore -lm +Cflags: -I${includedir} diff --git a/Library/Homebrew/os/mac/pkgconfig/10.13/sqlite3.pc b/Library/Homebrew/os/mac/pkgconfig/10.13/sqlite3.pc new file mode 100644 index 000000000..aa78d2c1d --- /dev/null +++ b/Library/Homebrew/os/mac/pkgconfig/10.13/sqlite3.pc @@ -0,0 +1,11 @@ +prefix=/usr +exec_prefix=${prefix} +libdir=${exec_prefix}/lib +includedir=${prefix}/include + +Name: SQLite +Description: SQL database engine +Version: 3.18.0 +Libs: -L${libdir} -lsqlite3 +Libs.private: +Cflags: -I${includedir} diff --git a/Library/Homebrew/os/mac/pkgconfig/10.13/zlib.pc b/Library/Homebrew/os/mac/pkgconfig/10.13/zlib.pc new file mode 100644 index 000000000..628892158 --- /dev/null +++ b/Library/Homebrew/os/mac/pkgconfig/10.13/zlib.pc @@ -0,0 +1,13 @@ +prefix=/usr +exec_prefix=${prefix} +libdir=${exec_prefix}/lib +sharedlibdir=${libdir} +includedir=${prefix}/include + +Name: zlib +Description: zlib compression library +Version: 1.2.8 + +Requires: +Libs: -L${libdir} -L${sharedlibdir} -lz +Cflags: -I${includedir} diff --git a/Library/Homebrew/os/mac/version.rb b/Library/Homebrew/os/mac/version.rb index 802ec3035..89016bb4d 100644 --- a/Library/Homebrew/os/mac/version.rb +++ b/Library/Homebrew/os/mac/version.rb @@ -4,6 +4,7 @@ module OS module Mac class Version < ::Version SYMBOLS = { + high_sierra: "10.13", sierra: "10.12", el_capitan: "10.11", yosemite: "10.10", diff --git a/Library/Homebrew/os/mac/xcode.rb b/Library/Homebrew/os/mac/xcode.rb index 9ed95d3f2..d957792af 100644 --- a/Library/Homebrew/os/mac/xcode.rb +++ b/Library/Homebrew/os/mac/xcode.rb @@ -17,17 +17,19 @@ module OS when "10.9" then "6.2" when "10.10" then "7.2.1" when "10.11" then "8.2.1" - when "10.12" then "8.3.2" + when "10.12" then "8.3.3" + when "10.13" then "9.0" else raise "macOS '#{MacOS.version}' is invalid" unless OS::Mac.prerelease? # Default to newest known version of Xcode for unreleased macOS versions. - "8.3.2" + "9.0" end end def minimum_version case MacOS.version + when "10.13" then "9.0" when "10.12" then "8.0" else "2.0" end @@ -116,7 +118,7 @@ module OS ].uniq.each do |xcodebuild_path| next unless File.executable? xcodebuild_path xcodebuild_output = Utils.popen_read(xcodebuild_path, "-version") - next unless $?.success? + next unless $CHILD_STATUS.success? xcode_version = xcodebuild_output[/Xcode (\d(\.\d)*)/, 1] return xcode_version if xcode_version @@ -152,7 +154,8 @@ module OS when 73 then "7.3" when 80 then "8.0" when 81 then "8.3" - else "8.3" + when 90 then "9.0" + else "9.0" end end @@ -213,6 +216,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.13" then "900.0.22.8" when "10.12" then "802.0.42" when "10.11" then "800.0.42.1" when "10.10" then "700.1.81" diff --git a/Library/Homebrew/patch.rb b/Library/Homebrew/patch.rb index 7f5a6af35..7045adf5e 100644 --- a/Library/Homebrew/patch.rb +++ b/Library/Homebrew/patch.rb @@ -68,7 +68,7 @@ class EmbeddedPatch cmd = "/usr/bin/patch" args = %W[-g 0 -f -#{strip}] IO.popen("#{cmd} #{args.join(" ")}", "w") { |p| p.write(data) } - raise ErrorDuringExecution.new(cmd, args) unless $?.success? + raise ErrorDuringExecution.new(cmd, args) unless $CHILD_STATUS.success? end def inspect diff --git a/Library/Homebrew/readall.rb b/Library/Homebrew/readall.rb index ddac58444..3595c16be 100644 --- a/Library/Homebrew/readall.rb +++ b/Library/Homebrew/readall.rb @@ -82,7 +82,7 @@ module Readall # Only syntax errors result in a non-zero status code. To detect syntax # warnings we also need to inspect the output to `$stderr`. - !$?.success? || !messages.chomp.empty? + !$CHILD_STATUS.success? || !messages.chomp.empty? end end end diff --git a/Library/Homebrew/requirement.rb b/Library/Homebrew/requirement.rb index cac8c6232..cfb925b49 100644 --- a/Library/Homebrew/requirement.rb +++ b/Library/Homebrew/requirement.rb @@ -61,7 +61,7 @@ class Requirement if parent = satisfied_result_parent parent.to_s =~ %r{(#{Regexp.escape(HOMEBREW_CELLAR)}|#{Regexp.escape(HOMEBREW_PREFIX)}/opt)/([\w+-.@]+)} - @formula = $2 + @formula = Regexp.last_match(2) end true diff --git a/Library/Homebrew/rubocops/formula_desc_cop.rb b/Library/Homebrew/rubocops/formula_desc_cop.rb index 54a14b39d..e44c222d8 100644 --- a/Library/Homebrew/rubocops/formula_desc_cop.rb +++ b/Library/Homebrew/rubocops/formula_desc_cop.rb @@ -8,27 +8,51 @@ module RuboCop # # - Checks for existence of `desc` # - Checks if size of `desc` > 80 - # - Checks if `desc` begins with an article - # - Checks for correct usage of `command-line` in `desc` - # - Checks if `desc` contains the formula name - class Desc < FormulaCop + class DescLength < FormulaCop def audit_formula(_node, _class_node, _parent_class_node, body) desc_call = find_node_method_by_name(body, :desc) + # Check if a formula's desc is present if desc_call.nil? problem "Formula should have a desc (Description)." return end + # Check if a formula's desc is too long desc = parameters(desc_call).first desc_length = "#{@formula_name}: #{string_content(desc)}".length max_desc_length = 80 - if desc_length > max_desc_length - problem <<-EOS.undent - Description is too long. "name: desc" should be less than #{max_desc_length} characters. - Length is calculated as #{@formula_name} + desc. (currently #{desc_length}) - EOS - end + return if desc_length <= max_desc_length + problem <<-EOS.undent + Description is too long. "name: desc" should be less than #{max_desc_length} characters. + Length is calculated as #{@formula_name} + desc. (currently #{desc_length}) + EOS + end + end + + # This cop audits `desc` in Formulae + # + # - Checks if `desc` begins with an article + # - Checks for correct usage of `command-line` in `desc` + # - Checks description starts with a capital letter + # - Checks if `desc` contains the formula name + class Desc < FormulaCop + VALID_LOWERCASE_WORDS = %w[ + ex + eXtensible + iOS + macOS + malloc + ooc + preexec + xUnit + ].freeze + + def audit_formula(_node, _class_node, _parent_class_node, body) + desc_call = find_node_method_by_name(body, :desc) + return if desc_call.nil? + + desc = parameters(desc_call).first # Check if command-line is wrongly used in formula's desc if match = regex_match_group(desc, /(command ?line)/i) @@ -36,16 +60,41 @@ module RuboCop problem "Description should use \"#{c}ommand-line\" instead of \"#{match}\"" end + # Check if a/an are used in a formula's desc if match = regex_match_group(desc, /^(an?)\s/i) - problem "Description shouldn't start with an indefinite article (#{match})" + problem "Description shouldn't start with an indefinite article i.e. \"#{match.to_s.strip}\"" end - if regex_match_group(desc, /^[a-z]/) + # Check if invalid uppercase words are at the start of a + # formula's desc + if !VALID_LOWERCASE_WORDS.include?(string_content(desc).split.first) && + regex_match_group(desc, /^[a-z]/) problem "Description should start with a capital letter" end # Check if formula's name is used in formula's desc - problem "Description shouldn't include the formula name" if regex_match_group(desc, /^#{@formula_name}\b/i) + return unless regex_match_group(desc, /(^|[^a-z])#{@formula_name}([^a-z]|$)/i) + problem "Description shouldn't include the formula name" + end + + private + + def autocorrect(node) + lambda do |corrector| + correction = node.source + first_word = string_content(node).split.first + unless VALID_LOWERCASE_WORDS.include?(first_word) + first_char = first_word.to_s.chars.first + correction.sub!(/^(['"]?)([a-z])/, "\\1#{first_char.upcase}") + end + correction.sub!(/^(['"]?)an?\s/i, "\\1") + correction.gsub!(/(ommand ?line)/i, "ommand-line") + correction.gsub!(/(^|[^a-z])#{@formula_name}([^a-z]|$)/i, "\\1\\2") + correction.gsub!(/^(['"]?)\s+/, "\\1") + correction.gsub!(/\s+(['"]?)$/, "\\1") + corrector.insert_before(node.source_range, correction) + corrector.remove(node.source_range) + end end end end diff --git a/Library/Homebrew/rubocops/homepage_cop.rb b/Library/Homebrew/rubocops/homepage_cop.rb index a40c7b049..25c0e9c51 100644 --- a/Library/Homebrew/rubocops/homepage_cop.rb +++ b/Library/Homebrew/rubocops/homepage_cop.rb @@ -54,7 +54,7 @@ module RuboCop problem "Please use https:// for #{homepage}" when %r{^http://([^/]*)\.(sf|sourceforge)\.net(/|$)} - problem "#{homepage} should be `https://#{$1}.sourceforge.io/`" + problem "#{homepage} should be `https://#{Regexp.last_match(1)}.sourceforge.io/`" # There's an auto-redirect here, but this mistake is incredibly common too. # Only applies to the homepage and subdomains for now, not the FTP URLs. diff --git a/Library/Homebrew/shims/super/g++-7 b/Library/Homebrew/shims/super/g++-7 new file mode 120000 index 000000000..2652f5f42 --- /dev/null +++ b/Library/Homebrew/shims/super/g++-7 @@ -0,0 +1 @@ +cc
\ No newline at end of file diff --git a/Library/Homebrew/shims/super/gcc-7 b/Library/Homebrew/shims/super/gcc-7 new file mode 120000 index 000000000..2652f5f42 --- /dev/null +++ b/Library/Homebrew/shims/super/gcc-7 @@ -0,0 +1 @@ +cc
\ No newline at end of file diff --git a/Library/Homebrew/system_config.rb b/Library/Homebrew/system_config.rb index 56826f62d..f89c79306 100644 --- a/Library/Homebrew/system_config.rb +++ b/Library/Homebrew/system_config.rb @@ -128,7 +128,7 @@ class SystemConfig return "N/A" unless File.executable? "/usr/libexec/java_home" java_xml = Utils.popen_read("/usr/libexec/java_home", "--xml", "--failfast") - return "N/A" unless $?.success? + return "N/A" unless $CHILD_STATUS.success? javas = [] REXML::XPath.each(REXML::Document.new(java_xml), "//key[text()='JVMVersion']/following-sibling::string") do |item| javas << item.text diff --git a/Library/Homebrew/tap.rb b/Library/Homebrew/tap.rb index 66aa10158..0aabce6c3 100644 --- a/Library/Homebrew/tap.rb +++ b/Library/Homebrew/tap.rb @@ -43,8 +43,8 @@ class Tap def self.from_path(path) path.to_s =~ HOMEBREW_TAP_PATH_REGEX - raise "Invalid tap path '#{path}'" unless $1 - fetch($1, $2) + raise "Invalid tap path '#{path}'" unless Regexp.last_match(1) + fetch(Regexp.last_match(1), Regexp.last_match(2)) rescue # No need to error as a nil tap is sufficient to show failure. nil diff --git a/Library/Homebrew/test/.codecov.yml b/Library/Homebrew/test/.codecov.yml index c53d9f9dd..9c75dfe6a 100644 --- a/Library/Homebrew/test/.codecov.yml +++ b/Library/Homebrew/test/.codecov.yml @@ -1,7 +1,4 @@ -comment: false -coverage: - fixes: - - "::Library/Homebrew/" - parsers: - v1: - include_full_missed_files: yes +comment: off + +fixes: + - "::Library/Homebrew/" diff --git a/Library/Homebrew/test/cask/artifact/suite_spec.rb b/Library/Homebrew/test/cask/artifact/suite_spec.rb index 98ae93311..eca6b6f17 100644 --- a/Library/Homebrew/test/cask/artifact/suite_spec.rb +++ b/Library/Homebrew/test/cask/artifact/suite_spec.rb @@ -10,19 +10,6 @@ describe Hbc::Artifact::Suite, :cask do InstallHelper.install_without_artifacts(cask) end - it "moves the suite to the proper directory" do - skip("flaky test") # FIXME - - shutup do - install_phase.call - end - - expect(target_path).to be_a_directory - expect(target_path).to be_a_symlink - expect(target_path.readlink).to exist - expect(source_path).not_to exist - end - it "creates a suite containing the expected app" do shutup do install_phase.call diff --git a/Library/Homebrew/test/cask/cli/audit_spec.rb b/Library/Homebrew/test/cask/cli/audit_spec.rb index 412db1481..01f506c8c 100644 --- a/Library/Homebrew/test/cask/cli/audit_spec.rb +++ b/Library/Homebrew/test/cask/cli/audit_spec.rb @@ -1,5 +1,5 @@ describe Hbc::CLI::Audit, :cask do - let(:cask) { double } + let(:cask) { double("cask", token: nil) } describe "selection of Casks to audit" do it "audits all Casks if no tokens are given" do diff --git a/Library/Homebrew/test/cask/cli/cat_spec.rb b/Library/Homebrew/test/cask/cli/cat_spec.rb index 28089b2f1..b726a0b36 100644 --- a/Library/Homebrew/test/cask/cli/cat_spec.rb +++ b/Library/Homebrew/test/cask/cli/cat_spec.rb @@ -34,9 +34,9 @@ describe Hbc::CLI::Cat, :cask do end it "raises an exception when the Cask does not exist" do - expect { - Hbc::CLI::Cat.run("notacask") - }.to raise_error(Hbc::CaskUnavailableError) + expect { Hbc::CLI::Cat.run("notacask") } + .to output(/is unavailable/).to_stderr + .and raise_error(Hbc::CaskError, "Cat incomplete.") end describe "when no Cask is specified" do diff --git a/Library/Homebrew/test/cask/cli/fetch_spec.rb b/Library/Homebrew/test/cask/cli/fetch_spec.rb index 9f3056631..54bdfc0c8 100644 --- a/Library/Homebrew/test/cask/cli/fetch_spec.rb +++ b/Library/Homebrew/test/cask/cli/fetch_spec.rb @@ -54,7 +54,7 @@ describe Hbc::CLI::Fetch, :cask do shutup do Hbc::CLI::Fetch.run("notacask") end - }.to raise_error(Hbc::CaskUnavailableError) + }.to raise_error(Hbc::CaskError, "Fetch incomplete.") end describe "when no Cask is specified" do diff --git a/Library/Homebrew/test/cask/cli/install_spec.rb b/Library/Homebrew/test/cask/cli/install_spec.rb index b1b26c867..cf69b5d86 100644 --- a/Library/Homebrew/test/cask/cli/install_spec.rb +++ b/Library/Homebrew/test/cask/cli/install_spec.rb @@ -41,7 +41,7 @@ describe Hbc::CLI::Install, :cask do expect { Hbc::CLI::Install.run("local-transmission") - }.to output(/Warning: A Cask for local-transmission is already installed./).to_stderr + }.to output(/Warning: Cask 'local-transmission' is already installed./).to_stderr end it "allows double install with --force" do @@ -70,7 +70,7 @@ describe Hbc::CLI::Install, :cask do shutup do Hbc::CLI::Install.run("notacask") end - }.to raise_error(Hbc::CaskError) + }.to raise_error(Hbc::CaskError, "Install incomplete.") end it "returns a suggestion for a misspelled Cask" do @@ -80,7 +80,7 @@ describe Hbc::CLI::Install, :cask do rescue Hbc::CaskError nil end - }.to output(/No available Cask for localcaffeine\. Did you mean:\nlocal-caffeine/).to_stderr + }.to output(/Cask 'localcaffeine' is unavailable: No Cask with this name exists\. Did you mean:\nlocal-caffeine/).to_stderr end it "returns multiple suggestions for a Cask fragment" do @@ -90,7 +90,7 @@ describe Hbc::CLI::Install, :cask do rescue Hbc::CaskError nil end - }.to output(/No available Cask for local-caf\. Did you mean one of:\nlocal-caffeine/).to_stderr + }.to output(/Cask 'local-caf' is unavailable: No Cask with this name exists\. Did you mean one of:\nlocal-caffeine/).to_stderr end describe "when no Cask is specified" do diff --git a/Library/Homebrew/test/cask/cli/style_spec.rb b/Library/Homebrew/test/cask/cli/style_spec.rb index 7d250c166..640eca5f4 100644 --- a/Library/Homebrew/test/cask/cli/style_spec.rb +++ b/Library/Homebrew/test/cask/cli/style_spec.rb @@ -1,4 +1,3 @@ -require "English" require "open3" require "rubygems" @@ -108,7 +107,7 @@ describe Hbc::CLI::Style, :cask do end it "tries to find paths for all tokens" do - expect(Hbc::CaskLoader).to receive(:path).twice + expect(Hbc::CaskLoader).to receive(:load).twice.and_return(double("cask", sourcefile_path: nil)) subject end end diff --git a/Library/Homebrew/test/cask/cli/uninstall_spec.rb b/Library/Homebrew/test/cask/cli/uninstall_spec.rb index bc1f52613..cc640fad7 100644 --- a/Library/Homebrew/test/cask/cli/uninstall_spec.rb +++ b/Library/Homebrew/test/cask/cli/uninstall_spec.rb @@ -17,15 +17,15 @@ describe Hbc::CLI::Uninstall, :cask do end it "shows an error when a bad Cask is provided" do - expect { - Hbc::CLI::Uninstall.run("notacask") - }.to raise_error(Hbc::CaskUnavailableError) + expect { Hbc::CLI::Uninstall.run("notacask") } + .to output(/is unavailable/).to_stderr + .and raise_error(Hbc::CaskError, "Uninstall incomplete.") end it "shows an error when a Cask is provided that's not installed" do - expect { - Hbc::CLI::Uninstall.run("local-caffeine") - }.to raise_error(Hbc::CaskNotInstalledError) + expect { Hbc::CLI::Uninstall.run("local-caffeine") } + .to output(/is not installed/).to_stderr + .and raise_error(Hbc::CaskError, "Uninstall incomplete.") end it "tries anyway on a non-present Cask when --force is given" do @@ -89,11 +89,9 @@ describe Hbc::CLI::Uninstall, :cask do Hbc.appdir.join("MyFancyApp.app").rmtree - expect { - shutup do - Hbc::CLI::Uninstall.run("with-uninstall-script-app") - end - }.to raise_error(Hbc::CaskError, /does not exist/) + expect { shutup { Hbc::CLI::Uninstall.run("with-uninstall-script-app") } } + .to output(/does not exist/).to_stderr + .and raise_error(Hbc::CaskError, "Uninstall incomplete.") expect(cask).to be_installed diff --git a/Library/Homebrew/test/cask/cli/zap_spec.rb b/Library/Homebrew/test/cask/cli/zap_spec.rb index f3af0e66f..e39ca61f8 100644 --- a/Library/Homebrew/test/cask/cli/zap_spec.rb +++ b/Library/Homebrew/test/cask/cli/zap_spec.rb @@ -1,8 +1,8 @@ describe Hbc::CLI::Zap, :cask do it "shows an error when a bad Cask is provided" do - expect { - Hbc::CLI::Zap.run("notacask") - }.to raise_error(Hbc::CaskUnavailableError) + expect { Hbc::CLI::Zap.run("notacask") } + .to output(/is unavailable/).to_stderr + .and raise_error(Hbc::CaskError, "Zap incomplete.") end it "can zap and unlink multiple Casks at once" do diff --git a/Library/Homebrew/test/cask/cli_spec.rb b/Library/Homebrew/test/cask/cli_spec.rb index 569b831de..51258c580 100644 --- a/Library/Homebrew/test/cask/cli_spec.rb +++ b/Library/Homebrew/test/cask/cli_spec.rb @@ -1,10 +1,10 @@ describe Hbc::CLI, :cask do it "lists the taps for Casks that show up in two taps" do - listing = Hbc::CLI.nice_listing(%w[ - caskroom/cask/adium - caskroom/cask/google-chrome - passcod/homebrew-cask/adium - ]) + listing = described_class.nice_listing(%w[ + caskroom/cask/adium + caskroom/cask/google-chrome + passcod/homebrew-cask/adium + ]) expect(listing).to eq(%w[ caskroom/cask/adium @@ -13,6 +13,13 @@ describe Hbc::CLI, :cask do ]) end + it "ignores the `--language` option, which is handled in `OS::Mac`" do + cli = described_class.new("--language=en") + expect(cli).to receive(:detect_command_and_arguments).with(no_args) + expect(cli).to receive(:exit).with(1) + shutup { cli.run } + end + context "when no option is specified" do it "--binaries is true by default" do command = Hbc::CLI::Install.new("some-cask") @@ -41,8 +48,8 @@ describe Hbc::CLI, :cask do end it "prints help output when subcommand receives `--help` flag" do - command = Hbc::CLI.new("noop", "--help") - expect(described_class).to receive(:run_command).with("help") + command = described_class.new("noop", "--help") + expect(described_class).to receive(:run_command).with("help", "noop") command.run expect(command.help?).to eq(true) end @@ -56,7 +63,7 @@ describe Hbc::CLI, :cask do it "exits with a status of 1 when something goes wrong" do allow(described_class).to receive(:lookup_command).and_raise(Hbc::CaskError) - command = Hbc::CLI.new("noop") + command = described_class.new("noop") expect(command).to receive(:exit).with(1) command.run end diff --git a/Library/Homebrew/test/cask/dsl_spec.rb b/Library/Homebrew/test/cask/dsl_spec.rb index 7eeabcf49..5849f581b 100644 --- a/Library/Homebrew/test/cask/dsl_spec.rb +++ b/Library/Homebrew/test/cask/dsl_spec.rb @@ -57,7 +57,7 @@ describe Hbc::DSL, :cask do it "raises an error" do expect { cask - }.to raise_error(Hbc::CaskTokenDoesNotMatchError, /Bad header line:.*does not match file name/) + }.to raise_error(Hbc::CaskTokenMismatchError, /header line does not match the file name/) end end diff --git a/Library/Homebrew/test/cask/installer_spec.rb b/Library/Homebrew/test/cask/installer_spec.rb index 0ae7c14a5..8ef82c1d5 100644 --- a/Library/Homebrew/test/cask/installer_spec.rb +++ b/Library/Homebrew/test/cask/installer_spec.rb @@ -37,45 +37,6 @@ describe Hbc::Installer, :cask do expect(Hbc.appdir.join("container")).to be_a_file end - it "works with cab-based Casks" do - skip("cabextract not installed") if which("cabextract").nil? - asset = Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/container-cab.rb") - - allow(asset).to receive(:depends_on).and_return(empty_depends_on_stub) - - shutup do - Hbc::Installer.new(asset).install - end - - expect(Hbc.caskroom.join("container-cab", asset.version)).to be_a_directory - expect(Hbc.appdir.join("container")).to be_a_file - end - - it "works with Adobe AIR-based Casks" do - skip("Adobe AIR not installed") unless Hbc::Container::Air.installer_exist? - asset = Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/container-air.rb") - - shutup do - Hbc::Installer.new(asset).install - end - - expect(Hbc.caskroom.join("container-air", asset.version)).to be_a_directory - expect(Hbc.appdir.join("container.app")).to be_a_directory - end - - it "works with 7z-based Casks" do - skip("unar not installed") if which("unar").nil? - asset = Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/container-7z.rb") - - allow(asset).to receive(:depends_on).and_return(empty_depends_on_stub) - shutup do - Hbc::Installer.new(asset).install - end - - expect(Hbc.caskroom.join("container-7z", asset.version)).to be_a_directory - expect(Hbc.appdir.join("container")).to be_a_file - end - it "works with xar-based Casks" do asset = Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/container-xar.rb") @@ -87,32 +48,6 @@ describe Hbc::Installer, :cask do expect(Hbc.appdir.join("container")).to be_a_file end - it "works with Stuffit-based Casks" do - skip("unar not installed") if which("unar").nil? - asset = Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/container-sit.rb") - - allow(asset).to receive(:depends_on).and_return(empty_depends_on_stub) - shutup do - Hbc::Installer.new(asset).install - end - - expect(Hbc.caskroom.join("container-sit", asset.version)).to be_a_directory - expect(Hbc.appdir.join("container")).to be_a_file - end - - it "works with RAR-based Casks" do - skip("unar not installed") if which("unar").nil? - asset = Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/container-rar.rb") - - allow(asset).to receive(:depends_on).and_return(empty_depends_on_stub) - shutup do - Hbc::Installer.new(asset).install - end - - expect(Hbc.caskroom.join("container-rar", asset.version)).to be_a_directory - expect(Hbc.appdir.join("container")).to be_a_file - end - it "works with pure bzip2-based Casks" do asset = Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/container-bzip2.rb") @@ -135,45 +70,6 @@ describe Hbc::Installer, :cask do expect(Hbc.appdir.join("container")).to be_a_file end - it "works with pure xz-based Casks" do - skip("unxz not installed") if which("unxz").nil? - asset = Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/container-xz.rb") - - allow(asset).to receive(:depends_on).and_return(empty_depends_on_stub) - shutup do - Hbc::Installer.new(asset).install - end - - expect(Hbc.caskroom.join("container-xz", asset.version)).to be_a_directory - expect(Hbc.appdir.join("container-xz--#{asset.version}")).to be_a_file - end - - it "works with lzma-based Casks" do - skip("unlzma not installed") if which("unlzma").nil? - asset = Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/container-lzma.rb") - - allow(asset).to receive(:depends_on).and_return(empty_depends_on_stub) - shutup do - Hbc::Installer.new(asset).install - end - - expect(Hbc.caskroom.join("container-lzma", asset.version)).to be_a_directory - expect(Hbc.appdir.join("container-lzma--#{asset.version}")).to be_a_file - end - - it "works with gpg-based Casks" do - skip("gpg not installed") if which("gpg").nil? - asset = Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/container-gpg.rb") - - allow(asset).to receive(:depends_on).and_return(empty_depends_on_stub) - shutup do - Hbc::Installer.new(asset).install - end - - expect(Hbc.caskroom.join("container-gpg", asset.version)).to be_a_directory - expect(Hbc.appdir.join("container")).to be_a_file - end - it "blows up on a bad checksum" do bad_checksum = Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/bad-checksum.rb") expect { @@ -249,22 +145,6 @@ describe Hbc::Installer, :cask do expect(with_macosx_dir.staged_path.join("__MACOSX")).not_to be_a_directory end - it "installer method raises an exception when already-installed Casks which auto-update are attempted" do - with_auto_updates = Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/auto-updates.rb") - - expect(with_auto_updates).not_to be_installed - - installer = Hbc::Installer.new(with_auto_updates) - - shutup do - installer.install - end - - expect { - installer.install - }.to raise_error(Hbc::CaskAlreadyInstalledAutoUpdatesError) - end - it "allows already-installed Casks which auto-update to be installed if force is provided" do with_auto_updates = Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/auto-updates.rb") diff --git a/Library/Homebrew/test/cask/verify/checksum_spec.rb b/Library/Homebrew/test/cask/verify/checksum_spec.rb index 55c0e5f44..4b8543d2b 100644 --- a/Library/Homebrew/test/cask/verify/checksum_spec.rb +++ b/Library/Homebrew/test/cask/verify/checksum_spec.rb @@ -1,5 +1,5 @@ describe Hbc::Verify::Checksum, :cask do - let(:cask) { double("cask") } + let(:cask) { double("cask", token: "cask") } let(:downloaded_path) { double("downloaded_path") } let(:verification) { described_class.new(cask, downloaded_path) } diff --git a/Library/Homebrew/test/cmd/cask_spec.rb b/Library/Homebrew/test/cmd/cask_spec.rb index fcd7e6a16..3bba5fbf4 100644 --- a/Library/Homebrew/test/cmd/cask_spec.rb +++ b/Library/Homebrew/test/cmd/cask_spec.rb @@ -1,4 +1,4 @@ -describe "brew cask", :integration_test, :needs_macos, :needs_official_cmd_taps do +describe "brew cask", :integration_test, :needs_macos, :needs_network do describe "list" do it "returns a list of installed Casks" do setup_remote_tap("caskroom/cask") diff --git a/Library/Homebrew/test/cmd/services_spec.rb b/Library/Homebrew/test/cmd/services_spec.rb index c456fea17..669e84e5f 100644 --- a/Library/Homebrew/test/cmd/services_spec.rb +++ b/Library/Homebrew/test/cmd/services_spec.rb @@ -1,4 +1,4 @@ -describe "brew services", :integration_test, :needs_macos, :needs_official_cmd_taps do +describe "brew services", :integration_test, :needs_macos, :needs_network do it "allows controlling services" do setup_remote_tap "homebrew/services" diff --git a/Library/Homebrew/test/gpg_spec.rb b/Library/Homebrew/test/gpg_spec.rb deleted file mode 100644 index 160e55379..000000000 --- a/Library/Homebrew/test/gpg_spec.rb +++ /dev/null @@ -1,25 +0,0 @@ -require "gpg" - -describe Gpg do - subject { described_class } - - describe "::create_test_key" do - it "creates a test key in the home directory" do - skip "GPG Unavailable" unless subject.available? - - mktmpdir do |dir| - ENV["HOME"] = dir - - shutup do - subject.create_test_key(dir) - end - - if subject.version == Version.create("2.0") - expect(dir/".gnupg/secring.gpg").to be_a_file - else - expect(dir/".gnupg/pubring.kbx").to be_a_file - end - end - end - end -end diff --git a/Library/Homebrew/test/os/mac/diagnostic_spec.rb b/Library/Homebrew/test/os/mac/diagnostic_spec.rb index 787f80fec..d6186e46b 100644 --- a/Library/Homebrew/test/os/mac/diagnostic_spec.rb +++ b/Library/Homebrew/test/os/mac/diagnostic_spec.rb @@ -45,4 +45,17 @@ describe Homebrew::Diagnostic::Checks do expect(subject.check_homebrew_prefix) .to match("Your Homebrew's prefix is not /usr/local.") end + + specify "#check_ruby_version" do + allow(MacOS).to receive(:version).and_return(OS::Mac::Version.new("10.13")) + stub_const("RUBY_VERSION", "2.3.3p222") + + expect(subject.check_ruby_version) + .to match <<-EOS.undent + Ruby version 2.3.3p222 is unsupported on 10.13. Homebrew + is developed and tested on Ruby 2.0, and may not work correctly + on other Rubies. Patches are accepted as long as they don't cause breakage + on supported Rubies. + EOS + end end diff --git a/Library/Homebrew/test/rubocops/formula_desc_cop_spec.rb b/Library/Homebrew/test/rubocops/formula_desc_cop_spec.rb index f6436d6a3..4e684be46 100644 --- a/Library/Homebrew/test/rubocops/formula_desc_cop_spec.rb +++ b/Library/Homebrew/test/rubocops/formula_desc_cop_spec.rb @@ -3,7 +3,7 @@ require "rubocop/rspec/support" require_relative "../../extend/string" require_relative "../../rubocops/formula_desc_cop" -describe RuboCop::Cop::FormulaAuditStrict::Desc do +describe RuboCop::Cop::FormulaAuditStrict::DescLength do subject(:cop) { described_class.new } context "When auditing formula desc" do @@ -31,7 +31,7 @@ describe RuboCop::Cop::FormulaAuditStrict::Desc do source = <<-EOS.undent class Foo < Formula url 'http://example.com/foo-1.0.tgz' - desc '#{"bar" * 30}' + desc 'Bar#{"bar" * 29}' end EOS @@ -55,7 +55,7 @@ describe RuboCop::Cop::FormulaAuditStrict::Desc do source = <<-EOS.undent class Foo < Formula url 'http://example.com/foo-1.0.tgz' - desc '#{"bar" * 10}'\ + desc 'Bar#{"bar" * 9}'\ '#{"foo" * 21}' end EOS @@ -75,7 +75,13 @@ describe RuboCop::Cop::FormulaAuditStrict::Desc do expect_offense(expected, actual) end end + end +end +describe RuboCop::Cop::FormulaAuditStrict::Desc do + subject(:cop) { described_class.new } + + context "When auditing formula desc" do it "When wrong \"command-line\" usage in desc" do source = <<-EOS.undent class Foo < Formula @@ -104,7 +110,27 @@ describe RuboCop::Cop::FormulaAuditStrict::Desc do end EOS - expected_offenses = [{ message: "Description shouldn't start with an indefinite article (An )", + expected_offenses = [{ message: "Description shouldn't start with an indefinite article i.e. \"An\"", + severity: :convention, + line: 3, + column: 8, + source: source }] + + inspect_source(cop, source) + expected_offenses.zip(cop.offenses).each do |expected, actual| + expect_offense(expected, actual) + end + end + + it "When an lowercase letter starts a desc" do + source = <<-EOS.undent + class Foo < Formula + url 'http://example.com/foo-1.0.tgz' + desc 'bar' + end + EOS + + expected_offenses = [{ message: "Description should start with a capital letter", severity: :convention, line: 3, column: 8, @@ -136,11 +162,22 @@ describe RuboCop::Cop::FormulaAuditStrict::Desc do end end - def expect_offense(expected, actual) - expect(actual.message).to eq(expected[:message]) - expect(actual.severity).to eq(expected[:severity]) - expect(actual.line).to eq(expected[:line]) - expect(actual.column).to eq(expected[:column]) + it "autocorrects all rules" do + source = <<-EOS.undent + class Foo < Formula + url 'http://example.com/foo-1.0.tgz' + desc ' an bar: commandline foo ' + end + EOS + correct_source = <<-EOS.undent + class Foo < Formula + url 'http://example.com/foo-1.0.tgz' + desc 'an bar: command-line' + end + EOS + + corrected_source = autocorrect_source(cop, source) + expect(corrected_source).to eq(correct_source) end end end diff --git a/Library/Homebrew/test/spec_helper.rb b/Library/Homebrew/test/spec_helper.rb index e193b91a0..03b14720b 100644 --- a/Library/Homebrew/test/spec_helper.rb +++ b/Library/Homebrew/test/spec_helper.rb @@ -23,6 +23,7 @@ require "test/support/helper/shutup" require "test/support/helper/fixtures" require "test/support/helper/formula" require "test/support/helper/mktmpdir" +require "test/support/helper/rubocop" require "test/support/helper/spec/shared_context/homebrew_cask" if OS.mac? require "test/support/helper/spec/shared_context/integration_test" @@ -44,6 +45,7 @@ RSpec.configure do |config| config.include(Test::Helper::Fixtures) config.include(Test::Helper::Formula) config.include(Test::Helper::MkTmpDir) + config.include(Test::Helper::RuboCop) config.before(:each, :needs_compat) do skip "Requires compatibility layer." if ENV["HOMEBREW_NO_COMPAT"] diff --git a/Library/Homebrew/test/support/fixtures/bottles/testball_bottle-0.1.high_sierra.bottle.tar.gz b/Library/Homebrew/test/support/fixtures/bottles/testball_bottle-0.1.high_sierra.bottle.tar.gz new file mode 120000 index 000000000..3e989830b --- /dev/null +++ b/Library/Homebrew/test/support/fixtures/bottles/testball_bottle-0.1.high_sierra.bottle.tar.gz @@ -0,0 +1 @@ +testball_bottle-0.1.yosemite.bottle.tar.gz
\ No newline at end of file diff --git a/Library/Homebrew/test/support/fixtures/cask/Casks/container-air.rb b/Library/Homebrew/test/support/fixtures/cask/Casks/container-air.rb deleted file mode 100644 index 5aaf3d53e..000000000 --- a/Library/Homebrew/test/support/fixtures/cask/Casks/container-air.rb +++ /dev/null @@ -1,9 +0,0 @@ -cask 'container-air' do - version '0.1' - sha256 '554472e163f8a028629b12b468e29acda9f16b223dff74fcd218bba73cc2365a' - - url "file://#{TEST_FIXTURE_DIR}/cask/container.air" - homepage 'https://example.com/container-air' - - app 'container.app' -end diff --git a/Library/Homebrew/test/support/fixtures/cask/Casks/container-gpg.rb b/Library/Homebrew/test/support/fixtures/cask/Casks/container-gpg.rb deleted file mode 100644 index 630527ce2..000000000 --- a/Library/Homebrew/test/support/fixtures/cask/Casks/container-gpg.rb +++ /dev/null @@ -1,12 +0,0 @@ -cask 'container-gpg' do - version '1.2.3' - sha256 :no_check - - url "file://#{TEST_FIXTURE_DIR}/cask/container.tar.xz.gpg" - gpg :embedded, key_id: 'B0976E51E5C047AD0FD051294E402EBF7C3C6A71' - - homepage 'https://example.com/container-gpg' - depends_on formula: 'gpg' - - app 'container' -end diff --git a/Library/Homebrew/test/support/fixtures/cask/Casks/container-lzma.rb b/Library/Homebrew/test/support/fixtures/cask/Casks/container-lzma.rb deleted file mode 100644 index 92d2c253e..000000000 --- a/Library/Homebrew/test/support/fixtures/cask/Casks/container-lzma.rb +++ /dev/null @@ -1,11 +0,0 @@ -cask 'container-lzma' do - version '1.2.3' - sha256 '9d7edb32d02ab9bd9749a5bde8756595ea4cfcb1da02ca11c30fb591d4c1ed85' - - url "file://#{TEST_FIXTURE_DIR}/cask/container.lzma" - homepage 'https://example.com/container-lzma' - - depends_on formula: 'lzma' - - app 'container-lzma--1.2.3' -end diff --git a/Library/Homebrew/test/support/fixtures/cask/Casks/container-rar.rb b/Library/Homebrew/test/support/fixtures/cask/Casks/container-rar.rb deleted file mode 100644 index 33ea670d1..000000000 --- a/Library/Homebrew/test/support/fixtures/cask/Casks/container-rar.rb +++ /dev/null @@ -1,11 +0,0 @@ -cask 'container-rar' do - version '1.2.3' - sha256 '419af7864c0e1f125515c49b08bd22e0f7de39f5285897c440fe03c714871763' - - url "file://#{TEST_FIXTURE_DIR}/cask/container.rar" - homepage 'https://example.com/container-rar' - - depends_on formula: 'unar' - - app 'container' -end diff --git a/Library/Homebrew/test/support/fixtures/cask/Casks/container-sit.rb b/Library/Homebrew/test/support/fixtures/cask/Casks/container-sit.rb deleted file mode 100644 index 5715795a7..000000000 --- a/Library/Homebrew/test/support/fixtures/cask/Casks/container-sit.rb +++ /dev/null @@ -1,11 +0,0 @@ -cask 'container-sit' do - version '1.2.3' - sha256 '0d21a64dce625044345c8ecca888e5439feaf254dac7f884917028a744f93cf3' - - url "file://#{TEST_FIXTURE_DIR}/cask/container.sit" - homepage 'https://example.com/container-sit' - - depends_on formula: 'unar' - - app 'container' -end diff --git a/Library/Homebrew/test/support/fixtures/cask/Casks/container-xz.rb b/Library/Homebrew/test/support/fixtures/cask/Casks/container-xz.rb deleted file mode 100644 index 3f844af04..000000000 --- a/Library/Homebrew/test/support/fixtures/cask/Casks/container-xz.rb +++ /dev/null @@ -1,11 +0,0 @@ -cask 'container-xz' do - version '1.2.3' - sha256 '839263f474edde1d54a9101606e6f0dc9d963acc93f6dcc5af8d10ebc3187c02' - - url "file://#{TEST_FIXTURE_DIR}/cask/container.xz" - homepage 'https://example.com/container-xz' - - depends_on formula: 'xz' - - app 'container-xz--1.2.3' -end diff --git a/Library/Homebrew/test/support/helper/rubocop.rb b/Library/Homebrew/test/support/helper/rubocop.rb new file mode 100644 index 000000000..351f2ad82 --- /dev/null +++ b/Library/Homebrew/test/support/helper/rubocop.rb @@ -0,0 +1,13 @@ +module Test + module Helper + module RuboCop + def expect_offense(expected, actual) + expect(actual).to_not be_nil + expect(actual.message).to eq(expected[:message]) + expect(actual.severity).to eq(expected[:severity]) + expect(actual.line).to eq(expected[:line]) + expect(actual.column).to eq(expected[:column]) + end + end + end +end diff --git a/Library/Homebrew/test/utils/popen_spec.rb b/Library/Homebrew/test/utils/popen_spec.rb index e3704a876..63bbc7b18 100644 --- a/Library/Homebrew/test/utils/popen_spec.rb +++ b/Library/Homebrew/test/utils/popen_spec.rb @@ -4,7 +4,7 @@ describe Utils do describe "::popen_read" do it "reads the standard output of a given command" do expect(subject.popen_read("sh", "-c", "echo success").chomp).to eq("success") - expect($?).to be_a_success + expect($CHILD_STATUS).to be_a_success end it "can be given a block to manually read from the pipe" do @@ -13,7 +13,7 @@ describe Utils do pipe.read.chomp end, ).to eq("success") - expect($?).to be_a_success + expect($CHILD_STATUS).to be_a_success end end @@ -22,7 +22,7 @@ describe Utils do subject.popen_write("grep", "-q", "success") do |pipe| pipe.write("success\n") end - expect($?).to be_a_success + expect($CHILD_STATUS).to be_a_success end end end diff --git a/Library/Homebrew/utils.rb b/Library/Homebrew/utils.rb index cde2ee306..529f3492d 100644 --- a/Library/Homebrew/utils.rb +++ b/Library/Homebrew/utils.rb @@ -15,6 +15,14 @@ require "utils/svn" require "utils/tty" require "time" +def require?(path) + return false if path.nil? + require path +rescue LoadError => e + # we should raise on syntax errors but not if the file doesn't exist. + raise unless e.message.include?(path) +end + def ohai(title, *sput) title = Tty.truncate(title) if $stdout.tty? && !ARGV.verbose? puts Formatter.headline(title, color: :blue) @@ -76,7 +84,7 @@ def odeprecated(method, replacement = nil, disable: false, disable_on: nil, call tap_message = nil caller_message = backtrace.detect do |line| next unless line =~ %r{^#{Regexp.escape(HOMEBREW_LIBRARY)}/Taps/([^/]+/[^/]+)/} - tap = Tap.fetch $1 + tap = Tap.fetch Regexp.last_match(1) tap_message = "\nPlease report this to the #{tap} tap!" true end @@ -151,9 +159,9 @@ def interactive_shell(f = nil) Process.wait fork { exec ENV["SHELL"] } - return if $?.success? - raise "Aborted due to non-zero exit status (#{$?.exitstatus})" if $?.exited? - raise $?.inspect + return if $CHILD_STATUS.success? + raise "Aborted due to non-zero exit status (#{$CHILD_STATUS.exitstatus})" if $CHILD_STATUS.exited? + raise $CHILD_STATUS.inspect end module Homebrew @@ -171,7 +179,7 @@ module Homebrew exit! 1 # never gets here unless exec failed end Process.wait(pid) - $?.success? + $CHILD_STATUS.success? end def system(cmd, *args) @@ -328,21 +336,16 @@ def which_all(cmd, path = ENV["PATH"]) end def which_editor - editor = ENV.values_at("HOMEBREW_EDITOR", "HOMEBREW_VISUAL").compact.reject(&:empty?).first - return editor unless editor.nil? - - # Find Textmate, BBEdit / TextWrangler, or vim - %w[mate edit vim].each do |candidate| - editor = candidate if which(candidate, ENV["HOMEBREW_PATH"]) + editor = ENV.values_at("HOMEBREW_EDITOR", "HOMEBREW_VISUAL") + .compact + .reject(&:empty?) + .first + return editor if editor + + # Find Atom, Sublime Text, Textmate, BBEdit / TextWrangler, or vim + editor = %w[atom subl mate edit vim].find do |candidate| + candidate if which(candidate, ENV["HOMEBREW_PATH"]) end - - # Find Textmate - editor = which("mate", ENV["HOMEBREW_PATH"]) - # Find BBEdit/TextWrangler - editor ||= which("edit", ENV["HOMEBREW_PATH"]) - # Find vim - editor ||= which("vim", ENV["HOMEBREW_PATH"]) - # Default to standard vim editor ||= "/usr/bin/vim" opoo <<-EOS.undent diff --git a/Library/Homebrew/utils/analytics.rb b/Library/Homebrew/utils/analytics.rb index 7dd54d3f1..23000f8dd 100644 --- a/Library/Homebrew/utils/analytics.rb +++ b/Library/Homebrew/utils/analytics.rb @@ -61,22 +61,15 @@ module Utils ev: value) end - def report_exception(exception, options = {}) - if exception.is_a?(BuildError) && - exception.formula.tap && - exception.formula.tap.installed? && - !exception.formula.tap.private? - report_event("BuildError", exception.formula.full_name) + def report_build_error(exception) + return unless exception.formula.tap + return unless exception.formula.tap.installed? + return if exception.formula.tap.private? + action = exception.formula.full_name + if (options = exception.options) + action = "#{action} #{options}".strip end - - fatal = options.fetch(:fatal, true) ? "1" : "0" - report(:exception, - exd: exception.class.name, - exf: fatal) - end - - def report_screenview(screen_name) - report(:screenview, cd: screen_name) + report_event("BuildError", action) end end end diff --git a/Library/Homebrew/utils/analytics.sh b/Library/Homebrew/utils/analytics.sh index 8d5cf2ff7..00527fd9f 100644 --- a/Library/Homebrew/utils/analytics.sh +++ b/Library/Homebrew/utils/analytics.sh @@ -66,56 +66,3 @@ setup-analytics() { export HOMEBREW_ANALYTICS_ID export HOMEBREW_ANALYTICS_USER_UUID } - -report-analytics-screenview-command() { - [[ -n "$HOMEBREW_NO_ANALYTICS" || -n "$HOMEBREW_NO_ANALYTICS_THIS_RUN" ]] && return - - # Don't report commands that are invoked as part of other commands. - [[ "$HOMEBREW_COMMAND_DEPTH" != 1 ]] && return - - # Don't report non-official commands. - if ! [[ "$HOMEBREW_COMMAND" = "bundle" || - "$HOMEBREW_COMMAND" = "services" || - -f "$HOMEBREW_LIBRARY/Homebrew/cmd/$HOMEBREW_COMMAND.rb" || - -f "$HOMEBREW_LIBRARY/Homebrew/cmd/$HOMEBREW_COMMAND.sh" || - -f "$HOMEBREW_LIBRARY/Homebrew/dev-cmd/$HOMEBREW_COMMAND.rb" || - -f "$HOMEBREW_LIBRARY/Homebrew/dev-cmd/$HOMEBREW_COMMAND.sh" ]] - then - return - fi - - # Don't report commands used mostly by our scripts and not users. - case "$HOMEBREW_COMMAND" in - --prefix|analytics|command|commands) - return - ;; - esac - - local args=( - --max-time 3 - --user-agent "$HOMEBREW_USER_AGENT_CURL" - --data v=1 - --data aip=1 - --data t=screenview - --data tid="$HOMEBREW_ANALYTICS_ID" - --data cid="$HOMEBREW_ANALYTICS_USER_UUID" - --data an="$HOMEBREW_PRODUCT" - --data av="$HOMEBREW_VERSION" - --data cd="$HOMEBREW_COMMAND" - ) - - # Send analytics. Don't send or store any personally identifiable information. - # http://docs.brew.sh/Analytics.html - # https://developers.google.com/analytics/devguides/collection/protocol/v1/devguide#screenView - # https://developers.google.com/analytics/devguides/collection/protocol/v1/parameters - if [[ -z "$HOMEBREW_ANALYTICS_DEBUG" ]] - then - "$HOMEBREW_CURL" https://www.google-analytics.com/collect \ - "${args[@]}" \ - --silent --output /dev/null &>/dev/null & disown - else - local url="https://www.google-analytics.com/debug/collect" - echo "$HOMEBREW_CURL $url ${args[*]}" - "$HOMEBREW_CURL" "$url" "${args[@]}" - fi -} diff --git a/Library/Homebrew/utils/fork.rb b/Library/Homebrew/utils/fork.rb index 35a55980e..92f5bf899 100644 --- a/Library/Homebrew/utils/fork.rb +++ b/Library/Homebrew/utils/fork.rb @@ -37,8 +37,8 @@ module Utils read.close Process.wait(pid) unless socket.nil? raise Marshal.load(data) unless data.nil? || data.empty? - raise Interrupt if $?.exitstatus == 130 - raise "Suspicious failure" unless $?.success? + raise Interrupt if $CHILD_STATUS.exitstatus == 130 + raise "Suspicious failure" unless $CHILD_STATUS.success? end end end diff --git a/Library/Homebrew/utils/tty.rb b/Library/Homebrew/utils/tty.rb index 642a33b91..e872e6460 100644 --- a/Library/Homebrew/utils/tty.rb +++ b/Library/Homebrew/utils/tty.rb @@ -6,7 +6,10 @@ module Tty end def width - (`/bin/stty size`.split[1] || 80).to_i + width = `/bin/stty size 2>/dev/null`.split[1] + width ||= `/usr/bin/tput cols 2>/dev/null`.split[0] + width ||= 80 + width.to_i end def truncate(string) |
