From 980db9d3fb6671c7562f97dfa3dd4f22fd74083f Mon Sep 17 00:00:00 2001 From: Andrew Yates Date: Thu, 3 Aug 2017 10:44:56 +0100 Subject: [PATCH 001/294] Remove errant pkg-config libdir We found an issue in Linuxbrew/homebrew-core#3366 where the addition of "/usr/lib/pkg-config" causes compilation issues if system pkg-config files are in that directory on Linux. Removing the line from here and adding it into the mac superenv. --- Library/Homebrew/extend/ENV/super.rb | 1 - 1 file changed, 1 deletion(-) diff --git a/Library/Homebrew/extend/ENV/super.rb b/Library/Homebrew/extend/ENV/super.rb index 692fd36239..b518c22a1c 100644 --- a/Library/Homebrew/extend/ENV/super.rb +++ b/Library/Homebrew/extend/ENV/super.rb @@ -138,7 +138,6 @@ module Superenv def determine_pkg_config_libdir PATH.new( - "/usr/lib/pkgconfig", homebrew_extra_pkg_config_paths, ).existing end From 19cfcc34ef3eb71fcbd45f01b98153fd517a6dfd Mon Sep 17 00:00:00 2001 From: Andrew Yates Date: Thu, 3 Aug 2017 10:46:12 +0100 Subject: [PATCH 002/294] Adding in "/usr/lib/pkg-config" Moving "/usr/lib/pkg-config" into the pkg-path path --- Library/Homebrew/extend/os/mac/extend/ENV/super.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/Library/Homebrew/extend/os/mac/extend/ENV/super.rb b/Library/Homebrew/extend/os/mac/extend/ENV/super.rb index f97a2dbbbf..b93e6d3b12 100644 --- a/Library/Homebrew/extend/os/mac/extend/ENV/super.rb +++ b/Library/Homebrew/extend/os/mac/extend/ENV/super.rb @@ -29,6 +29,7 @@ module Superenv def homebrew_extra_pkg_config_paths paths = \ ["#{HOMEBREW_LIBRARY}/Homebrew/os/mac/pkgconfig/#{MacOS.version}"] + paths << "/usr/lib/pkg-config" paths << "#{MacOS::X11.lib}/pkgconfig" << "#{MacOS::X11.share}/pkgconfig" if x11? paths end From 365c55573b26b9363746ac39c21f8b90e8ec992f Mon Sep 17 00:00:00 2001 From: Andrew Yates Date: Thu, 3 Aug 2017 17:22:18 +0100 Subject: [PATCH 003/294] Moving /usr/lib/pkg-config to be first Ensuring old functionality still happens and /usr/lib/pkg-config is the first location found in macOS. --- Library/Homebrew/extend/os/mac/extend/ENV/super.rb | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/Library/Homebrew/extend/os/mac/extend/ENV/super.rb b/Library/Homebrew/extend/os/mac/extend/ENV/super.rb index b93e6d3b12..f50aa52740 100644 --- a/Library/Homebrew/extend/os/mac/extend/ENV/super.rb +++ b/Library/Homebrew/extend/os/mac/extend/ENV/super.rb @@ -28,8 +28,7 @@ module Superenv # @private def homebrew_extra_pkg_config_paths paths = \ - ["#{HOMEBREW_LIBRARY}/Homebrew/os/mac/pkgconfig/#{MacOS.version}"] - paths << "/usr/lib/pkg-config" + ["/usr/lib/pkg-config", "#{HOMEBREW_LIBRARY}/Homebrew/os/mac/pkgconfig/#{MacOS.version}"] paths << "#{MacOS::X11.lib}/pkgconfig" << "#{MacOS::X11.share}/pkgconfig" if x11? paths end From 67327c75b56cbf9ab8a506879846118b9d3526ab Mon Sep 17 00:00:00 2001 From: Markus Reiter Date: Sat, 5 Aug 2017 15:56:34 +0200 Subject: [PATCH 004/294] Implement `conflicts_with :cask`. --- .../cask/lib/hbc/dsl/conflicts_with.rb | 19 +++++++------------ Library/Homebrew/cask/lib/hbc/exceptions.rb | 13 +++++++++++++ Library/Homebrew/cask/lib/hbc/installer.rb | 17 +++++++++++++++++ 3 files changed, 37 insertions(+), 12 deletions(-) diff --git a/Library/Homebrew/cask/lib/hbc/dsl/conflicts_with.rb b/Library/Homebrew/cask/lib/hbc/dsl/conflicts_with.rb index 9483482392..dfaa55a5c2 100644 --- a/Library/Homebrew/cask/lib/hbc/dsl/conflicts_with.rb +++ b/Library/Homebrew/cask/lib/hbc/dsl/conflicts_with.rb @@ -10,25 +10,20 @@ module Hbc :java, ] - attr_accessor(*VALID_KEYS) - attr_accessor :pairs + attr_reader *VALID_KEYS def initialize(pairs = {}) @pairs = pairs + + VALID_KEYS.each do |key| + instance_variable_set("@#{key}", Set.new) + end + pairs.each do |key, value| raise "invalid conflicts_with key: '#{key.inspect}'" unless VALID_KEYS.include?(key) - writer_method = "#{key}=".to_sym - send(writer_method, value) + instance_variable_set("@#{key}", instance_variable_get("@#{key}").merge([*value])) end end - - def to_yaml - @pairs.to_yaml - end - - def to_s - @pairs.inspect - end end end end diff --git a/Library/Homebrew/cask/lib/hbc/exceptions.rb b/Library/Homebrew/cask/lib/hbc/exceptions.rb index 1a246be65a..f7f9e43b66 100644 --- a/Library/Homebrew/cask/lib/hbc/exceptions.rb +++ b/Library/Homebrew/cask/lib/hbc/exceptions.rb @@ -17,6 +17,19 @@ module Hbc end end + class CaskConflictError < AbstractCaskErrorWithToken + attr_reader :conflicting_cask + + def initialize(token, conflicting_cask) + super(token) + @conflicting_cask = conflicting_cask + end + + def to_s + "Cask '#{token}' conflicts with '#{conflicting_cask}'." + end + end + class CaskUnavailableError < AbstractCaskErrorWithToken def to_s "Cask '#{token}' is unavailable" << (reason.empty? ? "." : ": #{reason}") diff --git a/Library/Homebrew/cask/lib/hbc/installer.rb b/Library/Homebrew/cask/lib/hbc/installer.rb index 53210ed4b4..37cc4e5612 100644 --- a/Library/Homebrew/cask/lib/hbc/installer.rb +++ b/Library/Homebrew/cask/lib/hbc/installer.rb @@ -86,6 +86,8 @@ module Hbc raise CaskAlreadyInstalledError, @cask end + check_conflicts + print_caveats fetch uninstall_existing_cask if @reinstall @@ -98,6 +100,21 @@ module Hbc puts summary end + def check_conflicts + return unless @cask.conflicts_with + + @cask.conflicts_with.cask.each do |conflicting_cask| + begin + conflicting_cask = CaskLoader.load(conflicting_cask) + if conflicting_cask.installed? + raise CaskConflictError.new(@cask, conflicting_cask) + end + rescue CaskUnavailableError + next # Ignore conflicting Casks that do not exist. + end + end + end + def reinstall odebug "Hbc::Installer#reinstall" @reinstall = true From f89e09b7857e8e3a6f6cd30258aa5927a1ac2872 Mon Sep 17 00:00:00 2001 From: Markus Reiter Date: Sat, 5 Aug 2017 16:20:03 +0200 Subject: [PATCH 005/294] Add spec for `conflicts_with cask`. --- .../Homebrew/test/cask/conflicts_with_spec.rb | 23 +++++++++++++++++++ .../cask/Casks/with-conflicts-with.rb | 2 +- 2 files changed, 24 insertions(+), 1 deletion(-) create mode 100644 Library/Homebrew/test/cask/conflicts_with_spec.rb diff --git a/Library/Homebrew/test/cask/conflicts_with_spec.rb b/Library/Homebrew/test/cask/conflicts_with_spec.rb new file mode 100644 index 0000000000..0dc51cb2d7 --- /dev/null +++ b/Library/Homebrew/test/cask/conflicts_with_spec.rb @@ -0,0 +1,23 @@ +describe "conflicts_with", :cask do + describe "conflicts_with cask" do + let(:local_caffeine) { + Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/local-caffeine.rb") + } + + let(:with_conflicts_with) { + Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/with-conflicts-with.rb") + } + + it "installs the dependency of a Cask and the Cask itself", :focus do + Hbc::Installer.new(local_caffeine).install + + expect(local_caffeine).to be_installed + + expect { + Hbc::Installer.new(with_conflicts_with).install + }.to raise_error(Hbc::CaskConflictError, "Cask 'with-conflicts-with' conflicts with 'local-caffeine'.") + + expect(with_conflicts_with).not_to be_installed + end + end +end diff --git a/Library/Homebrew/test/support/fixtures/cask/Casks/with-conflicts-with.rb b/Library/Homebrew/test/support/fixtures/cask/Casks/with-conflicts-with.rb index ab3631743c..13d1fc4fc6 100644 --- a/Library/Homebrew/test/support/fixtures/cask/Casks/with-conflicts-with.rb +++ b/Library/Homebrew/test/support/fixtures/cask/Casks/with-conflicts-with.rb @@ -5,7 +5,7 @@ cask 'with-conflicts-with' do url "file://#{TEST_FIXTURE_DIR}/cask/caffeine.zip" homepage 'http://example.com/with-conflicts-with' - conflicts_with formula: 'unar' + conflicts_with cask: 'local-caffeine' app 'Caffeine.app' end From e862bcbc32a5be45481df0fded949a7dc1b8b43d Mon Sep 17 00:00:00 2001 From: Mike McQuaid Date: Sat, 5 Aug 2017 18:03:04 +0100 Subject: [PATCH 006/294] keg: cleanup aliases correctly. This was missed when I was focused on cleaning up versioned aliases. Fixes #2992. --- Library/Homebrew/keg.rb | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/Library/Homebrew/keg.rb b/Library/Homebrew/keg.rb index 8fcbecfbda..92eab7ad31 100644 --- a/Library/Homebrew/keg.rb +++ b/Library/Homebrew/keg.rb @@ -253,6 +253,11 @@ class Keg FileUtils.rm_rf bad_tap_opt if bad_tap_opt.directory? end + aliases.each do |a| + alias_symlink = opt/a + alias_symlink.delete if alias_symlink.symlink? || alias_symlink.exist? + end + Pathname.glob("#{opt_record}@*").each do |a| a = a.basename next if aliases.include?(a) From affd9055c2aaaf3535ed1cb778b65a4bee5ef0e2 Mon Sep 17 00:00:00 2001 From: Gautham Goli Date: Sun, 30 Jul 2017 20:14:59 +0530 Subject: [PATCH 007/294] audit: Port classname and template comments audit rules from line_problems method to rubocop --- Library/Homebrew/dev-cmd/audit.rb | 25 ------------- .../Homebrew/rubocops/extend/formula_cop.rb | 14 +++++++ Library/Homebrew/rubocops/lines_cop.rb | 37 +++++++++++++++++++ Library/Homebrew/test/dev-cmd/audit_spec.rb | 22 ----------- 4 files changed, 51 insertions(+), 47 deletions(-) diff --git a/Library/Homebrew/dev-cmd/audit.rb b/Library/Homebrew/dev-cmd/audit.rb index 1f07fa89ea..323b37170b 100644 --- a/Library/Homebrew/dev-cmd/audit.rb +++ b/Library/Homebrew/dev-cmd/audit.rb @@ -809,28 +809,6 @@ class FormulaAuditor end def line_problems(line, _lineno) - if line =~ /<(Formula|AmazonWebServicesFormula|ScriptFileFormula|GithubGistFormula)/ - problem "Use a space in class inheritance: class Foo < #{Regexp.last_match(1)}" - end - - # Commented-out cmake support from default template - problem "Commented cmake call found" if line.include?('# system "cmake') - - # Comments from default template - [ - "# PLEASE REMOVE", - "# Documentation:", - "# if this fails, try separate make/make install steps", - "# The URL of the archive", - "## Naming --", - "# if your formula requires any X11/XQuartz components", - "# if your formula fails when building in parallel", - "# Remove unrecognized options if warned by configure", - ].each do |comment| - next unless line.include?(comment) - problem "Please remove default template comments" - end - # FileUtils is included in Formula # encfs modifies a file with this name, so check for some leading characters if line =~ %r{[^'"/]FileUtils\.(\w+)} @@ -891,9 +869,6 @@ class FormulaAuditor end end - # Commented-out depends_on - 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.#{Regexp.last_match(1).downcase}?\" instead" end diff --git a/Library/Homebrew/rubocops/extend/formula_cop.rb b/Library/Homebrew/rubocops/extend/formula_cop.rb index 4be0c0fe30..e7a23ecae8 100644 --- a/Library/Homebrew/rubocops/extend/formula_cop.rb +++ b/Library/Homebrew/rubocops/extend/formula_cop.rb @@ -302,6 +302,15 @@ module RuboCop end end + # Yields to a block with comment text as parameter + def audit_comments + @processed_source.comments.each do |comment_node| + @offensive_node = comment_node + @offense_source_range = :expression + yield comment_node.text + end + end + # Returns the begin position of the node's line in source code def line_start_column(node) node.source_range.source_buffer.line_range(node.loc.line).begin_pos @@ -312,6 +321,11 @@ module RuboCop node.source_range.begin_pos end + # Returns the ending position of the node in source code + def end_column(node) + node.source_range.end_pos + end + # Returns the line number of the node def line_number(node) node.loc.line diff --git a/Library/Homebrew/rubocops/lines_cop.rb b/Library/Homebrew/rubocops/lines_cop.rb index 22039869b4..abd46162f4 100644 --- a/Library/Homebrew/rubocops/lines_cop.rb +++ b/Library/Homebrew/rubocops/lines_cop.rb @@ -15,6 +15,43 @@ module RuboCop problem ":tex is deprecated" if depends_on?(:tex) end end + + class ClassInheritance < FormulaCop + def audit_formula(_node, class_node, parent_class_node, _body_node) + begin_pos = start_column(parent_class_node) + end_pos = end_column(class_node) + return unless begin_pos-end_pos != 3 + problem "Use a space in class inheritance: class #{@formula_name} < #{class_name(parent_class_node)}" + end + end + + class Comments < FormulaCop + def audit_formula(_node, _class_node, _parent_class_node, _body_node) + audit_comments do |comment| + [ + "# PLEASE REMOVE", + "# Documentation:", + "# if this fails, try separate make/make install steps", + "# The URL of the archive", + "## Naming --", + "# if your formula requires any X11/XQuartz components", + "# if your formula fails when building in parallel", + "# Remove unrecognized options if warned by configure", + '# system "cmake', + ].each do |template_comment| + next unless comment.include?(template_comment) + problem "Please remove default template comments" + break + end + end + + audit_comments do |comment| + # Commented-out depends_on + next unless comment =~ /#\s*depends_on\s+(.+)\s*$/ + problem "Commented-out dependency #{Regexp.last_match(1)}" + end + end + end end end end diff --git a/Library/Homebrew/test/dev-cmd/audit_spec.rb b/Library/Homebrew/test/dev-cmd/audit_spec.rb index f2d8a8e7c6..037865fdf1 100644 --- a/Library/Homebrew/test/dev-cmd/audit_spec.rb +++ b/Library/Homebrew/test/dev-cmd/audit_spec.rb @@ -263,28 +263,6 @@ describe FormulaAuditor do expect(fa.problems.shift) .to eq('Use pkgshare instead of (share/"foolibc++")') end - - specify "no space in class inheritance" do - fa = formula_auditor "foo", <<-EOS.undent - class Foo Date: Mon, 31 Jul 2017 14:30:37 +0530 Subject: [PATCH 008/294] audit: Port FileUtils, inreplace audit rules in audit_lines to rubocop --- Library/Homebrew/dev-cmd/audit.rb | 11 ----------- .../Homebrew/rubocops/extend/formula_cop.rb | 18 ++++++++++++++---- Library/Homebrew/rubocops/lines_cop.rb | 17 +++++++++++++++++ 3 files changed, 31 insertions(+), 15 deletions(-) diff --git a/Library/Homebrew/dev-cmd/audit.rb b/Library/Homebrew/dev-cmd/audit.rb index 323b37170b..cd5528cf5a 100644 --- a/Library/Homebrew/dev-cmd/audit.rb +++ b/Library/Homebrew/dev-cmd/audit.rb @@ -809,17 +809,6 @@ class FormulaAuditor end def line_problems(line, _lineno) - # 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 #{Regexp.last_match(1)}." - end - - # Check for long inreplace block vars - if line =~ /inreplace .* do \|(.{2,})\|/ - problem "\"inreplace 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 \"#{Regexp.last_match(2)}\" with #{Regexp.last_match(1)}" diff --git a/Library/Homebrew/rubocops/extend/formula_cop.rb b/Library/Homebrew/rubocops/extend/formula_cop.rb index e7a23ecae8..f8864538a4 100644 --- a/Library/Homebrew/rubocops/extend/formula_cop.rb +++ b/Library/Homebrew/rubocops/extend/formula_cop.rb @@ -85,9 +85,13 @@ module RuboCop end # Returns an array of method call nodes matching method_name in every descendant of node - def find_every_method_call_by_name(node, method_name) + # Returns every method call if no method_name is passed + def find_every_method_call_by_name(node, method_name = nil) return if node.nil? - node.each_descendant(:send).select { |method_node| method_name == method_node.method_name } + node.each_descendant(:send).select do |method_node| + method_name.nil? || + method_name == method_node.method_name + end end # Given a method_name and arguments, yields to a block with @@ -107,7 +111,7 @@ module RuboCop def find_instance_method_call(node, instance, method_name) methods = find_every_method_call_by_name(node, method_name) methods.each do |method| - next unless method.receiver.const_name == instance + next unless method.receiver && method.receiver.const_name == instance @offense_source_range = method.source_range @offensive_node = method yield method @@ -188,9 +192,15 @@ module RuboCop end # Returns an array of block nodes of any depth below node in AST + # If a block is given then yields matching block node to the block! def find_all_blocks(node, block_name) return if node.nil? - node.each_descendant(:block).select { |block_node| block_name == block_node.method_name } + blocks = node.each_descendant(:block).select { |block_node| block_name == block_node.method_name } + return blocks unless block_given? + blocks.each do |block_node| + offending_node(block_node) + yield block_node + end end # Returns a method definition node with method_name diff --git a/Library/Homebrew/rubocops/lines_cop.rb b/Library/Homebrew/rubocops/lines_cop.rb index abd46162f4..ed50ba49c9 100644 --- a/Library/Homebrew/rubocops/lines_cop.rb +++ b/Library/Homebrew/rubocops/lines_cop.rb @@ -52,6 +52,23 @@ module RuboCop end end end + + class Miscellaneous < FormulaCop + def audit_formula(_node, _class_node, _parent_class_node, body_node) + # FileUtils is included in Formula + # encfs modifies a file with this name, so check for some leading characters + find_instance_method_call(body_node, "FileUtils", nil) do |method_node| + problem "Don't need 'FileUtils.' before #{method_node.method_name}" + end + + # Check for long inreplace block vars + find_all_blocks(body_node, :inreplace) do |node| + block_arg = node.arguments.children.first + next unless block_arg.source.size>1 + problem "\"inreplace do |s|\" is preferred over \"|#{block_arg.source}|\"." + end + end + end end end end From 781da49df87f9f2ddbb3f812e3d53963500cc423 Mon Sep 17 00:00:00 2001 From: Gautham Goli Date: Wed, 2 Aug 2017 23:49:51 +0530 Subject: [PATCH 009/294] audit: Add tests for audit rules ported from line_problems method to rubocops --- .../Homebrew/test/rubocops/lines_cop_spec.rb | 151 ++++++++++++++++++ 1 file changed, 151 insertions(+) diff --git a/Library/Homebrew/test/rubocops/lines_cop_spec.rb b/Library/Homebrew/test/rubocops/lines_cop_spec.rb index c865e14801..b0ed8f4d1d 100644 --- a/Library/Homebrew/test/rubocops/lines_cop_spec.rb +++ b/Library/Homebrew/test/rubocops/lines_cop_spec.rb @@ -51,3 +51,154 @@ describe RuboCop::Cop::FormulaAudit::Lines do end end end + +describe RuboCop::Cop::FormulaAudit::ClassInheritance do + subject(:cop) { described_class.new } + + context "When auditing lines" do + it "with no space in class inheritance" do + source = <<-EOS.undent + class Foo do |s|\" is preferred over \"|longvar|\".", + severity: :convention, + line: 4, + column: 2, + source: source }] + + inspect_source(cop, source) + + expected_offenses.zip(cop.offenses).each do |expected, actual| + expect_offense(expected, actual) + end + end + end +end From 82173856272b354c067e826d1d4fb77d8dae1ded Mon Sep 17 00:00:00 2001 From: Mike McQuaid Date: Mon, 7 Aug 2017 10:12:52 +0100 Subject: [PATCH 010/294] software_spec: improve no resource version error. This should make it clearer to us that they needed to `brew update`. Fixes https://github.com/Homebrew/homebrew-core/issues/16075 Fixes https://github.com/Homebrew/brew/issues/2944 --- Library/Homebrew/software_spec.rb | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/Library/Homebrew/software_spec.rb b/Library/Homebrew/software_spec.rb index c6e7043506..49d818f0fa 100644 --- a/Library/Homebrew/software_spec.rb +++ b/Library/Homebrew/software_spec.rb @@ -51,8 +51,18 @@ class SoftwareSpec @owner = owner @resource.owner = self resources.each_value do |r| - r.owner = self - r.version ||= (version.head? ? Version.create("HEAD") : version.dup) + r.owner = self + r.version ||= begin + if version.nil? + raise "#{full_name}: version missing for \"#{r.name}\" resource!" + end + + if version.head? + Version.create("HEAD") + else + version.dup + end + end end patches.each { |p| p.owner = self } end From 12c454822aff7320cee503c0708d30a99f4a0e0c Mon Sep 17 00:00:00 2001 From: Mike McQuaid Date: Mon, 7 Aug 2017 11:16:36 +0100 Subject: [PATCH 011/294] sandbox: stop printing message. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit We’re always using the sandbox where possible now so this is just noise for the vast majority of our users. --- Library/Homebrew/cmd/postinstall.rb | 2 -- Library/Homebrew/dev-cmd/test.rb | 2 -- Library/Homebrew/formula_installer.rb | 2 -- Library/Homebrew/sandbox.rb | 6 ------ 4 files changed, 12 deletions(-) diff --git a/Library/Homebrew/cmd/postinstall.rb b/Library/Homebrew/cmd/postinstall.rb index f5d091227e..02fd8a5f64 100644 --- a/Library/Homebrew/cmd/postinstall.rb +++ b/Library/Homebrew/cmd/postinstall.rb @@ -29,8 +29,6 @@ module Homebrew args << "--devel" end - Sandbox.print_sandbox_message if Sandbox.formula?(formula) - Utils.safe_fork do if Sandbox.formula?(formula) sandbox = Sandbox.new diff --git a/Library/Homebrew/dev-cmd/test.rb b/Library/Homebrew/dev-cmd/test.rb index c678171acb..ab2b0edb0a 100644 --- a/Library/Homebrew/dev-cmd/test.rb +++ b/Library/Homebrew/dev-cmd/test.rb @@ -65,8 +65,6 @@ module Homebrew args << "--devel" end - Sandbox.print_sandbox_message if Sandbox.test? - Utils.safe_fork do if Sandbox.test? sandbox = Sandbox.new diff --git a/Library/Homebrew/formula_installer.rb b/Library/Homebrew/formula_installer.rb index b2a5283818..6c5b8bdabb 100644 --- a/Library/Homebrew/formula_installer.rb +++ b/Library/Homebrew/formula_installer.rb @@ -679,8 +679,6 @@ class FormulaInstaller #{formula.specified_path} ].concat(build_argv) - Sandbox.print_sandbox_message if Sandbox.formula?(formula) - Utils.safe_fork do # Invalidate the current sudo timestamp in case a build script calls sudo. # Travis CI's Linux sudoless workers have a weird sudo that fails here. diff --git a/Library/Homebrew/sandbox.rb b/Library/Homebrew/sandbox.rb index 0de9707731..8c662857e3 100644 --- a/Library/Homebrew/sandbox.rb +++ b/Library/Homebrew/sandbox.rb @@ -18,12 +18,6 @@ class Sandbox !ARGV.no_sandbox? end - def self.print_sandbox_message - return if @printed_sandbox_message - ohai "Using the sandbox" - @printed_sandbox_message = true - end - def initialize @profile = SandboxProfile.new end From 9b5a3b80bf536471f34f62c7ba5d4dc9ae3aec06 Mon Sep 17 00:00:00 2001 From: Andrew Yates Date: Mon, 7 Aug 2017 11:20:56 +0100 Subject: [PATCH 012/294] Incorrect - added I added an extra un-wanted - into the pkgconfig path. Now removed --- Library/Homebrew/extend/os/mac/extend/ENV/super.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Library/Homebrew/extend/os/mac/extend/ENV/super.rb b/Library/Homebrew/extend/os/mac/extend/ENV/super.rb index f50aa52740..9c20cc7c6f 100644 --- a/Library/Homebrew/extend/os/mac/extend/ENV/super.rb +++ b/Library/Homebrew/extend/os/mac/extend/ENV/super.rb @@ -28,7 +28,7 @@ module Superenv # @private def homebrew_extra_pkg_config_paths paths = \ - ["/usr/lib/pkg-config", "#{HOMEBREW_LIBRARY}/Homebrew/os/mac/pkgconfig/#{MacOS.version}"] + ["/usr/lib/pkgconfig", "#{HOMEBREW_LIBRARY}/Homebrew/os/mac/pkgconfig/#{MacOS.version}"] paths << "#{MacOS::X11.lib}/pkgconfig" << "#{MacOS::X11.share}/pkgconfig" if x11? paths end From e2070780f1d28756ba06c3aa623c63eb51c4826c Mon Sep 17 00:00:00 2001 From: Mike McQuaid Date: Mon, 7 Aug 2017 11:21:55 +0100 Subject: [PATCH 013/294] formula_cellar_checks: reinstall broken bottles. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit If we pour from a bottle and then immediately know it’s broken then we should tell users how to resolve their issue and where to file a issue to. Inspired by https://github.com/Homebrew/homebrew-core/issues/16477. --- .../extend/os/mac/formula_cellar_checks.rb | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/Library/Homebrew/extend/os/mac/formula_cellar_checks.rb b/Library/Homebrew/extend/os/mac/formula_cellar_checks.rb index 66e0387744..6d93304895 100644 --- a/Library/Homebrew/extend/os/mac/formula_cellar_checks.rb +++ b/Library/Homebrew/extend/os/mac/formula_cellar_checks.rb @@ -67,11 +67,19 @@ module FormulaCellarChecks checker = LinkageChecker.new(keg, formula) return unless checker.broken_dylibs? - problem_if_output <<-EOS.undent - The installation was broken. - Broken dylib links found: + output = <<-EOS.undent + #{formula} has broken dynamic library links: #{checker.broken_dylibs.to_a * "\n "} EOS + tab = Tab.for_keg(keg) + if tab.poured_from_bottle + output += <<-EOS.undent + Rebuild this from source with: + brew reinstall --build-from-source #{formula}` + If that's successful, file an issue#{formula.tap ? " here:\n #{formula.tap.issues_url}" : "."} + EOS + end + problem_if_output output end def audit_installed From a3219ca09cded33f80c2039c29f191b7369e2450 Mon Sep 17 00:00:00 2001 From: Gautham Goli Date: Sun, 6 Aug 2017 14:48:39 +0530 Subject: [PATCH 014/294] Add node pattern methods to handle dependency audits in a better way --- .../Homebrew/rubocops/extend/formula_cop.rb | 28 ++++++++--- .../Homebrew/test/rubocops/text_cop_spec.rb | 48 +++++++++++++++++++ 2 files changed, 69 insertions(+), 7 deletions(-) diff --git a/Library/Homebrew/rubocops/extend/formula_cop.rb b/Library/Homebrew/rubocops/extend/formula_cop.rb index 4be0c0fe30..8626640106 100644 --- a/Library/Homebrew/rubocops/extend/formula_cop.rb +++ b/Library/Homebrew/rubocops/extend/formula_cop.rb @@ -1,4 +1,5 @@ require "parser/current" +require_relative "../../extend/string" module RuboCop module Cop @@ -138,17 +139,14 @@ module RuboCop case type when :required - type_match = !node.method_args.nil? && - (node.method_args.first.str_type? || node.method_args.first.sym_type?) + type_match = required_dependency?(node) if type_match && !name_match - name_match = node_equals?(node.method_args.first, name) + name_match = required_dependency_name?(node, name) end when :build, :optional, :recommended, :run - type_match = !node.method_args.nil? && - node.method_args.first.hash_type? && - node.method_args.first.values.first.children.first == type + type_match = dependency_type_hash_match?(node, type) if type_match && !name_match - name_match = node_equals?(node.method_args.first.keys.first.children.first, name) + name_match = dependency_name_hash_match?(node, name) end else type_match = false @@ -161,6 +159,22 @@ module RuboCop type_match && name_match end + def_node_search :required_dependency?, <<-EOS.undent + (send nil :depends_on ({str sym} _)) + EOS + + def_node_search :required_dependency_name?, <<-EOS.undent + (send nil :depends_on ({str sym} %1)) + EOS + + def_node_search :dependency_type_hash_match?, <<-EOS.undent + (hash (pair ({str sym} _) ({str sym} %1))) + EOS + + def_node_search :dependency_name_hash_match?, <<-EOS.undent + (hash (pair ({str sym} %1) ({str sym} _))) + EOS + # To compare node with appropriate Ruby variable def node_equals?(node, var) node == Parser::CurrentRuby.parse(var.inspect) diff --git a/Library/Homebrew/test/rubocops/text_cop_spec.rb b/Library/Homebrew/test/rubocops/text_cop_spec.rb index b218e9c256..ec13c40415 100644 --- a/Library/Homebrew/test/rubocops/text_cop_spec.rb +++ b/Library/Homebrew/test/rubocops/text_cop_spec.rb @@ -7,6 +7,54 @@ describe RuboCop::Cop::FormulaAudit::Text do subject(:cop) { described_class.new } context "When auditing formula text" do + it "with both openssl and libressl optional dependencies" do + source = <<-EOS.undent + class Foo < Formula + url "http://example.com/foo-1.0.tgz" + homepage "http://example.com" + + depends_on "openssl" + depends_on "libressl" => :optional + end + EOS + + expected_offenses = [{ message: "Formulae should not depend on both OpenSSL and LibreSSL (even optionally).", + severity: :convention, + line: 6, + column: 2, + source: source }] + + inspect_source(cop, source) + + expected_offenses.zip(cop.offenses).each do |expected, actual| + expect_offense(expected, actual) + end + end + + it "with both openssl and libressl dependencies" do + source = <<-EOS.undent + class Foo < Formula + url "http://example.com/foo-1.0.tgz" + homepage "http://example.com" + + depends_on "openssl" + depends_on "libressl" + end + EOS + + expected_offenses = [{ message: "Formulae should not depend on both OpenSSL and LibreSSL (even optionally).", + severity: :convention, + line: 6, + column: 2, + source: source }] + + inspect_source(cop, source) + + expected_offenses.zip(cop.offenses).each do |expected, actual| + expect_offense(expected, actual) + end + end + it "When xcodebuild is called without SYMROOT" do source = <<-EOS.undent class Foo < Formula From 69799d97b1e7314912b2ee234dec2c179c5fb969 Mon Sep 17 00:00:00 2001 From: Mike McQuaid Date: Mon, 7 Aug 2017 11:48:45 +0100 Subject: [PATCH 015/294] formula_cellar_checks: remove stray backtick. --- Library/Homebrew/extend/os/mac/formula_cellar_checks.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Library/Homebrew/extend/os/mac/formula_cellar_checks.rb b/Library/Homebrew/extend/os/mac/formula_cellar_checks.rb index 6d93304895..4d5ce3e9e1 100644 --- a/Library/Homebrew/extend/os/mac/formula_cellar_checks.rb +++ b/Library/Homebrew/extend/os/mac/formula_cellar_checks.rb @@ -75,7 +75,7 @@ module FormulaCellarChecks if tab.poured_from_bottle output += <<-EOS.undent Rebuild this from source with: - brew reinstall --build-from-source #{formula}` + brew reinstall --build-from-source #{formula} If that's successful, file an issue#{formula.tap ? " here:\n #{formula.tap.issues_url}" : "."} EOS end From fb59e79689b15d71e6090d0f6f1f39f4d69800b1 Mon Sep 17 00:00:00 2001 From: Markus Reiter Date: Sat, 1 Jul 2017 17:57:39 +0200 Subject: [PATCH 016/294] Simplify SubversionDownloadStrategy. --- Library/Homebrew/cask/lib/hbc/container.rb | 3 + .../cask/lib/hbc/container/criteria.rb | 6 +- .../cask/lib/hbc/container/directory.rb | 24 ++++++++ .../cask/lib/hbc/container/executable.rb | 2 +- .../cask/lib/hbc/container/svn_repository.rb | 15 +++++ .../cask/lib/hbc/download_strategy.rb | 57 ++----------------- .../Homebrew/cask/lib/hbc/system_command.rb | 4 -- .../test/cask/download_strategy_spec.rb | 43 +------------- 8 files changed, 55 insertions(+), 99 deletions(-) create mode 100644 Library/Homebrew/cask/lib/hbc/container/directory.rb create mode 100644 Library/Homebrew/cask/lib/hbc/container/svn_repository.rb diff --git a/Library/Homebrew/cask/lib/hbc/container.rb b/Library/Homebrew/cask/lib/hbc/container.rb index 93e825e038..fab3a3c1c3 100644 --- a/Library/Homebrew/cask/lib/hbc/container.rb +++ b/Library/Homebrew/cask/lib/hbc/container.rb @@ -4,6 +4,7 @@ require "hbc/container/bzip2" require "hbc/container/cab" require "hbc/container/criteria" require "hbc/container/dmg" +require "hbc/container/directory" require "hbc/container/executable" require "hbc/container/generic_unar" require "hbc/container/gpg" @@ -14,6 +15,7 @@ require "hbc/container/otf" require "hbc/container/pkg" require "hbc/container/seven_zip" require "hbc/container/sit" +require "hbc/container/svn_repository" require "hbc/container/tar" require "hbc/container/ttf" require "hbc/container/rar" @@ -43,6 +45,7 @@ module Hbc Xz, # pure xz Gpg, # GnuPG signed data Executable, + SvnRepository, ] # for explicit use only (never autodetected): # Hbc::Container::Naked diff --git a/Library/Homebrew/cask/lib/hbc/container/criteria.rb b/Library/Homebrew/cask/lib/hbc/container/criteria.rb index 66ecb8c874..52f171d6a1 100644 --- a/Library/Homebrew/cask/lib/hbc/container/criteria.rb +++ b/Library/Homebrew/cask/lib/hbc/container/criteria.rb @@ -13,9 +13,11 @@ module Hbc end def magic_number(regex) + return false if path.directory? + # 262: length of the longest regex (currently: Hbc::Container::Tar) - @magic_number ||= File.open(@path, "rb") { |f| f.read(262) } - @magic_number =~ regex + @magic_number ||= File.open(path, "rb") { |f| f.read(262) } + @magic_number.match?(regex) end end end diff --git a/Library/Homebrew/cask/lib/hbc/container/directory.rb b/Library/Homebrew/cask/lib/hbc/container/directory.rb new file mode 100644 index 0000000000..e4bb1095b2 --- /dev/null +++ b/Library/Homebrew/cask/lib/hbc/container/directory.rb @@ -0,0 +1,24 @@ +require "hbc/container/base" + +module Hbc + class Container + class Directory < Base + def self.me?(*) + false + end + + def extract + @path.children.each do |child| + next if skip_path?(child) + FileUtils.cp child, @cask.staged_path + end + end + + private + + def skip_path?(*) + false + end + end + end +end diff --git a/Library/Homebrew/cask/lib/hbc/container/executable.rb b/Library/Homebrew/cask/lib/hbc/container/executable.rb index 848f6d4be2..af3b36fd10 100644 --- a/Library/Homebrew/cask/lib/hbc/container/executable.rb +++ b/Library/Homebrew/cask/lib/hbc/container/executable.rb @@ -8,7 +8,7 @@ module Hbc return true if criteria.magic_number(/^#!\s*\S+/) begin - MachO.open(criteria.path).header.executable? + criteria.path.file? && MachO.open(criteria.path).header.executable? rescue MachO::MagicError false end diff --git a/Library/Homebrew/cask/lib/hbc/container/svn_repository.rb b/Library/Homebrew/cask/lib/hbc/container/svn_repository.rb new file mode 100644 index 0000000000..cae613b2db --- /dev/null +++ b/Library/Homebrew/cask/lib/hbc/container/svn_repository.rb @@ -0,0 +1,15 @@ +require "hbc/container/directory" + +module Hbc + class Container + class SvnRepository < Directory + def self.me?(criteria) + criteria.path.join(".svn").directory? + end + + def skip_path?(path) + path.basename.to_s == ".svn" + end + end + end +end diff --git a/Library/Homebrew/cask/lib/hbc/download_strategy.rb b/Library/Homebrew/cask/lib/hbc/download_strategy.rb index 016bb66e6e..fb4319f5ea 100644 --- a/Library/Homebrew/cask/lib/hbc/download_strategy.rb +++ b/Library/Homebrew/cask/lib/hbc/download_strategy.rb @@ -10,7 +10,7 @@ module Hbc class AbstractDownloadStrategy attr_reader :cask, :name, :url, :uri_object, :version - def initialize(cask, command = SystemCommand) + def initialize(cask, command: SystemCommand) @cask = cask @command = command # TODO: this excess of attributes is a function of integrating @@ -33,8 +33,8 @@ module Hbc class HbVCSDownloadStrategy < AbstractDownloadStrategy REF_TYPES = [:branch, :revision, :revisions, :tag].freeze - def initialize(cask, command = SystemCommand) - super + def initialize(*args, **options) + super(*args, **options) @ref_type, @ref = extract_ref @clone = Hbc.cache.join(cache_filename) end @@ -64,11 +64,6 @@ module Hbc end class CurlDownloadStrategy < AbstractDownloadStrategy - # TODO: should be part of url object - def mirrors - @mirrors ||= [] - end - def tarball_path @tarball_path ||= Hbc.cache.join("#{name}--#{version}#{ext}") end @@ -131,11 +126,6 @@ module Hbc ignore_interrupts { temporary_path.rename(tarball_path) } end tarball_path - rescue CurlDownloadStrategyError - raise if mirrors.empty? - puts "Trying a mirror..." - @url = mirrors.shift - retry end private @@ -225,8 +215,8 @@ module Hbc # super does not provide checks for already-existing downloads def fetch - if tarball_path.exist? - puts "Already downloaded: #{tarball_path}" + if cached_location.directory? + puts "Already downloaded: #{cached_location}" else @url = @url.sub(/^svn\+/, "") if @url =~ %r{^svn\+http://} ohai "Checking out #{@url}" @@ -252,9 +242,8 @@ module Hbc else fetch_repo @clone, @url end - compress end - tarball_path + cached_location end # This primary reason for redefining this method is the trust_cert @@ -288,10 +277,6 @@ module Hbc print_stderr: false) end - def tarball_path - @tarball_path ||= cached_location.dirname.join(cached_location.basename.to_s + "-#{@cask.version}.tar") - end - def shell_quote(str) # Oh god escaping shell args. # See http://notetoself.vrensk.com/2008/08/escaping-single-quotes-in-ruby-harder-than-expected/ @@ -304,35 +289,5 @@ module Hbc yield name, url end end - - private - - # TODO/UPDATE: the tar approach explained below is fragile - # against challenges such as case-sensitive filesystems, - # and must be re-implemented. - # - # Seems nutty: we "download" the contents into a tape archive. - # Why? - # * A single file is tractable to the rest of the Cask toolchain, - # * An alternative would be to create a Directory container type. - # However, some type of file-serialization trick would still be - # needed in order to enable calculating a single checksum over - # a directory. So, in that alternative implementation, the - # special cases would propagate outside this class, including - # the use of tar or equivalent. - # * SubversionDownloadStrategy.cached_location is not versioned - # * tarball_path provides a needed return value for our overridden - # fetch method. - # * We can also take this private opportunity to strip files from - # the download which are protocol-specific. - - def compress - Dir.chdir(cached_location) do - @command.run!("/usr/bin/tar", - args: ['-s/^\.//', "--exclude", ".svn", "-cf", Pathname.new(tarball_path), "--", "."], - print_stderr: false) - end - clear_cache - end end end diff --git a/Library/Homebrew/cask/lib/hbc/system_command.rb b/Library/Homebrew/cask/lib/hbc/system_command.rb index 901617b71b..b735ae4f9c 100644 --- a/Library/Homebrew/cask/lib/hbc/system_command.rb +++ b/Library/Homebrew/cask/lib/hbc/system_command.rb @@ -112,11 +112,7 @@ module Hbc processed_output[:stderr], processed_status.exitstatus) end - end -end -module Hbc - class SystemCommand class Result attr_accessor :command, :stdout, :stderr, :exit_status diff --git a/Library/Homebrew/test/cask/download_strategy_spec.rb b/Library/Homebrew/test/cask/download_strategy_spec.rb index 222352c07e..0c18f56b56 100644 --- a/Library/Homebrew/test/cask/download_strategy_spec.rb +++ b/Library/Homebrew/test/cask/download_strategy_spec.rb @@ -138,7 +138,7 @@ describe "download strategies", :cask do describe Hbc::SubversionDownloadStrategy do let(:url_options) { { using: :svn } } let(:fake_system_command) { class_double(Hbc::SystemCommand) } - let(:downloader) { Hbc::SubversionDownloadStrategy.new(cask, fake_system_command) } + let(:downloader) { Hbc::SubversionDownloadStrategy.new(cask, command: fake_system_command) } before do allow(fake_system_command).to receive(:run!) end @@ -147,7 +147,7 @@ describe "download strategies", :cask do allow(downloader).to receive(:compress) allow(downloader).to receive(:fetch_repo) - expect(downloader.fetch).to equal(downloader.tarball_path) + expect(downloader.fetch).to equal(downloader.cached_location) end it "calls fetch_repo with default arguments for a simple Cask" do @@ -237,44 +237,5 @@ describe "download strategies", :cask do ) end end - - it "runs tar to serialize svn downloads" do - # sneaky stub to remake the directory, since homebrew code removes it - # before tar is called - allow(downloader).to receive(:fetch_repo) { - downloader.cached_location.mkdir - } - - downloader.fetch - - expect(fake_system_command).to have_received(:run!).with( - "/usr/bin/tar", - hash_including(args: [ - '-s/^\\.//', - "--exclude", - ".svn", - "-cf", - downloader.tarball_path, - "--", - ".", - ]), - ) - end end - - # does not work yet, because (for unknown reasons), the tar command - # returns an error code when running under the test suite - # it 'creates a tarball matching the expected checksum' do - # cask = Hbc::CaskLoader.load('svn-download-check-cask') - # downloader = Hbc::SubversionDownloadStrategy.new(cask) - # # special mocking required for tar to have something to work with - # def downloader.fetch_repo(target, url, revision = nil, ignore_externals=false) - # target.mkpath - # FileUtils.touch(target.join('empty_file.txt')) - # File.utime(1000,1000,target.join('empty_file.txt')) - # end - # expect(downloader.fetch).to equal(downloader.tarball_path) - # d = Hbc::Download.new(cask) - # d.send(:_check_sums, downloader.tarball_path, cask.sums) - # end end From dc5a2c1764b1da3cfa85d8910338eb72cd4da96c Mon Sep 17 00:00:00 2001 From: Markus Reiter Date: Fri, 4 Aug 2017 16:24:29 +0200 Subject: [PATCH 017/294] Simplify CurlDownloadStrategy. --- Library/Homebrew/cask/lib/hbc/audit.rb | 10 +- Library/Homebrew/cask/lib/hbc/cask_loader.rb | 2 +- .../cask/lib/hbc/download_strategy.rb | 28 +---- Library/Homebrew/cask/lib/hbc/dsl/appcast.rb | 6 +- Library/Homebrew/cask/lib/hbc/url.rb | 11 +- Library/Homebrew/cask/lib/hbc/verify/gpg.rb | 2 +- Library/Homebrew/dev-cmd/audit.rb | 8 +- Library/Homebrew/dev-cmd/mirror.rb | 10 +- Library/Homebrew/dev-cmd/pull.rb | 16 +-- Library/Homebrew/download_strategy.rb | 107 ++++++++---------- Library/Homebrew/formulary.rb | 2 +- .../test/cask/download_strategy_spec.rb | 23 ++-- .../Homebrew/test/cask/dsl/appcast_spec.rb | 11 +- Library/Homebrew/utils/curl.rb | 42 +++---- Library/Homebrew/utils/github.rb | 2 +- 15 files changed, 132 insertions(+), 148 deletions(-) diff --git a/Library/Homebrew/cask/lib/hbc/audit.rb b/Library/Homebrew/cask/lib/hbc/audit.rb index cee1fe8070..b8bb6ab814 100644 --- a/Library/Homebrew/cask/lib/hbc/audit.rb +++ b/Library/Homebrew/cask/lib/hbc/audit.rb @@ -143,7 +143,15 @@ module Hbc def check_appcast_http_code odebug "Verifying appcast returns 200 HTTP response code" - result = @command.run("/usr/bin/curl", args: ["--compressed", "--location", "--user-agent", URL::FAKE_USER_AGENT, "--output", "/dev/null", "--write-out", "%{http_code}", cask.appcast], print_stderr: false) + + curl_executable, *args = curl_args( + "--compressed", "--location", "--fail", + "--write-out", "%{http_code}", + "--output", "/dev/null", + cask.appcast, + user_agent: :fake + ) + result = @command.run(curl_executable, args: args, print_stderr: false) if result.success? http_code = result.stdout.chomp add_warning "unexpected HTTP response code retrieving appcast: #{http_code}" unless http_code == "200" diff --git a/Library/Homebrew/cask/lib/hbc/cask_loader.rb b/Library/Homebrew/cask/lib/hbc/cask_loader.rb index 5003146719..dd9c610899 100644 --- a/Library/Homebrew/cask/lib/hbc/cask_loader.rb +++ b/Library/Homebrew/cask/lib/hbc/cask_loader.rb @@ -71,7 +71,7 @@ module Hbc begin ohai "Downloading #{url}." - curl url, "-o", path + curl_download url, to: path rescue ErrorDuringExecution raise CaskUnavailableError.new(token, "Failed to download #{Formatter.url(url)}.") end diff --git a/Library/Homebrew/cask/lib/hbc/download_strategy.rb b/Library/Homebrew/cask/lib/hbc/download_strategy.rb index fb4319f5ea..245ad4adeb 100644 --- a/Library/Homebrew/cask/lib/hbc/download_strategy.rb +++ b/Library/Homebrew/cask/lib/hbc/download_strategy.rb @@ -90,13 +90,8 @@ module Hbc end end - def downloaded_size - temporary_path.size? || 0 - end - def _fetch - odebug "Calling curl with args #{cask_curl_args}" - curl(*cask_curl_args) + curl_download url, *cask_curl_args, to: temporary_path, user_agent: uri_object.user_agent end def fetch @@ -131,23 +126,7 @@ module Hbc private def cask_curl_args - default_curl_args.tap do |args| - args.concat(user_agent_args) - args.concat(cookies_args) - args.concat(referer_args) - end - end - - def default_curl_args - [url, "-C", downloaded_size, "-o", temporary_path] - end - - def user_agent_args - if uri_object.user_agent - ["-A", uri_object.user_agent] - else - [] - end + cookies_args + referer_args end def cookies_args @@ -181,8 +160,7 @@ module Hbc class CurlPostDownloadStrategy < CurlDownloadStrategy def cask_curl_args - super - default_curl_args.concat(post_args) + super.concat(post_args) end def post_args diff --git a/Library/Homebrew/cask/lib/hbc/dsl/appcast.rb b/Library/Homebrew/cask/lib/hbc/dsl/appcast.rb index d302d09460..fc7e83a20d 100644 --- a/Library/Homebrew/cask/lib/hbc/dsl/appcast.rb +++ b/Library/Homebrew/cask/lib/hbc/dsl/appcast.rb @@ -12,7 +12,11 @@ module Hbc end def calculate_checkpoint - result = SystemCommand.run("/usr/bin/curl", args: ["--compressed", "--location", "--user-agent", URL::FAKE_USER_AGENT, "--fail", @uri], print_stderr: false) + curl_executable, *args = curl_args( + "--compressed", "--location", "--fail", @uri, + user_agent: :fake + ) + result = SystemCommand.run(curl_executable, args: args, print_stderr: false) checkpoint = if result.success? processed_appcast_text = result.stdout.gsub(%r{[^<]*}m, "") diff --git a/Library/Homebrew/cask/lib/hbc/url.rb b/Library/Homebrew/cask/lib/hbc/url.rb index 15da2ced21..8c652657b6 100644 --- a/Library/Homebrew/cask/lib/hbc/url.rb +++ b/Library/Homebrew/cask/lib/hbc/url.rb @@ -1,8 +1,6 @@ module Hbc class URL - FAKE_USER_AGENT = "Mozilla/5.0 (Macintosh; Intel Mac OS X 10) https://caskroom.github.io".freeze - - attr_reader :using, :revision, :trust_cert, :uri, :cookies, :referer, :data + attr_reader :using, :revision, :trust_cert, :uri, :cookies, :referer, :data, :user_agent extend Forwardable def_delegators :uri, :path, :scheme, :to_s @@ -17,7 +15,7 @@ module Hbc def initialize(uri, options = {}) @uri = Hbc::UnderscoreSupportingURI.parse(uri) - @user_agent = options[:user_agent] + @user_agent = options.fetch(:user_agent, :default) @cookies = options[:cookies] @referer = options[:referer] @using = options[:using] @@ -25,10 +23,5 @@ module Hbc @trust_cert = options[:trust_cert] @data = options[:data] end - - def user_agent - return FAKE_USER_AGENT if @user_agent == :fake - @user_agent - end end end diff --git a/Library/Homebrew/cask/lib/hbc/verify/gpg.rb b/Library/Homebrew/cask/lib/hbc/verify/gpg.rb index dbb537756d..f4996a5b5e 100644 --- a/Library/Homebrew/cask/lib/hbc/verify/gpg.rb +++ b/Library/Homebrew/cask/lib/hbc/verify/gpg.rb @@ -33,7 +33,7 @@ module Hbc meta_dir = cached || cask.metadata_subdir("gpg", :now, true) sig_path = meta_dir.join("signature.asc") - curl(cask.gpg.signature, "-o", sig_path.to_s) unless cached || force + curl_download cask.gpg.signature, to: sig_path unless cached || force sig_path end diff --git a/Library/Homebrew/dev-cmd/audit.rb b/Library/Homebrew/dev-cmd/audit.rb index 1f07fa89ea..b3e0785a51 100644 --- a/Library/Homebrew/dev-cmd/audit.rb +++ b/Library/Homebrew/dev-cmd/audit.rb @@ -242,12 +242,10 @@ class FormulaAuditor def self.http_content_headers_and_checksum(url, hash_needed: false, user_agent: :default) max_time = hash_needed ? "600" : "25" - args = curl_args( - extra_args: ["--connect-timeout", "15", "--include", "--max-time", max_time, url], - show_output: true, - user_agent: user_agent, + output, = curl_output( + "--connect-timeout", "15", "--include", "--max-time", max_time, "--location", url, + user_agent: user_agent ) - output = Open3.popen3(*args) { |_, stdout, _, _| stdout.read } status_code = :unknown while status_code == :unknown || status_code.to_s.start_with?("3") diff --git a/Library/Homebrew/dev-cmd/mirror.rb b/Library/Homebrew/dev-cmd/mirror.rb index e2492203d3..6445bc34cf 100644 --- a/Library/Homebrew/dev-cmd/mirror.rb +++ b/Library/Homebrew/dev-cmd/mirror.rb @@ -25,9 +25,9 @@ module Homebrew "public_download_numbers": true, "public_stats": true} EOS - curl "--silent", "--fail", "-u#{bintray_user}:#{bintray_key}", - "-H", "Content-Type: application/json", - "-d", package_blob, bintray_repo_url + curl "--silent", "--fail", "--user", "#{bintray_user}:#{bintray_key}", + "--header", "Content-Type: application/json", + "--data", package_blob, bintray_repo_url puts end @@ -40,8 +40,8 @@ module Homebrew content_url = "https://api.bintray.com/content/homebrew/mirror" content_url += "/#{bintray_package}/#{f.pkg_version}/#{filename}" content_url += "?publish=1" - curl "--silent", "--fail", "-u#{bintray_user}:#{bintray_key}", - "-T", download, content_url + curl "--silent", "--fail", "--user", "#{bintray_user}:#{bintray_key}", + "--upload-file", download, content_url puts ohai "Mirrored #{filename}!" end diff --git a/Library/Homebrew/dev-cmd/pull.rb b/Library/Homebrew/dev-cmd/pull.rb index 9681bb2bc0..dd2bc62707 100644 --- a/Library/Homebrew/dev-cmd/pull.rb +++ b/Library/Homebrew/dev-cmd/pull.rb @@ -228,7 +228,7 @@ module Homebrew "https://github.com/BrewTestBot/homebrew-#{tap.repo}/compare/homebrew:master...pr-#{issue}" end - curl "--silent", "--fail", "-o", "/dev/null", "-I", bottle_commit_url + curl "--silent", "--fail", "--output", "/dev/null", "--head", bottle_commit_url safe_system "git", "checkout", "--quiet", "-B", bottle_branch, orig_revision pull_patch bottle_commit_url, "bottle commit" @@ -303,7 +303,7 @@ module Homebrew extra_msg = @description ? "(#{@description})" : nil ohai "Fetching patch #{extra_msg}" puts "Patch: #{patch_url}" - curl patch_url, "-s", "-o", patchpath + curl_download patch_url, to: patchpath end def apply_patch @@ -433,10 +433,10 @@ module Homebrew end version = info.pkg_version ohai "Publishing on Bintray: #{package} #{version}" - curl "-w", '\n', "--silent", "--fail", - "-u#{creds[:user]}:#{creds[:key]}", "-X", "POST", - "-H", "Content-Type: application/json", - "-d", '{"publish_wait_for_secs": 0}', + curl "--write-out", '\n', "--silent", "--fail", + "--user", "#{creds[:user]}:#{creds[:key]}", "--request", "POST", + "--header", "Content-Type: application/json", + "--data", '{"publish_wait_for_secs": 0}', "https://api.bintray.com/content/homebrew/#{repo}/#{package}/#{version}/publish" true rescue => e @@ -587,7 +587,7 @@ module Homebrew # We're in the cache; make sure to force re-download loop do begin - curl url, "-o", filename + curl_download url, to: filename break rescue if retry_count >= max_curl_retries @@ -606,7 +606,7 @@ module Homebrew end def check_bintray_mirror(name, url) - headers = curl_output("--connect-timeout", "15", "--head", url)[0] + headers, = curl_output("--connect-timeout", "15", "--location", "--head", url) status_code = headers.scan(%r{^HTTP\/.* (\d+)}).last.first return if status_code.start_with?("2") opoo "The Bintray mirror #{url} is not reachable (HTTP status code #{status_code})." diff --git a/Library/Homebrew/download_strategy.rb b/Library/Homebrew/download_strategy.rb index 7173347143..2a8b6e5859 100644 --- a/Library/Homebrew/download_strategy.rb +++ b/Library/Homebrew/download_strategy.rb @@ -375,75 +375,59 @@ class CurlDownloadStrategy < AbstractFileDownloadStrategy ohai "Downloading from #{url}" end - urls = actual_urls(url) - unless urls.empty? - ohai "Downloading from #{urls.last}" - if !ENV["HOMEBREW_NO_INSECURE_REDIRECT"].nil? && url.start_with?("https://") && - urls.any? { |u| !u.start_with? "https://" } - puts "HTTPS to HTTP redirect detected & HOMEBREW_NO_INSECURE_REDIRECT is set." - raise CurlDownloadStrategyError, url - end - url = urls.last - end - - curl url, "-C", downloaded_size, "-o", temporary_path + curl_download resolved_url(url), to: temporary_path end # Curl options to be always passed to curl, - # with raw head calls (`curl -I`) or with actual `fetch`. + # with raw head calls (`curl --head`) or with actual `fetch`. def _curl_opts - copts = [] - copts << "--user" << meta.fetch(:user) if meta.key?(:user) - copts + return ["--user" << meta.fetch(:user)] if meta.key?(:user) + [] end - def actual_urls(url) - urls = [] - curl_args = _curl_opts << "-I" << "-L" << url - Utils.popen_read("curl", *curl_args).scan(/^Location: (.+)$/).map do |m| - urls << URI.join(urls.last || url, m.first.chomp).to_s + def resolved_url(url) + redirect_url, _, status = curl_output( + *_curl_opts, "--silent", "--head", + "--write-out", "%{redirect_url}", + "--output", "/dev/null", + url.to_s + ) + + return url unless status.success? + return url if redirect_url.empty? + + ohai "Downloading from #{redirect_url}" + if ENV["HOMEBREW_NO_INSECURE_REDIRECT"] && + url.start_with?("https://") && !redirect_url.start_with?("https://") + puts "HTTPS to HTTP redirect detected & HOMEBREW_NO_INSECURE_REDIRECT is set." + raise CurlDownloadStrategyError, url end - urls + + redirect_url end - def downloaded_size - temporary_path.size? || 0 - end - - def curl(*args) + def curl(*args, **options) args.concat _curl_opts args << "--connect-timeout" << "5" unless mirrors.empty? - super + super(*args, **options) end end # Detect and download from Apache Mirror class CurlApacheMirrorDownloadStrategy < CurlDownloadStrategy def apache_mirrors - rd, wr = IO.pipe - buf = "" + mirrors, = Open3.capture3( + *curl_args(*_curl_opts, "--silent", "--location", "#{@url}&asjson=1"), + ) - pid = fork do - ENV.delete "HOMEBREW_CURL_VERBOSE" - rd.close - $stdout.reopen(wr) - $stderr.reopen(wr) - curl "#{@url}&asjson=1" - end - wr.close - - rd.readline if ARGV.verbose? # Remove Homebrew output - buf << rd.read until rd.eof? - rd.close - Process.wait(pid) - buf + JSON.parse(mirrors) end def _fetch return super if @tried_apache_mirror @tried_apache_mirror = true - mirrors = JSON.parse(apache_mirrors) + mirrors = apache_mirrors path_info = mirrors.fetch("path_info") @url = mirrors.fetch("preferred") + path_info @mirrors |= %W[https://archive.apache.org/dist/#{path_info}] @@ -460,7 +444,7 @@ end class CurlPostDownloadStrategy < CurlDownloadStrategy def _fetch base_url, data = @url.split("?") - curl base_url, "-d", data, "-C", downloaded_size, "-o", temporary_path + curl_download base_url, "--data", data, to: temporary_path end end @@ -530,7 +514,7 @@ class S3DownloadStrategy < CurlDownloadStrategy s3url = obj.public_url end - curl s3url, "-C", downloaded_size, "-o", temporary_path + curl_download s3url, to: temporary_path end end @@ -566,7 +550,7 @@ class GitHubPrivateRepositoryDownloadStrategy < CurlDownloadStrategy end def _fetch - curl download_url, "-C", downloaded_size, "-o", temporary_path + curl_download download_url, to: temporary_path end private @@ -615,7 +599,7 @@ class GitHubPrivateRepositoryReleaseDownloadStrategy < GitHubPrivateRepositoryDo def _fetch # HTTP request header `Accept: application/octet-stream` is required. # Without this, the GitHub API will respond with metadata, not binary. - curl download_url, "-C", downloaded_size, "-o", temporary_path, "-H", "Accept: application/octet-stream" + curl_download download_url, "--header", "Accept: application/octet-stream", to: temporary_path end private @@ -915,18 +899,27 @@ class GitHubGitDownloadStrategy < GitDownloadStrategy def github_last_commit return if ENV["HOMEBREW_NO_GITHUB_API"] - output, _, status = curl_output "-H", "Accept: application/vnd.github.v3.sha", \ - "-I", "https://api.github.com/repos/#{@user}/#{@repo}/commits/#{@ref}" + output, _, status = curl_output( + "--silent", "--head", "--location", + "-H", "Accept: application/vnd.github.v3.sha", + "https://api.github.com/repos/#{@user}/#{@repo}/commits/#{@ref}" + ) - commit = output[/^ETag: \"(\h+)\"/, 1] if status.success? + return unless status.success? + + commit = output[/^ETag: \"(\h+)\"/, 1] version.update_commit(commit) if commit commit end def multiple_short_commits_exist?(commit) return if ENV["HOMEBREW_NO_GITHUB_API"] - output, _, status = curl_output "-H", "Accept: application/vnd.github.v3.sha", \ - "-I", "https://api.github.com/repos/#{@user}/#{@repo}/commits/#{commit}" + + output, _, status = curl_output( + "--silent", "--head", "--location", + "-H", "Accept: application/vnd.github.v3.sha", + "https://api.github.com/repos/#{@user}/#{@repo}/commits/#{commit}" + ) !(status.success? && output && output[/^Status: (200)/, 1] == "200") end @@ -1159,15 +1152,13 @@ class DownloadStrategyDetector SubversionDownloadStrategy when %r{^cvs://} CVSDownloadStrategy - when %r{^https?://(.+?\.)?googlecode\.com/hg} - MercurialDownloadStrategy - when %r{^hg://} + when %r{^hg://}, %r{^https?://(.+?\.)?googlecode\.com/hg} MercurialDownloadStrategy when %r{^bzr://} BazaarDownloadStrategy when %r{^fossil://} FossilDownloadStrategy - when %r{^http://svn\.apache\.org/repos/}, %r{^svn\+http://} + when %r{^svn\+http://}, %r{^http://svn\.apache\.org/repos/} SubversionDownloadStrategy when %r{^https?://(.+?\.)?sourceforge\.net/hgweb/} MercurialDownloadStrategy diff --git a/Library/Homebrew/formulary.rb b/Library/Homebrew/formulary.rb index 195d15cece..dd67b4f243 100644 --- a/Library/Homebrew/formulary.rb +++ b/Library/Homebrew/formulary.rb @@ -165,7 +165,7 @@ module Formulary def load_file HOMEBREW_CACHE_FORMULA.mkpath FileUtils.rm_f(path) - curl url, "-o", path + curl_download url, to: path super rescue MethodDeprecatedError => e if url =~ %r{github.com/([\w-]+)/homebrew-([\w-]+)/} diff --git a/Library/Homebrew/test/cask/download_strategy_spec.rb b/Library/Homebrew/test/cask/download_strategy_spec.rb index 0c18f56b56..60d101bdb8 100644 --- a/Library/Homebrew/test/cask/download_strategy_spec.rb +++ b/Library/Homebrew/test/cask/download_strategy_spec.rb @@ -27,8 +27,11 @@ describe "download strategies", :cask do expect(downloader).to have_received(:curl).with( cask.url.to_s, - "-C", 0, - "-o", kind_of(Pathname) + "--location", + "--remote-time", + "--continue-at", "-", + "--output", kind_of(Pathname), + user_agent: :default ) end @@ -36,25 +39,25 @@ describe "download strategies", :cask do let(:url_options) { { user_agent: "Mozilla/25.0.1" } } it "adds the appropriate curl args" do - curl_args = [] - allow(downloader).to receive(:curl) { |*args| curl_args = args } + expect(downloader).to receive(:safe_system) { |*args| + expect(args.each_cons(2)).to include(["--user-agent", "Mozilla/25.0.1"]) + } downloader.fetch - - expect(curl_args.each_cons(2)).to include(["-A", "Mozilla/25.0.1"]) end end context "with a generalized fake user agent" do + alias_matcher :a_string_matching, :match + let(:url_options) { { user_agent: :fake } } it "adds the appropriate curl args" do - curl_args = [] - allow(downloader).to receive(:curl) { |*args| curl_args = args } + expect(downloader).to receive(:safe_system) { |*args| + expect(args.each_cons(2).to_a).to include(["--user-agent", a_string_matching(/Mozilla.*Mac OS X 10.*AppleWebKit/)]) + } downloader.fetch - - expect(curl_args.each_cons(2)).to include(["-A", "Mozilla/5.0 (Macintosh; Intel Mac OS X 10) https://caskroom.github.io"]) end end diff --git a/Library/Homebrew/test/cask/dsl/appcast_spec.rb b/Library/Homebrew/test/cask/dsl/appcast_spec.rb index b8903b1be8..ccc6a46338 100644 --- a/Library/Homebrew/test/cask/dsl/appcast_spec.rb +++ b/Library/Homebrew/test/cask/dsl/appcast_spec.rb @@ -33,13 +33,18 @@ describe Hbc::DSL::Appcast do describe "#calculate_checkpoint" do before do - expect(Hbc::SystemCommand).to receive(:run).with(*cmd_args).and_return(cmd_result) + expect(Hbc::SystemCommand).to receive(:run) do |executable, **options| + expect(executable).to eq "/usr/bin/curl" + expect(options[:args]).to include(*cmd_args) + expect(options[:print_stderr]).to be false + cmd_result + end allow(cmd_result).to receive(:success?).and_return(cmd_success) allow(cmd_result).to receive(:stdout).and_return(cmd_stdout) end context "when server returns a successful HTTP status" do - let(:cmd_args) { ["/usr/bin/curl", args: ["--compressed", "--location", "--user-agent", Hbc::URL::FAKE_USER_AGENT, "--fail", uri], print_stderr: false] } + let(:cmd_args) { [HOMEBREW_USER_AGENT_FAKE_SAFARI, "--compressed", "--location", "--fail", uri] } let(:cmd_result) { double("Hbc::SystemCommand::Result") } let(:cmd_success) { true } let(:cmd_stdout) { "hello world" } @@ -56,7 +61,7 @@ describe Hbc::DSL::Appcast do end context "when server returns a non-successful HTTP status" do - let(:cmd_args) { ["/usr/bin/curl", args: ["--compressed", "--location", "--user-agent", Hbc::URL::FAKE_USER_AGENT, "--fail", uri], print_stderr: false] } + let(:cmd_args) { [HOMEBREW_USER_AGENT_FAKE_SAFARI, "--compressed", "--location", "--fail", uri] } let(:cmd_result) { double("Hbc::SystemCommand::Result") } let(:cmd_success) { false } let(:cmd_stdout) { "some error message from the server" } diff --git a/Library/Homebrew/utils/curl.rb b/Library/Homebrew/utils/curl.rb index 5a40ae8469..6aaf9be0cb 100644 --- a/Library/Homebrew/utils/curl.rb +++ b/Library/Homebrew/utils/curl.rb @@ -1,42 +1,46 @@ require "pathname" require "open3" -def curl_args(options = {}) +def curl_executable curl = Pathname.new ENV["HOMEBREW_CURL"] curl = Pathname.new "/usr/bin/curl" unless curl.exist? - raise "#{curl} is not executable" unless curl.exist? && curl.executable? + return curl if curl.executable? + raise "#{curl} is not executable" +end +def curl_args(*extra_args, show_output: false, user_agent: :default) args = [ - curl.to_s, - "--remote-time", - "--location", + curl_executable.to_s, + "--fail", + "--show-error", ] - case options[:user_agent] - when :browser - args << "--user-agent" << HOMEBREW_USER_AGENT_FAKE_SAFARI + args << "--user-agent" << case user_agent + when :browser, :fake + HOMEBREW_USER_AGENT_FAKE_SAFARI + when :default + HOMEBREW_USER_AGENT_CURL else - args << "--user-agent" << HOMEBREW_USER_AGENT_CURL + user_agent end - unless options[:show_output] + unless show_output args << "--progress-bar" unless ARGV.verbose? args << "--verbose" if ENV["HOMEBREW_CURL_VERBOSE"] - args << "--fail" args << "--silent" if !$stdout.tty? || ENV["TRAVIS"] end - args += options[:extra_args] if options[:extra_args] - args + args + extra_args end def curl(*args) - safe_system(*curl_args(extra_args: args)) + safe_system(*curl_args(*args)) end -def curl_output(*args) - curl_args = curl_args(extra_args: args, show_output: true) - Open3.popen3(*curl_args) do |_, stdout, stderr, wait_thread| - [stdout.read, stderr.read, wait_thread.value] - end +def curl_download(*args, to: nil, **options) + curl(*args, "--location", "--remote-time", "--continue-at", "-", "--output", to, **options) +end + +def curl_output(*args, **options) + Open3.capture3(*curl_args(*args, show_output: true, **options)) end diff --git a/Library/Homebrew/utils/github.rb b/Library/Homebrew/utils/github.rb index 1a781cee64..07eea43849 100644 --- a/Library/Homebrew/utils/github.rb +++ b/Library/Homebrew/utils/github.rb @@ -166,7 +166,7 @@ module GitHub args += ["--dump-header", headers_tmpfile.path] - output, errors, status = curl_output(url.to_s, *args) + output, errors, status = curl_output(url.to_s, "--location", *args) output, _, http_code = output.rpartition("\n") output, _, http_code = output.rpartition("\n") if http_code == "000" headers = headers_tmpfile.read From 986887b413897413266151c92d5071d0a82cf966 Mon Sep 17 00:00:00 2001 From: ilovezfs Date: Mon, 7 Aug 2017 14:31:56 -0700 Subject: [PATCH 018/294] Revert "Refactor SVN and cURL download strategies." --- Library/Homebrew/cask/lib/hbc/audit.rb | 10 +- Library/Homebrew/cask/lib/hbc/cask_loader.rb | 2 +- Library/Homebrew/cask/lib/hbc/container.rb | 3 - .../cask/lib/hbc/container/criteria.rb | 6 +- .../cask/lib/hbc/container/directory.rb | 24 ---- .../cask/lib/hbc/container/executable.rb | 2 +- .../cask/lib/hbc/container/svn_repository.rb | 15 --- .../cask/lib/hbc/download_strategy.rb | 85 ++++++++++++-- Library/Homebrew/cask/lib/hbc/dsl/appcast.rb | 6 +- .../Homebrew/cask/lib/hbc/system_command.rb | 4 + Library/Homebrew/cask/lib/hbc/url.rb | 11 +- Library/Homebrew/cask/lib/hbc/verify/gpg.rb | 2 +- Library/Homebrew/dev-cmd/audit.rb | 8 +- Library/Homebrew/dev-cmd/mirror.rb | 10 +- Library/Homebrew/dev-cmd/pull.rb | 16 +-- Library/Homebrew/download_strategy.rb | 107 ++++++++++-------- Library/Homebrew/formulary.rb | 2 +- .../test/cask/download_strategy_spec.rb | 66 ++++++++--- .../Homebrew/test/cask/dsl/appcast_spec.rb | 11 +- Library/Homebrew/utils/curl.rb | 42 ++++--- Library/Homebrew/utils/github.rb | 2 +- 21 files changed, 247 insertions(+), 187 deletions(-) delete mode 100644 Library/Homebrew/cask/lib/hbc/container/directory.rb delete mode 100644 Library/Homebrew/cask/lib/hbc/container/svn_repository.rb diff --git a/Library/Homebrew/cask/lib/hbc/audit.rb b/Library/Homebrew/cask/lib/hbc/audit.rb index b8bb6ab814..cee1fe8070 100644 --- a/Library/Homebrew/cask/lib/hbc/audit.rb +++ b/Library/Homebrew/cask/lib/hbc/audit.rb @@ -143,15 +143,7 @@ module Hbc def check_appcast_http_code odebug "Verifying appcast returns 200 HTTP response code" - - curl_executable, *args = curl_args( - "--compressed", "--location", "--fail", - "--write-out", "%{http_code}", - "--output", "/dev/null", - cask.appcast, - user_agent: :fake - ) - result = @command.run(curl_executable, args: args, print_stderr: false) + result = @command.run("/usr/bin/curl", args: ["--compressed", "--location", "--user-agent", URL::FAKE_USER_AGENT, "--output", "/dev/null", "--write-out", "%{http_code}", cask.appcast], print_stderr: false) if result.success? http_code = result.stdout.chomp add_warning "unexpected HTTP response code retrieving appcast: #{http_code}" unless http_code == "200" diff --git a/Library/Homebrew/cask/lib/hbc/cask_loader.rb b/Library/Homebrew/cask/lib/hbc/cask_loader.rb index dd9c610899..5003146719 100644 --- a/Library/Homebrew/cask/lib/hbc/cask_loader.rb +++ b/Library/Homebrew/cask/lib/hbc/cask_loader.rb @@ -71,7 +71,7 @@ module Hbc begin ohai "Downloading #{url}." - curl_download url, to: path + curl url, "-o", path rescue ErrorDuringExecution raise CaskUnavailableError.new(token, "Failed to download #{Formatter.url(url)}.") end diff --git a/Library/Homebrew/cask/lib/hbc/container.rb b/Library/Homebrew/cask/lib/hbc/container.rb index fab3a3c1c3..93e825e038 100644 --- a/Library/Homebrew/cask/lib/hbc/container.rb +++ b/Library/Homebrew/cask/lib/hbc/container.rb @@ -4,7 +4,6 @@ require "hbc/container/bzip2" require "hbc/container/cab" require "hbc/container/criteria" require "hbc/container/dmg" -require "hbc/container/directory" require "hbc/container/executable" require "hbc/container/generic_unar" require "hbc/container/gpg" @@ -15,7 +14,6 @@ require "hbc/container/otf" require "hbc/container/pkg" require "hbc/container/seven_zip" require "hbc/container/sit" -require "hbc/container/svn_repository" require "hbc/container/tar" require "hbc/container/ttf" require "hbc/container/rar" @@ -45,7 +43,6 @@ module Hbc Xz, # pure xz Gpg, # GnuPG signed data Executable, - SvnRepository, ] # for explicit use only (never autodetected): # Hbc::Container::Naked diff --git a/Library/Homebrew/cask/lib/hbc/container/criteria.rb b/Library/Homebrew/cask/lib/hbc/container/criteria.rb index 52f171d6a1..66ecb8c874 100644 --- a/Library/Homebrew/cask/lib/hbc/container/criteria.rb +++ b/Library/Homebrew/cask/lib/hbc/container/criteria.rb @@ -13,11 +13,9 @@ module Hbc end def magic_number(regex) - return false if path.directory? - # 262: length of the longest regex (currently: Hbc::Container::Tar) - @magic_number ||= File.open(path, "rb") { |f| f.read(262) } - @magic_number.match?(regex) + @magic_number ||= File.open(@path, "rb") { |f| f.read(262) } + @magic_number =~ regex end end end diff --git a/Library/Homebrew/cask/lib/hbc/container/directory.rb b/Library/Homebrew/cask/lib/hbc/container/directory.rb deleted file mode 100644 index e4bb1095b2..0000000000 --- a/Library/Homebrew/cask/lib/hbc/container/directory.rb +++ /dev/null @@ -1,24 +0,0 @@ -require "hbc/container/base" - -module Hbc - class Container - class Directory < Base - def self.me?(*) - false - end - - def extract - @path.children.each do |child| - next if skip_path?(child) - FileUtils.cp child, @cask.staged_path - end - end - - private - - def skip_path?(*) - false - end - end - end -end diff --git a/Library/Homebrew/cask/lib/hbc/container/executable.rb b/Library/Homebrew/cask/lib/hbc/container/executable.rb index af3b36fd10..848f6d4be2 100644 --- a/Library/Homebrew/cask/lib/hbc/container/executable.rb +++ b/Library/Homebrew/cask/lib/hbc/container/executable.rb @@ -8,7 +8,7 @@ module Hbc return true if criteria.magic_number(/^#!\s*\S+/) begin - criteria.path.file? && MachO.open(criteria.path).header.executable? + MachO.open(criteria.path).header.executable? rescue MachO::MagicError false end diff --git a/Library/Homebrew/cask/lib/hbc/container/svn_repository.rb b/Library/Homebrew/cask/lib/hbc/container/svn_repository.rb deleted file mode 100644 index cae613b2db..0000000000 --- a/Library/Homebrew/cask/lib/hbc/container/svn_repository.rb +++ /dev/null @@ -1,15 +0,0 @@ -require "hbc/container/directory" - -module Hbc - class Container - class SvnRepository < Directory - def self.me?(criteria) - criteria.path.join(".svn").directory? - end - - def skip_path?(path) - path.basename.to_s == ".svn" - end - end - end -end diff --git a/Library/Homebrew/cask/lib/hbc/download_strategy.rb b/Library/Homebrew/cask/lib/hbc/download_strategy.rb index 245ad4adeb..016bb66e6e 100644 --- a/Library/Homebrew/cask/lib/hbc/download_strategy.rb +++ b/Library/Homebrew/cask/lib/hbc/download_strategy.rb @@ -10,7 +10,7 @@ module Hbc class AbstractDownloadStrategy attr_reader :cask, :name, :url, :uri_object, :version - def initialize(cask, command: SystemCommand) + def initialize(cask, command = SystemCommand) @cask = cask @command = command # TODO: this excess of attributes is a function of integrating @@ -33,8 +33,8 @@ module Hbc class HbVCSDownloadStrategy < AbstractDownloadStrategy REF_TYPES = [:branch, :revision, :revisions, :tag].freeze - def initialize(*args, **options) - super(*args, **options) + def initialize(cask, command = SystemCommand) + super @ref_type, @ref = extract_ref @clone = Hbc.cache.join(cache_filename) end @@ -64,6 +64,11 @@ module Hbc end class CurlDownloadStrategy < AbstractDownloadStrategy + # TODO: should be part of url object + def mirrors + @mirrors ||= [] + end + def tarball_path @tarball_path ||= Hbc.cache.join("#{name}--#{version}#{ext}") end @@ -90,8 +95,13 @@ module Hbc end end + def downloaded_size + temporary_path.size? || 0 + end + def _fetch - curl_download url, *cask_curl_args, to: temporary_path, user_agent: uri_object.user_agent + odebug "Calling curl with args #{cask_curl_args}" + curl(*cask_curl_args) end def fetch @@ -121,12 +131,33 @@ module Hbc ignore_interrupts { temporary_path.rename(tarball_path) } end tarball_path + rescue CurlDownloadStrategyError + raise if mirrors.empty? + puts "Trying a mirror..." + @url = mirrors.shift + retry end private def cask_curl_args - cookies_args + referer_args + default_curl_args.tap do |args| + args.concat(user_agent_args) + args.concat(cookies_args) + args.concat(referer_args) + end + end + + def default_curl_args + [url, "-C", downloaded_size, "-o", temporary_path] + end + + def user_agent_args + if uri_object.user_agent + ["-A", uri_object.user_agent] + else + [] + end end def cookies_args @@ -160,7 +191,8 @@ module Hbc class CurlPostDownloadStrategy < CurlDownloadStrategy def cask_curl_args - super.concat(post_args) + super + default_curl_args.concat(post_args) end def post_args @@ -193,8 +225,8 @@ module Hbc # super does not provide checks for already-existing downloads def fetch - if cached_location.directory? - puts "Already downloaded: #{cached_location}" + if tarball_path.exist? + puts "Already downloaded: #{tarball_path}" else @url = @url.sub(/^svn\+/, "") if @url =~ %r{^svn\+http://} ohai "Checking out #{@url}" @@ -220,8 +252,9 @@ module Hbc else fetch_repo @clone, @url end + compress end - cached_location + tarball_path end # This primary reason for redefining this method is the trust_cert @@ -255,6 +288,10 @@ module Hbc print_stderr: false) end + def tarball_path + @tarball_path ||= cached_location.dirname.join(cached_location.basename.to_s + "-#{@cask.version}.tar") + end + def shell_quote(str) # Oh god escaping shell args. # See http://notetoself.vrensk.com/2008/08/escaping-single-quotes-in-ruby-harder-than-expected/ @@ -267,5 +304,35 @@ module Hbc yield name, url end end + + private + + # TODO/UPDATE: the tar approach explained below is fragile + # against challenges such as case-sensitive filesystems, + # and must be re-implemented. + # + # Seems nutty: we "download" the contents into a tape archive. + # Why? + # * A single file is tractable to the rest of the Cask toolchain, + # * An alternative would be to create a Directory container type. + # However, some type of file-serialization trick would still be + # needed in order to enable calculating a single checksum over + # a directory. So, in that alternative implementation, the + # special cases would propagate outside this class, including + # the use of tar or equivalent. + # * SubversionDownloadStrategy.cached_location is not versioned + # * tarball_path provides a needed return value for our overridden + # fetch method. + # * We can also take this private opportunity to strip files from + # the download which are protocol-specific. + + def compress + Dir.chdir(cached_location) do + @command.run!("/usr/bin/tar", + args: ['-s/^\.//', "--exclude", ".svn", "-cf", Pathname.new(tarball_path), "--", "."], + print_stderr: false) + end + clear_cache + end end end diff --git a/Library/Homebrew/cask/lib/hbc/dsl/appcast.rb b/Library/Homebrew/cask/lib/hbc/dsl/appcast.rb index fc7e83a20d..d302d09460 100644 --- a/Library/Homebrew/cask/lib/hbc/dsl/appcast.rb +++ b/Library/Homebrew/cask/lib/hbc/dsl/appcast.rb @@ -12,11 +12,7 @@ module Hbc end def calculate_checkpoint - curl_executable, *args = curl_args( - "--compressed", "--location", "--fail", @uri, - user_agent: :fake - ) - result = SystemCommand.run(curl_executable, args: args, print_stderr: false) + result = SystemCommand.run("/usr/bin/curl", args: ["--compressed", "--location", "--user-agent", URL::FAKE_USER_AGENT, "--fail", @uri], print_stderr: false) checkpoint = if result.success? processed_appcast_text = result.stdout.gsub(%r{[^<]*}m, "") diff --git a/Library/Homebrew/cask/lib/hbc/system_command.rb b/Library/Homebrew/cask/lib/hbc/system_command.rb index b735ae4f9c..901617b71b 100644 --- a/Library/Homebrew/cask/lib/hbc/system_command.rb +++ b/Library/Homebrew/cask/lib/hbc/system_command.rb @@ -112,7 +112,11 @@ module Hbc processed_output[:stderr], processed_status.exitstatus) end + end +end +module Hbc + class SystemCommand class Result attr_accessor :command, :stdout, :stderr, :exit_status diff --git a/Library/Homebrew/cask/lib/hbc/url.rb b/Library/Homebrew/cask/lib/hbc/url.rb index 8c652657b6..15da2ced21 100644 --- a/Library/Homebrew/cask/lib/hbc/url.rb +++ b/Library/Homebrew/cask/lib/hbc/url.rb @@ -1,6 +1,8 @@ module Hbc class URL - attr_reader :using, :revision, :trust_cert, :uri, :cookies, :referer, :data, :user_agent + FAKE_USER_AGENT = "Mozilla/5.0 (Macintosh; Intel Mac OS X 10) https://caskroom.github.io".freeze + + attr_reader :using, :revision, :trust_cert, :uri, :cookies, :referer, :data extend Forwardable def_delegators :uri, :path, :scheme, :to_s @@ -15,7 +17,7 @@ module Hbc def initialize(uri, options = {}) @uri = Hbc::UnderscoreSupportingURI.parse(uri) - @user_agent = options.fetch(:user_agent, :default) + @user_agent = options[:user_agent] @cookies = options[:cookies] @referer = options[:referer] @using = options[:using] @@ -23,5 +25,10 @@ module Hbc @trust_cert = options[:trust_cert] @data = options[:data] end + + def user_agent + return FAKE_USER_AGENT if @user_agent == :fake + @user_agent + end end end diff --git a/Library/Homebrew/cask/lib/hbc/verify/gpg.rb b/Library/Homebrew/cask/lib/hbc/verify/gpg.rb index f4996a5b5e..dbb537756d 100644 --- a/Library/Homebrew/cask/lib/hbc/verify/gpg.rb +++ b/Library/Homebrew/cask/lib/hbc/verify/gpg.rb @@ -33,7 +33,7 @@ module Hbc meta_dir = cached || cask.metadata_subdir("gpg", :now, true) sig_path = meta_dir.join("signature.asc") - curl_download cask.gpg.signature, to: sig_path unless cached || force + curl(cask.gpg.signature, "-o", sig_path.to_s) unless cached || force sig_path end diff --git a/Library/Homebrew/dev-cmd/audit.rb b/Library/Homebrew/dev-cmd/audit.rb index b3e0785a51..1f07fa89ea 100644 --- a/Library/Homebrew/dev-cmd/audit.rb +++ b/Library/Homebrew/dev-cmd/audit.rb @@ -242,10 +242,12 @@ class FormulaAuditor def self.http_content_headers_and_checksum(url, hash_needed: false, user_agent: :default) max_time = hash_needed ? "600" : "25" - output, = curl_output( - "--connect-timeout", "15", "--include", "--max-time", max_time, "--location", url, - user_agent: user_agent + args = curl_args( + extra_args: ["--connect-timeout", "15", "--include", "--max-time", max_time, url], + show_output: true, + user_agent: user_agent, ) + output = Open3.popen3(*args) { |_, stdout, _, _| stdout.read } status_code = :unknown while status_code == :unknown || status_code.to_s.start_with?("3") diff --git a/Library/Homebrew/dev-cmd/mirror.rb b/Library/Homebrew/dev-cmd/mirror.rb index 6445bc34cf..e2492203d3 100644 --- a/Library/Homebrew/dev-cmd/mirror.rb +++ b/Library/Homebrew/dev-cmd/mirror.rb @@ -25,9 +25,9 @@ module Homebrew "public_download_numbers": true, "public_stats": true} EOS - curl "--silent", "--fail", "--user", "#{bintray_user}:#{bintray_key}", - "--header", "Content-Type: application/json", - "--data", package_blob, bintray_repo_url + curl "--silent", "--fail", "-u#{bintray_user}:#{bintray_key}", + "-H", "Content-Type: application/json", + "-d", package_blob, bintray_repo_url puts end @@ -40,8 +40,8 @@ module Homebrew content_url = "https://api.bintray.com/content/homebrew/mirror" content_url += "/#{bintray_package}/#{f.pkg_version}/#{filename}" content_url += "?publish=1" - curl "--silent", "--fail", "--user", "#{bintray_user}:#{bintray_key}", - "--upload-file", download, content_url + curl "--silent", "--fail", "-u#{bintray_user}:#{bintray_key}", + "-T", download, content_url puts ohai "Mirrored #{filename}!" end diff --git a/Library/Homebrew/dev-cmd/pull.rb b/Library/Homebrew/dev-cmd/pull.rb index dd2bc62707..9681bb2bc0 100644 --- a/Library/Homebrew/dev-cmd/pull.rb +++ b/Library/Homebrew/dev-cmd/pull.rb @@ -228,7 +228,7 @@ module Homebrew "https://github.com/BrewTestBot/homebrew-#{tap.repo}/compare/homebrew:master...pr-#{issue}" end - curl "--silent", "--fail", "--output", "/dev/null", "--head", bottle_commit_url + curl "--silent", "--fail", "-o", "/dev/null", "-I", bottle_commit_url safe_system "git", "checkout", "--quiet", "-B", bottle_branch, orig_revision pull_patch bottle_commit_url, "bottle commit" @@ -303,7 +303,7 @@ module Homebrew extra_msg = @description ? "(#{@description})" : nil ohai "Fetching patch #{extra_msg}" puts "Patch: #{patch_url}" - curl_download patch_url, to: patchpath + curl patch_url, "-s", "-o", patchpath end def apply_patch @@ -433,10 +433,10 @@ module Homebrew end version = info.pkg_version ohai "Publishing on Bintray: #{package} #{version}" - curl "--write-out", '\n', "--silent", "--fail", - "--user", "#{creds[:user]}:#{creds[:key]}", "--request", "POST", - "--header", "Content-Type: application/json", - "--data", '{"publish_wait_for_secs": 0}', + curl "-w", '\n', "--silent", "--fail", + "-u#{creds[:user]}:#{creds[:key]}", "-X", "POST", + "-H", "Content-Type: application/json", + "-d", '{"publish_wait_for_secs": 0}', "https://api.bintray.com/content/homebrew/#{repo}/#{package}/#{version}/publish" true rescue => e @@ -587,7 +587,7 @@ module Homebrew # We're in the cache; make sure to force re-download loop do begin - curl_download url, to: filename + curl url, "-o", filename break rescue if retry_count >= max_curl_retries @@ -606,7 +606,7 @@ module Homebrew end def check_bintray_mirror(name, url) - headers, = curl_output("--connect-timeout", "15", "--location", "--head", url) + headers = curl_output("--connect-timeout", "15", "--head", url)[0] status_code = headers.scan(%r{^HTTP\/.* (\d+)}).last.first return if status_code.start_with?("2") opoo "The Bintray mirror #{url} is not reachable (HTTP status code #{status_code})." diff --git a/Library/Homebrew/download_strategy.rb b/Library/Homebrew/download_strategy.rb index 2a8b6e5859..7173347143 100644 --- a/Library/Homebrew/download_strategy.rb +++ b/Library/Homebrew/download_strategy.rb @@ -375,59 +375,75 @@ class CurlDownloadStrategy < AbstractFileDownloadStrategy ohai "Downloading from #{url}" end - curl_download resolved_url(url), to: temporary_path + urls = actual_urls(url) + unless urls.empty? + ohai "Downloading from #{urls.last}" + if !ENV["HOMEBREW_NO_INSECURE_REDIRECT"].nil? && url.start_with?("https://") && + urls.any? { |u| !u.start_with? "https://" } + puts "HTTPS to HTTP redirect detected & HOMEBREW_NO_INSECURE_REDIRECT is set." + raise CurlDownloadStrategyError, url + end + url = urls.last + end + + curl url, "-C", downloaded_size, "-o", temporary_path end # Curl options to be always passed to curl, - # with raw head calls (`curl --head`) or with actual `fetch`. + # with raw head calls (`curl -I`) or with actual `fetch`. def _curl_opts - return ["--user" << meta.fetch(:user)] if meta.key?(:user) - [] + copts = [] + copts << "--user" << meta.fetch(:user) if meta.key?(:user) + copts end - def resolved_url(url) - redirect_url, _, status = curl_output( - *_curl_opts, "--silent", "--head", - "--write-out", "%{redirect_url}", - "--output", "/dev/null", - url.to_s - ) - - return url unless status.success? - return url if redirect_url.empty? - - ohai "Downloading from #{redirect_url}" - if ENV["HOMEBREW_NO_INSECURE_REDIRECT"] && - url.start_with?("https://") && !redirect_url.start_with?("https://") - puts "HTTPS to HTTP redirect detected & HOMEBREW_NO_INSECURE_REDIRECT is set." - raise CurlDownloadStrategyError, url + def actual_urls(url) + urls = [] + curl_args = _curl_opts << "-I" << "-L" << url + Utils.popen_read("curl", *curl_args).scan(/^Location: (.+)$/).map do |m| + urls << URI.join(urls.last || url, m.first.chomp).to_s end - - redirect_url + urls end - def curl(*args, **options) + def downloaded_size + temporary_path.size? || 0 + end + + def curl(*args) args.concat _curl_opts args << "--connect-timeout" << "5" unless mirrors.empty? - super(*args, **options) + super end end # Detect and download from Apache Mirror class CurlApacheMirrorDownloadStrategy < CurlDownloadStrategy def apache_mirrors - mirrors, = Open3.capture3( - *curl_args(*_curl_opts, "--silent", "--location", "#{@url}&asjson=1"), - ) + rd, wr = IO.pipe + buf = "" - JSON.parse(mirrors) + pid = fork do + ENV.delete "HOMEBREW_CURL_VERBOSE" + rd.close + $stdout.reopen(wr) + $stderr.reopen(wr) + curl "#{@url}&asjson=1" + end + wr.close + + rd.readline if ARGV.verbose? # Remove Homebrew output + buf << rd.read until rd.eof? + rd.close + Process.wait(pid) + buf end def _fetch return super if @tried_apache_mirror @tried_apache_mirror = true - mirrors = apache_mirrors + mirrors = JSON.parse(apache_mirrors) path_info = mirrors.fetch("path_info") @url = mirrors.fetch("preferred") + path_info @mirrors |= %W[https://archive.apache.org/dist/#{path_info}] @@ -444,7 +460,7 @@ end class CurlPostDownloadStrategy < CurlDownloadStrategy def _fetch base_url, data = @url.split("?") - curl_download base_url, "--data", data, to: temporary_path + curl base_url, "-d", data, "-C", downloaded_size, "-o", temporary_path end end @@ -514,7 +530,7 @@ class S3DownloadStrategy < CurlDownloadStrategy s3url = obj.public_url end - curl_download s3url, to: temporary_path + curl s3url, "-C", downloaded_size, "-o", temporary_path end end @@ -550,7 +566,7 @@ class GitHubPrivateRepositoryDownloadStrategy < CurlDownloadStrategy end def _fetch - curl_download download_url, to: temporary_path + curl download_url, "-C", downloaded_size, "-o", temporary_path end private @@ -599,7 +615,7 @@ class GitHubPrivateRepositoryReleaseDownloadStrategy < GitHubPrivateRepositoryDo def _fetch # HTTP request header `Accept: application/octet-stream` is required. # Without this, the GitHub API will respond with metadata, not binary. - curl_download download_url, "--header", "Accept: application/octet-stream", to: temporary_path + curl download_url, "-C", downloaded_size, "-o", temporary_path, "-H", "Accept: application/octet-stream" end private @@ -899,27 +915,18 @@ class GitHubGitDownloadStrategy < GitDownloadStrategy def github_last_commit return if ENV["HOMEBREW_NO_GITHUB_API"] - output, _, status = curl_output( - "--silent", "--head", "--location", - "-H", "Accept: application/vnd.github.v3.sha", - "https://api.github.com/repos/#{@user}/#{@repo}/commits/#{@ref}" - ) + output, _, status = curl_output "-H", "Accept: application/vnd.github.v3.sha", \ + "-I", "https://api.github.com/repos/#{@user}/#{@repo}/commits/#{@ref}" - return unless status.success? - - commit = output[/^ETag: \"(\h+)\"/, 1] + commit = output[/^ETag: \"(\h+)\"/, 1] if status.success? version.update_commit(commit) if commit commit end def multiple_short_commits_exist?(commit) return if ENV["HOMEBREW_NO_GITHUB_API"] - - output, _, status = curl_output( - "--silent", "--head", "--location", - "-H", "Accept: application/vnd.github.v3.sha", - "https://api.github.com/repos/#{@user}/#{@repo}/commits/#{commit}" - ) + output, _, status = curl_output "-H", "Accept: application/vnd.github.v3.sha", \ + "-I", "https://api.github.com/repos/#{@user}/#{@repo}/commits/#{commit}" !(status.success? && output && output[/^Status: (200)/, 1] == "200") end @@ -1152,13 +1159,15 @@ class DownloadStrategyDetector SubversionDownloadStrategy when %r{^cvs://} CVSDownloadStrategy - when %r{^hg://}, %r{^https?://(.+?\.)?googlecode\.com/hg} + when %r{^https?://(.+?\.)?googlecode\.com/hg} + MercurialDownloadStrategy + when %r{^hg://} MercurialDownloadStrategy when %r{^bzr://} BazaarDownloadStrategy when %r{^fossil://} FossilDownloadStrategy - when %r{^svn\+http://}, %r{^http://svn\.apache\.org/repos/} + when %r{^http://svn\.apache\.org/repos/}, %r{^svn\+http://} SubversionDownloadStrategy when %r{^https?://(.+?\.)?sourceforge\.net/hgweb/} MercurialDownloadStrategy diff --git a/Library/Homebrew/formulary.rb b/Library/Homebrew/formulary.rb index dd67b4f243..195d15cece 100644 --- a/Library/Homebrew/formulary.rb +++ b/Library/Homebrew/formulary.rb @@ -165,7 +165,7 @@ module Formulary def load_file HOMEBREW_CACHE_FORMULA.mkpath FileUtils.rm_f(path) - curl_download url, to: path + curl url, "-o", path super rescue MethodDeprecatedError => e if url =~ %r{github.com/([\w-]+)/homebrew-([\w-]+)/} diff --git a/Library/Homebrew/test/cask/download_strategy_spec.rb b/Library/Homebrew/test/cask/download_strategy_spec.rb index 60d101bdb8..222352c07e 100644 --- a/Library/Homebrew/test/cask/download_strategy_spec.rb +++ b/Library/Homebrew/test/cask/download_strategy_spec.rb @@ -27,11 +27,8 @@ describe "download strategies", :cask do expect(downloader).to have_received(:curl).with( cask.url.to_s, - "--location", - "--remote-time", - "--continue-at", "-", - "--output", kind_of(Pathname), - user_agent: :default + "-C", 0, + "-o", kind_of(Pathname) ) end @@ -39,25 +36,25 @@ describe "download strategies", :cask do let(:url_options) { { user_agent: "Mozilla/25.0.1" } } it "adds the appropriate curl args" do - expect(downloader).to receive(:safe_system) { |*args| - expect(args.each_cons(2)).to include(["--user-agent", "Mozilla/25.0.1"]) - } + curl_args = [] + allow(downloader).to receive(:curl) { |*args| curl_args = args } downloader.fetch + + expect(curl_args.each_cons(2)).to include(["-A", "Mozilla/25.0.1"]) end end context "with a generalized fake user agent" do - alias_matcher :a_string_matching, :match - let(:url_options) { { user_agent: :fake } } it "adds the appropriate curl args" do - expect(downloader).to receive(:safe_system) { |*args| - expect(args.each_cons(2).to_a).to include(["--user-agent", a_string_matching(/Mozilla.*Mac OS X 10.*AppleWebKit/)]) - } + curl_args = [] + allow(downloader).to receive(:curl) { |*args| curl_args = args } downloader.fetch + + expect(curl_args.each_cons(2)).to include(["-A", "Mozilla/5.0 (Macintosh; Intel Mac OS X 10) https://caskroom.github.io"]) end end @@ -141,7 +138,7 @@ describe "download strategies", :cask do describe Hbc::SubversionDownloadStrategy do let(:url_options) { { using: :svn } } let(:fake_system_command) { class_double(Hbc::SystemCommand) } - let(:downloader) { Hbc::SubversionDownloadStrategy.new(cask, command: fake_system_command) } + let(:downloader) { Hbc::SubversionDownloadStrategy.new(cask, fake_system_command) } before do allow(fake_system_command).to receive(:run!) end @@ -150,7 +147,7 @@ describe "download strategies", :cask do allow(downloader).to receive(:compress) allow(downloader).to receive(:fetch_repo) - expect(downloader.fetch).to equal(downloader.cached_location) + expect(downloader.fetch).to equal(downloader.tarball_path) end it "calls fetch_repo with default arguments for a simple Cask" do @@ -240,5 +237,44 @@ describe "download strategies", :cask do ) end end + + it "runs tar to serialize svn downloads" do + # sneaky stub to remake the directory, since homebrew code removes it + # before tar is called + allow(downloader).to receive(:fetch_repo) { + downloader.cached_location.mkdir + } + + downloader.fetch + + expect(fake_system_command).to have_received(:run!).with( + "/usr/bin/tar", + hash_including(args: [ + '-s/^\\.//', + "--exclude", + ".svn", + "-cf", + downloader.tarball_path, + "--", + ".", + ]), + ) + end end + + # does not work yet, because (for unknown reasons), the tar command + # returns an error code when running under the test suite + # it 'creates a tarball matching the expected checksum' do + # cask = Hbc::CaskLoader.load('svn-download-check-cask') + # downloader = Hbc::SubversionDownloadStrategy.new(cask) + # # special mocking required for tar to have something to work with + # def downloader.fetch_repo(target, url, revision = nil, ignore_externals=false) + # target.mkpath + # FileUtils.touch(target.join('empty_file.txt')) + # File.utime(1000,1000,target.join('empty_file.txt')) + # end + # expect(downloader.fetch).to equal(downloader.tarball_path) + # d = Hbc::Download.new(cask) + # d.send(:_check_sums, downloader.tarball_path, cask.sums) + # end end diff --git a/Library/Homebrew/test/cask/dsl/appcast_spec.rb b/Library/Homebrew/test/cask/dsl/appcast_spec.rb index ccc6a46338..b8903b1be8 100644 --- a/Library/Homebrew/test/cask/dsl/appcast_spec.rb +++ b/Library/Homebrew/test/cask/dsl/appcast_spec.rb @@ -33,18 +33,13 @@ describe Hbc::DSL::Appcast do describe "#calculate_checkpoint" do before do - expect(Hbc::SystemCommand).to receive(:run) do |executable, **options| - expect(executable).to eq "/usr/bin/curl" - expect(options[:args]).to include(*cmd_args) - expect(options[:print_stderr]).to be false - cmd_result - end + expect(Hbc::SystemCommand).to receive(:run).with(*cmd_args).and_return(cmd_result) allow(cmd_result).to receive(:success?).and_return(cmd_success) allow(cmd_result).to receive(:stdout).and_return(cmd_stdout) end context "when server returns a successful HTTP status" do - let(:cmd_args) { [HOMEBREW_USER_AGENT_FAKE_SAFARI, "--compressed", "--location", "--fail", uri] } + let(:cmd_args) { ["/usr/bin/curl", args: ["--compressed", "--location", "--user-agent", Hbc::URL::FAKE_USER_AGENT, "--fail", uri], print_stderr: false] } let(:cmd_result) { double("Hbc::SystemCommand::Result") } let(:cmd_success) { true } let(:cmd_stdout) { "hello world" } @@ -61,7 +56,7 @@ describe Hbc::DSL::Appcast do end context "when server returns a non-successful HTTP status" do - let(:cmd_args) { [HOMEBREW_USER_AGENT_FAKE_SAFARI, "--compressed", "--location", "--fail", uri] } + let(:cmd_args) { ["/usr/bin/curl", args: ["--compressed", "--location", "--user-agent", Hbc::URL::FAKE_USER_AGENT, "--fail", uri], print_stderr: false] } let(:cmd_result) { double("Hbc::SystemCommand::Result") } let(:cmd_success) { false } let(:cmd_stdout) { "some error message from the server" } diff --git a/Library/Homebrew/utils/curl.rb b/Library/Homebrew/utils/curl.rb index 6aaf9be0cb..5a40ae8469 100644 --- a/Library/Homebrew/utils/curl.rb +++ b/Library/Homebrew/utils/curl.rb @@ -1,46 +1,42 @@ require "pathname" require "open3" -def curl_executable +def curl_args(options = {}) curl = Pathname.new ENV["HOMEBREW_CURL"] curl = Pathname.new "/usr/bin/curl" unless curl.exist? - return curl if curl.executable? - raise "#{curl} is not executable" -end + raise "#{curl} is not executable" unless curl.exist? && curl.executable? -def curl_args(*extra_args, show_output: false, user_agent: :default) args = [ - curl_executable.to_s, - "--fail", - "--show-error", + curl.to_s, + "--remote-time", + "--location", ] - args << "--user-agent" << case user_agent - when :browser, :fake - HOMEBREW_USER_AGENT_FAKE_SAFARI - when :default - HOMEBREW_USER_AGENT_CURL + case options[:user_agent] + when :browser + args << "--user-agent" << HOMEBREW_USER_AGENT_FAKE_SAFARI else - user_agent + args << "--user-agent" << HOMEBREW_USER_AGENT_CURL end - unless show_output + unless options[:show_output] args << "--progress-bar" unless ARGV.verbose? args << "--verbose" if ENV["HOMEBREW_CURL_VERBOSE"] + args << "--fail" args << "--silent" if !$stdout.tty? || ENV["TRAVIS"] end - args + extra_args + args += options[:extra_args] if options[:extra_args] + args end def curl(*args) - safe_system(*curl_args(*args)) + safe_system(*curl_args(extra_args: args)) end -def curl_download(*args, to: nil, **options) - curl(*args, "--location", "--remote-time", "--continue-at", "-", "--output", to, **options) -end - -def curl_output(*args, **options) - Open3.capture3(*curl_args(*args, show_output: true, **options)) +def curl_output(*args) + curl_args = curl_args(extra_args: args, show_output: true) + Open3.popen3(*curl_args) do |_, stdout, stderr, wait_thread| + [stdout.read, stderr.read, wait_thread.value] + end end diff --git a/Library/Homebrew/utils/github.rb b/Library/Homebrew/utils/github.rb index 07eea43849..1a781cee64 100644 --- a/Library/Homebrew/utils/github.rb +++ b/Library/Homebrew/utils/github.rb @@ -166,7 +166,7 @@ module GitHub args += ["--dump-header", headers_tmpfile.path] - output, errors, status = curl_output(url.to_s, "--location", *args) + output, errors, status = curl_output(url.to_s, *args) output, _, http_code = output.rpartition("\n") output, _, http_code = output.rpartition("\n") if http_code == "000" headers = headers_tmpfile.read From 3b7113b304b9b377fa99fce1a4b0b66be1b0d77b Mon Sep 17 00:00:00 2001 From: "Bob W. Hogg" Date: Mon, 7 Aug 2017 18:18:54 -0700 Subject: [PATCH 019/294] cmd/search: use new Fedora package search pkgdb has been put into read-only mode, so it won't be updated for new Fedora releases going forward. Use apps.fedoraproject.org/packages instead. Signed-off-by: Bob W. Hogg --- Library/Homebrew/cmd/search.rb | 2 +- Library/Homebrew/test/cmd/search_spec.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Library/Homebrew/cmd/search.rb b/Library/Homebrew/cmd/search.rb index b2d0697445..5b83d80e22 100644 --- a/Library/Homebrew/cmd/search.rb +++ b/Library/Homebrew/cmd/search.rb @@ -34,7 +34,7 @@ module Homebrew elsif ARGV.include? "--opensuse" exec_browser "https://software.opensuse.org/search?q=#{ARGV.next}" elsif ARGV.include? "--fedora" - exec_browser "https://admin.fedoraproject.org/pkgdb/packages/%2A#{ARGV.next}%2A/" + exec_browser "https://apps.fedoraproject.org/packages/s/#{ARGV.next}" elsif ARGV.include? "--ubuntu" exec_browser "http://packages.ubuntu.com/search?keywords=#{ARGV.next}&searchon=names&suite=all§ion=all" elsif ARGV.include? "--desc" diff --git a/Library/Homebrew/test/cmd/search_spec.rb b/Library/Homebrew/test/cmd/search_spec.rb index 06b7073d88..bd2056a48c 100644 --- a/Library/Homebrew/test/cmd/search_spec.rb +++ b/Library/Homebrew/test/cmd/search_spec.rb @@ -44,7 +44,7 @@ describe "brew search", :integration_test do "fink" => "http://pdb.finkproject.org/pdb/browse.php?summary=testball", "debian" => "https://packages.debian.org/search?keywords=testball&searchon=names&suite=all§ion=all", "opensuse" => "https://software.opensuse.org/search?q=testball", - "fedora" => "https://admin.fedoraproject.org/pkgdb/packages/%2Atestball%2A/", + "fedora" => "https://apps.fedoraproject.org/packages/s/testball", "ubuntu" => "http://packages.ubuntu.com/search?keywords=testball&searchon=names&suite=all§ion=all", }.each do |flag, url| specify "--#{flag}" do From 93051b27d6886dae6df01544c86df579f21f6410 Mon Sep 17 00:00:00 2001 From: Mike McQuaid Date: Tue, 8 Aug 2017 11:08:03 +0100 Subject: [PATCH 020/294] formula_cellar_checks: fix broken dylib spacing. --- Library/Homebrew/extend/os/mac/formula_cellar_checks.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Library/Homebrew/extend/os/mac/formula_cellar_checks.rb b/Library/Homebrew/extend/os/mac/formula_cellar_checks.rb index 4d5ce3e9e1..32e5774f69 100644 --- a/Library/Homebrew/extend/os/mac/formula_cellar_checks.rb +++ b/Library/Homebrew/extend/os/mac/formula_cellar_checks.rb @@ -69,7 +69,7 @@ module FormulaCellarChecks return unless checker.broken_dylibs? output = <<-EOS.undent #{formula} has broken dynamic library links: - #{checker.broken_dylibs.to_a * "\n "} + #{checker.broken_dylibs.to_a * "\n "} EOS tab = Tab.for_keg(keg) if tab.poured_from_bottle From b6b8e8863fe70fbdfd0758dd72127de0a96e329f Mon Sep 17 00:00:00 2001 From: Markus Reiter Date: Tue, 8 Aug 2017 18:10:01 +0200 Subject: [PATCH 021/294] Simplify SubversionDownloadStrategy. --- Library/Homebrew/cask/lib/hbc/container.rb | 3 + .../cask/lib/hbc/container/criteria.rb | 6 +- .../cask/lib/hbc/container/directory.rb | 24 ++++++++ .../cask/lib/hbc/container/executable.rb | 2 +- .../cask/lib/hbc/container/svn_repository.rb | 15 +++++ .../cask/lib/hbc/download_strategy.rb | 57 ++----------------- .../Homebrew/cask/lib/hbc/system_command.rb | 4 -- .../test/cask/download_strategy_spec.rb | 43 +------------- 8 files changed, 55 insertions(+), 99 deletions(-) create mode 100644 Library/Homebrew/cask/lib/hbc/container/directory.rb create mode 100644 Library/Homebrew/cask/lib/hbc/container/svn_repository.rb diff --git a/Library/Homebrew/cask/lib/hbc/container.rb b/Library/Homebrew/cask/lib/hbc/container.rb index 93e825e038..fab3a3c1c3 100644 --- a/Library/Homebrew/cask/lib/hbc/container.rb +++ b/Library/Homebrew/cask/lib/hbc/container.rb @@ -4,6 +4,7 @@ require "hbc/container/bzip2" require "hbc/container/cab" require "hbc/container/criteria" require "hbc/container/dmg" +require "hbc/container/directory" require "hbc/container/executable" require "hbc/container/generic_unar" require "hbc/container/gpg" @@ -14,6 +15,7 @@ require "hbc/container/otf" require "hbc/container/pkg" require "hbc/container/seven_zip" require "hbc/container/sit" +require "hbc/container/svn_repository" require "hbc/container/tar" require "hbc/container/ttf" require "hbc/container/rar" @@ -43,6 +45,7 @@ module Hbc Xz, # pure xz Gpg, # GnuPG signed data Executable, + SvnRepository, ] # for explicit use only (never autodetected): # Hbc::Container::Naked diff --git a/Library/Homebrew/cask/lib/hbc/container/criteria.rb b/Library/Homebrew/cask/lib/hbc/container/criteria.rb index 66ecb8c874..52f171d6a1 100644 --- a/Library/Homebrew/cask/lib/hbc/container/criteria.rb +++ b/Library/Homebrew/cask/lib/hbc/container/criteria.rb @@ -13,9 +13,11 @@ module Hbc end def magic_number(regex) + return false if path.directory? + # 262: length of the longest regex (currently: Hbc::Container::Tar) - @magic_number ||= File.open(@path, "rb") { |f| f.read(262) } - @magic_number =~ regex + @magic_number ||= File.open(path, "rb") { |f| f.read(262) } + @magic_number.match?(regex) end end end diff --git a/Library/Homebrew/cask/lib/hbc/container/directory.rb b/Library/Homebrew/cask/lib/hbc/container/directory.rb new file mode 100644 index 0000000000..e4bb1095b2 --- /dev/null +++ b/Library/Homebrew/cask/lib/hbc/container/directory.rb @@ -0,0 +1,24 @@ +require "hbc/container/base" + +module Hbc + class Container + class Directory < Base + def self.me?(*) + false + end + + def extract + @path.children.each do |child| + next if skip_path?(child) + FileUtils.cp child, @cask.staged_path + end + end + + private + + def skip_path?(*) + false + end + end + end +end diff --git a/Library/Homebrew/cask/lib/hbc/container/executable.rb b/Library/Homebrew/cask/lib/hbc/container/executable.rb index 848f6d4be2..af3b36fd10 100644 --- a/Library/Homebrew/cask/lib/hbc/container/executable.rb +++ b/Library/Homebrew/cask/lib/hbc/container/executable.rb @@ -8,7 +8,7 @@ module Hbc return true if criteria.magic_number(/^#!\s*\S+/) begin - MachO.open(criteria.path).header.executable? + criteria.path.file? && MachO.open(criteria.path).header.executable? rescue MachO::MagicError false end diff --git a/Library/Homebrew/cask/lib/hbc/container/svn_repository.rb b/Library/Homebrew/cask/lib/hbc/container/svn_repository.rb new file mode 100644 index 0000000000..cae613b2db --- /dev/null +++ b/Library/Homebrew/cask/lib/hbc/container/svn_repository.rb @@ -0,0 +1,15 @@ +require "hbc/container/directory" + +module Hbc + class Container + class SvnRepository < Directory + def self.me?(criteria) + criteria.path.join(".svn").directory? + end + + def skip_path?(path) + path.basename.to_s == ".svn" + end + end + end +end diff --git a/Library/Homebrew/cask/lib/hbc/download_strategy.rb b/Library/Homebrew/cask/lib/hbc/download_strategy.rb index 016bb66e6e..fb4319f5ea 100644 --- a/Library/Homebrew/cask/lib/hbc/download_strategy.rb +++ b/Library/Homebrew/cask/lib/hbc/download_strategy.rb @@ -10,7 +10,7 @@ module Hbc class AbstractDownloadStrategy attr_reader :cask, :name, :url, :uri_object, :version - def initialize(cask, command = SystemCommand) + def initialize(cask, command: SystemCommand) @cask = cask @command = command # TODO: this excess of attributes is a function of integrating @@ -33,8 +33,8 @@ module Hbc class HbVCSDownloadStrategy < AbstractDownloadStrategy REF_TYPES = [:branch, :revision, :revisions, :tag].freeze - def initialize(cask, command = SystemCommand) - super + def initialize(*args, **options) + super(*args, **options) @ref_type, @ref = extract_ref @clone = Hbc.cache.join(cache_filename) end @@ -64,11 +64,6 @@ module Hbc end class CurlDownloadStrategy < AbstractDownloadStrategy - # TODO: should be part of url object - def mirrors - @mirrors ||= [] - end - def tarball_path @tarball_path ||= Hbc.cache.join("#{name}--#{version}#{ext}") end @@ -131,11 +126,6 @@ module Hbc ignore_interrupts { temporary_path.rename(tarball_path) } end tarball_path - rescue CurlDownloadStrategyError - raise if mirrors.empty? - puts "Trying a mirror..." - @url = mirrors.shift - retry end private @@ -225,8 +215,8 @@ module Hbc # super does not provide checks for already-existing downloads def fetch - if tarball_path.exist? - puts "Already downloaded: #{tarball_path}" + if cached_location.directory? + puts "Already downloaded: #{cached_location}" else @url = @url.sub(/^svn\+/, "") if @url =~ %r{^svn\+http://} ohai "Checking out #{@url}" @@ -252,9 +242,8 @@ module Hbc else fetch_repo @clone, @url end - compress end - tarball_path + cached_location end # This primary reason for redefining this method is the trust_cert @@ -288,10 +277,6 @@ module Hbc print_stderr: false) end - def tarball_path - @tarball_path ||= cached_location.dirname.join(cached_location.basename.to_s + "-#{@cask.version}.tar") - end - def shell_quote(str) # Oh god escaping shell args. # See http://notetoself.vrensk.com/2008/08/escaping-single-quotes-in-ruby-harder-than-expected/ @@ -304,35 +289,5 @@ module Hbc yield name, url end end - - private - - # TODO/UPDATE: the tar approach explained below is fragile - # against challenges such as case-sensitive filesystems, - # and must be re-implemented. - # - # Seems nutty: we "download" the contents into a tape archive. - # Why? - # * A single file is tractable to the rest of the Cask toolchain, - # * An alternative would be to create a Directory container type. - # However, some type of file-serialization trick would still be - # needed in order to enable calculating a single checksum over - # a directory. So, in that alternative implementation, the - # special cases would propagate outside this class, including - # the use of tar or equivalent. - # * SubversionDownloadStrategy.cached_location is not versioned - # * tarball_path provides a needed return value for our overridden - # fetch method. - # * We can also take this private opportunity to strip files from - # the download which are protocol-specific. - - def compress - Dir.chdir(cached_location) do - @command.run!("/usr/bin/tar", - args: ['-s/^\.//', "--exclude", ".svn", "-cf", Pathname.new(tarball_path), "--", "."], - print_stderr: false) - end - clear_cache - end end end diff --git a/Library/Homebrew/cask/lib/hbc/system_command.rb b/Library/Homebrew/cask/lib/hbc/system_command.rb index 901617b71b..b735ae4f9c 100644 --- a/Library/Homebrew/cask/lib/hbc/system_command.rb +++ b/Library/Homebrew/cask/lib/hbc/system_command.rb @@ -112,11 +112,7 @@ module Hbc processed_output[:stderr], processed_status.exitstatus) end - end -end -module Hbc - class SystemCommand class Result attr_accessor :command, :stdout, :stderr, :exit_status diff --git a/Library/Homebrew/test/cask/download_strategy_spec.rb b/Library/Homebrew/test/cask/download_strategy_spec.rb index 222352c07e..0c18f56b56 100644 --- a/Library/Homebrew/test/cask/download_strategy_spec.rb +++ b/Library/Homebrew/test/cask/download_strategy_spec.rb @@ -138,7 +138,7 @@ describe "download strategies", :cask do describe Hbc::SubversionDownloadStrategy do let(:url_options) { { using: :svn } } let(:fake_system_command) { class_double(Hbc::SystemCommand) } - let(:downloader) { Hbc::SubversionDownloadStrategy.new(cask, fake_system_command) } + let(:downloader) { Hbc::SubversionDownloadStrategy.new(cask, command: fake_system_command) } before do allow(fake_system_command).to receive(:run!) end @@ -147,7 +147,7 @@ describe "download strategies", :cask do allow(downloader).to receive(:compress) allow(downloader).to receive(:fetch_repo) - expect(downloader.fetch).to equal(downloader.tarball_path) + expect(downloader.fetch).to equal(downloader.cached_location) end it "calls fetch_repo with default arguments for a simple Cask" do @@ -237,44 +237,5 @@ describe "download strategies", :cask do ) end end - - it "runs tar to serialize svn downloads" do - # sneaky stub to remake the directory, since homebrew code removes it - # before tar is called - allow(downloader).to receive(:fetch_repo) { - downloader.cached_location.mkdir - } - - downloader.fetch - - expect(fake_system_command).to have_received(:run!).with( - "/usr/bin/tar", - hash_including(args: [ - '-s/^\\.//', - "--exclude", - ".svn", - "-cf", - downloader.tarball_path, - "--", - ".", - ]), - ) - end end - - # does not work yet, because (for unknown reasons), the tar command - # returns an error code when running under the test suite - # it 'creates a tarball matching the expected checksum' do - # cask = Hbc::CaskLoader.load('svn-download-check-cask') - # downloader = Hbc::SubversionDownloadStrategy.new(cask) - # # special mocking required for tar to have something to work with - # def downloader.fetch_repo(target, url, revision = nil, ignore_externals=false) - # target.mkpath - # FileUtils.touch(target.join('empty_file.txt')) - # File.utime(1000,1000,target.join('empty_file.txt')) - # end - # expect(downloader.fetch).to equal(downloader.tarball_path) - # d = Hbc::Download.new(cask) - # d.send(:_check_sums, downloader.tarball_path, cask.sums) - # end end From ae4bafdb365cfa380d129b0a03bd99a1e4d960a4 Mon Sep 17 00:00:00 2001 From: Markus Reiter Date: Tue, 8 Aug 2017 18:10:13 +0200 Subject: [PATCH 022/294] Simplify CurlDownloadStrategy. --- Library/Homebrew/cask/lib/hbc/audit.rb | 10 +- Library/Homebrew/cask/lib/hbc/cask_loader.rb | 2 +- .../cask/lib/hbc/download_strategy.rb | 28 +---- Library/Homebrew/cask/lib/hbc/dsl/appcast.rb | 6 +- Library/Homebrew/cask/lib/hbc/url.rb | 11 +- Library/Homebrew/cask/lib/hbc/verify/gpg.rb | 2 +- Library/Homebrew/dev-cmd/audit.rb | 8 +- Library/Homebrew/dev-cmd/mirror.rb | 10 +- Library/Homebrew/dev-cmd/pull.rb | 16 +-- Library/Homebrew/download_strategy.rb | 107 ++++++++---------- Library/Homebrew/formulary.rb | 2 +- .../test/cask/download_strategy_spec.rb | 23 ++-- .../Homebrew/test/cask/dsl/appcast_spec.rb | 11 +- Library/Homebrew/utils/curl.rb | 42 +++---- Library/Homebrew/utils/github.rb | 2 +- 15 files changed, 132 insertions(+), 148 deletions(-) diff --git a/Library/Homebrew/cask/lib/hbc/audit.rb b/Library/Homebrew/cask/lib/hbc/audit.rb index cee1fe8070..b8bb6ab814 100644 --- a/Library/Homebrew/cask/lib/hbc/audit.rb +++ b/Library/Homebrew/cask/lib/hbc/audit.rb @@ -143,7 +143,15 @@ module Hbc def check_appcast_http_code odebug "Verifying appcast returns 200 HTTP response code" - result = @command.run("/usr/bin/curl", args: ["--compressed", "--location", "--user-agent", URL::FAKE_USER_AGENT, "--output", "/dev/null", "--write-out", "%{http_code}", cask.appcast], print_stderr: false) + + curl_executable, *args = curl_args( + "--compressed", "--location", "--fail", + "--write-out", "%{http_code}", + "--output", "/dev/null", + cask.appcast, + user_agent: :fake + ) + result = @command.run(curl_executable, args: args, print_stderr: false) if result.success? http_code = result.stdout.chomp add_warning "unexpected HTTP response code retrieving appcast: #{http_code}" unless http_code == "200" diff --git a/Library/Homebrew/cask/lib/hbc/cask_loader.rb b/Library/Homebrew/cask/lib/hbc/cask_loader.rb index 5003146719..dd9c610899 100644 --- a/Library/Homebrew/cask/lib/hbc/cask_loader.rb +++ b/Library/Homebrew/cask/lib/hbc/cask_loader.rb @@ -71,7 +71,7 @@ module Hbc begin ohai "Downloading #{url}." - curl url, "-o", path + curl_download url, to: path rescue ErrorDuringExecution raise CaskUnavailableError.new(token, "Failed to download #{Formatter.url(url)}.") end diff --git a/Library/Homebrew/cask/lib/hbc/download_strategy.rb b/Library/Homebrew/cask/lib/hbc/download_strategy.rb index fb4319f5ea..245ad4adeb 100644 --- a/Library/Homebrew/cask/lib/hbc/download_strategy.rb +++ b/Library/Homebrew/cask/lib/hbc/download_strategy.rb @@ -90,13 +90,8 @@ module Hbc end end - def downloaded_size - temporary_path.size? || 0 - end - def _fetch - odebug "Calling curl with args #{cask_curl_args}" - curl(*cask_curl_args) + curl_download url, *cask_curl_args, to: temporary_path, user_agent: uri_object.user_agent end def fetch @@ -131,23 +126,7 @@ module Hbc private def cask_curl_args - default_curl_args.tap do |args| - args.concat(user_agent_args) - args.concat(cookies_args) - args.concat(referer_args) - end - end - - def default_curl_args - [url, "-C", downloaded_size, "-o", temporary_path] - end - - def user_agent_args - if uri_object.user_agent - ["-A", uri_object.user_agent] - else - [] - end + cookies_args + referer_args end def cookies_args @@ -181,8 +160,7 @@ module Hbc class CurlPostDownloadStrategy < CurlDownloadStrategy def cask_curl_args - super - default_curl_args.concat(post_args) + super.concat(post_args) end def post_args diff --git a/Library/Homebrew/cask/lib/hbc/dsl/appcast.rb b/Library/Homebrew/cask/lib/hbc/dsl/appcast.rb index d302d09460..fc7e83a20d 100644 --- a/Library/Homebrew/cask/lib/hbc/dsl/appcast.rb +++ b/Library/Homebrew/cask/lib/hbc/dsl/appcast.rb @@ -12,7 +12,11 @@ module Hbc end def calculate_checkpoint - result = SystemCommand.run("/usr/bin/curl", args: ["--compressed", "--location", "--user-agent", URL::FAKE_USER_AGENT, "--fail", @uri], print_stderr: false) + curl_executable, *args = curl_args( + "--compressed", "--location", "--fail", @uri, + user_agent: :fake + ) + result = SystemCommand.run(curl_executable, args: args, print_stderr: false) checkpoint = if result.success? processed_appcast_text = result.stdout.gsub(%r{[^<]*}m, "") diff --git a/Library/Homebrew/cask/lib/hbc/url.rb b/Library/Homebrew/cask/lib/hbc/url.rb index 15da2ced21..8c652657b6 100644 --- a/Library/Homebrew/cask/lib/hbc/url.rb +++ b/Library/Homebrew/cask/lib/hbc/url.rb @@ -1,8 +1,6 @@ module Hbc class URL - FAKE_USER_AGENT = "Mozilla/5.0 (Macintosh; Intel Mac OS X 10) https://caskroom.github.io".freeze - - attr_reader :using, :revision, :trust_cert, :uri, :cookies, :referer, :data + attr_reader :using, :revision, :trust_cert, :uri, :cookies, :referer, :data, :user_agent extend Forwardable def_delegators :uri, :path, :scheme, :to_s @@ -17,7 +15,7 @@ module Hbc def initialize(uri, options = {}) @uri = Hbc::UnderscoreSupportingURI.parse(uri) - @user_agent = options[:user_agent] + @user_agent = options.fetch(:user_agent, :default) @cookies = options[:cookies] @referer = options[:referer] @using = options[:using] @@ -25,10 +23,5 @@ module Hbc @trust_cert = options[:trust_cert] @data = options[:data] end - - def user_agent - return FAKE_USER_AGENT if @user_agent == :fake - @user_agent - end end end diff --git a/Library/Homebrew/cask/lib/hbc/verify/gpg.rb b/Library/Homebrew/cask/lib/hbc/verify/gpg.rb index dbb537756d..f4996a5b5e 100644 --- a/Library/Homebrew/cask/lib/hbc/verify/gpg.rb +++ b/Library/Homebrew/cask/lib/hbc/verify/gpg.rb @@ -33,7 +33,7 @@ module Hbc meta_dir = cached || cask.metadata_subdir("gpg", :now, true) sig_path = meta_dir.join("signature.asc") - curl(cask.gpg.signature, "-o", sig_path.to_s) unless cached || force + curl_download cask.gpg.signature, to: sig_path unless cached || force sig_path end diff --git a/Library/Homebrew/dev-cmd/audit.rb b/Library/Homebrew/dev-cmd/audit.rb index 1f07fa89ea..b3e0785a51 100644 --- a/Library/Homebrew/dev-cmd/audit.rb +++ b/Library/Homebrew/dev-cmd/audit.rb @@ -242,12 +242,10 @@ class FormulaAuditor def self.http_content_headers_and_checksum(url, hash_needed: false, user_agent: :default) max_time = hash_needed ? "600" : "25" - args = curl_args( - extra_args: ["--connect-timeout", "15", "--include", "--max-time", max_time, url], - show_output: true, - user_agent: user_agent, + output, = curl_output( + "--connect-timeout", "15", "--include", "--max-time", max_time, "--location", url, + user_agent: user_agent ) - output = Open3.popen3(*args) { |_, stdout, _, _| stdout.read } status_code = :unknown while status_code == :unknown || status_code.to_s.start_with?("3") diff --git a/Library/Homebrew/dev-cmd/mirror.rb b/Library/Homebrew/dev-cmd/mirror.rb index e2492203d3..6445bc34cf 100644 --- a/Library/Homebrew/dev-cmd/mirror.rb +++ b/Library/Homebrew/dev-cmd/mirror.rb @@ -25,9 +25,9 @@ module Homebrew "public_download_numbers": true, "public_stats": true} EOS - curl "--silent", "--fail", "-u#{bintray_user}:#{bintray_key}", - "-H", "Content-Type: application/json", - "-d", package_blob, bintray_repo_url + curl "--silent", "--fail", "--user", "#{bintray_user}:#{bintray_key}", + "--header", "Content-Type: application/json", + "--data", package_blob, bintray_repo_url puts end @@ -40,8 +40,8 @@ module Homebrew content_url = "https://api.bintray.com/content/homebrew/mirror" content_url += "/#{bintray_package}/#{f.pkg_version}/#{filename}" content_url += "?publish=1" - curl "--silent", "--fail", "-u#{bintray_user}:#{bintray_key}", - "-T", download, content_url + curl "--silent", "--fail", "--user", "#{bintray_user}:#{bintray_key}", + "--upload-file", download, content_url puts ohai "Mirrored #{filename}!" end diff --git a/Library/Homebrew/dev-cmd/pull.rb b/Library/Homebrew/dev-cmd/pull.rb index 9681bb2bc0..dd2bc62707 100644 --- a/Library/Homebrew/dev-cmd/pull.rb +++ b/Library/Homebrew/dev-cmd/pull.rb @@ -228,7 +228,7 @@ module Homebrew "https://github.com/BrewTestBot/homebrew-#{tap.repo}/compare/homebrew:master...pr-#{issue}" end - curl "--silent", "--fail", "-o", "/dev/null", "-I", bottle_commit_url + curl "--silent", "--fail", "--output", "/dev/null", "--head", bottle_commit_url safe_system "git", "checkout", "--quiet", "-B", bottle_branch, orig_revision pull_patch bottle_commit_url, "bottle commit" @@ -303,7 +303,7 @@ module Homebrew extra_msg = @description ? "(#{@description})" : nil ohai "Fetching patch #{extra_msg}" puts "Patch: #{patch_url}" - curl patch_url, "-s", "-o", patchpath + curl_download patch_url, to: patchpath end def apply_patch @@ -433,10 +433,10 @@ module Homebrew end version = info.pkg_version ohai "Publishing on Bintray: #{package} #{version}" - curl "-w", '\n', "--silent", "--fail", - "-u#{creds[:user]}:#{creds[:key]}", "-X", "POST", - "-H", "Content-Type: application/json", - "-d", '{"publish_wait_for_secs": 0}', + curl "--write-out", '\n', "--silent", "--fail", + "--user", "#{creds[:user]}:#{creds[:key]}", "--request", "POST", + "--header", "Content-Type: application/json", + "--data", '{"publish_wait_for_secs": 0}', "https://api.bintray.com/content/homebrew/#{repo}/#{package}/#{version}/publish" true rescue => e @@ -587,7 +587,7 @@ module Homebrew # We're in the cache; make sure to force re-download loop do begin - curl url, "-o", filename + curl_download url, to: filename break rescue if retry_count >= max_curl_retries @@ -606,7 +606,7 @@ module Homebrew end def check_bintray_mirror(name, url) - headers = curl_output("--connect-timeout", "15", "--head", url)[0] + headers, = curl_output("--connect-timeout", "15", "--location", "--head", url) status_code = headers.scan(%r{^HTTP\/.* (\d+)}).last.first return if status_code.start_with?("2") opoo "The Bintray mirror #{url} is not reachable (HTTP status code #{status_code})." diff --git a/Library/Homebrew/download_strategy.rb b/Library/Homebrew/download_strategy.rb index 7173347143..2a8b6e5859 100644 --- a/Library/Homebrew/download_strategy.rb +++ b/Library/Homebrew/download_strategy.rb @@ -375,75 +375,59 @@ class CurlDownloadStrategy < AbstractFileDownloadStrategy ohai "Downloading from #{url}" end - urls = actual_urls(url) - unless urls.empty? - ohai "Downloading from #{urls.last}" - if !ENV["HOMEBREW_NO_INSECURE_REDIRECT"].nil? && url.start_with?("https://") && - urls.any? { |u| !u.start_with? "https://" } - puts "HTTPS to HTTP redirect detected & HOMEBREW_NO_INSECURE_REDIRECT is set." - raise CurlDownloadStrategyError, url - end - url = urls.last - end - - curl url, "-C", downloaded_size, "-o", temporary_path + curl_download resolved_url(url), to: temporary_path end # Curl options to be always passed to curl, - # with raw head calls (`curl -I`) or with actual `fetch`. + # with raw head calls (`curl --head`) or with actual `fetch`. def _curl_opts - copts = [] - copts << "--user" << meta.fetch(:user) if meta.key?(:user) - copts + return ["--user" << meta.fetch(:user)] if meta.key?(:user) + [] end - def actual_urls(url) - urls = [] - curl_args = _curl_opts << "-I" << "-L" << url - Utils.popen_read("curl", *curl_args).scan(/^Location: (.+)$/).map do |m| - urls << URI.join(urls.last || url, m.first.chomp).to_s + def resolved_url(url) + redirect_url, _, status = curl_output( + *_curl_opts, "--silent", "--head", + "--write-out", "%{redirect_url}", + "--output", "/dev/null", + url.to_s + ) + + return url unless status.success? + return url if redirect_url.empty? + + ohai "Downloading from #{redirect_url}" + if ENV["HOMEBREW_NO_INSECURE_REDIRECT"] && + url.start_with?("https://") && !redirect_url.start_with?("https://") + puts "HTTPS to HTTP redirect detected & HOMEBREW_NO_INSECURE_REDIRECT is set." + raise CurlDownloadStrategyError, url end - urls + + redirect_url end - def downloaded_size - temporary_path.size? || 0 - end - - def curl(*args) + def curl(*args, **options) args.concat _curl_opts args << "--connect-timeout" << "5" unless mirrors.empty? - super + super(*args, **options) end end # Detect and download from Apache Mirror class CurlApacheMirrorDownloadStrategy < CurlDownloadStrategy def apache_mirrors - rd, wr = IO.pipe - buf = "" + mirrors, = Open3.capture3( + *curl_args(*_curl_opts, "--silent", "--location", "#{@url}&asjson=1"), + ) - pid = fork do - ENV.delete "HOMEBREW_CURL_VERBOSE" - rd.close - $stdout.reopen(wr) - $stderr.reopen(wr) - curl "#{@url}&asjson=1" - end - wr.close - - rd.readline if ARGV.verbose? # Remove Homebrew output - buf << rd.read until rd.eof? - rd.close - Process.wait(pid) - buf + JSON.parse(mirrors) end def _fetch return super if @tried_apache_mirror @tried_apache_mirror = true - mirrors = JSON.parse(apache_mirrors) + mirrors = apache_mirrors path_info = mirrors.fetch("path_info") @url = mirrors.fetch("preferred") + path_info @mirrors |= %W[https://archive.apache.org/dist/#{path_info}] @@ -460,7 +444,7 @@ end class CurlPostDownloadStrategy < CurlDownloadStrategy def _fetch base_url, data = @url.split("?") - curl base_url, "-d", data, "-C", downloaded_size, "-o", temporary_path + curl_download base_url, "--data", data, to: temporary_path end end @@ -530,7 +514,7 @@ class S3DownloadStrategy < CurlDownloadStrategy s3url = obj.public_url end - curl s3url, "-C", downloaded_size, "-o", temporary_path + curl_download s3url, to: temporary_path end end @@ -566,7 +550,7 @@ class GitHubPrivateRepositoryDownloadStrategy < CurlDownloadStrategy end def _fetch - curl download_url, "-C", downloaded_size, "-o", temporary_path + curl_download download_url, to: temporary_path end private @@ -615,7 +599,7 @@ class GitHubPrivateRepositoryReleaseDownloadStrategy < GitHubPrivateRepositoryDo def _fetch # HTTP request header `Accept: application/octet-stream` is required. # Without this, the GitHub API will respond with metadata, not binary. - curl download_url, "-C", downloaded_size, "-o", temporary_path, "-H", "Accept: application/octet-stream" + curl_download download_url, "--header", "Accept: application/octet-stream", to: temporary_path end private @@ -915,18 +899,27 @@ class GitHubGitDownloadStrategy < GitDownloadStrategy def github_last_commit return if ENV["HOMEBREW_NO_GITHUB_API"] - output, _, status = curl_output "-H", "Accept: application/vnd.github.v3.sha", \ - "-I", "https://api.github.com/repos/#{@user}/#{@repo}/commits/#{@ref}" + output, _, status = curl_output( + "--silent", "--head", "--location", + "-H", "Accept: application/vnd.github.v3.sha", + "https://api.github.com/repos/#{@user}/#{@repo}/commits/#{@ref}" + ) - commit = output[/^ETag: \"(\h+)\"/, 1] if status.success? + return unless status.success? + + commit = output[/^ETag: \"(\h+)\"/, 1] version.update_commit(commit) if commit commit end def multiple_short_commits_exist?(commit) return if ENV["HOMEBREW_NO_GITHUB_API"] - output, _, status = curl_output "-H", "Accept: application/vnd.github.v3.sha", \ - "-I", "https://api.github.com/repos/#{@user}/#{@repo}/commits/#{commit}" + + output, _, status = curl_output( + "--silent", "--head", "--location", + "-H", "Accept: application/vnd.github.v3.sha", + "https://api.github.com/repos/#{@user}/#{@repo}/commits/#{commit}" + ) !(status.success? && output && output[/^Status: (200)/, 1] == "200") end @@ -1159,15 +1152,13 @@ class DownloadStrategyDetector SubversionDownloadStrategy when %r{^cvs://} CVSDownloadStrategy - when %r{^https?://(.+?\.)?googlecode\.com/hg} - MercurialDownloadStrategy - when %r{^hg://} + when %r{^hg://}, %r{^https?://(.+?\.)?googlecode\.com/hg} MercurialDownloadStrategy when %r{^bzr://} BazaarDownloadStrategy when %r{^fossil://} FossilDownloadStrategy - when %r{^http://svn\.apache\.org/repos/}, %r{^svn\+http://} + when %r{^svn\+http://}, %r{^http://svn\.apache\.org/repos/} SubversionDownloadStrategy when %r{^https?://(.+?\.)?sourceforge\.net/hgweb/} MercurialDownloadStrategy diff --git a/Library/Homebrew/formulary.rb b/Library/Homebrew/formulary.rb index 195d15cece..dd67b4f243 100644 --- a/Library/Homebrew/formulary.rb +++ b/Library/Homebrew/formulary.rb @@ -165,7 +165,7 @@ module Formulary def load_file HOMEBREW_CACHE_FORMULA.mkpath FileUtils.rm_f(path) - curl url, "-o", path + curl_download url, to: path super rescue MethodDeprecatedError => e if url =~ %r{github.com/([\w-]+)/homebrew-([\w-]+)/} diff --git a/Library/Homebrew/test/cask/download_strategy_spec.rb b/Library/Homebrew/test/cask/download_strategy_spec.rb index 0c18f56b56..60d101bdb8 100644 --- a/Library/Homebrew/test/cask/download_strategy_spec.rb +++ b/Library/Homebrew/test/cask/download_strategy_spec.rb @@ -27,8 +27,11 @@ describe "download strategies", :cask do expect(downloader).to have_received(:curl).with( cask.url.to_s, - "-C", 0, - "-o", kind_of(Pathname) + "--location", + "--remote-time", + "--continue-at", "-", + "--output", kind_of(Pathname), + user_agent: :default ) end @@ -36,25 +39,25 @@ describe "download strategies", :cask do let(:url_options) { { user_agent: "Mozilla/25.0.1" } } it "adds the appropriate curl args" do - curl_args = [] - allow(downloader).to receive(:curl) { |*args| curl_args = args } + expect(downloader).to receive(:safe_system) { |*args| + expect(args.each_cons(2)).to include(["--user-agent", "Mozilla/25.0.1"]) + } downloader.fetch - - expect(curl_args.each_cons(2)).to include(["-A", "Mozilla/25.0.1"]) end end context "with a generalized fake user agent" do + alias_matcher :a_string_matching, :match + let(:url_options) { { user_agent: :fake } } it "adds the appropriate curl args" do - curl_args = [] - allow(downloader).to receive(:curl) { |*args| curl_args = args } + expect(downloader).to receive(:safe_system) { |*args| + expect(args.each_cons(2).to_a).to include(["--user-agent", a_string_matching(/Mozilla.*Mac OS X 10.*AppleWebKit/)]) + } downloader.fetch - - expect(curl_args.each_cons(2)).to include(["-A", "Mozilla/5.0 (Macintosh; Intel Mac OS X 10) https://caskroom.github.io"]) end end diff --git a/Library/Homebrew/test/cask/dsl/appcast_spec.rb b/Library/Homebrew/test/cask/dsl/appcast_spec.rb index b8903b1be8..ccc6a46338 100644 --- a/Library/Homebrew/test/cask/dsl/appcast_spec.rb +++ b/Library/Homebrew/test/cask/dsl/appcast_spec.rb @@ -33,13 +33,18 @@ describe Hbc::DSL::Appcast do describe "#calculate_checkpoint" do before do - expect(Hbc::SystemCommand).to receive(:run).with(*cmd_args).and_return(cmd_result) + expect(Hbc::SystemCommand).to receive(:run) do |executable, **options| + expect(executable).to eq "/usr/bin/curl" + expect(options[:args]).to include(*cmd_args) + expect(options[:print_stderr]).to be false + cmd_result + end allow(cmd_result).to receive(:success?).and_return(cmd_success) allow(cmd_result).to receive(:stdout).and_return(cmd_stdout) end context "when server returns a successful HTTP status" do - let(:cmd_args) { ["/usr/bin/curl", args: ["--compressed", "--location", "--user-agent", Hbc::URL::FAKE_USER_AGENT, "--fail", uri], print_stderr: false] } + let(:cmd_args) { [HOMEBREW_USER_AGENT_FAKE_SAFARI, "--compressed", "--location", "--fail", uri] } let(:cmd_result) { double("Hbc::SystemCommand::Result") } let(:cmd_success) { true } let(:cmd_stdout) { "hello world" } @@ -56,7 +61,7 @@ describe Hbc::DSL::Appcast do end context "when server returns a non-successful HTTP status" do - let(:cmd_args) { ["/usr/bin/curl", args: ["--compressed", "--location", "--user-agent", Hbc::URL::FAKE_USER_AGENT, "--fail", uri], print_stderr: false] } + let(:cmd_args) { [HOMEBREW_USER_AGENT_FAKE_SAFARI, "--compressed", "--location", "--fail", uri] } let(:cmd_result) { double("Hbc::SystemCommand::Result") } let(:cmd_success) { false } let(:cmd_stdout) { "some error message from the server" } diff --git a/Library/Homebrew/utils/curl.rb b/Library/Homebrew/utils/curl.rb index 5a40ae8469..6aaf9be0cb 100644 --- a/Library/Homebrew/utils/curl.rb +++ b/Library/Homebrew/utils/curl.rb @@ -1,42 +1,46 @@ require "pathname" require "open3" -def curl_args(options = {}) +def curl_executable curl = Pathname.new ENV["HOMEBREW_CURL"] curl = Pathname.new "/usr/bin/curl" unless curl.exist? - raise "#{curl} is not executable" unless curl.exist? && curl.executable? + return curl if curl.executable? + raise "#{curl} is not executable" +end +def curl_args(*extra_args, show_output: false, user_agent: :default) args = [ - curl.to_s, - "--remote-time", - "--location", + curl_executable.to_s, + "--fail", + "--show-error", ] - case options[:user_agent] - when :browser - args << "--user-agent" << HOMEBREW_USER_AGENT_FAKE_SAFARI + args << "--user-agent" << case user_agent + when :browser, :fake + HOMEBREW_USER_AGENT_FAKE_SAFARI + when :default + HOMEBREW_USER_AGENT_CURL else - args << "--user-agent" << HOMEBREW_USER_AGENT_CURL + user_agent end - unless options[:show_output] + unless show_output args << "--progress-bar" unless ARGV.verbose? args << "--verbose" if ENV["HOMEBREW_CURL_VERBOSE"] - args << "--fail" args << "--silent" if !$stdout.tty? || ENV["TRAVIS"] end - args += options[:extra_args] if options[:extra_args] - args + args + extra_args end def curl(*args) - safe_system(*curl_args(extra_args: args)) + safe_system(*curl_args(*args)) end -def curl_output(*args) - curl_args = curl_args(extra_args: args, show_output: true) - Open3.popen3(*curl_args) do |_, stdout, stderr, wait_thread| - [stdout.read, stderr.read, wait_thread.value] - end +def curl_download(*args, to: nil, **options) + curl(*args, "--location", "--remote-time", "--continue-at", "-", "--output", to, **options) +end + +def curl_output(*args, **options) + Open3.capture3(*curl_args(*args, show_output: true, **options)) end diff --git a/Library/Homebrew/utils/github.rb b/Library/Homebrew/utils/github.rb index 1a781cee64..07eea43849 100644 --- a/Library/Homebrew/utils/github.rb +++ b/Library/Homebrew/utils/github.rb @@ -166,7 +166,7 @@ module GitHub args += ["--dump-header", headers_tmpfile.path] - output, errors, status = curl_output(url.to_s, *args) + output, errors, status = curl_output(url.to_s, "--location", *args) output, _, http_code = output.rpartition("\n") output, _, http_code = output.rpartition("\n") if http_code == "000" headers = headers_tmpfile.read From 82b2978171fd35d89c19c525db3381c58bf48e97 Mon Sep 17 00:00:00 2001 From: Dominyk Tiller Date: Tue, 8 Aug 2017 18:58:24 +0100 Subject: [PATCH 023/294] mac/xcode: update expected Clang on 10.13 --- Library/Homebrew/os/mac/xcode.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Library/Homebrew/os/mac/xcode.rb b/Library/Homebrew/os/mac/xcode.rb index e23a7cf3d9..6f7deaa10c 100644 --- a/Library/Homebrew/os/mac/xcode.rb +++ b/Library/Homebrew/os/mac/xcode.rb @@ -216,7 +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.31" + when "10.13" then "900.0.34.1" when "10.12" then "802.0.42" when "10.11" then "800.0.42.1" when "10.10" then "700.1.81" From e1ebaab0cbb3bfb050ea5db8e9ad35c17f90dfdf Mon Sep 17 00:00:00 2001 From: JCount Date: Tue, 8 Aug 2017 16:51:46 -0400 Subject: [PATCH 024/294] audit: fix mismatch in versioned alias names in non-core taps Fixes #3022 --- Library/Homebrew/dev-cmd/audit.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/Library/Homebrew/dev-cmd/audit.rb b/Library/Homebrew/dev-cmd/audit.rb index b3e0785a51..170fb6d5f5 100644 --- a/Library/Homebrew/dev-cmd/audit.rb +++ b/Library/Homebrew/dev-cmd/audit.rb @@ -328,6 +328,7 @@ class FormulaAuditor valid_alias_names = [alias_name_major, alias_name_major_minor] if formula.tap && !formula.tap.core_tap? + versioned_aliases.map! { |a| "#{formula.tap}/#{a}" } valid_alias_names.map! { |a| "#{formula.tap}/#{a}" } end From 2cba3222008a6b326b60bbe0180c3985b6cb3a0a Mon Sep 17 00:00:00 2001 From: Markus Reiter Date: Tue, 8 Aug 2017 22:28:08 +0200 Subject: [PATCH 025/294] Allow `curl` args to be overriden. --- Library/Homebrew/test/cask/download_strategy_spec.rb | 2 +- Library/Homebrew/utils/curl.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Library/Homebrew/test/cask/download_strategy_spec.rb b/Library/Homebrew/test/cask/download_strategy_spec.rb index 60d101bdb8..17da1e36e4 100644 --- a/Library/Homebrew/test/cask/download_strategy_spec.rb +++ b/Library/Homebrew/test/cask/download_strategy_spec.rb @@ -26,11 +26,11 @@ describe "download strategies", :cask do downloader.fetch expect(downloader).to have_received(:curl).with( - cask.url.to_s, "--location", "--remote-time", "--continue-at", "-", "--output", kind_of(Pathname), + cask.url.to_s, user_agent: :default ) end diff --git a/Library/Homebrew/utils/curl.rb b/Library/Homebrew/utils/curl.rb index 6aaf9be0cb..9f0d8f75d6 100644 --- a/Library/Homebrew/utils/curl.rb +++ b/Library/Homebrew/utils/curl.rb @@ -38,7 +38,7 @@ def curl(*args) end def curl_download(*args, to: nil, **options) - curl(*args, "--location", "--remote-time", "--continue-at", "-", "--output", to, **options) + curl("--location", "--remote-time", "--continue-at", "-", "--output", to, *args, **options) end def curl_output(*args, **options) From 0ae22c0e3607ac3c2dba8627541ce275e9b0eb36 Mon Sep 17 00:00:00 2001 From: "Bob W. Hogg" Date: Mon, 7 Aug 2017 18:57:55 -0700 Subject: [PATCH 026/294] dev-cmd/bump-formula-pr: search for tar We first search for gtar in PATH, then check if Homebrew's gtar is available, then finally search for tar in PATH. Signed-off-by: Bob W. Hogg --- Library/Homebrew/dev-cmd/bump-formula-pr.rb | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/Library/Homebrew/dev-cmd/bump-formula-pr.rb b/Library/Homebrew/dev-cmd/bump-formula-pr.rb index 1c56749a34..e9e98d4501 100644 --- a/Library/Homebrew/dev-cmd/bump-formula-pr.rb +++ b/Library/Homebrew/dev-cmd/bump-formula-pr.rb @@ -176,7 +176,10 @@ module Homebrew rsrc.version = forced_version if forced_version odie "No version specified!" unless rsrc.version rsrc_path = rsrc.fetch - if Utils.popen_read("/usr/bin/tar", "-tf", rsrc_path) =~ %r{/.*\.} + gnu_tar_gtar_path = HOMEBREW_PREFIX/"opt/gnu-tar/bin/gtar" + gnu_tar_gtar = gnu_tar_gtar_path if gnu_tar_gtar_path.executable? + tar = which("gtar") || gnu_tar_gtar || which("tar") + if Utils.popen_read(tar, "-tf", rsrc_path) =~ %r{/.*\.} new_hash = rsrc_path.sha256 elsif new_url.include? ".tar" odie "#{formula}: no url/#{hash_type} specified!" From ca9b8bea2e57264a9ff7c2be8d0dd02ba25eafb3 Mon Sep 17 00:00:00 2001 From: Dominyk Tiller Date: Wed, 9 Aug 2017 16:52:52 +0100 Subject: [PATCH 027/294] gpg: flip search priority order Makes more sense this way around now Homebrew has migrated across to 2.1.x & the latest version of that doesn't install as `gpg2` any more. Doesn't need to be merged before this PR but for the sake of referencing the PR introducing the upstream death of the `gpg2` symlink is: https://github.com/Homebrew/homebrew-core/pull/16580 --- Library/Homebrew/gpg.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Library/Homebrew/gpg.rb b/Library/Homebrew/gpg.rb index cb9e367dfc..3b7c4f726d 100644 --- a/Library/Homebrew/gpg.rb +++ b/Library/Homebrew/gpg.rb @@ -7,8 +7,8 @@ class Gpg next unless gpg_short_version gpg_version = Version.create(gpg_short_version.to_s) @version = gpg_version - gpg_version == Version.create("2.0") || - gpg_version == Version.create("2.1") + gpg_version == Version.create("2.1") || + gpg_version == Version.create("2.0") end end @@ -20,7 +20,7 @@ class Gpg find_gpg("gpg2") end - GPG_EXECUTABLE = gpg2 || gpg + GPG_EXECUTABLE = gpg || gpg2 def self.available? File.executable?(GPG_EXECUTABLE.to_s) From 0762cc6e74446bc46fa2daa4faffa229dd40e49c Mon Sep 17 00:00:00 2001 From: Dominyk Tiller Date: Wed, 9 Aug 2017 17:02:14 +0100 Subject: [PATCH 028/294] gpg2_requirement: flip search priority --- Library/Homebrew/requirements/gpg2_requirement.rb | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Library/Homebrew/requirements/gpg2_requirement.rb b/Library/Homebrew/requirements/gpg2_requirement.rb index 97fabcca0d..d570983eb1 100644 --- a/Library/Homebrew/requirements/gpg2_requirement.rb +++ b/Library/Homebrew/requirements/gpg2_requirement.rb @@ -5,8 +5,8 @@ class GPG2Requirement < Requirement fatal true default_formula "gnupg" - # MacGPG2/GPGTools installs GnuPG 2.0.x as a vanilla `gpg` symlink - # pointing to `gpg2`, as do we. Ensure we're actually using a 2.0 `gpg`. - # Support both the 2.0.x "stable" and 2.1.x "modern" series. - satisfy(build_env: false) { Gpg.gpg2 || Gpg.gpg } + # GPGTools installs GnuPG 2.0.x as a vanilla `gpg` symlink + # pointing to `gpg2`. Homebrew install 2.1.x as a non-symlink `gpg`. + # We support both the 2.0.x "stable" and 2.1.x "modern" series here. + satisfy(build_env: false) { Gpg.gpg || Gpg.gpg2 } end From 88bf6abd102ba7da0d9ccdc4564ced66a896cfb6 Mon Sep 17 00:00:00 2001 From: Shaun Jackman Date: Wed, 9 Aug 2017 12:44:41 -0700 Subject: [PATCH 029/294] shims/super/cc: Fix c++ -xc++-header Compiling a precompiled header should be mode :cxx rather than :cxxld. --- Library/Homebrew/shims/super/cc | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Library/Homebrew/shims/super/cc b/Library/Homebrew/shims/super/cc index d894d3d69a..afe72156fb 100755 --- a/Library/Homebrew/shims/super/cc +++ b/Library/Homebrew/shims/super/cc @@ -43,6 +43,8 @@ class Cmd else :cc end + elsif @args.include?("-xc++-header") || @args.each_cons(2).include?(["-x", "c++-header"]) + :cxx elsif @args.include? "-E" :ccE else From fd477365b51fbb129d9ec6aeadd8a7694a64f403 Mon Sep 17 00:00:00 2001 From: Markus Reiter Date: Thu, 10 Aug 2017 18:53:23 +0200 Subject: [PATCH 030/294] `curl_download`: Retry once on error `33`. --- Library/Homebrew/utils/curl.rb | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/Library/Homebrew/utils/curl.rb b/Library/Homebrew/utils/curl.rb index 9f0d8f75d6..c330762435 100644 --- a/Library/Homebrew/utils/curl.rb +++ b/Library/Homebrew/utils/curl.rb @@ -38,7 +38,16 @@ def curl(*args) end def curl_download(*args, to: nil, **options) - curl("--location", "--remote-time", "--continue-at", "-", "--output", to, *args, **options) + continue_at ||= "-" + curl("--location", "--remote-time", "--continue-at", continue_at, "--output", to, *args, **options) +rescue ErrorDuringExecution + # `curl` error 33: HTTP server doesn't seem to support byte ranges. Cannot resume. + if $CHILD_STATUS.exitstatus == 33 && continue_at == "-" + continue_at = "0" + retry + end + + raise end def curl_output(*args, **options) From d9587a8b5e15e75bc71ee19c90770688d361e1e1 Mon Sep 17 00:00:00 2001 From: Markus Reiter Date: Fri, 11 Aug 2017 12:28:58 +0200 Subject: [PATCH 031/294] =?UTF-8?q?Don=E2=80=99t=20pass=20`--fail`=20for?= =?UTF-8?q?=20`curl=5Foutput`.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Library/Homebrew/utils/curl.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Library/Homebrew/utils/curl.rb b/Library/Homebrew/utils/curl.rb index c330762435..52d03c93e9 100644 --- a/Library/Homebrew/utils/curl.rb +++ b/Library/Homebrew/utils/curl.rb @@ -11,7 +11,6 @@ end def curl_args(*extra_args, show_output: false, user_agent: :default) args = [ curl_executable.to_s, - "--fail", "--show-error", ] @@ -25,6 +24,7 @@ def curl_args(*extra_args, show_output: false, user_agent: :default) end unless show_output + args << "--fail" args << "--progress-bar" unless ARGV.verbose? args << "--verbose" if ENV["HOMEBREW_CURL_VERBOSE"] args << "--silent" if !$stdout.tty? || ENV["TRAVIS"] From 0e3f1ab27337338c19996a15e8f1e3b72ec270f1 Mon Sep 17 00:00:00 2001 From: Mike McQuaid Date: Fri, 11 Aug 2017 17:23:11 +0100 Subject: [PATCH 032/294] Note cases when pinned formulae get upgraded. Fixes #3021. --- Library/Homebrew/cmd/pin.rb | 3 ++- Library/Homebrew/cmd/unpin.rb | 4 ++-- docs/FAQ.md | 2 ++ docs/Manpage.md | 7 ++++--- manpages/brew-cask.1 | 2 +- manpages/brew.1 | 6 +++--- 6 files changed, 14 insertions(+), 10 deletions(-) diff --git a/Library/Homebrew/cmd/pin.rb b/Library/Homebrew/cmd/pin.rb index c5087f6d4c..5a14f853ce 100644 --- a/Library/Homebrew/cmd/pin.rb +++ b/Library/Homebrew/cmd/pin.rb @@ -1,6 +1,7 @@ #: * `pin` : #: Pin the specified , preventing them from being upgraded when -#: issuing the `brew upgrade` command. See also `unpin`. +#: issuing the `brew upgrade ` command (but can still be upgraded +#: as dependencies for other formulae). See also `unpin`. require "formula" diff --git a/Library/Homebrew/cmd/unpin.rb b/Library/Homebrew/cmd/unpin.rb index a669df1ec4..e15a156ead 100644 --- a/Library/Homebrew/cmd/unpin.rb +++ b/Library/Homebrew/cmd/unpin.rb @@ -1,6 +1,6 @@ #: * `unpin` : -#: Unpin , allowing them to be upgraded by `brew upgrade`. See also -#: `pin`. +#: Unpin , allowing them to be upgraded by `brew upgrade `. +#: See also `pin`. require "formula" diff --git a/docs/FAQ.md b/docs/FAQ.md index 23f53d54ce..788c496262 100644 --- a/docs/FAQ.md +++ b/docs/FAQ.md @@ -26,6 +26,8 @@ To allow that formulae to update again: brew unpin +Note that pinned, outdated formulae that are depended on by another formula will be upgraded when required as we do not allow formulae to be built against non-latest versions. + ## How do I uninstall old versions of a formula? By default, Homebrew does not uninstall old versions of a formula, so over time you will accumulate old versions. To remove them, simply use: diff --git a/docs/Manpage.md b/docs/Manpage.md index 49f6bb5aee..0fbaf7fc76 100644 --- a/docs/Manpage.md +++ b/docs/Manpage.md @@ -364,7 +364,8 @@ With `--verbose` or `-v`, many commands print extra debugging information. Note * `pin` `formulae`: Pin the specified `formulae`, preventing them from being upgraded when - issuing the `brew upgrade` command. See also `unpin`. + issuing the `brew upgrade `formulae`` command (but can still be upgraded + as dependencies for other formulae). See also `unpin`. * `postinstall` `formula`: Rerun the post-install steps for `formula`. @@ -529,8 +530,8 @@ With `--verbose` or `-v`, many commands print extra debugging information. Note source. This is useful for creating patches for the software. * `unpin` `formulae`: - Unpin `formulae`, allowing them to be upgraded by `brew upgrade`. See also - `pin`. + Unpin `formulae`, allowing them to be upgraded by `brew upgrade `formulae``. + See also `pin`. * `untap` `tap`: Remove a tapped repository. diff --git a/manpages/brew-cask.1 b/manpages/brew-cask.1 index f11d48c094..763d78ebe6 100644 --- a/manpages/brew-cask.1 +++ b/manpages/brew-cask.1 @@ -1,7 +1,7 @@ .\" generated with Ronn/v0.7.3 .\" http://github.com/rtomayko/ronn/tree/0.7.3 . -.TH "BREW\-CASK" "1" "July 2017" "Homebrew" "brew-cask" +.TH "BREW\-CASK" "1" "August 2017" "Homebrew" "brew-cask" . .SH "NAME" \fBbrew\-cask\fR \- a friendly binary installer for macOS diff --git a/manpages/brew.1 b/manpages/brew.1 index 2d8ba3f09f..fc075ed815 100644 --- a/manpages/brew.1 +++ b/manpages/brew.1 @@ -1,7 +1,7 @@ .\" generated with Ronn/v0.7.3 .\" http://github.com/rtomayko/ronn/tree/0.7.3 . -.TH "BREW" "1" "July 2017" "Homebrew" "brew" +.TH "BREW" "1" "August 2017" "Homebrew" "brew" . .SH "NAME" \fBbrew\fR \- The missing package manager for macOS @@ -378,7 +378,7 @@ If \fB\-\-fetch\-HEAD\fR is passed, fetch the upstream repository to detect if t . .TP \fBpin\fR \fIformulae\fR -Pin the specified \fIformulae\fR, preventing them from being upgraded when issuing the \fBbrew upgrade\fR command\. See also \fBunpin\fR\. +Pin the specified \fIformulae\fR, preventing them from being upgraded when issuing the \fBbrew upgrade \fR command (but can still be upgraded as dependencies for other formulae)\. See also \fBunpin\fR\. . .TP \fBpostinstall\fR \fIformula\fR @@ -549,7 +549,7 @@ If \fB\-\-git\fR (or \fB\-g\fR) is passed, a Git repository will be initialized . .TP \fBunpin\fR \fIformulae\fR -Unpin \fIformulae\fR, allowing them to be upgraded by \fBbrew upgrade\fR\. See also \fBpin\fR\. +Unpin \fIformulae\fR, allowing them to be upgraded by \fBbrew upgrade \fR\. See also \fBpin\fR\. . .TP \fBuntap\fR \fItap\fR From 348fefea106d75bae5d1ffe814fc309540040d68 Mon Sep 17 00:00:00 2001 From: Ben Muschol Date: Fri, 11 Aug 2017 13:04:37 -0400 Subject: [PATCH 033/294] Replace search_tap with search_taps --- Library/Homebrew/cmd/search.rb | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/Library/Homebrew/cmd/search.rb b/Library/Homebrew/cmd/search.rb index 5b83d80e22..229139838b 100644 --- a/Library/Homebrew/cmd/search.rb +++ b/Library/Homebrew/cmd/search.rb @@ -43,15 +43,14 @@ module Homebrew Descriptions.search(regex, :desc).print elsif ARGV.first =~ HOMEBREW_TAP_FORMULA_REGEX query = ARGV.first - user, repo, name = query.split("/", 3) begin result = Formulary.factory(query).name + results = Array(result) rescue FormulaUnavailableError - result = search_tap(user, repo, name) + results = search_taps(query) end - results = Array(result) puts Formatter.columns(results) unless results.empty? else query = ARGV.first From b06fceda57ea8306e130ba11ccb2bd71f6907c23 Mon Sep 17 00:00:00 2001 From: Ben Muschol Date: Fri, 11 Aug 2017 15:49:57 -0400 Subject: [PATCH 034/294] Add a test --- Library/Homebrew/cmd/search.rb | 2 +- Library/Homebrew/test/cmd/search_spec.rb | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/Library/Homebrew/cmd/search.rb b/Library/Homebrew/cmd/search.rb index 229139838b..cd0f1d66ce 100644 --- a/Library/Homebrew/cmd/search.rb +++ b/Library/Homebrew/cmd/search.rb @@ -48,7 +48,7 @@ module Homebrew result = Formulary.factory(query).name results = Array(result) rescue FormulaUnavailableError - results = search_taps(query) + results = search_taps(query.split('/')[-1]) end puts Formatter.columns(results) unless results.empty? diff --git a/Library/Homebrew/test/cmd/search_spec.rb b/Library/Homebrew/test/cmd/search_spec.rb index bd2056a48c..84cc24d41d 100644 --- a/Library/Homebrew/test/cmd/search_spec.rb +++ b/Library/Homebrew/test/cmd/search_spec.rb @@ -1,6 +1,7 @@ describe "brew search", :integration_test do before(:each) do setup_test_formula "testball" + setup_remote_tap "caskroom/cask/test" end it "lists all available Formulae when no argument is given" do @@ -24,6 +25,13 @@ describe "brew search", :integration_test do .and be_a_success end + it "falls back to a tap search when no formula is found" do + expect { brew "search", "caskroom/cask/firefox" } + .to output(/firefox/).to_stdout + .and not_to_output.to_stderr + .and be_a_success + end + describe "--desc" do let(:desc_cache) { HOMEBREW_CACHE/"desc_cache.json" } From eb009503ed8c8c86506f548d4d950b256b25d14c Mon Sep 17 00:00:00 2001 From: Ben Muschol Date: Fri, 11 Aug 2017 15:52:50 -0400 Subject: [PATCH 035/294] Fix test typo --- Library/Homebrew/test/cmd/search_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Library/Homebrew/test/cmd/search_spec.rb b/Library/Homebrew/test/cmd/search_spec.rb index 84cc24d41d..7c97e6e357 100644 --- a/Library/Homebrew/test/cmd/search_spec.rb +++ b/Library/Homebrew/test/cmd/search_spec.rb @@ -1,7 +1,7 @@ describe "brew search", :integration_test do before(:each) do setup_test_formula "testball" - setup_remote_tap "caskroom/cask/test" + setup_remote_tap "caskroom/cask" end it "lists all available Formulae when no argument is given" do From cb1650075c9f6c74a637f108e3f43deb4250b837 Mon Sep 17 00:00:00 2001 From: Ben Muschol Date: Fri, 11 Aug 2017 15:59:08 -0400 Subject: [PATCH 036/294] Fix style --- Library/Homebrew/cmd/search.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Library/Homebrew/cmd/search.rb b/Library/Homebrew/cmd/search.rb index cd0f1d66ce..0d47f8ab17 100644 --- a/Library/Homebrew/cmd/search.rb +++ b/Library/Homebrew/cmd/search.rb @@ -48,7 +48,8 @@ module Homebrew result = Formulary.factory(query).name results = Array(result) rescue FormulaUnavailableError - results = search_taps(query.split('/')[-1]) + _, _, name = query.split("/", 3) + results = search_taps(name) end puts Formatter.columns(results) unless results.empty? From bb85581df054d64f108ee6916fc5196bea93055c Mon Sep 17 00:00:00 2001 From: Andrew Janke Date: Thu, 3 Aug 2017 00:41:51 -0400 Subject: [PATCH 037/294] brew deps: add --include-requirements --- Library/Homebrew/cmd/deps.rb | 134 ++++++++++++++++++++++++++--------- completions/zsh/_brew | 10 ++- docs/Manpage.md | 13 +++- manpages/brew-cask.1 | 2 +- manpages/brew.1 | 16 +++-- 5 files changed, 130 insertions(+), 45 deletions(-) diff --git a/Library/Homebrew/cmd/deps.rb b/Library/Homebrew/cmd/deps.rb index bbf0c1b0b4..de7aa4a512 100644 --- a/Library/Homebrew/cmd/deps.rb +++ b/Library/Homebrew/cmd/deps.rb @@ -1,4 +1,4 @@ -#: * `deps` [`--1`] [`-n`] [`--union`] [`--full-name`] [`--installed`] [`--include-build`] [`--include-optional`] [`--skip-recommended`] : +#: * `deps` [`--1`] [`-n`] [`--union`] [`--full-name`] [`--installed`] [`--include-build`] [`--include-optional`] [`--skip-recommended`] [`--include-requirements`] : #: Show dependencies for . When given multiple formula arguments, #: show the intersection of dependencies for . #: @@ -19,15 +19,22 @@ #: . To include the `:build` type dependencies, pass `--include-build`. #: Similarly, pass `--include-optional` to include `:optional` dependencies. #: To skip `:recommended` type dependencies, pass `--skip-recommended`. +#: To include requirements in addition to dependencies, pass `--include-requirements`. #: -#: * `deps` `--tree` [] (|`--installed`): +#: * `deps` `--tree` [`--1`] [] [`--annotate`] (|`--installed`): #: Show dependencies as a tree. When given multiple formula arguments, output #: individual trees for every formula. #: +#: If `--1` is passed, only one level of children is displayed. +#: #: If `--installed` is passed, output a tree for every installed formula. #: #: The placeholder is any combination of options `--include-build`, -#: `--include-optional`, and `--skip-recommended` as documented above. +#: `--include-optional`, `--skip-recommended`, and `--include-requirements` as +#: documented above. +#: +#: If `--annotate` is passed, the build, optional, and recommended dependencies +#: are marked as such in the output. #: #: * `deps` [] (`--installed`|`--all`): #: Show dependencies for installed or all available formulae. Every line of @@ -37,6 +44,10 @@ #: The placeholder is any combination of options `--include-build`, #: `--include-optional`, and `--skip-recommended` as documented above. +# The undocumented `--for-each` option will switch into the mode used by `deps --all`, +# but only list dependencies for specified formula, one specified formula per line. +# This is used for debugging the `--installed`/`--all` display mode. + # encoding: UTF-8 require "formula" @@ -52,20 +63,26 @@ module Homebrew all?: ARGV.include?("--all"), topo_order?: ARGV.include?("-n"), union?: ARGV.include?("--union"), + for_each?: ARGV.include?("--for-each"), ) - if mode.installed? && mode.tree? - puts_deps_tree Formula.installed + if mode.tree? + if mode.installed? + puts_deps_tree Formula.installed, !ARGV.one? + else + raise FormulaUnspecifiedError if ARGV.named.empty? + puts_deps_tree ARGV.formulae, !ARGV.one? + end elsif mode.all? puts_deps Formula - elsif mode.tree? - raise FormulaUnspecifiedError if ARGV.named.empty? - puts_deps_tree ARGV.formulae elsif ARGV.named.empty? raise FormulaUnspecifiedError unless mode.installed? puts_deps Formula.installed + elsif mode.for_each? + puts_deps ARGV.formulae else all_deps = deps_for_formulae(ARGV.formulae, !ARGV.one?, &(mode.union? ? :| : :&)) + all_deps = condense_requirements(all_deps) all_deps = all_deps.select(&:installed?) if mode.installed? all_deps = all_deps.map(&method(:dep_display_name)).uniq all_deps.sort! unless mode.topo_order? @@ -73,24 +90,59 @@ module Homebrew end end - def dep_display_name(d) - ARGV.include?("--full-name") ? d.to_formula.full_name : d.name + def condense_requirements(deps) + if ARGV.include?("--include-requirements") + deps + else + deps.map do |dep| + if dep.is_a? Dependency + dep + elsif dep.default_formula? + dep.to_dependency + end + end.compact + end + end + + def dep_display_name(dep) + str = if dep.is_a? Requirement + if ARGV.include?("--include-requirements") + if dep.default_formula? + ":#{dep.display_s} (#{dep_display_name(dep.to_dependency)})" + else + ":#{dep.display_s}" + end + elsif dep.default_formula? + dep_display_name(dep.to_dependency) + else + # This shouldn't happen, but we'll put something here to help debugging + "::#{dep.name}" + end + else + ARGV.include?("--full-name") ? dep.to_formula.full_name : dep.name + end + if ARGV.include?("--annotate") + str = "#{str} [build]" if dep.build? + str = "#{str} [optional" if dep.optional? + str = "#{str} [recommended]" if dep.recommended? + end + str end def deps_for_formula(f, recursive = false) includes = [] ignores = [] - if ARGV.include? "--include-build" + if ARGV.include?("--include-build") includes << "build?" else ignores << "build?" end - if ARGV.include? "--include-optional" + if ARGV.include?("--include-optional") includes << "optional?" else ignores << "optional?" end - ignores << "recommended?" if ARGV.include? "--skip-recommended" + ignores << "recommended?" if ARGV.include?("--skip-recommended") if recursive deps = f.recursive_dependencies do |dependent, dep| @@ -120,7 +172,7 @@ module Homebrew end end - deps + reqs.select(&:default_formula?).map(&:to_dependency) + deps + reqs.to_a end def deps_for_formulae(formulae, recursive = false, &block) @@ -129,41 +181,55 @@ module Homebrew def puts_deps(formulae) formulae.each do |f| - deps = deps_for_formula(f).sort_by(&:name).map(&method(:dep_display_name)) + deps = deps_for_formula(f) + deps = condense_requirements(deps) + deps = deps.sort_by(&:name).map(&method(:dep_display_name)) puts "#{f.full_name}: #{deps.join(" ")}" end end - def puts_deps_tree(formulae) + def puts_deps_tree(formulae, recursive = false) formulae.each do |f| - puts "#{f.full_name} (required dependencies)" - recursive_deps_tree(f, "") + puts f.full_name + @dep_stack = [] + recursive_deps_tree(f, "", recursive) puts end end - def recursive_deps_tree(f, prefix) - reqs = f.requirements.select(&:default_formula?) - deps = f.deps.default - max = reqs.length - 1 - reqs.each_with_index do |req, i| - chr = if i == max && deps.empty? + def recursive_deps_tree(f, prefix, recursive) + reqs = f.requirements + deps = f.deps + dependables = reqs + deps + dependables = dependables.reject(&:optional?) unless ARGV.include?("--include-optional") + dependables = dependables.reject(&:build?) unless ARGV.include?("--include-build") + dependables = dependables.reject(&:recommended?) if ARGV.include?("--skip-recommended") + max = dependables.length - 1 + @dep_stack.push f.name + dependables.each_with_index do |dep, i| + next if !ARGV.include?("--include-requirements") && dep.is_a?(Requirement) && !dep.default_formula? + tree_lines = if i == max "└──" else "├──" end - puts prefix + "#{chr} :#{dep_display_name(req.to_dependency)}" - end - max = deps.length - 1 - deps.each_with_index do |dep, i| - chr = if i == max - "└──" + display_s = "#{tree_lines} #{dep_display_name(dep)}" + is_circular = @dep_stack.include?(dep.name) + display_s = "#{display_s} (CIRCULAR DEPENDENCY)" if is_circular + puts "#{prefix}#{display_s}" + next if !recursive || is_circular + prefix_addition = if i == max + " " else - "├──" + "│ " + end + if dep.is_a?(Requirement) && dep.default_formula? + recursive_deps_tree(Formulary.factory(dep.to_dependency.name), prefix + prefix_addition, true) + end + if dep.is_a? Dependency + recursive_deps_tree(Formulary.factory(dep.name), prefix + prefix_addition, true) end - prefix_ext = (i == max) ? " " : "│ " - puts prefix + "#{chr} #{dep_display_name(dep)}" - recursive_deps_tree(Formulary.factory(dep.name), prefix + prefix_ext) end + @dep_stack.pop end end diff --git a/completions/zsh/_brew b/completions/zsh/_brew index 61dc26b42d..bc88f402b5 100644 --- a/completions/zsh/_brew +++ b/completions/zsh/_brew @@ -284,8 +284,8 @@ _brew_create() { ':url:_urls' } -# brew deps [--1] [-n] [--union] [--full-name] [--installed] [--include-build] [--include-optional] [--skip-recommended] formulae -# brew deps --tree [filters] (formulae|--installed) +# brew deps [--1] [-n] [--union] [--full-name] [--installed] [--include-build] [--include-optional] [--skip-recommended] [--include-requirements] formulae +# brew deps --tree [--1] [filters] (formulae|--installed) # brew deps [filters] (--installed|--all) # The filters placeholder is any combination of options --include-build, --include-optional, and --skip-recommended as documented above. _brew_deps() { @@ -294,6 +294,7 @@ _brew_deps() { '--include-build[include \:build dependencies]' \ '--include-optional[include \:optional dependencies]' \ '--skip-recommended[skip \:recommended type dependencies]' \ + '--include-requirements[include requirements]' \ '--1[only show dependencies one level down, instead of recursing]' \ '-n[show dependencies in topological order]' \ '--union[show the union of dependencies for formulae, instead of the intersection]' \ @@ -303,6 +304,11 @@ _brew_deps() { - tree-deps \ '--tree[show dependencies as a tree]' \ '(*)--installed[show dependencies for all installed formulae]' \ + '--include-build[include \:build dependencies]' \ + '--include-optional[include \:optional dependencies]' \ + '--skip-recommended[skip \:recommended type dependencies]' \ + '--include-requirements[include requirements]' \ + '--1[only show dependencies one level down, instead of recursing]' \ '(--installed)*:formulae:__brew_formulae' \ - installed-all \ '--include-build[include \:build dependencies]' \ diff --git a/docs/Manpage.md b/docs/Manpage.md index 49f6bb5aee..1ec9493954 100644 --- a/docs/Manpage.md +++ b/docs/Manpage.md @@ -77,7 +77,7 @@ With `--verbose` or `-v`, many commands print extra debugging information. Note a bug report, you will likely be asked for this information if you do not provide it. - * `deps` [`--1`] [`-n`] [`--union`] [`--full-name`] [`--installed`] [`--include-build`] [`--include-optional`] [`--skip-recommended`] `formulae`: + * `deps` [`--1`] [`-n`] [`--union`] [`--full-name`] [`--installed`] [`--include-build`] [`--include-optional`] [`--skip-recommended`] [`--include-requirements`] `formulae`: Show dependencies for `formulae`. When given multiple formula arguments, show the intersection of dependencies for `formulae`. @@ -98,15 +98,22 @@ With `--verbose` or `-v`, many commands print extra debugging information. Note `formulae`. To include the `:build` type dependencies, pass `--include-build`. Similarly, pass `--include-optional` to include `:optional` dependencies. To skip `:recommended` type dependencies, pass `--skip-recommended`. + To include requirements in addition to dependencies, pass `--include-requirements`. - * `deps` `--tree` [`filters`] (`formulae`|`--installed`): + * `deps` `--tree` [`--1`] [`filters`] [`--annotate`] (`formulae`|`--installed`): Show dependencies as a tree. When given multiple formula arguments, output individual trees for every formula. + If `--1` is passed, only one level of children is displayed. + If `--installed` is passed, output a tree for every installed formula. The `filters` placeholder is any combination of options `--include-build`, - `--include-optional`, and `--skip-recommended` as documented above. + `--include-optional`, `--skip-recommended`, and `--include-requirements` as + documented above. + + If `--annotate` is passed, the build, optional, and recommended dependencies + are marked as such in the output. * `deps` [`filters`] (`--installed`|`--all`): Show dependencies for installed or all available formulae. Every line of diff --git a/manpages/brew-cask.1 b/manpages/brew-cask.1 index f11d48c094..763d78ebe6 100644 --- a/manpages/brew-cask.1 +++ b/manpages/brew-cask.1 @@ -1,7 +1,7 @@ .\" generated with Ronn/v0.7.3 .\" http://github.com/rtomayko/ronn/tree/0.7.3 . -.TH "BREW\-CASK" "1" "July 2017" "Homebrew" "brew-cask" +.TH "BREW\-CASK" "1" "August 2017" "Homebrew" "brew-cask" . .SH "NAME" \fBbrew\-cask\fR \- a friendly binary installer for macOS diff --git a/manpages/brew.1 b/manpages/brew.1 index 2d8ba3f09f..46a1d9bd92 100644 --- a/manpages/brew.1 +++ b/manpages/brew.1 @@ -1,7 +1,7 @@ .\" generated with Ronn/v0.7.3 .\" http://github.com/rtomayko/ronn/tree/0.7.3 . -.TH "BREW" "1" "July 2017" "Homebrew" "brew" +.TH "BREW" "1" "August 2017" "Homebrew" "brew" . .SH "NAME" \fBbrew\fR \- The missing package manager for macOS @@ -88,7 +88,7 @@ If \fB\-\-quiet\fR is passed, list only the names of commands without the header Show Homebrew and system configuration useful for debugging\. If you file a bug report, you will likely be asked for this information if you do not provide it\. . .TP -\fBdeps\fR [\fB\-\-1\fR] [\fB\-n\fR] [\fB\-\-union\fR] [\fB\-\-full\-name\fR] [\fB\-\-installed\fR] [\fB\-\-include\-build\fR] [\fB\-\-include\-optional\fR] [\fB\-\-skip\-recommended\fR] \fIformulae\fR +\fBdeps\fR [\fB\-\-1\fR] [\fB\-n\fR] [\fB\-\-union\fR] [\fB\-\-full\-name\fR] [\fB\-\-installed\fR] [\fB\-\-include\-build\fR] [\fB\-\-include\-optional\fR] [\fB\-\-skip\-recommended\fR] [\fB\-\-include\-requirements\fR] \fIformulae\fR Show dependencies for \fIformulae\fR\. When given multiple formula arguments, show the intersection of dependencies for \fIformulae\fR\. . .IP @@ -107,17 +107,23 @@ If \fB\-\-full\-name\fR is passed, list dependencies by their full name\. If \fB\-\-installed\fR is passed, only list those dependencies that are currently installed\. . .IP -By default, \fBdeps\fR shows required and recommended dependencies for \fIformulae\fR\. To include the \fB:build\fR type dependencies, pass \fB\-\-include\-build\fR\. Similarly, pass \fB\-\-include\-optional\fR to include \fB:optional\fR dependencies\. To skip \fB:recommended\fR type dependencies, pass \fB\-\-skip\-recommended\fR\. +By default, \fBdeps\fR shows required and recommended dependencies for \fIformulae\fR\. To include the \fB:build\fR type dependencies, pass \fB\-\-include\-build\fR\. Similarly, pass \fB\-\-include\-optional\fR to include \fB:optional\fR dependencies\. To skip \fB:recommended\fR type dependencies, pass \fB\-\-skip\-recommended\fR\. To include requirements in addition to dependencies, pass \fB\-\-include\-requirements\fR\. . .TP -\fBdeps\fR \fB\-\-tree\fR [\fIfilters\fR] (\fIformulae\fR|\fB\-\-installed\fR) +\fBdeps\fR \fB\-\-tree\fR [\fB\-\-1\fR] [\fIfilters\fR] [\fB\-\-annotate\fR] (\fIformulae\fR|\fB\-\-installed\fR) Show dependencies as a tree\. When given multiple formula arguments, output individual trees for every formula\. . .IP +If \fB\-\-1\fR is passed, only one level of children is displayed\. +. +.IP If \fB\-\-installed\fR is passed, output a tree for every installed formula\. . .IP -The \fIfilters\fR placeholder is any combination of options \fB\-\-include\-build\fR, \fB\-\-include\-optional\fR, and \fB\-\-skip\-recommended\fR as documented above\. +The \fIfilters\fR placeholder is any combination of options \fB\-\-include\-build\fR, \fB\-\-include\-optional\fR, \fB\-\-skip\-recommended\fR, and \fB\-\-include\-requirements\fR as documented above\. +. +.IP +If \fB\-\-annotate\fR is passed, the build, optional, and recommended dependencies are marked as such in the output\. . .TP \fBdeps\fR [\fIfilters\fR] (\fB\-\-installed\fR|\fB\-\-all\fR) From 4760f4e8032694d37f934257f6a58f0164438151 Mon Sep 17 00:00:00 2001 From: Alyssa Ross Date: Fri, 11 Aug 2017 22:40:08 +0100 Subject: [PATCH 038/294] Raise an exception when double loading a formula (As proposed in #2673) --- Library/Homebrew/formulary.rb | 2 ++ Library/Homebrew/test/formulary_spec.rb | 10 ++++++++++ 2 files changed, 12 insertions(+) diff --git a/Library/Homebrew/formulary.rb b/Library/Homebrew/formulary.rb index dd67b4f243..b26846e006 100644 --- a/Library/Homebrew/formulary.rb +++ b/Library/Homebrew/formulary.rb @@ -20,6 +20,8 @@ module Formulary raise "Formula loading disabled by HOMEBREW_DISABLE_LOAD_FORMULA!" end + raise "Formula #{name} has already been loaded" if const_defined?(namespace) + mod = Module.new const_set(namespace, mod) begin diff --git a/Library/Homebrew/test/formulary_spec.rb b/Library/Homebrew/test/formulary_spec.rb index 234ebc93c3..7a7c8811af 100644 --- a/Library/Homebrew/test/formulary_spec.rb +++ b/Library/Homebrew/test/formulary_spec.rb @@ -27,6 +27,16 @@ describe Formulary do let(:bottle_dir) { Pathname.new("#{TEST_FIXTURE_DIR}/bottles") } let(:bottle) { bottle_dir/"testball_bottle-0.1.#{Utils::Bottles.tag}.bottle.tar.gz" } + describe "::load_formula" do + it "does not allow namespace repetition" do |example| + definition = "Foo = Class.new(Formula)" + namespace = "Test#{example.description.hash.abs}" + subject.load_formula("foo", "bar", definition, namespace) + expect { subject.load_formula("foo", "bar", definition, namespace) } + .to raise_error RuntimeError, /already.* loaded/ + end + end + describe "::class_s" do it "replaces '+' with 'x'" do expect(subject.class_s("foo++")).to eq("Fooxx") From a34f1d3a53d2be5825f1a820fe72b401a41eabfc Mon Sep 17 00:00:00 2001 From: "Tim D. Smith" Date: Fri, 11 Aug 2017 22:13:20 -0700 Subject: [PATCH 039/294] Update Python docs Reflect some of the wisdom learned over the last couple of years, which contradict some of the earlier dicta. --- docs/Homebrew-and-Python.md | 8 ++--- docs/Python-for-Formula-Authors.md | 48 ++++++++++-------------------- 2 files changed, 19 insertions(+), 37 deletions(-) diff --git a/docs/Homebrew-and-Python.md b/docs/Homebrew-and-Python.md index 692e5c617b..8b263cb388 100644 --- a/docs/Homebrew-and-Python.md +++ b/docs/Homebrew-and-Python.md @@ -24,13 +24,13 @@ The Python formulae install [pip](http://www.pip-installer.org) (as `pip2` or `p Setuptools can be updated via pip, without having to re-brew Python: ```sh -pip install --upgrade setuptools +python2 -m pip --upgrade setuptools ``` Similarly, pip can be used to upgrade itself via: ```sh -pip install --upgrade pip +python2 -m pip install --upgrade pip ``` ### Note on `pip install --user` @@ -39,7 +39,7 @@ The normal `pip install --user` is disabled for brewed Python. This is because o A possible workaround (which puts executable scripts in `~/Library/Python/./bin`) is: ```sh -pip install --user --install-option="--prefix=" +python2 -m pip install --user --install-option="--prefix=" ``` ## `site-packages` and the `PYTHONPATH` @@ -86,7 +86,7 @@ CFLAGS=-I$(brew --prefix)/include LDFLAGS=-L$(brew --prefix)/lib pip install :python -``` - -Or if the import name is different from the module name: - -```ruby -depends_on "MacFSEvents" => [:python, "fsevents"] -``` - -If you submit a formula with this syntax to core, you may be asked to rewrite it as a `Requirement`. +In general, applications should unconditionally bundle all of their Python-language dependencies and libraries and should install any unsatisfied dependencies; these strategies are discussed in depth in the following sections. ## Applications @@ -147,9 +121,9 @@ in case you need to do different things for different resources. ## Bindings -To add an option to a formula to build Python bindings, use `depends_on :python => :recommended` and install the bindings conditionally on `build.with? "python"` in your `install` method. +It should be okay to build bindings with system Python and use them with any binary-compatible Python. If that's the case, go ahead and build and install Python 2 bindings and don't add an option. If that isn't the case, it's an upstream bug; [here's some advice for resolving it](http://blog.tim-smith.us/2015/09/python-extension-modules-os-x/). -Python bindings should be optional because if the formula is bottled, any `:recommended` or mandatory dependencies on `:python` are always resolved by installing the Homebrew `python` formula, which will upset users that prefer to use the system Python. This is because we cannot generally create a binary package that works against both versions of Python. +If you'd like to add bindings for Python 3, please add `depends_on :python3 => :optional` and make the bindings conditional on `build.with?("python3")`. ### Dependencies @@ -179,9 +153,7 @@ Sometimes we have to `inreplace` a `Makefile` to use our prefix for the Python b ### Python declarations -Libraries **should** declare a dependency on `:python` or `:python3` as appropriate, which will respectively cause the formula to use the first python or python3 discovered in `PATH` at install time. If a library supports both Python 2.x and Python 3.x, the `:python` dependency **should** be `:recommended` (i.e. built by default) and the `:python3` dependency should be `:optional`. Python 2.x libraries **must** function when they are installed against either the system Python or Homebrew Python. - -Formulae that declare a dependency on `:python` will always be bottled against Homebrew's python, since we cannot in general build binary packages that can be imported from both Pythons. Users can add `--build-from-source` after `brew install` to compile against whichever python is in `PATH`. +Python 2 libraries probably do not need a `depends_on :python` declaration; this way, they will be built with system Python, but should still be usable with any other Python 2.7. If this is not the case, it is an upstream bug; [here is some advice for resolving it](http://blog.tim-smith.us/2015/09/python-extension-modules-os-x/). Libraries built for Python 3 should include `depends_on :python3`, which will bottle against Homebrew's python3, and use the first python3 discovered in `PATH` at build time when installing from source with `brew install --build-from-source`. If a library supports both Python 2.x and Python 3.x, the `:python3` dependency may be `:optional`. Python 2.x libraries must function when they are installed against either the system Python or Homebrew Python. ### Installing @@ -191,7 +163,7 @@ Most formulae presently just install to `prefix`. ### Dependencies -The dependencies of libraries must be installed so that they are importable. The principle of minimum surprise suggests that installing a Homebrew library should not alter the other libraries in a user's `sys.path`. The best way to achieve this is to only install dependencies if they are not already installed. To minimize the potential for linking conflicts, dependencies should be installed to `libexec/"vendor"` and added to `sys.path` by writing a second .pth file (named like "homebrew-foo-dependencies.pth") to the `prefix` site-packages. +The dependencies of libraries must be installed so that they are importable. To minimize the potential for linking conflicts, dependencies should be installed to `libexec/"vendor"` and added to `sys.path` by writing a second .pth file (named like "homebrew-foo-dependencies.pth") to the `prefix` site-packages. The [matplotlib](https://github.com/Homebrew/homebrew-science/blob/master/matplotlib.rb) formula in [homebrew/science](https://github.com/Homebrew/homebrew-science) deploys this strategy. @@ -209,6 +181,16 @@ Distutils and pip use a "flat" installation hierarchy that installs modules as i Distribute (not to be confused with distutils) is an obsolete fork of setuptools. Distlib is a package maintained outside the standard library which is used by pip for some low-level packaging operations and is not relevant to most `setup.py` users. +### Running `setup.py` + +In the event that a formula needs to interact with `setup.py` instead of calling `pip`, Homebrew provides a helper method, `Language::Python.setup_install_args`, which returns useful arguments for invoking `setup.py`. Your formula should use this instead of invoking `setup.py` explicitly. The syntax is: + +```ruby +system "python", *Language::Python.setup_install_args(prefix) +``` + +where `prefix` is the destination prefix (usually `libexec` or `prefix`). + ### What is `--single-version-externally-managed`? `--single-version-externally-managed` ("SVEM") is a setuptools-only [argument to `setup.py install`](https://setuptools.readthedocs.io/en/latest/setuptools.html?#install-run-easy-install-or-old-style-installation). The primary effect of SVEM is to use distutils to perform the install instead of using setuptools' `easy_install`. From 1939952dc46eab137a52170da407218fd8db0434 Mon Sep 17 00:00:00 2001 From: Mike McQuaid Date: Sat, 12 Aug 2017 12:59:14 +0100 Subject: [PATCH 040/294] Remove some hedge words. --- docs/Python-for-Formula-Authors.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/docs/Python-for-Formula-Authors.md b/docs/Python-for-Formula-Authors.md index de0708735a..129f5ba5ed 100644 --- a/docs/Python-for-Formula-Authors.md +++ b/docs/Python-for-Formula-Authors.md @@ -10,7 +10,7 @@ Bindings are a special case of libraries that allow Python code to interact with Homebrew is happy to accept applications that are built in Python, whether the apps are available from PyPI or not. Homebrew generally won't accept libraries that can be installed correctly with `pip install foo`. Bindings may be installed for packages that provide them, especially if equivalent functionality isn't available through pip. -In general, applications should unconditionally bundle all of their Python-language dependencies and libraries and should install any unsatisfied dependencies; these strategies are discussed in depth in the following sections. +Applications should unconditionally bundle all of their Python-language dependencies and libraries and should install any unsatisfied dependencies; these strategies are discussed in depth in the following sections. ## Applications @@ -121,9 +121,9 @@ in case you need to do different things for different resources. ## Bindings -It should be okay to build bindings with system Python and use them with any binary-compatible Python. If that's the case, go ahead and build and install Python 2 bindings and don't add an option. If that isn't the case, it's an upstream bug; [here's some advice for resolving it](http://blog.tim-smith.us/2015/09/python-extension-modules-os-x/). +Build bindings with system Python by default (don't add an option) and they should be usable with any binary-compatible Python. If that isn't the case, it's an upstream bug; [here's some advice for resolving it](http://blog.tim-smith.us/2015/09/python-extension-modules-os-x/). -If you'd like to add bindings for Python 3, please add `depends_on :python3 => :optional` and make the bindings conditional on `build.with?("python3")`. +To add bindings for Python 3, please add `depends_on :python3 => :optional` and make the bindings conditional on `build.with?("python3")`. ### Dependencies @@ -153,7 +153,7 @@ Sometimes we have to `inreplace` a `Makefile` to use our prefix for the Python b ### Python declarations -Python 2 libraries probably do not need a `depends_on :python` declaration; this way, they will be built with system Python, but should still be usable with any other Python 2.7. If this is not the case, it is an upstream bug; [here is some advice for resolving it](http://blog.tim-smith.us/2015/09/python-extension-modules-os-x/). Libraries built for Python 3 should include `depends_on :python3`, which will bottle against Homebrew's python3, and use the first python3 discovered in `PATH` at build time when installing from source with `brew install --build-from-source`. If a library supports both Python 2.x and Python 3.x, the `:python3` dependency may be `:optional`. Python 2.x libraries must function when they are installed against either the system Python or Homebrew Python. +Python 2 libraries do not need a `depends_on :python` declaration; they will be built with system Python, but should still be usable with any other Python 2.7. If this is not the case, it is an upstream bug; [here is some advice for resolving it](http://blog.tim-smith.us/2015/09/python-extension-modules-os-x/). Libraries built for Python 3 should include `depends_on :python3`, which will bottle against Homebrew's python3, and use the first python3 discovered in `PATH` at build time when installing from source with `brew install --build-from-source`. If a library supports both Python 2.x and Python 3.x, the `:python3` dependency should be `:optional`. Python 2.x libraries must function when they are installed against either the system Python or Homebrew Python. ### Installing @@ -183,7 +183,7 @@ Distribute (not to be confused with distutils) is an obsolete fork of setuptools ### Running `setup.py` -In the event that a formula needs to interact with `setup.py` instead of calling `pip`, Homebrew provides a helper method, `Language::Python.setup_install_args`, which returns useful arguments for invoking `setup.py`. Your formula should use this instead of invoking `setup.py` explicitly. The syntax is: +In the event that a formula needs to interact with `setup.py` instead of calling `pip`, Homebrew provides a helper method, `Language::Python.setup_install_args`, which returns useful arguments for invoking `setup.py`. Your formula should use this instead of invoking `setup.py` explicitly. The syntax is: ```ruby system "python", *Language::Python.setup_install_args(prefix) From ae8235c555d6bdcbce140e26343a12da95cf46fc Mon Sep 17 00:00:00 2001 From: Mike McQuaid Date: Sat, 12 Aug 2017 15:00:36 +0100 Subject: [PATCH 041/294] Revert "Raise an exception when double loading a formula" --- Library/Homebrew/formulary.rb | 2 -- Library/Homebrew/test/formulary_spec.rb | 10 ---------- 2 files changed, 12 deletions(-) diff --git a/Library/Homebrew/formulary.rb b/Library/Homebrew/formulary.rb index b26846e006..dd67b4f243 100644 --- a/Library/Homebrew/formulary.rb +++ b/Library/Homebrew/formulary.rb @@ -20,8 +20,6 @@ module Formulary raise "Formula loading disabled by HOMEBREW_DISABLE_LOAD_FORMULA!" end - raise "Formula #{name} has already been loaded" if const_defined?(namespace) - mod = Module.new const_set(namespace, mod) begin diff --git a/Library/Homebrew/test/formulary_spec.rb b/Library/Homebrew/test/formulary_spec.rb index 7a7c8811af..234ebc93c3 100644 --- a/Library/Homebrew/test/formulary_spec.rb +++ b/Library/Homebrew/test/formulary_spec.rb @@ -27,16 +27,6 @@ describe Formulary do let(:bottle_dir) { Pathname.new("#{TEST_FIXTURE_DIR}/bottles") } let(:bottle) { bottle_dir/"testball_bottle-0.1.#{Utils::Bottles.tag}.bottle.tar.gz" } - describe "::load_formula" do - it "does not allow namespace repetition" do |example| - definition = "Foo = Class.new(Formula)" - namespace = "Test#{example.description.hash.abs}" - subject.load_formula("foo", "bar", definition, namespace) - expect { subject.load_formula("foo", "bar", definition, namespace) } - .to raise_error RuntimeError, /already.* loaded/ - end - end - describe "::class_s" do it "replaces '+' with 'x'" do expect(subject.class_s("foo++")).to eq("Fooxx") From 3396387b52ed835c8ee394e35c1a9c3bdb0e320d Mon Sep 17 00:00:00 2001 From: Randall Wood Date: Sun, 13 Aug 2017 08:46:48 -0400 Subject: [PATCH 042/294] Remove "*instal" aliases from bash completion Remove all command aliases ending in "instal" (single letter L) from the bash completion. This has the practical effect of removing the aliases "instal" and "uninstal" from bash completion, allowing "install" and "uninstall" to be auto completed once the first three characters of each "ins" or "uni" are typed in. --- completions/bash/brew | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/completions/bash/brew b/completions/bash/brew index 03a05cb37d..ac1fd3e4f1 100644 --- a/completions/bash/brew +++ b/completions/bash/brew @@ -563,10 +563,10 @@ _brew() { if [[ "$i" -eq "$COMP_CWORD" ]] then - # Do not auto-complete "instal" abbreviation for "install" command. + # Do not auto-complete "*instal" abbreviations for "*install" commands. # Prefix newline to prevent not checking the first command. - local cmds=$'\n'"$(brew commands --quiet --include-aliases)" - __brewcomp "${cmds/$'\n'instal$'\n'/$'\n'}" + local cmds=$'\n'"$(brew commands --quiet --include-aliases | grep -v instal$)" + __brewcomp "${cmds}" return fi From d7baf8137325b27f3ae45bca430d1db25af8bb62 Mon Sep 17 00:00:00 2001 From: Randall Wood Date: Sun, 13 Aug 2017 10:58:58 -0400 Subject: [PATCH 043/294] Make comment easier to read. --- completions/bash/brew | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/completions/bash/brew b/completions/bash/brew index ac1fd3e4f1..60c272f739 100644 --- a/completions/bash/brew +++ b/completions/bash/brew @@ -563,7 +563,7 @@ _brew() { if [[ "$i" -eq "$COMP_CWORD" ]] then - # Do not auto-complete "*instal" abbreviations for "*install" commands. + # Do not auto-complete "*instal" or "*uninstal" aliases for "*install" commands. # Prefix newline to prevent not checking the first command. local cmds=$'\n'"$(brew commands --quiet --include-aliases | grep -v instal$)" __brewcomp "${cmds}" From e93ec12b32f3449f4669cf53469a4d5308b10cc3 Mon Sep 17 00:00:00 2001 From: Ben Muschol Date: Sun, 13 Aug 2017 13:10:38 -0400 Subject: [PATCH 044/294] Remove duplicate url generation logic in Github module --- Library/Homebrew/cask/lib/hbc/cli/search.rb | 5 +- Library/Homebrew/cmd/search.rb | 5 +- Library/Homebrew/test/utils/github_spec.rb | 22 +++++++- Library/Homebrew/utils/github.rb | 57 ++++++++++++--------- 4 files changed, 59 insertions(+), 30 deletions(-) diff --git a/Library/Homebrew/cask/lib/hbc/cli/search.rb b/Library/Homebrew/cask/lib/hbc/cli/search.rb index 643d18d554..0cc4cc56c8 100644 --- a/Library/Homebrew/cask/lib/hbc/cli/search.rb +++ b/Library/Homebrew/cask/lib/hbc/cli/search.rb @@ -15,8 +15,9 @@ module Hbc end def self.search_remote(query) - matches = GitHub.search_code("user:caskroom", "path:Casks", "filename:#{query}", "extension:rb") - [*matches].map do |match| + matches = GitHub.search_code(user: "caskroom", path: "Casks", + filename: query, extension: "rb") + Array(matches).map do |match| tap = Tap.fetch(match["repository"]["full_name"]) next if tap.installed? "#{tap.name}/#{File.basename(match["path"], ".rb")}" diff --git a/Library/Homebrew/cmd/search.rb b/Library/Homebrew/cmd/search.rb index 5b83d80e22..4607f6d1a0 100644 --- a/Library/Homebrew/cmd/search.rb +++ b/Library/Homebrew/cmd/search.rb @@ -102,8 +102,9 @@ module Homebrew def search_taps(query) valid_dirnames = ["Formula", "HomebrewFormula", "Casks", "."].freeze - matches = GitHub.search_code("user:Homebrew", "user:caskroom", "filename:#{query}", "extension:rb") - [*matches].map do |match| + matches = GitHub.search_code(user: ["Homebrew", "caskroom"], filename: query, extension: "rb") + + Array(matches).map do |match| dirname, filename = File.split(match["path"]) next unless valid_dirnames.include?(dirname) tap = Tap.fetch(match["repository"]["full_name"]) diff --git a/Library/Homebrew/test/utils/github_spec.rb b/Library/Homebrew/test/utils/github_spec.rb index 9b539262fb..cf5f6c8080 100644 --- a/Library/Homebrew/test/utils/github_spec.rb +++ b/Library/Homebrew/test/utils/github_spec.rb @@ -2,12 +2,30 @@ require "utils/github" describe GitHub do describe "::search_code", :needs_network do - it "searches code" do - results = subject.search_code("repo:Homebrew/brew", "path:/", "filename:readme", "language:markdown") + it "queries GitHub code with the passed paramaters" do + results = subject.search_code(repo: "Homebrew/brew", path: "/", + filename: "readme", language: "markdown") expect(results.count).to eq(1) expect(results.first["name"]).to eq("README.md") expect(results.first["path"]).to eq("README.md") end end + + describe "::query_string" do + it "builds a query with the given hash parameters formatted as key:value" do + query = subject.query_string(user: "Homebrew", repo: "Brew") + expect(query).to eq("q=user%3aHomebrew+repo%3aTest&per_page=100") + end + + it "adds a variable number of top-level string parameters to the query when provided" do + query = subject.query_string("value1", "value2", user: "Homebrew") + expect(query).to eq("q=value1+value2+user%3aHomebrew&per_page=100") + end + + it "turns array values into multiple key:value parameters" do + query = subject.query_string(user: ["Homebrew", "caskroom"]) + expect(query).to eq("q=user%3aHomebrew+user%3acaskroom&per_page=100") + end + end end diff --git a/Library/Homebrew/utils/github.rb b/Library/Homebrew/utils/github.rb index 07eea43849..6f56e505c5 100644 --- a/Library/Homebrew/utils/github.rb +++ b/Library/Homebrew/utils/github.rb @@ -228,34 +228,15 @@ module GitHub end def issues_matching(query, qualifiers = {}) - uri = URI.parse("#{API_URL}/search/issues") - uri.query = build_query_string(query, qualifiers) - open(uri) { |json| json["items"] } + search("issues", query, **qualifiers) end def repository(user, repo) - open(URI.parse("#{API_URL}/repos/#{user}/#{repo}")) + open(path_to("repos", user, repo)) end - def search_code(*params) - uri = URI.parse("#{API_URL}/search/code") - uri.query = "q=#{uri_escape(params.join(" "))}" - open(uri) { |json| json["items"] } - end - - def build_query_string(query, qualifiers) - s = "q=#{uri_escape(query)}+" - s << build_search_qualifier_string(qualifiers) - s << "&per_page=100" - end - - def build_search_qualifier_string(qualifiers) - { - repo: "Homebrew/homebrew-core", - in: "title", - }.update(qualifiers).map do |qualifier, value| - "#{qualifier}:#{value}" - end.join("+") + def search_code(**params) + search("code", **params) end def uri_escape(query) @@ -292,7 +273,35 @@ module GitHub end def private_repo?(full_name) - uri = URI.parse("#{API_URL}/repos/#{full_name}") + uri = path_to "repos", full_name open(uri) { |json| json["private"] } end + + def query_string(*main_params, **qualifiers) + params_list = main_params + + qualifiers.each do |key, value| + if value.is_a? Array + value.each { |v| params_list << format_parameter(key, v) } + else + params_list << format_parameter(key, v) + end + end + + "q=#{uri_escape(params_list.join(" "))}&per_page=100" + end + + def format_paramater(key, value) + "#{key}:#{value}" + end + + def path_to(*subroutes) + URI.parse(File.join(API_URL, *subroutes)) + end + + def search(entity, *queries, **qualifiers) + uri = path_to "search", entity + uri.query = query_string(*queries, **qualifiers) + open(uri) { |json| json["items"] } + end end From acf46fce5f08712084dc9454fee66637796055c6 Mon Sep 17 00:00:00 2001 From: Ben Muschol Date: Sun, 13 Aug 2017 15:01:37 -0400 Subject: [PATCH 045/294] Rename path_to -> url_to since it returns a url --- Library/Homebrew/utils/github.rb | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Library/Homebrew/utils/github.rb b/Library/Homebrew/utils/github.rb index 6f56e505c5..c10a8ed0da 100644 --- a/Library/Homebrew/utils/github.rb +++ b/Library/Homebrew/utils/github.rb @@ -232,7 +232,7 @@ module GitHub end def repository(user, repo) - open(path_to("repos", user, repo)) + open(url_to("repos", user, repo)) end def search_code(**params) @@ -273,7 +273,7 @@ module GitHub end def private_repo?(full_name) - uri = path_to "repos", full_name + uri = url_to "repos", full_name open(uri) { |json| json["private"] } end @@ -295,12 +295,12 @@ module GitHub "#{key}:#{value}" end - def path_to(*subroutes) + def url_to(*subroutes) URI.parse(File.join(API_URL, *subroutes)) end def search(entity, *queries, **qualifiers) - uri = path_to "search", entity + uri = url_to "search", entity uri.query = query_string(*queries, **qualifiers) open(uri) { |json| json["items"] } end From 91b139aca293bea1aa926c5301754e8603c9275e Mon Sep 17 00:00:00 2001 From: Ben Muschol Date: Sun, 13 Aug 2017 16:15:26 -0400 Subject: [PATCH 046/294] Fix syntax error --- Library/Homebrew/utils/github.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Library/Homebrew/utils/github.rb b/Library/Homebrew/utils/github.rb index c10a8ed0da..59c7d7ac85 100644 --- a/Library/Homebrew/utils/github.rb +++ b/Library/Homebrew/utils/github.rb @@ -284,7 +284,7 @@ module GitHub if value.is_a? Array value.each { |v| params_list << format_parameter(key, v) } else - params_list << format_parameter(key, v) + params_list << format_parameter(key, value) end end From d052f503f90ad08f6f889891e3fb72e97988a80e Mon Sep 17 00:00:00 2001 From: Ben Muschol Date: Sun, 13 Aug 2017 16:41:18 -0400 Subject: [PATCH 047/294] fix typo --- Library/Homebrew/utils/github.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Library/Homebrew/utils/github.rb b/Library/Homebrew/utils/github.rb index 59c7d7ac85..05ef7e3c86 100644 --- a/Library/Homebrew/utils/github.rb +++ b/Library/Homebrew/utils/github.rb @@ -291,7 +291,7 @@ module GitHub "q=#{uri_escape(params_list.join(" "))}&per_page=100" end - def format_paramater(key, value) + def format_parameter(key, value) "#{key}:#{value}" end From 24da1ecd3de86177f669072c542c9a01e6d6649d Mon Sep 17 00:00:00 2001 From: Ben Muschol Date: Sun, 13 Aug 2017 17:16:45 -0400 Subject: [PATCH 048/294] Fix url encoded in expected values --- Library/Homebrew/test/utils/github_spec.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Library/Homebrew/test/utils/github_spec.rb b/Library/Homebrew/test/utils/github_spec.rb index cf5f6c8080..79a26083a3 100644 --- a/Library/Homebrew/test/utils/github_spec.rb +++ b/Library/Homebrew/test/utils/github_spec.rb @@ -15,17 +15,17 @@ describe GitHub do describe "::query_string" do it "builds a query with the given hash parameters formatted as key:value" do query = subject.query_string(user: "Homebrew", repo: "Brew") - expect(query).to eq("q=user%3aHomebrew+repo%3aTest&per_page=100") + expect(query).to eq("q=user%3AHomebrew+repo%3ABrew&per_page=100") end it "adds a variable number of top-level string parameters to the query when provided" do query = subject.query_string("value1", "value2", user: "Homebrew") - expect(query).to eq("q=value1+value2+user%3aHomebrew&per_page=100") + expect(query).to eq("q=value1+value2+user%3AHomebrew&per_page=100") end it "turns array values into multiple key:value parameters" do query = subject.query_string(user: ["Homebrew", "caskroom"]) - expect(query).to eq("q=user%3aHomebrew+user%3acaskroom&per_page=100") + expect(query).to eq("q=user%3AHomebrew+user%3Acaskroom&per_page=100") end end end From 603bdd01a81e62d6b97a5da26d75d409e839a8fa Mon Sep 17 00:00:00 2001 From: Ben Muschol Date: Mon, 14 Aug 2017 11:08:56 -0400 Subject: [PATCH 049/294] Implement PR feedback --- Library/Homebrew/cask/lib/hbc/cli/search.rb | 2 +- Library/Homebrew/cmd/search.rb | 2 +- Library/Homebrew/test/utils/github_spec.rb | 4 ++-- Library/Homebrew/utils/github.rb | 4 ++-- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/Library/Homebrew/cask/lib/hbc/cli/search.rb b/Library/Homebrew/cask/lib/hbc/cli/search.rb index 0cc4cc56c8..e89dced925 100644 --- a/Library/Homebrew/cask/lib/hbc/cli/search.rb +++ b/Library/Homebrew/cask/lib/hbc/cli/search.rb @@ -17,7 +17,7 @@ module Hbc def self.search_remote(query) matches = GitHub.search_code(user: "caskroom", path: "Casks", filename: query, extension: "rb") - Array(matches).map do |match| + matches.map do |match| tap = Tap.fetch(match["repository"]["full_name"]) next if tap.installed? "#{tap.name}/#{File.basename(match["path"], ".rb")}" diff --git a/Library/Homebrew/cmd/search.rb b/Library/Homebrew/cmd/search.rb index 4607f6d1a0..a133d04999 100644 --- a/Library/Homebrew/cmd/search.rb +++ b/Library/Homebrew/cmd/search.rb @@ -104,7 +104,7 @@ module Homebrew valid_dirnames = ["Formula", "HomebrewFormula", "Casks", "."].freeze matches = GitHub.search_code(user: ["Homebrew", "caskroom"], filename: query, extension: "rb") - Array(matches).map do |match| + matches.map do |match| dirname, filename = File.split(match["path"]) next unless valid_dirnames.include?(dirname) tap = Tap.fetch(match["repository"]["full_name"]) diff --git a/Library/Homebrew/test/utils/github_spec.rb b/Library/Homebrew/test/utils/github_spec.rb index 79a26083a3..5c315aec4a 100644 --- a/Library/Homebrew/test/utils/github_spec.rb +++ b/Library/Homebrew/test/utils/github_spec.rb @@ -14,8 +14,8 @@ describe GitHub do describe "::query_string" do it "builds a query with the given hash parameters formatted as key:value" do - query = subject.query_string(user: "Homebrew", repo: "Brew") - expect(query).to eq("q=user%3AHomebrew+repo%3ABrew&per_page=100") + query = subject.query_string(user: "Homebrew", repo: "brew") + expect(query).to eq("q=user%3AHomebrew+repo%3Abrew&per_page=100") end it "adds a variable number of top-level string parameters to the query when provided" do diff --git a/Library/Homebrew/utils/github.rb b/Library/Homebrew/utils/github.rb index 05ef7e3c86..960b563d91 100644 --- a/Library/Homebrew/utils/github.rb +++ b/Library/Homebrew/utils/github.rb @@ -296,12 +296,12 @@ module GitHub end def url_to(*subroutes) - URI.parse(File.join(API_URL, *subroutes)) + URI.parse([API_URL, *subroutes].join("/")) end def search(entity, *queries, **qualifiers) uri = url_to "search", entity uri.query = query_string(*queries, **qualifiers) - open(uri) { |json| json["items"] } + open(uri) { |json| Array(json["items"]) } end end From 68cdb550f7b90318a136e4dd484249ab678f5fbc Mon Sep 17 00:00:00 2001 From: Ben Muschol Date: Mon, 14 Aug 2017 11:41:29 -0400 Subject: [PATCH 050/294] Spec for issues search --- Library/Homebrew/test/utils/github_spec.rb | 8 ++++++++ Library/Homebrew/utils/github.rb | 2 +- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/Library/Homebrew/test/utils/github_spec.rb b/Library/Homebrew/test/utils/github_spec.rb index 5c315aec4a..80f0ef7861 100644 --- a/Library/Homebrew/test/utils/github_spec.rb +++ b/Library/Homebrew/test/utils/github_spec.rb @@ -28,4 +28,12 @@ describe GitHub do expect(query).to eq("q=user%3AHomebrew+user%3Acaskroom&per_page=100") end end + + describe "::issues_matching", :needs_network do + it "queries GitHub issues with the passed parameters" do + results = subject.issues_matching("brew search", repo: "Homebrew/brew", author: "avetamine", is: "closed") + expect(results.count).to eq(1) + expect(results.first["title"]).to eq("brew search : 422 Unprocessable Entity") + end + end end diff --git a/Library/Homebrew/utils/github.rb b/Library/Homebrew/utils/github.rb index 960b563d91..8096c7b9c4 100644 --- a/Library/Homebrew/utils/github.rb +++ b/Library/Homebrew/utils/github.rb @@ -266,7 +266,7 @@ module GitHub puts "Closed pull requests:" prs = open_or_closed_prs else - return + return [] end prs.each { |i| puts "#{i["title"]} (#{i["html_url"]})" } From 5f8d212ccccb8172985da9f71945fea6a8ea1b1a Mon Sep 17 00:00:00 2001 From: Ben Muschol Date: Mon, 14 Aug 2017 12:51:32 -0400 Subject: [PATCH 051/294] Unify vocabulary in github module, remove unnecessary logic Fix duplication bug --- Library/Homebrew/test/utils/github_spec.rb | 4 +- Library/Homebrew/utils/github.rb | 43 ++++++---------------- 2 files changed, 14 insertions(+), 33 deletions(-) diff --git a/Library/Homebrew/test/utils/github_spec.rb b/Library/Homebrew/test/utils/github_spec.rb index 80f0ef7861..0b19c8c9e9 100644 --- a/Library/Homebrew/test/utils/github_spec.rb +++ b/Library/Homebrew/test/utils/github_spec.rb @@ -29,9 +29,9 @@ describe GitHub do end end - describe "::issues_matching", :needs_network do + describe "::search_issues", :needs_network do it "queries GitHub issues with the passed parameters" do - results = subject.issues_matching("brew search", repo: "Homebrew/brew", author: "avetamine", is: "closed") + results = subject.search_issues("brew search", repo: "Homebrew/brew", author: "avetamine", is: "closed") expect(results.count).to eq(1) expect(results.first["title"]).to eq("brew search : 422 Unprocessable Entity") end diff --git a/Library/Homebrew/utils/github.rb b/Library/Homebrew/utils/github.rb index 8096c7b9c4..cff292598a 100644 --- a/Library/Homebrew/utils/github.rb +++ b/Library/Homebrew/utils/github.rb @@ -227,7 +227,7 @@ module GitHub end end - def issues_matching(query, qualifiers = {}) + def search_issues(query, **qualifiers) search("issues", query, **qualifiers) end @@ -235,38 +235,27 @@ module GitHub open(url_to("repos", user, repo)) end - def search_code(**params) - search("code", **params) - end - - def uri_escape(query) - if URI.respond_to?(:encode_www_form_component) - URI.encode_www_form_component(query) - else - require "erb" - ERB::Util.url_encode(query) - end + def search_code(**qualifiers) + search("code", **qualifiers) end def issues_for_formula(name, options = {}) tap = options[:tap] || CoreTap.instance - issues_matching(name, state: "open", repo: "#{tap.user}/homebrew-#{tap.repo}") + search_issues(name, state: "open", repo: "#{tap.user}/homebrew-#{tap.repo}") end def print_pull_requests_matching(query) return [] if ENV["HOMEBREW_NO_GITHUB_API"] - open_or_closed_prs = issues_matching(query, type: "pr") + open_or_closed_prs = search_issues(query, type: "pr") open_prs = open_or_closed_prs.select { |i| i["state"] == "open" } - if !open_prs.empty? + prs = if !open_prs.empty? puts "Open pull requests:" - prs = open_prs - elsif !open_or_closed_prs.empty? - puts "Closed pull requests:" - prs = open_or_closed_prs + open_prs else - return [] + puts "Closed pull requests:" unless open_or_closed_prs.empty? + open_or_closed_prs end prs.each { |i| puts "#{i["title"]} (#{i["html_url"]})" } @@ -280,19 +269,11 @@ module GitHub def query_string(*main_params, **qualifiers) params_list = main_params - qualifiers.each do |key, value| - if value.is_a? Array - value.each { |v| params_list << format_parameter(key, v) } - else - params_list << format_parameter(key, value) - end + params_list += qualifiers.flat_map do |key, value| + Array(value).map { |v| "#{key}:#{v}" } end - "q=#{uri_escape(params_list.join(" "))}&per_page=100" - end - - def format_parameter(key, value) - "#{key}:#{value}" + "q=#{URI.encode_www_form_component(params_list.join(" "))}&per_page=100" end def url_to(*subroutes) From c1ed6b8858fd84f0f1794bc85e9b83d21a962acd Mon Sep 17 00:00:00 2001 From: JCount Date: Mon, 14 Aug 2017 17:27:37 -0400 Subject: [PATCH 052/294] gpg: prevent pinentry from launching when creating test key this is accomplished by setting an empty password in the gnupg batch input file --- Library/Homebrew/gpg.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/Library/Homebrew/gpg.rb b/Library/Homebrew/gpg.rb index 3b7c4f726d..f56473df3f 100644 --- a/Library/Homebrew/gpg.rb +++ b/Library/Homebrew/gpg.rb @@ -38,6 +38,7 @@ class Gpg Key-Length: 2048 Subkey-Type: RSA Subkey-Length: 2048 + Passphrase: '' Name-Real: Testing Name-Email: testing@foo.bar Expire-Date: 1d From 961d79011e0f0b2c63cf33f7818a4f0437e1643e Mon Sep 17 00:00:00 2001 From: Mike McQuaid Date: Tue, 15 Aug 2017 10:25:51 +0100 Subject: [PATCH 053/294] search: explain why it takes the time it does. Provide a bit of clarity that this isn't just searching a local database but doing an GitHub API and Git history query. --- Library/Homebrew/cmd/search.rb | 10 ++++++++++ Library/Homebrew/test/cmd/search_spec.rb | 6 +++--- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/Library/Homebrew/cmd/search.rb b/Library/Homebrew/cmd/search.rb index 0d47f8ab17..53767e75f9 100644 --- a/Library/Homebrew/cmd/search.rb +++ b/Library/Homebrew/cmd/search.rb @@ -58,12 +58,14 @@ module Homebrew regex = query_regexp(query) local_results = search_formulae(regex) puts Formatter.columns(local_results) unless local_results.empty? + tap_results = search_taps(query) puts Formatter.columns(tap_results) unless tap_results.empty? if $stdout.tty? count = local_results.length + tap_results.length + ohai "Searching blacklisted, migrated and deleted formulae..." if reason = Homebrew::MissingFormula.reason(query, silent: true) if count > 0 puts @@ -101,6 +103,11 @@ module Homebrew end def search_taps(query) + return [] if ENV["HOMEBREW_NO_GITHUB_API"] + + # Use stderr to avoid breaking parsed output + $stderr.puts Formatter.headline("Searching taps on GitHub...", color: :blue) + valid_dirnames = ["Formula", "HomebrewFormula", "Casks", "."].freeze matches = GitHub.search_code("user:Homebrew", "user:caskroom", "filename:#{query}", "extension:rb") [*matches].map do |match| @@ -113,6 +120,9 @@ module Homebrew end def search_formulae(regex) + # Use stderr to avoid breaking parsed output + $stderr.puts Formatter.headline("Searching local taps...", color: :blue) + aliases = Formula.alias_full_names results = (Formula.full_names + aliases).grep(regex).sort diff --git a/Library/Homebrew/test/cmd/search_spec.rb b/Library/Homebrew/test/cmd/search_spec.rb index 7c97e6e357..77c2c63521 100644 --- a/Library/Homebrew/test/cmd/search_spec.rb +++ b/Library/Homebrew/test/cmd/search_spec.rb @@ -14,7 +14,7 @@ describe "brew search", :integration_test do it "supports searching by name" do expect { brew "search", "testball" } .to output(/testball/).to_stdout - .and not_to_output.to_stderr + .and output(/Searching/).to_stderr .and be_a_success end @@ -25,10 +25,10 @@ describe "brew search", :integration_test do .and be_a_success end - it "falls back to a tap search when no formula is found" do + it "falls back to a GitHub tap search when no formula is found", :needs_network do expect { brew "search", "caskroom/cask/firefox" } .to output(/firefox/).to_stdout - .and not_to_output.to_stderr + .and output(/Searching/).to_stderr .and be_a_success end From 80ae5b2660d293adc9d1ad4aaa376500910a339a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mislav=20Marohni=C4=87?= Date: Tue, 15 Aug 2017 17:32:12 +0200 Subject: [PATCH 054/294] bump-formula-pr: forward compatibility with `hub fork` Due to limitations of `hub fork` in hub 2.2, scripts had to repeat the command at least two times; the 2nd time was to read the fork name from the "fatal: remote MYNAME already exists" message output from git. In upcoming hub 2.3, the `hub fork` command is improved to always output the remote name, regardless of whether one already existed or not. With this approach, only one `hub fork` call will ever be necessary when hub is up to date. --- Library/Homebrew/dev-cmd/bump-formula-pr.rb | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/Library/Homebrew/dev-cmd/bump-formula-pr.rb b/Library/Homebrew/dev-cmd/bump-formula-pr.rb index e9e98d4501..521c763023 100644 --- a/Library/Homebrew/dev-cmd/bump-formula-pr.rb +++ b/Library/Homebrew/dev-cmd/bump-formula-pr.rb @@ -296,9 +296,7 @@ module Homebrew ohai "git fetch --unshallow origin" if shallow ohai "git checkout --no-track -b #{branch} origin/master" ohai "git commit --no-edit --verbose --message='#{formula.name} #{new_formula_version}#{devel_message}' -- #{formula.path}" - ohai "hub fork --no-remote" - ohai "hub fork" - ohai "hub fork (to read $HUB_REMOTE)" + ohai "hub fork # read $HUB_REMOTE" ohai "git push --set-upstream $HUB_REMOTE #{branch}:#{branch}" ohai "hub pull-request --browse -m '#{formula.name} #{new_formula_version}#{devel_message}'" ohai "git checkout -" @@ -308,9 +306,9 @@ module Homebrew safe_system "git", "commit", "--no-edit", "--verbose", "--message=#{formula.name} #{new_formula_version}#{devel_message}", "--", formula.path - safe_system "hub", "fork", "--no-remote" - quiet_system "hub", "fork" - remote = Utils.popen_read("hub fork 2>&1")[/fatal: remote (.+) already exists\./, 1] + remote = Utils.popen_read("hub fork 2>&1")[/remote:? (\S+)/, 1] + # repeat for hub 2.2 backwards compatibility: + remote = Utils.popen_read("hub fork 2>&1")[/remote:? (\S+)/, 1] if remote.to_s.empty? odie "cannot get remote from 'hub'!" if remote.to_s.empty? safe_system "git", "push", "--set-upstream", remote, "#{branch}:#{branch}" pr_message = <<-EOS.undent From db20b0c281899e42d4d4bbe5a98e644e1f543df4 Mon Sep 17 00:00:00 2001 From: Gautham Goli Date: Thu, 17 Aug 2017 11:41:58 +0530 Subject: [PATCH 055/294] audit: In Cops and their tests convert all multiline strings to heredocs --- Library/Homebrew/rubocops/patches_cop.rb | 20 ++++-- Library/Homebrew/rubocops/urls_cop.rb | 6 +- .../test/rubocops/patches_cop_spec.rb | 66 ++++++++++++++----- .../Homebrew/test/rubocops/urls_cop_spec.rb | 21 ++++-- 4 files changed, 83 insertions(+), 30 deletions(-) diff --git a/Library/Homebrew/rubocops/patches_cop.rb b/Library/Homebrew/rubocops/patches_cop.rb index fb14d8acca..b272833821 100644 --- a/Library/Homebrew/rubocops/patches_cop.rb +++ b/Library/Homebrew/rubocops/patches_cop.rb @@ -31,7 +31,10 @@ module RuboCop %r{gist\.githubusercontent\.com/.+/raw}]) if regex_match_group(patch, gh_patch_patterns) unless patch_url =~ /[a-fA-F0-9]{40}/ - problem "GitHub/Gist patches should specify a revision:\n#{patch_url}" + problem <<-EOS.undent.chomp + GitHub/Gist patches should specify a revision: + #{patch_url} + EOS end end @@ -46,15 +49,24 @@ module RuboCop end if regex_match_group(patch, %r{macports/trunk}) - problem "MacPorts patches should specify a revision instead of trunk:\n#{patch_url}" + problem <<-EOS.undent.chomp + MacPorts patches should specify a revision instead of trunk: + #{patch_url} + EOS end if regex_match_group(patch, %r{^http://trac\.macports\.org}) - problem "Patches from MacPorts Trac should be https://, not http:\n#{patch_url}" + problem <<-EOS.undent.chomp + Patches from MacPorts Trac should be https://, not http: + #{patch_url} + EOS end return unless regex_match_group(patch, %r{^http://bugs\.debian\.org}) - problem "Patches from Debian should be https://, not http:\n#{patch_url}" + problem <<-EOS.undent.chomp + Patches from Debian should be https://, not http: + #{patch_url} + EOS end end end diff --git a/Library/Homebrew/rubocops/urls_cop.rb b/Library/Homebrew/rubocops/urls_cop.rb index 676e735238..071a4c42d6 100644 --- a/Library/Homebrew/rubocops/urls_cop.rb +++ b/Library/Homebrew/rubocops/urls_cop.rb @@ -104,8 +104,10 @@ module RuboCop end if url =~ %r{^https?://prdownloads\.} - problem "Don't use prdownloads in SourceForge urls (url is #{url}).\n" \ - "\tSee: http://librelist.com/browser/homebrew/2011/1/12/prdownloads-is-bad/" + problem <<-EOS.undent.chomp + Don't use prdownloads in SourceForge urls (url is #{url}). + See: http://librelist.com/browser/homebrew/2011/1/12/prdownloads-is-bad/ + EOS end if url =~ %r{^http://\w+\.dl\.} diff --git a/Library/Homebrew/test/rubocops/patches_cop_spec.rb b/Library/Homebrew/test/rubocops/patches_cop_spec.rb index 4bd79bf357..092782bfb1 100644 --- a/Library/Homebrew/test/rubocops/patches_cop_spec.rb +++ b/Library/Homebrew/test/rubocops/patches_cop_spec.rb @@ -62,34 +62,48 @@ describe RuboCop::Cop::FormulaAudit::Patches do inspect_source(cop, source) if patch_url =~ %r{/raw\.github\.com/} - expected_offenses = [{ message: "GitHub/Gist patches should specify a revision:\n#{patch_url}", + expected_offenses = [{ message: <<-EOS.undent.chomp, + GitHub/Gist patches should specify a revision: + #{patch_url} + EOS severity: :convention, line: 5, column: 12, source: source }] elsif patch_url =~ %r{macports/trunk} - expected_offenses = [{ message: "MacPorts patches should specify a revision instead of trunk:\n#{patch_url}", + expected_offenses = [{ message: <<-EOS.undent.chomp, + MacPorts patches should specify a revision instead of trunk: + #{patch_url} + EOS severity: :convention, line: 5, column: 33, source: source }] elsif patch_url =~ %r{^http://trac\.macports\.org} - expected_offenses = [{ message: "Patches from MacPorts Trac should be https://, not http:\n#{patch_url}", + expected_offenses = [{ message: <<-EOS.undent.chomp, + Patches from MacPorts Trac should be https://, not http: + #{patch_url} + EOS severity: :convention, line: 5, column: 5, source: source }] elsif patch_url =~ %r{^http://bugs\.debian\.org} - expected_offenses = [{ message: "Patches from Debian should be https://, not http:\n#{patch_url}", + expected_offenses = [{ message: <<-EOS.undent.chomp, + Patches from Debian should be https://, not http: + #{patch_url} + EOS severity: :convention, line: 5, column: 5, source: source }] elsif patch_url =~ %r{https?://patch-diff\.githubusercontent\.com/raw/(.+)/(.+)/pull/(.+)\.(?:diff|patch)} - expected_offenses = [{ message: "use GitHub pull request URLs:\n"\ - " https://github.com/foo/foo-bar/pull/100.patch\n"\ - "Rather than patch-diff:\n"\ - " https://patch-diff.githubusercontent.com/raw/foo/foo-bar/pull/100.patch\n", + expected_offenses = [{ message: <<-EOS.undent, + use GitHub pull request URLs: + https://github.com/foo/foo-bar/pull/100.patch + Rather than patch-diff: + https://patch-diff.githubusercontent.com/raw/foo/foo-bar/pull/100.patch + EOS severity: :convention, line: 5, column: 5, @@ -121,8 +135,10 @@ describe RuboCop::Cop::FormulaAudit::Patches do line: 4, column: 2, source: source }, - { message: "Patches from MacPorts Trac should be https://, not http:\n"\ - "http://trac.macports.org/export/68507/trunk/dports/net/trafshow/files/", + { message: <<-EOS.undent.chomp, + Patches from MacPorts Trac should be https://, not http: + http://trac.macports.org/export/68507/trunk/dports/net/trafshow/files/ + EOS severity: :convention, line: 8, column: 26, @@ -159,34 +175,48 @@ describe RuboCop::Cop::FormulaAudit::Patches do inspect_source(cop, source) if patch_url =~ %r{/raw\.github\.com/} - expected_offenses = [{ message: "GitHub/Gist patches should specify a revision:\n#{patch_url}", + expected_offenses = [{ message: <<-EOS.undent.chomp, + GitHub/Gist patches should specify a revision: + #{patch_url} + EOS severity: :convention, line: 5, column: 16, source: source }] elsif patch_url =~ %r{macports/trunk} - expected_offenses = [{ message: "MacPorts patches should specify a revision instead of trunk:\n#{patch_url}", + expected_offenses = [{ message: <<-EOS.undent.chomp, + MacPorts patches should specify a revision instead of trunk: + #{patch_url} + EOS severity: :convention, line: 5, column: 37, source: source }] elsif patch_url =~ %r{^http://trac\.macports\.org} - expected_offenses = [{ message: "Patches from MacPorts Trac should be https://, not http:\n#{patch_url}", + expected_offenses = [{ message: <<-EOS.undent.chomp, + Patches from MacPorts Trac should be https://, not http: + #{patch_url} + EOS severity: :convention, line: 5, column: 9, source: source }] elsif patch_url =~ %r{^http://bugs\.debian\.org} - expected_offenses = [{ message: "Patches from Debian should be https://, not http:\n#{patch_url}", + expected_offenses = [{ message: <<-EOS.undent.chomp, + Patches from Debian should be https://, not http: + #{patch_url} + EOS severity: :convention, line: 5, column: 9, source: source }] elsif patch_url =~ %r{https?://patch-diff\.githubusercontent\.com/raw/(.+)/(.+)/pull/(.+)\.(?:diff|patch)} - expected_offenses = [{ message: "use GitHub pull request URLs:\n"\ - " https://github.com/foo/foo-bar/pull/100.patch\n"\ - "Rather than patch-diff:\n"\ - " https://patch-diff.githubusercontent.com/raw/foo/foo-bar/pull/100.patch\n", + expected_offenses = [{ message: <<-EOS.undent, + use GitHub pull request URLs: + https://github.com/foo/foo-bar/pull/100.patch + Rather than patch-diff: + https://patch-diff.githubusercontent.com/raw/foo/foo-bar/pull/100.patch + EOS severity: :convention, line: 5, column: 9, diff --git a/Library/Homebrew/test/rubocops/urls_cop_spec.rb b/Library/Homebrew/test/rubocops/urls_cop_spec.rb index 280da6314c..e51fb6be0e 100644 --- a/Library/Homebrew/test/rubocops/urls_cop_spec.rb +++ b/Library/Homebrew/test/rubocops/urls_cop_spec.rb @@ -54,8 +54,10 @@ describe RuboCop::Cop::FormulaAudit::Urls do "col" => 2, }, { "url" => "http://prdownloads.sourceforge.net/foo/foo-1.tar.gz", - "msg" => "Don't use prdownloads in SourceForge urls (url is http://prdownloads.sourceforge.net/foo/foo-1.tar.gz).\n" \ - "\tSee: http://librelist.com/browser/homebrew/2011/1/12/prdownloads-is-bad/", + "msg" => <<-EOS.undent.chomp, + Don't use prdownloads in SourceForge urls (url is http://prdownloads.sourceforge.net/foo/foo-1.tar.gz). + See: http://librelist.com/browser/homebrew/2011/1/12/prdownloads-is-bad/ + EOS "col" => 2, }, { "url" => "http://foo.dl.sourceforge.net/sourceforge/foozip/foozip_1.0.tar.bz2", @@ -67,8 +69,11 @@ describe RuboCop::Cop::FormulaAudit::Urls do "col" => 2, }, { "url" => "http://http.debian.net/debian/dists/foo/", - "msg" => "Please use a secure mirror for Debian URLs.\nWe recommend:\n"\ - " https://mirrors.ocf.berkeley.edu/debian/dists/foo/\n", + "msg" => <<-EOS.undent, + Please use a secure mirror for Debian URLs. + We recommend: + https://mirrors.ocf.berkeley.edu/debian/dists/foo/ + EOS "col" => 2, }, { "url" => "http://foo.googlecode.com/files/foo-1.0.zip", @@ -96,8 +101,12 @@ describe RuboCop::Cop::FormulaAudit::Urls do "col" => 2, }, { "url" => "https://codeload.github.com/foo/bar/tar.gz/v0.1.1", - "msg" => "Use GitHub archive URLs:\n https://github.com/foo/bar/archive/v0.1.1.tar.gz\n"\ - "Rather than codeload:\n https://codeload.github.com/foo/bar/tar.gz/v0.1.1\n", + "msg" => <<-EOS.undent, + Use GitHub archive URLs: + https://github.com/foo/bar/archive/v0.1.1.tar.gz + Rather than codeload: + https://codeload.github.com/foo/bar/tar.gz/v0.1.1 + EOS "col" => 2, }, { "url" => "https://central.maven.org/maven2/com/bar/foo/1.1/foo-1.1.jar", From 7a93638105474c8e17a115dd2c16ae52f8f6806f Mon Sep 17 00:00:00 2001 From: Ben Muschol Date: Thu, 17 Aug 2017 11:40:32 -0400 Subject: [PATCH 056/294] Make test more resilient --- Library/Homebrew/test/utils/github_spec.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Library/Homebrew/test/utils/github_spec.rb b/Library/Homebrew/test/utils/github_spec.rb index 0b19c8c9e9..7bfb4a9308 100644 --- a/Library/Homebrew/test/utils/github_spec.rb +++ b/Library/Homebrew/test/utils/github_spec.rb @@ -32,8 +32,8 @@ describe GitHub do describe "::search_issues", :needs_network do it "queries GitHub issues with the passed parameters" do results = subject.search_issues("brew search", repo: "Homebrew/brew", author: "avetamine", is: "closed") - expect(results.count).to eq(1) - expect(results.first["title"]).to eq("brew search : 422 Unprocessable Entity") + expect(results.count).to be > 1 + expect(results.last["title"]).to eq("brew search : 422 Unprocessable Entity") end end end From e096836b7b46e605fb4d1c10c632157dd6b11186 Mon Sep 17 00:00:00 2001 From: Ben Muschol Date: Thu, 17 Aug 2017 11:57:58 -0400 Subject: [PATCH 057/294] Improve rspec readability --- Library/Homebrew/test/utils/github_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Library/Homebrew/test/utils/github_spec.rb b/Library/Homebrew/test/utils/github_spec.rb index 7bfb4a9308..151b6430d1 100644 --- a/Library/Homebrew/test/utils/github_spec.rb +++ b/Library/Homebrew/test/utils/github_spec.rb @@ -32,7 +32,7 @@ describe GitHub do describe "::search_issues", :needs_network do it "queries GitHub issues with the passed parameters" do results = subject.search_issues("brew search", repo: "Homebrew/brew", author: "avetamine", is: "closed") - expect(results.count).to be > 1 + expect(results.count).not_to be_empty expect(results.last["title"]).to eq("brew search : 422 Unprocessable Entity") end end From 564a06dfbb711a995558c64c55b353d1fdfcb473 Mon Sep 17 00:00:00 2001 From: Ben Muschol Date: Thu, 17 Aug 2017 13:44:18 -0400 Subject: [PATCH 058/294] Fix typo in spec --- Library/Homebrew/test/utils/github_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Library/Homebrew/test/utils/github_spec.rb b/Library/Homebrew/test/utils/github_spec.rb index 151b6430d1..9322898eee 100644 --- a/Library/Homebrew/test/utils/github_spec.rb +++ b/Library/Homebrew/test/utils/github_spec.rb @@ -32,7 +32,7 @@ describe GitHub do describe "::search_issues", :needs_network do it "queries GitHub issues with the passed parameters" do results = subject.search_issues("brew search", repo: "Homebrew/brew", author: "avetamine", is: "closed") - expect(results.count).not_to be_empty + expect(results).not_to be_empty expect(results.last["title"]).to eq("brew search : 422 Unprocessable Entity") end end From ca05c7f010ed952b316fe541f94a8fc2a83446ec Mon Sep 17 00:00:00 2001 From: Ben Muschol Date: Thu, 17 Aug 2017 14:38:50 -0400 Subject: [PATCH 059/294] Change var name --- Library/Homebrew/utils/github.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Library/Homebrew/utils/github.rb b/Library/Homebrew/utils/github.rb index cff292598a..578d967a49 100644 --- a/Library/Homebrew/utils/github.rb +++ b/Library/Homebrew/utils/github.rb @@ -267,13 +267,13 @@ module GitHub end def query_string(*main_params, **qualifiers) - params_list = main_params + params = main_params - params_list += qualifiers.flat_map do |key, value| + params += qualifiers.flat_map do |key, value| Array(value).map { |v| "#{key}:#{v}" } end - "q=#{URI.encode_www_form_component(params_list.join(" "))}&per_page=100" + "q=#{URI.encode_www_form_component(params.join(" "))}&per_page=100" end def url_to(*subroutes) From f28430049512dd1e82261779e91ae30434c24b25 Mon Sep 17 00:00:00 2001 From: Francisco Souza Date: Sat, 19 Aug 2017 19:59:33 -0400 Subject: [PATCH 060/294] Skip search_remote on cask search when HOMEBREW_NO_GITHUB_API is set Fixes #3069. --- Library/Homebrew/cask/lib/hbc/cli/search.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/Library/Homebrew/cask/lib/hbc/cli/search.rb b/Library/Homebrew/cask/lib/hbc/cli/search.rb index e89dced925..b299f03ce5 100644 --- a/Library/Homebrew/cask/lib/hbc/cli/search.rb +++ b/Library/Homebrew/cask/lib/hbc/cli/search.rb @@ -15,6 +15,7 @@ module Hbc end def self.search_remote(query) + return [] if ENV["HOMEBREW_NO_GITHUB_API"] matches = GitHub.search_code(user: "caskroom", path: "Casks", filename: query, extension: "rb") matches.map do |match| From 56ef168e7088962ba7b1cdc3da89d30842a8eb69 Mon Sep 17 00:00:00 2001 From: Markus Reiter Date: Sun, 20 Aug 2017 16:23:15 +0200 Subject: [PATCH 061/294] Move fix from #3070 inside `GitHub` module. --- Library/Homebrew/cask/lib/hbc/cli/search.rb | 1 - Library/Homebrew/utils/github.rb | 6 ++---- 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/Library/Homebrew/cask/lib/hbc/cli/search.rb b/Library/Homebrew/cask/lib/hbc/cli/search.rb index b299f03ce5..e89dced925 100644 --- a/Library/Homebrew/cask/lib/hbc/cli/search.rb +++ b/Library/Homebrew/cask/lib/hbc/cli/search.rb @@ -15,7 +15,6 @@ module Hbc end def self.search_remote(query) - return [] if ENV["HOMEBREW_NO_GITHUB_API"] matches = GitHub.search_code(user: "caskroom", path: "Casks", filename: query, extension: "rb") matches.map do |match| diff --git a/Library/Homebrew/utils/github.rb b/Library/Homebrew/utils/github.rb index 578d967a49..a1cf5fbbac 100644 --- a/Library/Homebrew/utils/github.rb +++ b/Library/Homebrew/utils/github.rb @@ -133,7 +133,7 @@ module GitHub def open(url, data: nil, scopes: [].freeze) # This is a no-op if the user is opting out of using the GitHub API. - return if ENV["HOMEBREW_NO_GITHUB_API"] + return block_given? ? yield({}) : {} if ENV["HOMEBREW_NO_GITHUB_API"] args = %W[--header application/vnd.github.v3+json --write-out \n%{http_code}] args += curl_args @@ -245,8 +245,6 @@ module GitHub end def print_pull_requests_matching(query) - return [] if ENV["HOMEBREW_NO_GITHUB_API"] - open_or_closed_prs = search_issues(query, type: "pr") open_prs = open_or_closed_prs.select { |i| i["state"] == "open" } @@ -283,6 +281,6 @@ module GitHub def search(entity, *queries, **qualifiers) uri = url_to "search", entity uri.query = query_string(*queries, **qualifiers) - open(uri) { |json| Array(json["items"]) } + open(uri) { |json| json.fetch("items", []) } end end From 15e572702e8dbd998e31aec110bce3cc0c9df811 Mon Sep 17 00:00:00 2001 From: Markus Reiter Date: Mon, 21 Aug 2017 19:32:16 +0200 Subject: [PATCH 062/294] Fix `pull`. --- Library/Homebrew/dev-cmd/pull.rb | 2 +- Library/Homebrew/utils/curl.rb | 7 +++---- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/Library/Homebrew/dev-cmd/pull.rb b/Library/Homebrew/dev-cmd/pull.rb index dd2bc62707..a8f35531f9 100644 --- a/Library/Homebrew/dev-cmd/pull.rb +++ b/Library/Homebrew/dev-cmd/pull.rb @@ -587,7 +587,7 @@ module Homebrew # We're in the cache; make sure to force re-download loop do begin - curl_download url, to: filename + curl_download url, continue_at: 0, to: filename break rescue if retry_count >= max_curl_retries diff --git a/Library/Homebrew/utils/curl.rb b/Library/Homebrew/utils/curl.rb index 52d03c93e9..bc7055c0c3 100644 --- a/Library/Homebrew/utils/curl.rb +++ b/Library/Homebrew/utils/curl.rb @@ -37,13 +37,12 @@ def curl(*args) safe_system(*curl_args(*args)) end -def curl_download(*args, to: nil, **options) - continue_at ||= "-" - curl("--location", "--remote-time", "--continue-at", continue_at, "--output", to, *args, **options) +def curl_download(*args, to: nil, continue_at: "-", **options) + curl("--location", "--remote-time", "--continue-at", continue_at.to_s, "--output", to, *args, **options) rescue ErrorDuringExecution # `curl` error 33: HTTP server doesn't seem to support byte ranges. Cannot resume. if $CHILD_STATUS.exitstatus == 33 && continue_at == "-" - continue_at = "0" + continue_at = 0 retry end From c53af2952e2ea60b47951ed4b74295be37cfc79d Mon Sep 17 00:00:00 2001 From: Camden Narzt Date: Mon, 21 Aug 2017 10:51:19 -0600 Subject: [PATCH 063/294] Fix curl --user flag being broken in dc5a2c17 --- Library/Homebrew/download_strategy.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Library/Homebrew/download_strategy.rb b/Library/Homebrew/download_strategy.rb index 2a8b6e5859..adeb0a02ad 100644 --- a/Library/Homebrew/download_strategy.rb +++ b/Library/Homebrew/download_strategy.rb @@ -381,7 +381,7 @@ class CurlDownloadStrategy < AbstractFileDownloadStrategy # Curl options to be always passed to curl, # with raw head calls (`curl --head`) or with actual `fetch`. def _curl_opts - return ["--user" << meta.fetch(:user)] if meta.key?(:user) + return ["--user", meta.fetch(:user)] if meta.key?(:user) [] end From ab8a6f31e81ab294c599f1137683c3489ebab0f7 Mon Sep 17 00:00:00 2001 From: Camden Narzt Date: Mon, 21 Aug 2017 11:13:25 -0600 Subject: [PATCH 064/294] Add test --- Library/Homebrew/test/download_strategies_spec.rb | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/Library/Homebrew/test/download_strategies_spec.rb b/Library/Homebrew/test/download_strategies_spec.rb index 8c376a6493..07e18ffd0b 100644 --- a/Library/Homebrew/test/download_strategies_spec.rb +++ b/Library/Homebrew/test/download_strategies_spec.rb @@ -200,6 +200,17 @@ describe GitDownloadStrategy do end end +describe CurlDownloadStrategy do + subject { described_class.new(name, resource) } + let(:name) { "foo" } + let(:url) { "http://example.com/foo.tar.gz" } + let(:resource) { double(Resource, url: url, mirrors: [], specs: {user: "download:123456"}, version: nil) } + + it "parses the opts and sets the corresponding args" do + expect(subject.send(:_curl_opts)).to eq(["--user","download:123456"]) + end +end + describe DownloadStrategyDetector do describe "::detect" do subject { described_class.detect(url) } From c9f4d1c35df6bedc9c6c017a27d618055b5aeeca Mon Sep 17 00:00:00 2001 From: Camden Narzt Date: Mon, 21 Aug 2017 19:25:37 -0600 Subject: [PATCH 065/294] style --- Library/Homebrew/test/download_strategies_spec.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Library/Homebrew/test/download_strategies_spec.rb b/Library/Homebrew/test/download_strategies_spec.rb index 07e18ffd0b..06d6fa855c 100644 --- a/Library/Homebrew/test/download_strategies_spec.rb +++ b/Library/Homebrew/test/download_strategies_spec.rb @@ -204,10 +204,10 @@ describe CurlDownloadStrategy do subject { described_class.new(name, resource) } let(:name) { "foo" } let(:url) { "http://example.com/foo.tar.gz" } - let(:resource) { double(Resource, url: url, mirrors: [], specs: {user: "download:123456"}, version: nil) } + let(:resource) { double(Resource, url: url, mirrors: [], specs: { user: "download:123456" }, version: nil) } it "parses the opts and sets the corresponding args" do - expect(subject.send(:_curl_opts)).to eq(["--user","download:123456"]) + expect(subject.send(:_curl_opts)).to eq(["--user", "download:123456"]) end end From beb411fefc60b74d69c6a27bc1a04d7ae41eb9ca Mon Sep 17 00:00:00 2001 From: Dominyk Tiller Date: Tue, 22 Aug 2017 03:44:30 +0100 Subject: [PATCH 066/294] mac/xcode: update expected Clang on 10.13 --- Library/Homebrew/os/mac/xcode.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Library/Homebrew/os/mac/xcode.rb b/Library/Homebrew/os/mac/xcode.rb index 6f7deaa10c..37bc55a2fd 100644 --- a/Library/Homebrew/os/mac/xcode.rb +++ b/Library/Homebrew/os/mac/xcode.rb @@ -216,7 +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.34.1" + when "10.13" then "900.0.35" when "10.12" then "802.0.42" when "10.11" then "800.0.42.1" when "10.10" then "700.1.81" From b44c7a1022976a4fcd9e7ea9b6069ec971d6b235 Mon Sep 17 00:00:00 2001 From: Viktor Szakats Date: Tue, 22 Aug 2017 10:31:21 +0000 Subject: [PATCH 067/294] upgrade more urls to https --- Library/Homebrew/cmd/search.rb | 2 +- Library/Homebrew/extend/fileutils.rb | 2 +- Library/Homebrew/extend/pathname.rb | 2 +- Library/Homebrew/test/cmd/search_spec.rb | 2 +- docs/Formula-Cookbook.md | 2 +- docs/Prose-Style-Guidelines.md | 2 +- 6 files changed, 6 insertions(+), 6 deletions(-) diff --git a/Library/Homebrew/cmd/search.rb b/Library/Homebrew/cmd/search.rb index 0718a3af4c..4a3e21971b 100644 --- a/Library/Homebrew/cmd/search.rb +++ b/Library/Homebrew/cmd/search.rb @@ -36,7 +36,7 @@ module Homebrew elsif ARGV.include? "--fedora" exec_browser "https://apps.fedoraproject.org/packages/s/#{ARGV.next}" elsif ARGV.include? "--ubuntu" - exec_browser "http://packages.ubuntu.com/search?keywords=#{ARGV.next}&searchon=names&suite=all§ion=all" + exec_browser "https://packages.ubuntu.com/search?keywords=#{ARGV.next}&searchon=names&suite=all§ion=all" elsif ARGV.include? "--desc" query = ARGV.next regex = query_regexp(query) diff --git a/Library/Homebrew/extend/fileutils.rb b/Library/Homebrew/extend/fileutils.rb index 52d4cbf511..ed5bfe6c33 100644 --- a/Library/Homebrew/extend/fileutils.rb +++ b/Library/Homebrew/extend/fileutils.rb @@ -3,7 +3,7 @@ require "tmpdir" require "etc" # Homebrew extends Ruby's `FileUtils` to make our code more readable. -# @see http://ruby-doc.org/stdlib-2.0.0/libdoc/fileutils/rdoc/FileUtils.html Ruby's FileUtils API +# @see https://ruby-doc.org/stdlib-2.0.0/libdoc/fileutils/rdoc/FileUtils.html Ruby's FileUtils API module FileUtils # Create a temporary directory then yield. When the block returns, # recursively delete the temporary directory. Passing opts[:retain] diff --git a/Library/Homebrew/extend/pathname.rb b/Library/Homebrew/extend/pathname.rb index 767d83ff91..e1acd1f775 100644 --- a/Library/Homebrew/extend/pathname.rb +++ b/Library/Homebrew/extend/pathname.rb @@ -59,7 +59,7 @@ module DiskUsageExtension end # Homebrew extends Ruby's `Pathname` to make our code more readable. -# @see http://ruby-doc.org/stdlib-1.8.7/libdoc/pathname/rdoc/Pathname.html Ruby's Pathname API +# @see https://ruby-doc.org/stdlib-1.8.7/libdoc/pathname/rdoc/Pathname.html Ruby's Pathname API class Pathname include DiskUsageExtension diff --git a/Library/Homebrew/test/cmd/search_spec.rb b/Library/Homebrew/test/cmd/search_spec.rb index 77c2c63521..36ddde3e1d 100644 --- a/Library/Homebrew/test/cmd/search_spec.rb +++ b/Library/Homebrew/test/cmd/search_spec.rb @@ -53,7 +53,7 @@ describe "brew search", :integration_test do "debian" => "https://packages.debian.org/search?keywords=testball&searchon=names&suite=all§ion=all", "opensuse" => "https://software.opensuse.org/search?q=testball", "fedora" => "https://apps.fedoraproject.org/packages/s/testball", - "ubuntu" => "http://packages.ubuntu.com/search?keywords=testball&searchon=names&suite=all§ion=all", + "ubuntu" => "https://packages.ubuntu.com/search?keywords=testball&searchon=names&suite=all§ion=all", }.each do |flag, url| specify "--#{flag}" do expect { brew "search", "--#{flag}", "testball", "HOMEBREW_BROWSER" => "echo" } diff --git a/docs/Formula-Cookbook.md b/docs/Formula-Cookbook.md index e60afe071b..0266d39e53 100644 --- a/docs/Formula-Cookbook.md +++ b/docs/Formula-Cookbook.md @@ -693,7 +693,7 @@ Note that [`option`](http://www.rubydoc.info/github/Homebrew/brew/master/Formula ### File level operations -You can use the file utilities provided by Ruby's [`FileUtils`](http://www.ruby-doc.org/stdlib/libdoc/fileutils/rdoc/index.html). These are included in the `Formula` class, so you do not need the `FileUtils.` prefix to use them. +You can use the file utilities provided by Ruby's [`FileUtils`](https://www.ruby-doc.org/stdlib/libdoc/fileutils/rdoc/index.html). These are included in the `Formula` class, so you do not need the `FileUtils.` prefix to use them. When creating symlinks, take special care to ensure they are *relative* symlinks. This makes it easier to create a relocatable bottle. For example, to create a symlink in `bin` to an executable in `libexec`, use diff --git a/docs/Prose-Style-Guidelines.md b/docs/Prose-Style-Guidelines.md index 232ccb1bea..4fe19bdb82 100644 --- a/docs/Prose-Style-Guidelines.md +++ b/docs/Prose-Style-Guidelines.md @@ -16,7 +16,7 @@ Homebrew's audience includes users with a wide range of education and experience We strive for "correct" but not "fancy" usage. Think newspaper article, not academic paper. -This is a set of guidelines to be applied using human judgment, not a set of hard and fast rules. It is like [The Economist's Style Guide](http://www.economist.com/styleguide/introduction) or [Garner's Modern American Usage](https://en.wikipedia.org/wiki/Garner's_Modern_American_Usage). It is less like the [Ruby Style Guide](https://github.com/bbatsov/ruby-style-guide). All guidelines here are open to interpretation and discussion. 100% conformance to these guidelines is *not* a goal. +This is a set of guidelines to be applied using human judgment, not a set of hard and fast rules. It is like [The Economist's Style Guide](https://www.economist.com/styleguide/introduction) or [Garner's Modern American Usage](https://en.wikipedia.org/wiki/Garner's_Modern_American_Usage). It is less like the [Ruby Style Guide](https://github.com/bbatsov/ruby-style-guide). All guidelines here are open to interpretation and discussion. 100% conformance to these guidelines is *not* a goal. The intent of this document is to help authors make decisions about clarity, style, and consistency. It is not to help settle arguments about who knows English better. Don't use this document to be a jerk. From 9bc706f1fcc7bce3a71e63c11d98257e49cac76f Mon Sep 17 00:00:00 2001 From: puredanger Date: Tue, 22 Aug 2017 12:17:11 -0500 Subject: [PATCH 068/294] remove blacklisting of Clojure to allow adding a Clojure formula --- Library/Homebrew/missing_formula.rb | 9 --------- Library/Homebrew/test/missing_formula_spec.rb | 6 ------ 2 files changed, 15 deletions(-) diff --git a/Library/Homebrew/missing_formula.rb b/Library/Homebrew/missing_formula.rb index 4d90ddb618..c3625c8bb0 100644 --- a/Library/Homebrew/missing_formula.rb +++ b/Library/Homebrew/missing_formula.rb @@ -55,15 +55,6 @@ module Homebrew when "gsutil" then <<-EOS.undent Install gsutil with `pip install gsutil` EOS - when "clojure" then <<-EOS.undent - Clojure isn't really a program but a library managed as part of a - project and Leiningen is the user interface to that library. - - To install Clojure you should install Leiningen: - brew install leiningen - and then follow the tutorial: - #{Formatter.url("https://github.com/technomancy/leiningen/blob/stable/doc/TUTORIAL.md")} - EOS when "gfortran" then <<-EOS.undent GNU Fortran is now provided as part of GCC, and can be installed with: brew install gcc diff --git a/Library/Homebrew/test/missing_formula_spec.rb b/Library/Homebrew/test/missing_formula_spec.rb index a48f12ecd1..0a905004ba 100644 --- a/Library/Homebrew/test/missing_formula_spec.rb +++ b/Library/Homebrew/test/missing_formula_spec.rb @@ -82,12 +82,6 @@ describe Homebrew::MissingFormula do it { is_expected.to be_blacklisted } end - context "clojure" do - subject { "clojure" } - - it { is_expected.to be_blacklisted } - end - context "gfortran" do subject { "gfortran" } From 00803b1a0b2a302a84871a05ae2abbdfe7f01a5c Mon Sep 17 00:00:00 2001 From: Alexey Alekhin Date: Wed, 23 Aug 2017 03:23:33 +0200 Subject: [PATCH 069/294] brew cask search without query just outputs all available cask tokens --- Library/Homebrew/cask/lib/hbc/cli/search.rb | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/Library/Homebrew/cask/lib/hbc/cli/search.rb b/Library/Homebrew/cask/lib/hbc/cli/search.rb index e89dced925..42be4592ae 100644 --- a/Library/Homebrew/cask/lib/hbc/cli/search.rb +++ b/Library/Homebrew/cask/lib/hbc/cli/search.rb @@ -2,8 +2,12 @@ module Hbc class CLI class Search < AbstractCommand def run - results = self.class.search(*args) - self.class.render_results(*results) + if args.empty? + puts Formatter.columns(CLI.nice_listing(Hbc.all_tokens)) + else + results = self.class.search(*args) + self.class.render_results(*results) + end end def self.extract_regexp(string) From a5640fdfeeea7347e51c14abac481f4b210527ab Mon Sep 17 00:00:00 2001 From: Alexey Alekhin Date: Wed, 23 Aug 2017 16:54:21 +0200 Subject: [PATCH 070/294] Added rescue block for the remote cask search failure --- Library/Homebrew/cask/lib/hbc/cli/search.rb | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/Library/Homebrew/cask/lib/hbc/cli/search.rb b/Library/Homebrew/cask/lib/hbc/cli/search.rb index 42be4592ae..9f4f9f31d1 100644 --- a/Library/Homebrew/cask/lib/hbc/cli/search.rb +++ b/Library/Homebrew/cask/lib/hbc/cli/search.rb @@ -19,8 +19,18 @@ module Hbc end def self.search_remote(query) - matches = GitHub.search_code(user: "caskroom", path: "Casks", - filename: query, extension: "rb") + matches = begin GitHub.search_code( + user: "caskroom", + path: "Casks", + filename: query, + extension: "rb" + ) + rescue Exception => e + onoe e + $stderr.puts e.backtrace + [] + end + matches.map do |match| tap = Tap.fetch(match["repository"]["full_name"]) next if tap.installed? From 9e2caa8d6a55c0c48c46d916520ab827a23f504e Mon Sep 17 00:00:00 2001 From: Alexey Alekhin Date: Wed, 23 Aug 2017 17:54:01 +0200 Subject: [PATCH 071/294] Fixed style issues --- Library/Homebrew/cask/lib/hbc/cli/search.rb | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/Library/Homebrew/cask/lib/hbc/cli/search.rb b/Library/Homebrew/cask/lib/hbc/cli/search.rb index 9f4f9f31d1..fbc2487ae2 100644 --- a/Library/Homebrew/cask/lib/hbc/cli/search.rb +++ b/Library/Homebrew/cask/lib/hbc/cli/search.rb @@ -23,14 +23,13 @@ module Hbc user: "caskroom", path: "Casks", filename: query, - extension: "rb" + extension: "rb", ) - rescue Exception => e + rescue StandardError => e onoe e $stderr.puts e.backtrace [] end - matches.map do |match| tap = Tap.fetch(match["repository"]["full_name"]) next if tap.installed? From f0605f4a30ae1125ad2e3d8187a45af09b24def0 Mon Sep 17 00:00:00 2001 From: Mike McQuaid Date: Wed, 23 Aug 2017 18:40:30 +0100 Subject: [PATCH 072/294] audit: don't output when searching taps. This messaging was added for the `brew search` command and having it in audit is annoying: (https://github.com/Homebrew/brew/pull/3059#issuecomment-323638672) As a side note: this is why randomly including `cmd/*` is a bad idea. --- Library/Homebrew/cmd/search.rb | 6 ++++-- Library/Homebrew/dev-cmd/audit.rb | 2 +- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/Library/Homebrew/cmd/search.rb b/Library/Homebrew/cmd/search.rb index 4a3e21971b..acee9817fd 100644 --- a/Library/Homebrew/cmd/search.rb +++ b/Library/Homebrew/cmd/search.rb @@ -102,11 +102,13 @@ module Homebrew odie "#{query} is not a valid regex" end - def search_taps(query) + def search_taps(query, silent: false) return [] if ENV["HOMEBREW_NO_GITHUB_API"] # Use stderr to avoid breaking parsed output - $stderr.puts Formatter.headline("Searching taps on GitHub...", color: :blue) + unless silent + $stderr.puts Formatter.headline("Searching taps on GitHub...", color: :blue) + end valid_dirnames = ["Formula", "HomebrewFormula", "Casks", "."].freeze matches = GitHub.search_code(user: ["Homebrew", "caskroom"], filename: query, extension: "rb") diff --git a/Library/Homebrew/dev-cmd/audit.rb b/Library/Homebrew/dev-cmd/audit.rb index 170fb6d5f5..89a6fb0090 100644 --- a/Library/Homebrew/dev-cmd/audit.rb +++ b/Library/Homebrew/dev-cmd/audit.rb @@ -412,7 +412,7 @@ class FormulaAuditor same_name_tap_formulae = @@local_official_taps_name_map[name] || [] if @online - Homebrew.search_taps(name).each do |tap_formula_full_name| + Homebrew.search_taps(name, silent: true).each do |tap_formula_full_name| tap_formula_name = tap_formula_full_name.split("/").last next if tap_formula_name != name same_name_tap_formulae << tap_formula_full_name From 15d2a9c7cd2ab37ec7b790ad1c0a4aa653826a60 Mon Sep 17 00:00:00 2001 From: Alexey Alekhin Date: Wed, 23 Aug 2017 19:47:47 +0200 Subject: [PATCH 073/294] Formatting fix --- Library/Homebrew/cask/lib/hbc/cli/search.rb | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/Library/Homebrew/cask/lib/hbc/cli/search.rb b/Library/Homebrew/cask/lib/hbc/cli/search.rb index fbc2487ae2..2b290bbdf2 100644 --- a/Library/Homebrew/cask/lib/hbc/cli/search.rb +++ b/Library/Homebrew/cask/lib/hbc/cli/search.rb @@ -19,12 +19,13 @@ module Hbc end def self.search_remote(query) - matches = begin GitHub.search_code( - user: "caskroom", - path: "Casks", - filename: query, - extension: "rb", - ) + matches = begin + GitHub.search_code( + user: "caskroom", + path: "Casks", + filename: query, + extension: "rb", + ) rescue StandardError => e onoe e $stderr.puts e.backtrace From 2cc6ef48ff6927db568616d2099b9d8163b90652 Mon Sep 17 00:00:00 2001 From: Alexey Alekhin Date: Thu, 24 Aug 2017 00:29:22 +0200 Subject: [PATCH 074/294] Narrowed rescued error type --- Library/Homebrew/cask/lib/hbc/cli/search.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Library/Homebrew/cask/lib/hbc/cli/search.rb b/Library/Homebrew/cask/lib/hbc/cli/search.rb index 2b290bbdf2..785f4b4b11 100644 --- a/Library/Homebrew/cask/lib/hbc/cli/search.rb +++ b/Library/Homebrew/cask/lib/hbc/cli/search.rb @@ -26,7 +26,7 @@ module Hbc filename: query, extension: "rb", ) - rescue StandardError => e + rescue GitHub::Error => e onoe e $stderr.puts e.backtrace [] From 00eb4324de2035e417344b7b7a2cac6e5a8f29a5 Mon Sep 17 00:00:00 2001 From: Frederick Akalin Date: Sat, 19 Aug 2017 17:08:07 -0700 Subject: [PATCH 075/294] Update FAQ entry --- docs/FAQ.md | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/docs/FAQ.md b/docs/FAQ.md index 788c496262..053c1f971a 100644 --- a/docs/FAQ.md +++ b/docs/FAQ.md @@ -68,13 +68,15 @@ Be careful as this is a destructive operation. Which is usually: `~/Library/Caches/Homebrew` ## My Mac `.app`s don’t find `/usr/local/bin` utilities! -GUI apps on macOS don’t have `/usr/local/bin` in their `PATH` by default. -If you’re on Mountain Lion, you can fix this by running -`launchctl setenv PATH "/usr/local/bin:$PATH"`. [More details -here](https://stackoverflow.com/questions/135688/setting-environment-variables-in-os-x/5444960#5444960), -including how to set this across reboots. If you’re pre-Mountain Lion, -[here’s an official -alternative](https://developer.apple.com/legacy/library/qa/qa1067/_index.html). +GUI apps on macOS don’t have `/usr/local/bin` in their `PATH` by +default. If you're on Mountain Lion or later, you can fix this by +running `sudo launchctl config user path "/usr/local/bin:$PATH"` and +then rebooting. Note that this sets the launchctl PATH for _all users_ +([more details here](https://apple.stackexchange.com/a/198282)). For +earlier versions, +see [this page](https://stackoverflow.com/a/5444960/7869253), +or +[this page](https://developer.apple.com/legacy/library/qa/qa1067/_index.html). ## How do I contribute to Homebrew? Read [CONTRIBUTING.md](https://github.com/Homebrew/brew/blob/master/CONTRIBUTING.md). From 6f76627943e042049f159acdd9af2fab6942abcf Mon Sep 17 00:00:00 2001 From: Frederick Akalin Date: Tue, 22 Aug 2017 18:18:19 -0700 Subject: [PATCH 076/294] Just have the Apple documentation link --- docs/FAQ.md | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/docs/FAQ.md b/docs/FAQ.md index 053c1f971a..c874c27cf0 100644 --- a/docs/FAQ.md +++ b/docs/FAQ.md @@ -73,9 +73,7 @@ default. If you're on Mountain Lion or later, you can fix this by running `sudo launchctl config user path "/usr/local/bin:$PATH"` and then rebooting. Note that this sets the launchctl PATH for _all users_ ([more details here](https://apple.stackexchange.com/a/198282)). For -earlier versions, -see [this page](https://stackoverflow.com/a/5444960/7869253), -or +earlier versions of macOS, see [this page](https://developer.apple.com/legacy/library/qa/qa1067/_index.html). ## How do I contribute to Homebrew? From 94c56a88d9101c60478c7cf60fb01bbcfd44a66b Mon Sep 17 00:00:00 2001 From: Frederick Akalin Date: Wed, 23 Aug 2017 15:53:51 -0700 Subject: [PATCH 077/294] Fix apostrophe --- docs/FAQ.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/FAQ.md b/docs/FAQ.md index c874c27cf0..632b4bdf3b 100644 --- a/docs/FAQ.md +++ b/docs/FAQ.md @@ -69,7 +69,7 @@ Which is usually: `~/Library/Caches/Homebrew` ## My Mac `.app`s don’t find `/usr/local/bin` utilities! GUI apps on macOS don’t have `/usr/local/bin` in their `PATH` by -default. If you're on Mountain Lion or later, you can fix this by +default. If you’re on Mountain Lion or later, you can fix this by running `sudo launchctl config user path "/usr/local/bin:$PATH"` and then rebooting. Note that this sets the launchctl PATH for _all users_ ([more details here](https://apple.stackexchange.com/a/198282)). For From 661995238a42ad5fa363797e323d837cbcfa579d Mon Sep 17 00:00:00 2001 From: Frederick Akalin Date: Wed, 23 Aug 2017 15:56:00 -0700 Subject: [PATCH 078/294] Change to man page reference --- docs/FAQ.md | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/docs/FAQ.md b/docs/FAQ.md index 632b4bdf3b..9d76bf4ab6 100644 --- a/docs/FAQ.md +++ b/docs/FAQ.md @@ -71,9 +71,8 @@ Which is usually: `~/Library/Caches/Homebrew` GUI apps on macOS don’t have `/usr/local/bin` in their `PATH` by default. If you’re on Mountain Lion or later, you can fix this by running `sudo launchctl config user path "/usr/local/bin:$PATH"` and -then rebooting. Note that this sets the launchctl PATH for _all users_ -([more details here](https://apple.stackexchange.com/a/198282)). For -earlier versions of macOS, see +then rebooting, as documented in `man launchctl`. Note that this sets +the launchctl PATH for _all users_. For earlier versions of macOS, see [this page](https://developer.apple.com/legacy/library/qa/qa1067/_index.html). ## How do I contribute to Homebrew? From 6676e4051cd354bf116904b09c62b8a6d36dbc1b Mon Sep 17 00:00:00 2001 From: Mike McQuaid Date: Thu, 24 Aug 2017 11:45:41 +0100 Subject: [PATCH 079/294] ISSUE_TEMPLATE: firm up language Try to be even clearer that we need you to read this. --- .github/ISSUE_TEMPLATE.md | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/.github/ISSUE_TEMPLATE.md b/.github/ISSUE_TEMPLATE.md index f4e56604e5..287e95b03a 100644 --- a/.github/ISSUE_TEMPLATE.md +++ b/.github/ISSUE_TEMPLATE.md @@ -1,17 +1,22 @@ +**Please note we will close your issue without comment if you delete, do not read or do not fill out the issue checklist below and provide ALL the requested information. If you repeatedly fail to use the issue template, we will block you from ever submitting issues to Homebrew again.** + # Please always follow these steps: -- [ ] Confirmed this is a problem with running a `brew` command and not `brew install`ing or the post-install behaviour of one or more formulae? If it's a formulae-specific problem please file this issue at https://github.com/Homebrew/homebrew-core/issues/new +- [ ] Confirmed this is a problem with running a `brew` command and not `brew install`ing or the post-install behaviour of one or more formulae? If it's a formulae-specific problem please file this issue at the relevant tap e.g. for Homebrew/homebrew-core https://github.com/Homebrew/homebrew-core/issues/new - [ ] Ran `brew update` and retried your prior step? - [ ] Ran `brew doctor`, fixed all issues and retried your prior step? - [ ] Ran `brew config` and `brew doctor` and included their output with your issue? -**Please note we will close your issue without comment if you delete or do not fill out the issue checklist and provide ALL the requested information.** - To help us debug your issue please explain: - What you were trying to do (and why) - What happened (include command output) - What you expected to happen - Step-by-step reproduction instructions (by running `brew` commands) -# Or propose a feature: -Please replace this section with a detailed description of your proposed feature, the motivation for it, how it would be relevant to at least 90% of Homebrew users and alternatives considered. -Please note we will close this issue or ask you to create a pull-request if it's something we're not actively planning to work on. +# Features +Please replace this section with: +- a detailed description of your proposed feature +- the motivation for the feature +- how the feature would be relevant to at least 90% of Homebrew users +- what alternatives to the feature you have considered + +We will close this issue or ask you to create a pull-request if it's something we're not actively planning to work on. From 7b96fd008e332949b9d53ffe08e9de20dbff0e2d Mon Sep 17 00:00:00 2001 From: Shaun Jackman Date: Fri, 25 Aug 2017 12:35:03 -0700 Subject: [PATCH 080/294] safe_fork: Improve the error message --- Library/Homebrew/utils/fork.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Library/Homebrew/utils/fork.rb b/Library/Homebrew/utils/fork.rb index 92f5bf899b..2f2a403e2a 100644 --- a/Library/Homebrew/utils/fork.rb +++ b/Library/Homebrew/utils/fork.rb @@ -38,7 +38,7 @@ module Utils Process.wait(pid) unless socket.nil? raise Marshal.load(data) unless data.nil? || data.empty? raise Interrupt if $CHILD_STATUS.exitstatus == 130 - raise "Suspicious failure" unless $CHILD_STATUS.success? + raise "Forked child process failed: #{$CHILD_STATUS}" unless $CHILD_STATUS.success? end end end From 3b7e0d8dbe3d9652b6d9a81f01bc3e68479b17bc Mon Sep 17 00:00:00 2001 From: Alexey Alekhin Date: Sat, 26 Aug 2017 01:54:24 +0200 Subject: [PATCH 081/294] Added tests for cask search with online search failure --- Library/Homebrew/test/cask/cli/search_spec.rb | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/Library/Homebrew/test/cask/cli/search_spec.rb b/Library/Homebrew/test/cask/cli/search_spec.rb index e237ad464f..e7065404d7 100644 --- a/Library/Homebrew/test/cask/cli/search_spec.rb +++ b/Library/Homebrew/test/cask/cli/search_spec.rb @@ -22,16 +22,29 @@ describe Hbc::CLI::Search, :cask do EOS end + it "returns matches even when online search failed" do + allow(GitHub).to receive(:search_code).and_raise(GitHub::Error.new("reason")) + expect { + Hbc::CLI::Search.run("local") + }.to output(<<-EOS.undent).to_stdout + local-caffeine + local-transmission + EOS + .and output(/^Error: reason\n/).to_stderr + end + it "shows that there are no Casks matching a search term that did not result in anything" do expect { Hbc::CLI::Search.run("foo-bar-baz") }.to output("No Cask found for \"foo-bar-baz\".\n").to_stdout.as_tty end - it "lists all available Casks with no search term" do + it "lists all Casks available offline with no search term" do + allow(GitHub).to receive(:search_code).and_raise(GitHub::Error.new("reason")) expect { Hbc::CLI::Search.run }.to output(/local-caffeine/).to_stdout.as_tty + .and not_to_output.to_stderr end it "ignores hyphens in search terms" do From 68c837f0412f0958817ee2d827b770f26d51bad6 Mon Sep 17 00:00:00 2001 From: Alexey Alekhin Date: Sat, 26 Aug 2017 02:01:08 +0200 Subject: [PATCH 082/294] Unified tests formatting for multiline output matching --- Library/Homebrew/test/cask/cli/search_spec.rb | 22 ++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/Library/Homebrew/test/cask/cli/search_spec.rb b/Library/Homebrew/test/cask/cli/search_spec.rb index e7065404d7..f3b693d991 100644 --- a/Library/Homebrew/test/cask/cli/search_spec.rb +++ b/Library/Homebrew/test/cask/cli/search_spec.rb @@ -36,7 +36,9 @@ describe Hbc::CLI::Search, :cask do it "shows that there are no Casks matching a search term that did not result in anything" do expect { Hbc::CLI::Search.run("foo-bar-baz") - }.to output("No Cask found for \"foo-bar-baz\".\n").to_stdout.as_tty + }.to output(<<-EOS.undent).to_stdout.as_tty + No Cask found for "foo-bar-baz". + EOS end it "lists all Casks available offline with no search term" do @@ -68,19 +70,29 @@ describe Hbc::CLI::Search, :cask do it "accepts a regexp argument" do expect { Hbc::CLI::Search.run("/^local-c[a-z]ffeine$/") - }.to output("==> Regexp Matches\nlocal-caffeine\n").to_stdout.as_tty + }.to output(<<-EOS.undent).to_stdout.as_tty + ==> Regexp Matches + local-caffeine + EOS end - it "Returns both exact and partial matches" do + it "returns both exact and partial matches" do expect { Hbc::CLI::Search.run("test-opera") - }.to output(/^==> Exact Match\ntest-opera\n==> Partial Matches\ntest-opera-mail/).to_stdout.as_tty + }.to output(<<-EOS.undent).to_stdout.as_tty + ==> Exact Match + test-opera + ==> Partial Matches + test-opera-mail + EOS end it "does not search the Tap name" do expect { Hbc::CLI::Search.run("caskroom") - }.to output(/^No Cask found for "caskroom"\.\n/).to_stdout.as_tty + }.to output(<<-EOS.undent).to_stdout.as_tty + No Cask found for "caskroom". + EOS end it "doesn't highlight packages that aren't installed" do From 29b0c7d7472dc26c8c8913db9a16e996ce68f6d2 Mon Sep 17 00:00:00 2001 From: Alexey Alekhin Date: Sat, 26 Aug 2017 02:05:35 +0200 Subject: [PATCH 083/294] Added a test for no-macthes output to non-TTY --- Library/Homebrew/test/cask/cli/search_spec.rb | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/Library/Homebrew/test/cask/cli/search_spec.rb b/Library/Homebrew/test/cask/cli/search_spec.rb index f3b693d991..48a4d556d7 100644 --- a/Library/Homebrew/test/cask/cli/search_spec.rb +++ b/Library/Homebrew/test/cask/cli/search_spec.rb @@ -41,6 +41,13 @@ describe Hbc::CLI::Search, :cask do EOS end + it "doesn't output anything to non-TTY stdout when there are no matches" do + expect { + Hbc::CLI::Search.run("foo-bar-baz") + }.to not_to_output.to_stdout + .and not_to_output.to_stderr + end + it "lists all Casks available offline with no search term" do allow(GitHub).to receive(:search_code).and_raise(GitHub::Error.new("reason")) expect { From abe47b79c898c49d762df5d0f52541722e8e202c Mon Sep 17 00:00:00 2001 From: Ben Muschol Date: Fri, 25 Aug 2017 20:25:58 -0400 Subject: [PATCH 084/294] Add check for HEAD ref in diagnostics --- Library/Homebrew/diagnostic.rb | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/Library/Homebrew/diagnostic.rb b/Library/Homebrew/diagnostic.rb index ceb6ad4d1d..55124b91e6 100644 --- a/Library/Homebrew/diagnostic.rb +++ b/Library/Homebrew/diagnostic.rb @@ -756,7 +756,7 @@ module Homebrew end end - def check_coretap_git_origin + def check_coretap_git_config coretap_path = CoreTap.instance.path return if !Utils.git_available? || !(coretap_path/".git").exist? @@ -785,6 +785,22 @@ module Homebrew git -C "#{coretap_path}" remote set-url origin #{Formatter.url("https://github.com/Homebrew/homebrew-core.git")} EOS end + + head = coretap_path.head + return unless head && head !~ %r{refs/heads/master} + + <<-EOS.undent + Suspicious #{CoreTap.instance} git head found. + + With a non-standard head, your local version of Homebrew might not + have all of the changes intended for the most recent release. The + current git head is: + #{head} + + Unless you have compelling reasons, consider setting the head to + point at the master branch by running: + git checkout master + EOS end def __check_linked_brew(f) From 2a3f83b8d4ceeca370a60bbcb494990a2bd20801 Mon Sep 17 00:00:00 2001 From: Alexey Alekhin Date: Sat, 26 Aug 2017 02:37:39 +0200 Subject: [PATCH 085/294] Changed online search failure to warning and removed stacktrace --- Library/Homebrew/cask/lib/hbc/cli/search.rb | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/Library/Homebrew/cask/lib/hbc/cli/search.rb b/Library/Homebrew/cask/lib/hbc/cli/search.rb index 785f4b4b11..8fb8b91ecc 100644 --- a/Library/Homebrew/cask/lib/hbc/cli/search.rb +++ b/Library/Homebrew/cask/lib/hbc/cli/search.rb @@ -26,9 +26,8 @@ module Hbc filename: query, extension: "rb", ) - rescue GitHub::Error => e - onoe e - $stderr.puts e.backtrace + rescue GitHub::Error => error + opoo "Online search failed: #{error}\n" [] end matches.map do |match| From 6ac0b9881de5a00a884ca5e59553583d1ada0fc5 Mon Sep 17 00:00:00 2001 From: Alexey Alekhin Date: Sat, 26 Aug 2017 02:43:28 +0200 Subject: [PATCH 086/294] Fixed test for the changed error message --- Library/Homebrew/test/cask/cli/search_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Library/Homebrew/test/cask/cli/search_spec.rb b/Library/Homebrew/test/cask/cli/search_spec.rb index 48a4d556d7..06f0b4b32c 100644 --- a/Library/Homebrew/test/cask/cli/search_spec.rb +++ b/Library/Homebrew/test/cask/cli/search_spec.rb @@ -30,7 +30,7 @@ describe Hbc::CLI::Search, :cask do local-caffeine local-transmission EOS - .and output(/^Error: reason\n/).to_stderr + .and output(/^Warning: Online search failed: reason/).to_stderr end it "shows that there are no Casks matching a search term that did not result in anything" do From b351c3f3ff960f3a3a61d5738eb9e126889aac30 Mon Sep 17 00:00:00 2001 From: Ben Muschol Date: Fri, 25 Aug 2017 21:04:23 -0400 Subject: [PATCH 087/294] Fix method name --- Library/Homebrew/diagnostic.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Library/Homebrew/diagnostic.rb b/Library/Homebrew/diagnostic.rb index 55124b91e6..d5f1a61f24 100644 --- a/Library/Homebrew/diagnostic.rb +++ b/Library/Homebrew/diagnostic.rb @@ -786,7 +786,7 @@ module Homebrew EOS end - head = coretap_path.head + head = coretap_path.git_head return unless head && head !~ %r{refs/heads/master} <<-EOS.undent From 7b31dd606288cbd976015efde61b6a6e2eb17a38 Mon Sep 17 00:00:00 2001 From: Ben Muschol Date: Sat, 26 Aug 2017 08:25:08 -0400 Subject: [PATCH 088/294] Prefer if over unless, simplify messaging --- Library/Homebrew/diagnostic.rb | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/Library/Homebrew/diagnostic.rb b/Library/Homebrew/diagnostic.rb index d5f1a61f24..8108c5da0b 100644 --- a/Library/Homebrew/diagnostic.rb +++ b/Library/Homebrew/diagnostic.rb @@ -787,19 +787,13 @@ module Homebrew end head = coretap_path.git_head - return unless head && head !~ %r{refs/heads/master} + return if head.nil? || head =~ %r{refs/heads/master} <<-EOS.undent - Suspicious #{CoreTap.instance} git head found. + Homebrew/homebrew-core is not on the master branch - With a non-standard head, your local version of Homebrew might not - have all of the changes intended for the most recent release. The - current git head is: - #{head} - - Unless you have compelling reasons, consider setting the head to - point at the master branch by running: - git checkout master + Check out the master branch by running: + git -C "$(brew --repo homebrew/core)" checkout master EOS end From d00c515dd8f9fced95a94ab373e0ee9bf5d74ac0 Mon Sep 17 00:00:00 2001 From: Gautham Goli Date: Fri, 25 Aug 2017 20:07:45 +0530 Subject: [PATCH 089/294] audit: Add previously unported GH patch audit rule in Patches cop --- Library/Homebrew/rubocops/patches_cop.rb | 12 +- .../test/rubocops/patches_cop_spec.rb | 222 +++++++++--------- 2 files changed, 127 insertions(+), 107 deletions(-) diff --git a/Library/Homebrew/rubocops/patches_cop.rb b/Library/Homebrew/rubocops/patches_cop.rb index b272833821..7ee1a127a3 100644 --- a/Library/Homebrew/rubocops/patches_cop.rb +++ b/Library/Homebrew/rubocops/patches_cop.rb @@ -25,12 +25,22 @@ module RuboCop def patch_problems(patch) patch_url = string_content(patch) + gh_patch_param_pattern = %r{https?://github\.com/.+/.+/(?:commit|pull)/[a-fA-F0-9]*.(?:patch|diff)} + if regex_match_group(patch, gh_patch_param_pattern) + if patch_url !~ /\?full_index=\w+$/ + problem <<-EOS.undent + GitHub patches should use the full_index parameter: + #{patch_url}?full_index=1 + EOS + end + end + gh_patch_patterns = Regexp.union([%r{/raw\.github\.com/}, %r{gist\.github\.com/raw}, %r{gist\.github\.com/.+/raw}, %r{gist\.githubusercontent\.com/.+/raw}]) if regex_match_group(patch, gh_patch_patterns) - unless patch_url =~ /[a-fA-F0-9]{40}/ + if patch_url !~ /[a-fA-F0-9]{40}/ problem <<-EOS.undent.chomp GitHub/Gist patches should specify a revision: #{patch_url} diff --git a/Library/Homebrew/test/rubocops/patches_cop_spec.rb b/Library/Homebrew/test/rubocops/patches_cop_spec.rb index 092782bfb1..28915a1ec9 100644 --- a/Library/Homebrew/test/rubocops/patches_cop_spec.rb +++ b/Library/Homebrew/test/rubocops/patches_cop_spec.rb @@ -28,11 +28,11 @@ describe RuboCop::Cop::FormulaAudit::Patches do end EOS - expected_offenses = [{ message: "Use the patch DSL instead of defining a 'patches' method", - severity: :convention, - line: 4, - column: 2, - source: source }] + expected_offenses = [{ message: "Use the patch DSL instead of defining a 'patches' method", + severity: :convention, + line: 4, + column: 2, + source: source }] inspect_source(cop, source) @@ -48,6 +48,7 @@ describe RuboCop::Cop::FormulaAudit::Patches do "http://trac.macports.org/export/102865/trunk/dports/mail/uudeview/files/inews.c.patch", "http://bugs.debian.org/cgi-bin/bugreport.cgi?msg=5;filename=patch-libunac1.txt;att=1;bug=623340", "https://patch-diff.githubusercontent.com/raw/foo/foo-bar/pull/100.patch", + "https://github.com/dlang/dub/pull/1221.patch", ] patch_urls.each do |patch_url| source = <<-EOS.undent @@ -61,55 +62,64 @@ describe RuboCop::Cop::FormulaAudit::Patches do EOS inspect_source(cop, source) - if patch_url =~ %r{/raw\.github\.com/} - expected_offenses = [{ message: <<-EOS.undent.chomp, - GitHub/Gist patches should specify a revision: - #{patch_url} - EOS - severity: :convention, - line: 5, - column: 12, - source: source }] + expected_offense = if patch_url =~ %r{/raw\.github\.com/} + [{ message: <<-EOS.undent.chomp, + GitHub/Gist patches should specify a revision: + #{patch_url} + EOS + severity: :convention, + line: 5, + column: 12, + source: source }] elsif patch_url =~ %r{macports/trunk} - expected_offenses = [{ message: <<-EOS.undent.chomp, - MacPorts patches should specify a revision instead of trunk: - #{patch_url} - EOS - severity: :convention, - line: 5, - column: 33, - source: source }] + [{ message: <<-EOS.undent.chomp, + MacPorts patches should specify a revision instead of trunk: + #{patch_url} + EOS + severity: :convention, + line: 5, + column: 33, + source: source }] elsif patch_url =~ %r{^http://trac\.macports\.org} - expected_offenses = [{ message: <<-EOS.undent.chomp, - Patches from MacPorts Trac should be https://, not http: - #{patch_url} - EOS - severity: :convention, - line: 5, - column: 5, - source: source }] + [{ message: <<-EOS.undent.chomp, + Patches from MacPorts Trac should be https://, not http: + #{patch_url} + EOS + severity: :convention, + line: 5, + column: 5, + source: source }] elsif patch_url =~ %r{^http://bugs\.debian\.org} - expected_offenses = [{ message: <<-EOS.undent.chomp, - Patches from Debian should be https://, not http: - #{patch_url} - EOS - severity: :convention, - line: 5, - column: 5, - source: source }] + [{ message: <<-EOS.undent.chomp, + Patches from Debian should be https://, not http: + #{patch_url} + EOS + severity: :convention, + line: 5, + column: 5, + source: source }] elsif patch_url =~ %r{https?://patch-diff\.githubusercontent\.com/raw/(.+)/(.+)/pull/(.+)\.(?:diff|patch)} - expected_offenses = [{ message: <<-EOS.undent, - use GitHub pull request URLs: - https://github.com/foo/foo-bar/pull/100.patch - Rather than patch-diff: - https://patch-diff.githubusercontent.com/raw/foo/foo-bar/pull/100.patch - EOS - severity: :convention, - line: 5, - column: 5, - source: source }] + [{ message: <<-EOS.undent, + use GitHub pull request URLs: + https://github.com/foo/foo-bar/pull/100.patch + Rather than patch-diff: + https://patch-diff.githubusercontent.com/raw/foo/foo-bar/pull/100.patch + EOS + severity: :convention, + line: 5, + column: 5, + source: source }] + elsif patch_url =~ %r{https?://github\.com/.+/.+/(?:commit|pull)/[a-fA-F0-9]*.(?:patch|diff)} + [{ message: <<-EOS.undent, + GitHub patches should use the full_index parameter: + #{patch_url}?full_index=1 + EOS + severity: :convention, + line: 5, + column: 5, + source: source }] end - expected_offenses.zip([cop.offenses.last]).each do |expected, actual| + expected_offense.zip([cop.offenses.last]).each do |expected, actual| expect_offense(expected, actual) end end @@ -130,19 +140,19 @@ describe RuboCop::Cop::FormulaAudit::Patches do end EOS - expected_offenses = [{ message: "Use the patch DSL instead of defining a 'patches' method", - severity: :convention, - line: 4, - column: 2, - source: source }, - { message: <<-EOS.undent.chomp, - Patches from MacPorts Trac should be https://, not http: - http://trac.macports.org/export/68507/trunk/dports/net/trafshow/files/ - EOS - severity: :convention, - line: 8, - column: 26, - source: source }] + expected_offenses = [{ message: "Use the patch DSL instead of defining a 'patches' method", + severity: :convention, + line: 4, + column: 2, + source: source }, + { message: <<-EOS.undent.chomp, + Patches from MacPorts Trac should be https://, not http: + http://trac.macports.org/export/68507/trunk/dports/net/trafshow/files/ + EOS + severity: :convention, + line: 8, + column: 26, + source: source }] inspect_source(cop, source) @@ -174,55 +184,55 @@ describe RuboCop::Cop::FormulaAudit::Patches do EOS inspect_source(cop, source) - if patch_url =~ %r{/raw\.github\.com/} - expected_offenses = [{ message: <<-EOS.undent.chomp, - GitHub/Gist patches should specify a revision: - #{patch_url} - EOS - severity: :convention, - line: 5, - column: 16, - source: source }] + expected_offense = if patch_url =~ %r{/raw\.github\.com/} + [{ message: <<-EOS.undent.chomp, + GitHub/Gist patches should specify a revision: + #{patch_url} + EOS + severity: :convention, + line: 5, + column: 16, + source: source }] elsif patch_url =~ %r{macports/trunk} - expected_offenses = [{ message: <<-EOS.undent.chomp, - MacPorts patches should specify a revision instead of trunk: - #{patch_url} - EOS - severity: :convention, - line: 5, - column: 37, - source: source }] + [{ message: <<-EOS.undent.chomp, + MacPorts patches should specify a revision instead of trunk: + #{patch_url} + EOS + severity: :convention, + line: 5, + column: 37, + source: source }] elsif patch_url =~ %r{^http://trac\.macports\.org} - expected_offenses = [{ message: <<-EOS.undent.chomp, - Patches from MacPorts Trac should be https://, not http: - #{patch_url} - EOS - severity: :convention, - line: 5, - column: 9, - source: source }] + [{ message: <<-EOS.undent.chomp, + Patches from MacPorts Trac should be https://, not http: + #{patch_url} + EOS + severity: :convention, + line: 5, + column: 9, + source: source }] elsif patch_url =~ %r{^http://bugs\.debian\.org} - expected_offenses = [{ message: <<-EOS.undent.chomp, - Patches from Debian should be https://, not http: - #{patch_url} - EOS - severity: :convention, - line: 5, - column: 9, - source: source }] + [{ message: <<-EOS.undent.chomp, + Patches from Debian should be https://, not http: + #{patch_url} + EOS + severity: :convention, + line: 5, + column: 9, + source: source }] elsif patch_url =~ %r{https?://patch-diff\.githubusercontent\.com/raw/(.+)/(.+)/pull/(.+)\.(?:diff|patch)} - expected_offenses = [{ message: <<-EOS.undent, - use GitHub pull request URLs: - https://github.com/foo/foo-bar/pull/100.patch - Rather than patch-diff: - https://patch-diff.githubusercontent.com/raw/foo/foo-bar/pull/100.patch - EOS - severity: :convention, - line: 5, - column: 9, - source: source }] + [{ message: <<-EOS.undent, + use GitHub pull request URLs: + https://github.com/foo/foo-bar/pull/100.patch + Rather than patch-diff: + https://patch-diff.githubusercontent.com/raw/foo/foo-bar/pull/100.patch + EOS + severity: :convention, + line: 5, + column: 9, + source: source }] end - expected_offenses.zip([cop.offenses.last]).each do |expected, actual| + expected_offense.zip([cop.offenses.last]).each do |expected, actual| expect_offense(expected, actual) end end From cb5b14307ca4640e1ba68cfd28e7fef34a3b771b Mon Sep 17 00:00:00 2001 From: Mike McQuaid Date: Sat, 26 Aug 2017 14:44:26 +0100 Subject: [PATCH 090/294] diagnostic: don't check CI core branch. --- Library/Homebrew/diagnostic.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/Library/Homebrew/diagnostic.rb b/Library/Homebrew/diagnostic.rb index 8108c5da0b..3d3c5e5dc1 100644 --- a/Library/Homebrew/diagnostic.rb +++ b/Library/Homebrew/diagnostic.rb @@ -786,6 +786,7 @@ module Homebrew EOS end + return if ENV["CI"] head = coretap_path.git_head return if head.nil? || head =~ %r{refs/heads/master} From db41f9d1182ff8c4c3b42b458e38d5c58b496ffb Mon Sep 17 00:00:00 2001 From: Mike McQuaid Date: Sat, 26 Aug 2017 14:50:55 +0100 Subject: [PATCH 091/294] diagnostic: also don't check Jenkins core branch. --- Library/Homebrew/diagnostic.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Library/Homebrew/diagnostic.rb b/Library/Homebrew/diagnostic.rb index 3d3c5e5dc1..ef9f065690 100644 --- a/Library/Homebrew/diagnostic.rb +++ b/Library/Homebrew/diagnostic.rb @@ -786,7 +786,7 @@ module Homebrew EOS end - return if ENV["CI"] + return if ENV["CI"] || ENV["JENKINS_HOME"] head = coretap_path.git_head return if head.nil? || head =~ %r{refs/heads/master} From b1e0998f585357121ca39389d1092150e02ec69f Mon Sep 17 00:00:00 2001 From: ilovezfs Date: Sat, 26 Aug 2017 10:13:43 -0700 Subject: [PATCH 092/294] Revert "diagnostic: also don't check Jenkins core branch." This reverts commit db41f9d1182ff8c4c3b42b458e38d5c58b496ffb. --- Library/Homebrew/diagnostic.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Library/Homebrew/diagnostic.rb b/Library/Homebrew/diagnostic.rb index ef9f065690..3d3c5e5dc1 100644 --- a/Library/Homebrew/diagnostic.rb +++ b/Library/Homebrew/diagnostic.rb @@ -786,7 +786,7 @@ module Homebrew EOS end - return if ENV["CI"] || ENV["JENKINS_HOME"] + return if ENV["CI"] head = coretap_path.git_head return if head.nil? || head =~ %r{refs/heads/master} From 784a85f885cf94082eb22c4c913699ba52cfe08b Mon Sep 17 00:00:00 2001 From: ilovezfs Date: Sat, 26 Aug 2017 10:14:23 -0700 Subject: [PATCH 093/294] Revert "diagnostic: don't check CI core branch." This reverts commit cb5b14307ca4640e1ba68cfd28e7fef34a3b771b. --- Library/Homebrew/diagnostic.rb | 1 - 1 file changed, 1 deletion(-) diff --git a/Library/Homebrew/diagnostic.rb b/Library/Homebrew/diagnostic.rb index 3d3c5e5dc1..8108c5da0b 100644 --- a/Library/Homebrew/diagnostic.rb +++ b/Library/Homebrew/diagnostic.rb @@ -786,7 +786,6 @@ module Homebrew EOS end - return if ENV["CI"] head = coretap_path.git_head return if head.nil? || head =~ %r{refs/heads/master} From 78a742c1ff8777432b28a913f6048b38e5d44b62 Mon Sep 17 00:00:00 2001 From: ilovezfs Date: Sat, 26 Aug 2017 10:15:35 -0700 Subject: [PATCH 094/294] Revert "Add check for HEAD ref in diagnostics" --- Library/Homebrew/diagnostic.rb | 12 +----------- 1 file changed, 1 insertion(+), 11 deletions(-) diff --git a/Library/Homebrew/diagnostic.rb b/Library/Homebrew/diagnostic.rb index 8108c5da0b..ceb6ad4d1d 100644 --- a/Library/Homebrew/diagnostic.rb +++ b/Library/Homebrew/diagnostic.rb @@ -756,7 +756,7 @@ module Homebrew end end - def check_coretap_git_config + def check_coretap_git_origin coretap_path = CoreTap.instance.path return if !Utils.git_available? || !(coretap_path/".git").exist? @@ -785,16 +785,6 @@ module Homebrew git -C "#{coretap_path}" remote set-url origin #{Formatter.url("https://github.com/Homebrew/homebrew-core.git")} EOS end - - head = coretap_path.git_head - return if head.nil? || head =~ %r{refs/heads/master} - - <<-EOS.undent - Homebrew/homebrew-core is not on the master branch - - Check out the master branch by running: - git -C "$(brew --repo homebrew/core)" checkout master - EOS end def __check_linked_brew(f) From c1799bb49712b9362b54e8bccae1e721ce6542e0 Mon Sep 17 00:00:00 2001 From: mansimarkaur Date: Wed, 31 May 2017 02:00:27 +0530 Subject: [PATCH 095/294] Added tests for disk_cleanup and unremovable kegs --- Library/Homebrew/test/cleanup_spec.rb | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/Library/Homebrew/test/cleanup_spec.rb b/Library/Homebrew/test/cleanup_spec.rb index 4e5e42efac..81cd631474 100644 --- a/Library/Homebrew/test/cleanup_spec.rb +++ b/Library/Homebrew/test/cleanup_spec.rb @@ -63,6 +63,28 @@ describe Homebrew::Cleanup do end end + specify "::update_disk_cleanup_size" do + shutup do + described_class.instance_eval("@disk_cleanup_size = 0") + described_class.update_disk_cleanup_size(128) + end + expect(described_class.instance_variable_get("@disk_cleanup_size")).to eq(128) + end + + specify "::disk_cleanup_size" do + shutup do + described_class.instance_eval("@disk_cleanup_size = 0") + end + expect(described_class.disk_cleanup_size).to eq(described_class.instance_variable_get("@disk_cleanup_size")) + end + + specify "::unremovable_kegs" do + shutup do + described_class.unremovable_kegs + end + expect(described_class.instance_variable_get("@unremovable_kegs")).to eq([]) + end + specify "::cleanup_formula" do f1 = Class.new(Testball) do version "1.0" From 5e17d63010c74dd23f02222feb61b76f515908d4 Mon Sep 17 00:00:00 2001 From: mansimarkaur Date: Wed, 19 Jul 2017 02:46:45 +0530 Subject: [PATCH 096/294] Added tests for ARGV prune 'all' --- Library/Homebrew/test/cleanup_spec.rb | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/Library/Homebrew/test/cleanup_spec.rb b/Library/Homebrew/test/cleanup_spec.rb index 81cd631474..f1a6e770ec 100644 --- a/Library/Homebrew/test/cleanup_spec.rb +++ b/Library/Homebrew/test/cleanup_spec.rb @@ -163,5 +163,21 @@ describe Homebrew::Cleanup do expect(npm_cache).not_to exist end + + it "cleans up files and directories with name containing -- if ARGV prune is all" do + a = (HOMEBREW_CACHE/"--a") + b = (HOMEBREW_CACHE/"b") + c = (HOMEBREW_CACHE/"c") + a.mkpath + b.mkpath + FileUtils.touch c + allow(ARGV).to receive(:value).with("prune").and_return("all") + shutup do + described_class.cleanup_cache + end + expect(a).not_to exist + expect(b).to exist + expect(c).not_to exist + end end end From 265d43444bcd09d5d54963161f2fe77cdef35ef9 Mon Sep 17 00:00:00 2001 From: mansimarkaur Date: Fri, 4 Aug 2017 05:47:05 +0530 Subject: [PATCH 097/294] improved prune all test --- Library/Homebrew/test/cleanup_spec.rb | 41 +++++++++++++++++++-------- 1 file changed, 29 insertions(+), 12 deletions(-) diff --git a/Library/Homebrew/test/cleanup_spec.rb b/Library/Homebrew/test/cleanup_spec.rb index f1a6e770ec..da6796d5f3 100644 --- a/Library/Homebrew/test/cleanup_spec.rb +++ b/Library/Homebrew/test/cleanup_spec.rb @@ -164,20 +164,37 @@ describe Homebrew::Cleanup do expect(npm_cache).not_to exist end - it "cleans up files and directories with name containing -- if ARGV prune is all" do - a = (HOMEBREW_CACHE/"--a") - b = (HOMEBREW_CACHE/"b") - c = (HOMEBREW_CACHE/"c") - a.mkpath - b.mkpath - FileUtils.touch c + it "cleans up all files and directories" do + git = (HOMEBREW_CACHE/"gist--git") + gist = (HOMEBREW_CACHE/"gist") + svn = (HOMEBREW_CACHE/"gist--svn") + git.mkpath + gist.mkpath + FileUtils.touch svn allow(ARGV).to receive(:value).with("prune").and_return("all") - shutup do - described_class.cleanup_cache + begin + shutup do + described_class.cleanup_cache + end + expect(git).not_to exist + expect(gist).to exist + expect(svn).not_to exist + ensure + FileUtils.rm_rf(git) + FileUtils.rm_rf(gist) + FileUtils.rm_rf(svn) + end + end + + it "raises error when formula name is ambiguous" do + bottle = (HOMEBREW_CACHE/"foo-0.2.bottle.gz") + FileUtils.touch bottle + (HOMEBREW_CELLAR/"foo/foo-0.2").mkpath + begin + described_class.cleanup_cache + ensure + FileUtils.rm_rf(bottle) end - expect(a).not_to exist - expect(b).to exist - expect(c).not_to exist end end end From 134539aa55af17be779bc05fc18e1fabceaeb3d0 Mon Sep 17 00:00:00 2001 From: mansimarkaur Date: Sat, 5 Aug 2017 06:06:33 +0530 Subject: [PATCH 098/294] Added tests for cleaning up old files in HOMEBREW_CACHE --- Library/Homebrew/test/cleanup_spec.rb | 61 ++++++++++++++++++--------- 1 file changed, 40 insertions(+), 21 deletions(-) diff --git a/Library/Homebrew/test/cleanup_spec.rb b/Library/Homebrew/test/cleanup_spec.rb index da6796d5f3..32ffbd3573 100644 --- a/Library/Homebrew/test/cleanup_spec.rb +++ b/Library/Homebrew/test/cleanup_spec.rb @@ -64,24 +64,18 @@ describe Homebrew::Cleanup do end specify "::update_disk_cleanup_size" do - shutup do - described_class.instance_eval("@disk_cleanup_size = 0") - described_class.update_disk_cleanup_size(128) - end + described_class.instance_eval("@disk_cleanup_size = 0") + described_class.update_disk_cleanup_size(128) expect(described_class.instance_variable_get("@disk_cleanup_size")).to eq(128) end specify "::disk_cleanup_size" do - shutup do - described_class.instance_eval("@disk_cleanup_size = 0") - end + described_class.instance_eval("@disk_cleanup_size = 0") expect(described_class.disk_cleanup_size).to eq(described_class.instance_variable_get("@disk_cleanup_size")) end specify "::unremovable_kegs" do - shutup do - described_class.unremovable_kegs - end + described_class.unremovable_kegs expect(described_class.instance_variable_get("@unremovable_kegs")).to eq([]) end @@ -173,9 +167,7 @@ describe Homebrew::Cleanup do FileUtils.touch svn allow(ARGV).to receive(:value).with("prune").and_return("all") begin - shutup do - described_class.cleanup_cache - end + described_class.cleanup_cache expect(git).not_to exist expect(gist).to exist expect(svn).not_to exist @@ -186,14 +178,41 @@ describe Homebrew::Cleanup do end end - it "raises error when formula name is ambiguous" do - bottle = (HOMEBREW_CACHE/"foo-0.2.bottle.gz") - FileUtils.touch bottle - (HOMEBREW_CELLAR/"foo/foo-0.2").mkpath - begin - described_class.cleanup_cache - ensure - FileUtils.rm_rf(bottle) + context "cleaning old files in HOMEBREW_CACHE" do + before(:each) do + @bottle = (HOMEBREW_CACHE/"testball-0.0.1.bottle.tar.gz") + @testball = (HOMEBREW_CACHE/"testball-0.0.1") + FileUtils.touch(@bottle) + FileUtils.touch(@testball) + (HOMEBREW_CELLAR/"testball"/"0.0.1").mkpath + FileUtils.touch(CoreTap.instance.formula_dir/"testball.rb") + end + + after(:each) do + FileUtils.rm_rf(@bottle) + FileUtils.rm_rf(@testball) + FileUtils.rm_rf(HOMEBREW_CELLAR/"testball") + FileUtils.rm_rf(CoreTap.instance.formula_dir/"testball.rb") + end + + it "cleans up file if outdated" do + allow(Utils::Bottles).to receive(:file_outdated?).with(any_args).and_return(true) + described_class.cleanup_cache + expect(@bottle).not_to exist + expect(@testball).not_to exist + end + + it "cleans up file if ARGV has -s and formula not installed" do + ARGV << "-s" + described_class.cleanup_cache + expect(@bottle).not_to exist + expect(@testball).not_to exist + end + + it "cleans up file if stale" do + puts described_class.cleanup_cache + expect(@bottle).not_to exist + expect(@testball).not_to exist end end end From 86f7d208d09c4ebb6e4ca3b4cbf82b563307d65d Mon Sep 17 00:00:00 2001 From: mansimarkaur Date: Sat, 5 Aug 2017 19:36:35 +0530 Subject: [PATCH 099/294] Added tests for prune? --- Library/Homebrew/test/cleanup_spec.rb | 37 ++++++++++++++++++--------- 1 file changed, 25 insertions(+), 12 deletions(-) diff --git a/Library/Homebrew/test/cleanup_spec.rb b/Library/Homebrew/test/cleanup_spec.rb index 32ffbd3573..a66157976e 100644 --- a/Library/Homebrew/test/cleanup_spec.rb +++ b/Library/Homebrew/test/cleanup_spec.rb @@ -63,22 +63,11 @@ describe Homebrew::Cleanup do end end - specify "::update_disk_cleanup_size" do - described_class.instance_eval("@disk_cleanup_size = 0") - described_class.update_disk_cleanup_size(128) - expect(described_class.instance_variable_get("@disk_cleanup_size")).to eq(128) - end - specify "::disk_cleanup_size" do described_class.instance_eval("@disk_cleanup_size = 0") expect(described_class.disk_cleanup_size).to eq(described_class.instance_variable_get("@disk_cleanup_size")) end - specify "::unremovable_kegs" do - described_class.unremovable_kegs - expect(described_class.instance_variable_get("@unremovable_kegs")).to eq([]) - end - specify "::cleanup_formula" do f1 = Class.new(Testball) do version "1.0" @@ -178,7 +167,20 @@ describe Homebrew::Cleanup do end end - context "cleaning old files in HOMEBREW_CACHE" do + it "cleans up VCS checkout directories with modified time < prune time" do + foo = (HOMEBREW_CACHE/"--foo") + foo.mkpath + allow(ARGV).to receive(:value).with("prune").and_return("1") + allow_any_instance_of(Pathname).to receive(:mtime).and_return(Time.now - 60 * 60 * 24 * 2) + begin + described_class.cleanup_cache + expect(foo).not_to exist + ensure + FileUtils.rm_rf(foo) + end + end + + context "cleans old files in HOMEBREW_CACHE" do before(:each) do @bottle = (HOMEBREW_CACHE/"testball-0.0.1.bottle.tar.gz") @testball = (HOMEBREW_CACHE/"testball-0.0.1") @@ -216,4 +218,15 @@ describe Homebrew::Cleanup do end end end + + specify "::prune?" do + foo = mktmpdir/"foo.rb" + foo.mkpath + allow_any_instance_of(Pathname).to receive(:mtime).and_return(Time.now - 60 * 60 * 24 * 2) + begin + expect(described_class.prune?(foo, days_default: "1")).to be_truthy + ensure + FileUtils.rm_rf(foo) + end + end end From 6b5e4bb938c38bf97e9fd31fde1813bf93fe1b4d Mon Sep 17 00:00:00 2001 From: mansimarkaur Date: Tue, 8 Aug 2017 00:25:01 +0530 Subject: [PATCH 100/294] Use let over instance_var --- Library/Homebrew/test/cleanup_spec.rb | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/Library/Homebrew/test/cleanup_spec.rb b/Library/Homebrew/test/cleanup_spec.rb index a66157976e..98cdb9bd07 100644 --- a/Library/Homebrew/test/cleanup_spec.rb +++ b/Library/Homebrew/test/cleanup_spec.rb @@ -181,18 +181,19 @@ describe Homebrew::Cleanup do end context "cleans old files in HOMEBREW_CACHE" do + let(:bottle) { (HOMEBREW_CACHE/"testball-0.0.1.bottle.tar.gz") } + let(:testball) { (HOMEBREW_CACHE/"testball-0.0.1") } + before(:each) do - @bottle = (HOMEBREW_CACHE/"testball-0.0.1.bottle.tar.gz") - @testball = (HOMEBREW_CACHE/"testball-0.0.1") - FileUtils.touch(@bottle) - FileUtils.touch(@testball) + FileUtils.touch(bottle) + FileUtils.touch(testball) (HOMEBREW_CELLAR/"testball"/"0.0.1").mkpath FileUtils.touch(CoreTap.instance.formula_dir/"testball.rb") end after(:each) do - FileUtils.rm_rf(@bottle) - FileUtils.rm_rf(@testball) + FileUtils.rm_rf(bottle) + FileUtils.rm_rf(testball) FileUtils.rm_rf(HOMEBREW_CELLAR/"testball") FileUtils.rm_rf(CoreTap.instance.formula_dir/"testball.rb") end @@ -200,21 +201,21 @@ describe Homebrew::Cleanup do it "cleans up file if outdated" do allow(Utils::Bottles).to receive(:file_outdated?).with(any_args).and_return(true) described_class.cleanup_cache - expect(@bottle).not_to exist - expect(@testball).not_to exist + expect(bottle).not_to exist + expect(testball).not_to exist end it "cleans up file if ARGV has -s and formula not installed" do ARGV << "-s" described_class.cleanup_cache - expect(@bottle).not_to exist - expect(@testball).not_to exist + expect(bottle).not_to exist + expect(testball).not_to exist end it "cleans up file if stale" do puts described_class.cleanup_cache - expect(@bottle).not_to exist - expect(@testball).not_to exist + expect(bottle).not_to exist + expect(testball).not_to exist end end end From e7c2efa42fbf1846ef32e86eb3bcd57482e399b4 Mon Sep 17 00:00:00 2001 From: mansimarkaur Date: Tue, 8 Aug 2017 00:45:29 +0530 Subject: [PATCH 101/294] Corrected disk_cleanup_size test --- Library/Homebrew/test/cleanup_spec.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Library/Homebrew/test/cleanup_spec.rb b/Library/Homebrew/test/cleanup_spec.rb index 98cdb9bd07..b1bf3fb18d 100644 --- a/Library/Homebrew/test/cleanup_spec.rb +++ b/Library/Homebrew/test/cleanup_spec.rb @@ -64,8 +64,8 @@ describe Homebrew::Cleanup do end specify "::disk_cleanup_size" do - described_class.instance_eval("@disk_cleanup_size = 0") - expect(described_class.disk_cleanup_size).to eq(described_class.instance_variable_get("@disk_cleanup_size")) + disk_cleanup_size = described_class.instance_variable_get(:@disk_cleanup_size) + expect(described_class.disk_cleanup_size).to eq(disk_cleanup_size) end specify "::cleanup_formula" do From 9a83856a4920e5e382df5025361bc405643d90f5 Mon Sep 17 00:00:00 2001 From: mansimarkaur Date: Sun, 13 Aug 2017 04:21:07 +0530 Subject: [PATCH 102/294] Added attr_reader disk_cleanup_size --- Library/Homebrew/cleanup.rb | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Library/Homebrew/cleanup.rb b/Library/Homebrew/cleanup.rb index d1f0b25163..3401612043 100644 --- a/Library/Homebrew/cleanup.rb +++ b/Library/Homebrew/cleanup.rb @@ -6,6 +6,10 @@ module Homebrew module Cleanup @disk_cleanup_size = 0 + class << self + attr_reader :disk_cleanup_size + end + module_function def cleanup @@ -21,10 +25,6 @@ module Homebrew @disk_cleanup_size += path_size end - def disk_cleanup_size - @disk_cleanup_size - end - def unremovable_kegs @unremovable_kegs ||= [] end From ec30de69c3b3e1c3afb3638e0e13d3518148871d Mon Sep 17 00:00:00 2001 From: mansimarkaur Date: Sun, 13 Aug 2017 04:21:26 +0530 Subject: [PATCH 103/294] Added tests for existence of files --- Library/Homebrew/test/cleanup_spec.rb | 108 +++++++++++++++++--------- 1 file changed, 73 insertions(+), 35 deletions(-) diff --git a/Library/Homebrew/test/cleanup_spec.rb b/Library/Homebrew/test/cleanup_spec.rb index b1bf3fb18d..cf3af5d352 100644 --- a/Library/Homebrew/test/cleanup_spec.rb +++ b/Library/Homebrew/test/cleanup_spec.rb @@ -63,11 +63,6 @@ describe Homebrew::Cleanup do end end - specify "::disk_cleanup_size" do - disk_cleanup_size = described_class.instance_variable_get(:@disk_cleanup_size) - expect(described_class.disk_cleanup_size).to eq(disk_cleanup_size) - end - specify "::cleanup_formula" do f1 = Class.new(Testball) do version "1.0" @@ -109,14 +104,30 @@ describe Homebrew::Cleanup do expect(f4).to be_installed end - specify "::cleanup_logs" do - path = (HOMEBREW_LOGS/"delete_me") - path.mkpath - ARGV << "--prune=all" + describe "::cleanup_logs" do + before do + path.mkpath + end - described_class.cleanup_logs + let(:path) { (HOMEBREW_LOGS/"delete_me") } - expect(path).not_to exist + it "cleans all logs if prune all" do + ARGV << "--prune=all" + described_class.cleanup_logs + expect(path).not_to exist + end + + it "cleans up logs if older than 14 days" do + allow_any_instance_of(Pathname).to receive(:mtime).and_return(Time.now - 60 * 60 * 24 * 15) + described_class.cleanup_logs + expect(path).not_to exist + end + + it "does not clean up logs less than 14 days old" do + allow_any_instance_of(Pathname).to receive(:mtime).and_return(Time.now - 60 * 60 * 24 * 2) + described_class.cleanup_logs + expect(path).to exist + end end describe "::cleanup_cache" do @@ -129,6 +140,15 @@ describe Homebrew::Cleanup do expect(incomplete).not_to exist end + it "cleans up 'glide_home'" do + glide_home = (HOMEBREW_CACHE/"glide_home") + glide_home.mkpath + + described_class.cleanup_cache + + expect(glide_home).not_to exist + end + it "cleans up 'java_cache'" do java_cache = (HOMEBREW_CACHE/"java_cache") java_cache.mkpath @@ -151,20 +171,28 @@ describe Homebrew::Cleanup do git = (HOMEBREW_CACHE/"gist--git") gist = (HOMEBREW_CACHE/"gist") svn = (HOMEBREW_CACHE/"gist--svn") + git.mkpath gist.mkpath FileUtils.touch svn + allow(ARGV).to receive(:value).with("prune").and_return("all") - begin - described_class.cleanup_cache - expect(git).not_to exist - expect(gist).to exist - expect(svn).not_to exist - ensure - FileUtils.rm_rf(git) - FileUtils.rm_rf(gist) - FileUtils.rm_rf(svn) - end + + described_class.cleanup_cache + + expect(git).not_to exist + expect(gist).to exist + expect(svn).not_to exist + end + + it "does not clean up directories that are not VCS checkouts" do + git = (HOMEBREW_CACHE/"git") + git.mkpath + allow(ARGV).to receive(:value).with("prune").and_return("all") + + described_class.cleanup_cache + + expect(git).to exist end it "cleans up VCS checkout directories with modified time < prune time" do @@ -172,12 +200,16 @@ describe Homebrew::Cleanup do foo.mkpath allow(ARGV).to receive(:value).with("prune").and_return("1") allow_any_instance_of(Pathname).to receive(:mtime).and_return(Time.now - 60 * 60 * 24 * 2) - begin - described_class.cleanup_cache - expect(foo).not_to exist - ensure - FileUtils.rm_rf(foo) - end + described_class.cleanup_cache + expect(foo).not_to exist + end + + it "does not clean up VCS checkout directories with modified time >= prune time" do + foo = (HOMEBREW_CACHE/"--foo") + foo.mkpath + allow(ARGV).to receive(:value).with("prune").and_return("1") + described_class.cleanup_cache + expect(foo).to exist end context "cleans old files in HOMEBREW_CACHE" do @@ -213,21 +245,27 @@ describe Homebrew::Cleanup do end it "cleans up file if stale" do - puts described_class.cleanup_cache + described_class.cleanup_cache expect(bottle).not_to exist expect(testball).not_to exist end end end - specify "::prune?" do - foo = mktmpdir/"foo.rb" - foo.mkpath - allow_any_instance_of(Pathname).to receive(:mtime).and_return(Time.now - 60 * 60 * 24 * 2) - begin + describe "::prune?" do + before do + foo.mkpath + end + + let(:foo) { mktmpdir/"foo.rb" } + + it "returns true when path_modified_time < days_default" do + allow_any_instance_of(Pathname).to receive(:mtime).and_return(Time.now - 60 * 60 * 24 * 2) expect(described_class.prune?(foo, days_default: "1")).to be_truthy - ensure - FileUtils.rm_rf(foo) + end + + it "returns true when path_modified_time >= days_default" do + expect(described_class.prune?(foo, days_default: "2")).to be_falsey end end end From 5f7a93bcebf2f18f4740f0fd5e676555880c5d71 Mon Sep 17 00:00:00 2001 From: mansimarkaur Date: Sat, 19 Aug 2017 17:17:38 +0530 Subject: [PATCH 104/294] Corrected test name --- Library/Homebrew/test/cleanup_spec.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Library/Homebrew/test/cleanup_spec.rb b/Library/Homebrew/test/cleanup_spec.rb index cf3af5d352..3e9cdc79cc 100644 --- a/Library/Homebrew/test/cleanup_spec.rb +++ b/Library/Homebrew/test/cleanup_spec.rb @@ -105,12 +105,12 @@ describe Homebrew::Cleanup do end describe "::cleanup_logs" do + let(:path) { (HOMEBREW_LOGS/"delete_me") } + before do path.mkpath end - let(:path) { (HOMEBREW_LOGS/"delete_me") } - it "cleans all logs if prune all" do ARGV << "--prune=all" described_class.cleanup_logs @@ -264,7 +264,7 @@ describe Homebrew::Cleanup do expect(described_class.prune?(foo, days_default: "1")).to be_truthy end - it "returns true when path_modified_time >= days_default" do + it "returns false when path_modified_time >= days_default" do expect(described_class.prune?(foo, days_default: "2")).to be_falsey end end From 01714b17ee4abd08082ef5a37810a7b21ec80d6a Mon Sep 17 00:00:00 2001 From: mansimarkaur Date: Sat, 26 Aug 2017 02:01:45 +0530 Subject: [PATCH 105/294] Used let for sec_in_a_day and removed redundant after(:each) block --- Library/Homebrew/test/cleanup_spec.rb | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/Library/Homebrew/test/cleanup_spec.rb b/Library/Homebrew/test/cleanup_spec.rb index 3e9cdc79cc..da262c5ca0 100644 --- a/Library/Homebrew/test/cleanup_spec.rb +++ b/Library/Homebrew/test/cleanup_spec.rb @@ -5,6 +5,7 @@ require "pathname" describe Homebrew::Cleanup do let(:ds_store) { Pathname.new("#{HOMEBREW_PREFIX}/Library/.DS_Store") } + let(:sec_in_a_day) { 60 * 60 * 24 } around(:each) do |example| begin @@ -118,13 +119,13 @@ describe Homebrew::Cleanup do end it "cleans up logs if older than 14 days" do - allow_any_instance_of(Pathname).to receive(:mtime).and_return(Time.now - 60 * 60 * 24 * 15) + allow_any_instance_of(Pathname).to receive(:mtime).and_return(Time.now - sec_in_a_day * 15) described_class.cleanup_logs expect(path).not_to exist end it "does not clean up logs less than 14 days old" do - allow_any_instance_of(Pathname).to receive(:mtime).and_return(Time.now - 60 * 60 * 24 * 2) + allow_any_instance_of(Pathname).to receive(:mtime).and_return(Time.now - sec_in_a_day * 2) described_class.cleanup_logs expect(path).to exist end @@ -199,7 +200,7 @@ describe Homebrew::Cleanup do foo = (HOMEBREW_CACHE/"--foo") foo.mkpath allow(ARGV).to receive(:value).with("prune").and_return("1") - allow_any_instance_of(Pathname).to receive(:mtime).and_return(Time.now - 60 * 60 * 24 * 2) + allow_any_instance_of(Pathname).to receive(:mtime).and_return(Time.now - sec_in_a_day * 2) described_class.cleanup_cache expect(foo).not_to exist end @@ -223,13 +224,6 @@ describe Homebrew::Cleanup do FileUtils.touch(CoreTap.instance.formula_dir/"testball.rb") end - after(:each) do - FileUtils.rm_rf(bottle) - FileUtils.rm_rf(testball) - FileUtils.rm_rf(HOMEBREW_CELLAR/"testball") - FileUtils.rm_rf(CoreTap.instance.formula_dir/"testball.rb") - end - it "cleans up file if outdated" do allow(Utils::Bottles).to receive(:file_outdated?).with(any_args).and_return(true) described_class.cleanup_cache @@ -257,10 +251,10 @@ describe Homebrew::Cleanup do foo.mkpath end - let(:foo) { mktmpdir/"foo.rb" } + let(:foo) { HOMEBREW_CACHE/"foo" } it "returns true when path_modified_time < days_default" do - allow_any_instance_of(Pathname).to receive(:mtime).and_return(Time.now - 60 * 60 * 24 * 2) + allow_any_instance_of(Pathname).to receive(:mtime).and_return(Time.now - sec_in_a_day * 2) expect(described_class.prune?(foo, days_default: "1")).to be_truthy end From d91036e8912b31e3eb145b1cb3964a321a587c4f Mon Sep 17 00:00:00 2001 From: mansimarkaur Date: Fri, 28 Jul 2017 00:37:32 +0530 Subject: [PATCH 106/294] Added tests for last_revision_commit_of_file --- Library/Homebrew/test/utils/git_spec.rb | 47 +++++++++++++++++++++++++ Library/Homebrew/utils/git.rb | 10 +++--- 2 files changed, 51 insertions(+), 6 deletions(-) create mode 100644 Library/Homebrew/test/utils/git_spec.rb diff --git a/Library/Homebrew/test/utils/git_spec.rb b/Library/Homebrew/test/utils/git_spec.rb new file mode 100644 index 0000000000..d4eb978200 --- /dev/null +++ b/Library/Homebrew/test/utils/git_spec.rb @@ -0,0 +1,47 @@ +require "utils/git" + +describe Git do + before(:all) do + git = HOMEBREW_SHIMS_PATH/"scm/git" + file = "lib/blah.rb" + repo = Pathname.new("repo") + FileUtils.mkpath("repo/lib") + `#{git} init` + FileUtils.touch("repo/#{file}") + File.open(repo.to_s+"/"+file, "w") { |f| f.write("blah") } + `#{git} add repo/#{file}` + `#{git} commit -m"File added"` + @hash1 = `git rev-parse HEAD` + File.open(repo.to_s+"/"+file, "w") { |f| f.write("brew") } + `#{git} add repo/#{file}` + `#{git} commit -m"written to File"` + @hash2 = `git rev-parse HEAD` + end + + let(:file) { "lib/blah.rb" } + let(:repo) { Pathname.new("repo") } + + # after(:all) do + # FileUtils.rm_rf("repo") + # end + + describe "#last_revision_commit_of_file" do + it "sets args as --skip=1 when before_commit is nil" do + expect(described_class.last_revision_commit_of_file(repo, file)).to eq(@hash1[0..6]) + end + + it "sets args as --skip=1 when before_commit is nil" do + expect(described_class.last_revision_commit_of_file(repo, file, before_commit: "0..3")).to eq(@hash2[0..6]) + end + end + + describe "#last_revision_of_file" do + it "returns last revision of file" do + expect(described_class.last_revision_of_file(repo, repo.to_s+"/"+file)).to eq("blah") + end + + it "returns last revision of file based on before_commit" do + expect(described_class.last_revision_of_file(repo, repo.to_s+"/"+file, before_commit: "0..3")).to eq("brew") + end + end +end diff --git a/Library/Homebrew/utils/git.rb b/Library/Homebrew/utils/git.rb index 43d93b64ec..3668b9d115 100644 --- a/Library/Homebrew/utils/git.rb +++ b/Library/Homebrew/utils/git.rb @@ -4,7 +4,7 @@ module Git module_function def last_revision_commit_of_file(repo, file, before_commit: nil) - args = [before_commit.nil? ? "--skip=1" : before_commit.split("..").first] + args = ["--skip=#{before_commit.nil? ? 1 : before_commit.split("..").first}"] out, = Open3.capture3( HOMEBREW_SHIMS_PATH/"scm/git", "-C", repo, @@ -16,11 +16,10 @@ module Git def last_revision_of_file(repo, file, before_commit: nil) relative_file = Pathname(file).relative_path_from(repo) - commit_hash = last_revision_commit_of_file(repo, file, before_commit: before_commit) - + commit_hash = last_revision_commit_of_file(repo, relative_file, before_commit: before_commit) out, = Open3.capture3( HOMEBREW_SHIMS_PATH/"scm/git", "-C", repo, - "show", "#{commit_hash}:#{relative_file}" + "show", "#{commit_hash}:#{file}" ) out end @@ -28,8 +27,7 @@ end module Utils def self.git_available? - return @git if instance_variable_defined?(:@git) - @git = quiet_system HOMEBREW_SHIMS_PATH/"scm/git", "--version" + @git ||= quiet_system HOMEBREW_SHIMS_PATH/"scm/git", "--version" end def self.git_path From 657b6ef7fb67231540bac9bcf4126ec27e8e1841 Mon Sep 17 00:00:00 2001 From: mansimarkaur Date: Fri, 28 Jul 2017 02:02:40 +0530 Subject: [PATCH 107/294] Added tests for git_available? --- Library/Homebrew/test/utils/git_spec.rb | 19 +++++++++++++++++++ Library/Homebrew/utils/git.rb | 3 ++- 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/Library/Homebrew/test/utils/git_spec.rb b/Library/Homebrew/test/utils/git_spec.rb index d4eb978200..39b28794ab 100644 --- a/Library/Homebrew/test/utils/git_spec.rb +++ b/Library/Homebrew/test/utils/git_spec.rb @@ -45,3 +45,22 @@ describe Git do end end end + +describe Utils do + describe "::git_available?" do + it "returns true if git --version command succeeds" do + allow_any_instance_of(Process::Status).to receive(:success?).and_return(true) + expect(described_class.git_available?).to be_truthy + end + + it "returns false if git --version command does not succeed" do + allow_any_instance_of(Process::Status).to receive(:success?).and_return(false) + expect(described_class.git_available?).to be_falsey + end + + it "returns git version if already set" do + described_class.instance_variable_set(:@git, true) + expect(described_class.git_available?).to be_truthy + end + end +end diff --git a/Library/Homebrew/utils/git.rb b/Library/Homebrew/utils/git.rb index 3668b9d115..1e2e360e67 100644 --- a/Library/Homebrew/utils/git.rb +++ b/Library/Homebrew/utils/git.rb @@ -27,7 +27,8 @@ end module Utils def self.git_available? - @git ||= quiet_system HOMEBREW_SHIMS_PATH/"scm/git", "--version" + return @git if instance_variable_defined?(:@git) + @git = quiet_system HOMEBREW_SHIMS_PATH/"scm/git", "--version" end def self.git_path From 660617a35b81ccb223682f2267cd641d7baf31c6 Mon Sep 17 00:00:00 2001 From: mansimarkaur Date: Fri, 28 Jul 2017 03:45:10 +0530 Subject: [PATCH 108/294] Added tests for Utils --- Library/Homebrew/test/utils/git_spec.rb | 116 +++++++++++++++++++++++- 1 file changed, 113 insertions(+), 3 deletions(-) diff --git a/Library/Homebrew/test/utils/git_spec.rb b/Library/Homebrew/test/utils/git_spec.rb index 39b28794ab..37ca331e3f 100644 --- a/Library/Homebrew/test/utils/git_spec.rb +++ b/Library/Homebrew/test/utils/git_spec.rb @@ -21,9 +21,9 @@ describe Git do let(:file) { "lib/blah.rb" } let(:repo) { Pathname.new("repo") } - # after(:all) do - # FileUtils.rm_rf("repo") - # end + after(:all) do + FileUtils.rm_rf("repo") + end describe "#last_revision_commit_of_file" do it "sets args as --skip=1 when before_commit is nil" do @@ -61,6 +61,116 @@ describe Utils do it "returns git version if already set" do described_class.instance_variable_set(:@git, true) expect(described_class.git_available?).to be_truthy + described_class.instance_variable_set(:@git, nil) + end + end + + describe "::git_path" do + context "when git is not available" do + before do + described_class.instance_variable_set(:@git, false) + end + + it "returns" do + expect(described_class.git_path).to eq(nil) + end + end + + context "when git is available" do + before do + described_class.instance_variable_set(:@git, true) + end + + it "returns path of git" do + expect(described_class.git_path).to eq("/Applications/Xcode.app/Contents/Developer/usr/bin/git") + end + + it "returns git_path if already set" do + described_class.instance_variable_set(:@git_path, "git") + expect(described_class.git_path).to eq("git") + described_class.instance_variable_set(:@git_path, nil) + end + end + end + + describe "::git_version" do + context "when git is not available" do + before do + described_class.instance_variable_set(:@git, false) + end + + it "returns" do + expect(described_class.git_path).to eq(nil) + end + end + + context "when git is available" do + before do + described_class.instance_variable_set(:@git, true) + end + + it "returns version of git" do + expect(described_class.git_version).not_to be_nil + end + + it "returns git_version if already set" do + described_class.instance_variable_set(:@git_version, "v1") + expect(described_class.git_version).to eq("v1") + described_class.instance_variable_set(:@git_version, nil) + end + end + end + + describe "::git_remote_exists" do + context "when git is not available" do + before do + described_class.instance_variable_set(:@git, false) + end + + it "returns true" do + expect(described_class.git_remote_exists("blah")).to be_truthy + end + end + + context "when git is available" do + before(:all) do + described_class.instance_variable_set(:@git, true) + git = HOMEBREW_SHIMS_PATH/"scm/git" + @repo = Pathname.new("hey") + FileUtils.mkpath("hey") + `cd #{@repo}` + `#{git} init` + `#{git} remote add origin git@github.com:Homebrew/brew` + `cd ..` + end + + after(:all) do + FileUtils.rm_rf(@repo) + end + + it "returns true when git remote exists" do + expect(described_class.git_remote_exists("git@github.com:Homebrew/brew")).to be_truthy + end + + it "returns false when git remote does not exist" do + expect(described_class.git_remote_exists("blah")).to be_falsey + end + end + end + + describe "::clear_git_available_cache" do + it "removes @git_path and @git_version if defined" do + described_class.clear_git_available_cache + expect(@git_path).to be_nil + expect(@git_version).to be_nil + end + + it "removes @git if defined" do + described_class.instance_variable_set(:@git, true) + described_class.clear_git_available_cache + expect(@git).to be_nil + expect(@git_path).to be_nil + expect(@git_version).to be_nil end end end From 4f0f55a7748b1fd477937d2e9c48a45f754ac725 Mon Sep 17 00:00:00 2001 From: mansimarkaur Date: Mon, 31 Jul 2017 22:30:36 +0530 Subject: [PATCH 109/294] Used system command to run git commands --- Library/Homebrew/test/utils/git_spec.rb | 41 ++++++++++++++----------- 1 file changed, 23 insertions(+), 18 deletions(-) diff --git a/Library/Homebrew/test/utils/git_spec.rb b/Library/Homebrew/test/utils/git_spec.rb index 37ca331e3f..46c8b1e4f3 100644 --- a/Library/Homebrew/test/utils/git_spec.rb +++ b/Library/Homebrew/test/utils/git_spec.rb @@ -6,16 +6,18 @@ describe Git do file = "lib/blah.rb" repo = Pathname.new("repo") FileUtils.mkpath("repo/lib") - `#{git} init` - FileUtils.touch("repo/#{file}") - File.open(repo.to_s+"/"+file, "w") { |f| f.write("blah") } - `#{git} add repo/#{file}` - `#{git} commit -m"File added"` - @hash1 = `git rev-parse HEAD` - File.open(repo.to_s+"/"+file, "w") { |f| f.write("brew") } - `#{git} add repo/#{file}` - `#{git} commit -m"written to File"` - @hash2 = `git rev-parse HEAD` + shutup do + system "#{git} init" + FileUtils.touch("repo/#{file}") + File.open(repo.join("file").to_s, "w") { |f| f.write("blah") } + system "#{git} add repo/#{file}" + system "#{git} commit -m'File added'" + @hash1 = `git rev-parse HEAD` + File.open(repo.join("file").to_s, "w") { |f| f.write("brew") } + system "#{git} add repo/#{file}" + system "#{git} commit -m'written to File'" + @hash2 = `git rev-parse HEAD` + end end let(:file) { "lib/blah.rb" } @@ -37,11 +39,11 @@ describe Git do describe "#last_revision_of_file" do it "returns last revision of file" do - expect(described_class.last_revision_of_file(repo, repo.to_s+"/"+file)).to eq("blah") + expect(described_class.last_revision_of_file(repo, repo.join("file").to_s)).to eq("blah") end it "returns last revision of file based on before_commit" do - expect(described_class.last_revision_of_file(repo, repo.to_s+"/"+file, before_commit: "0..3")).to eq("brew") + expect(described_class.last_revision_of_file(repo, repo.join("file").to_s, before_commit: "0..3")).to eq("brew") end end end @@ -82,7 +84,8 @@ describe Utils do end it "returns path of git" do - expect(described_class.git_path).to eq("/Applications/Xcode.app/Contents/Developer/usr/bin/git") + allow(Utils).to receive(popen_read).with(HOMEBREW_SHIMS_PATH/"scm/git", "--homebrew=print-path").and_return("git") + expect(described_class.git_path).to eq("git") end it "returns git_path if already set" do @@ -99,7 +102,7 @@ describe Utils do described_class.instance_variable_set(:@git, false) end - it "returns" do + it "returns nil" do expect(described_class.git_path).to eq(nil) end end @@ -138,10 +141,12 @@ describe Utils do git = HOMEBREW_SHIMS_PATH/"scm/git" @repo = Pathname.new("hey") FileUtils.mkpath("hey") - `cd #{@repo}` - `#{git} init` - `#{git} remote add origin git@github.com:Homebrew/brew` - `cd ..` + shutup do + system "cd #{@repo}" + system "#{git} init" + system "#{git} remote add origin git@github.com:Homebrew/brew" + system "cd .." + end end after(:all) do From abe78ebb8e75079da901ccbe908efdc9af0d0a78 Mon Sep 17 00:00:00 2001 From: mansimarkaur Date: Tue, 1 Aug 2017 22:27:24 +0530 Subject: [PATCH 110/294] Removed shutup --- Library/Homebrew/test/utils/git_spec.rb | 107 ++++++++++++++++-------- 1 file changed, 70 insertions(+), 37 deletions(-) diff --git a/Library/Homebrew/test/utils/git_spec.rb b/Library/Homebrew/test/utils/git_spec.rb index 46c8b1e4f3..931699c1b4 100644 --- a/Library/Homebrew/test/utils/git_spec.rb +++ b/Library/Homebrew/test/utils/git_spec.rb @@ -5,50 +5,71 @@ describe Git do git = HOMEBREW_SHIMS_PATH/"scm/git" file = "lib/blah.rb" repo = Pathname.new("repo") - FileUtils.mkpath("repo/lib") - shutup do - system "#{git} init" - FileUtils.touch("repo/#{file}") - File.open(repo.join("file").to_s, "w") { |f| f.write("blah") } - system "#{git} add repo/#{file}" - system "#{git} commit -m'File added'" - @hash1 = `git rev-parse HEAD` - File.open(repo.join("file").to_s, "w") { |f| f.write("brew") } - system "#{git} add repo/#{file}" - system "#{git} commit -m'written to File'" - @hash2 = `git rev-parse HEAD` - end + + (repo/"lib").mkpath + system git, "init" + FileUtils.touch("repo/#{file}") + + File.open(repo/file, "w") { |f| f.write("blah") } + system git, "add", repo/file + system git, "commit", "-m", "'File added'" + @h1 = `git rev-parse HEAD` + + File.open(repo/file, "w") { |f| f.write("brew") } + system git, "add", repo/file + system git, "commit", "-m", "'written to File'" + @h2 = `git rev-parse HEAD` end let(:file) { "lib/blah.rb" } let(:repo) { Pathname.new("repo") } + let(:hash1) { @h1[0..6] } + let(:hash2) { @h2[0..6] } after(:all) do FileUtils.rm_rf("repo") end describe "#last_revision_commit_of_file" do - it "sets args as --skip=1 when before_commit is nil" do - expect(described_class.last_revision_commit_of_file(repo, file)).to eq(@hash1[0..6]) + it "gives last revision commit when before_commit is nil" do + expect( + described_class.last_revision_commit_of_file(repo, file), + ).to eq(hash1) end - it "sets args as --skip=1 when before_commit is nil" do - expect(described_class.last_revision_commit_of_file(repo, file, before_commit: "0..3")).to eq(@hash2[0..6]) + it "gives revision commit based on before_commit when it is not nil" do + expect( + described_class.last_revision_commit_of_file(repo, + file, + before_commit: "0..3"), + ).to eq(hash2) end end describe "#last_revision_of_file" do it "returns last revision of file" do - expect(described_class.last_revision_of_file(repo, repo.join("file").to_s)).to eq("blah") + expect( + described_class.last_revision_of_file(repo, + repo/file), + ).to eq("blah") end it "returns last revision of file based on before_commit" do - expect(described_class.last_revision_of_file(repo, repo.join("file").to_s, before_commit: "0..3")).to eq("brew") + expect( + described_class.last_revision_of_file(repo, repo/file, + before_commit: "0..3"), + ).to eq("brew") end end end describe Utils do + before(:each) do + if described_class.instance_variable_defined?(:@git) + described_class.send(:remove_instance_variable, :@git) + end + end + describe "::git_available?" do it "returns true if git --version command succeeds" do allow_any_instance_of(Process::Status).to receive(:success?).and_return(true) @@ -73,7 +94,7 @@ describe Utils do described_class.instance_variable_set(:@git, false) end - it "returns" do + it "returns nil" do expect(described_class.git_path).to eq(nil) end end @@ -84,8 +105,7 @@ describe Utils do end it "returns path of git" do - allow(Utils).to receive(popen_read).with(HOMEBREW_SHIMS_PATH/"scm/git", "--homebrew=print-path").and_return("git") - expect(described_class.git_path).to eq("git") + expect(described_class.git_path).to end_with("git") end it "returns git_path if already set" do @@ -138,23 +158,27 @@ describe Utils do context "when git is available" do before(:all) do described_class.instance_variable_set(:@git, true) - git = HOMEBREW_SHIMS_PATH/"scm/git" - @repo = Pathname.new("hey") - FileUtils.mkpath("hey") - shutup do - system "cd #{@repo}" - system "#{git} init" - system "#{git} remote add origin git@github.com:Homebrew/brew" - system "cd .." - end end after(:all) do - FileUtils.rm_rf(@repo) + if described_class.instance_variable_defined?(:@git) + described_class.send(:remove_instance_variable, :@git) + end end - it "returns true when git remote exists" do + it "returns true when git remote exists", :needs_network do + git = HOMEBREW_SHIMS_PATH/"scm/git" + repo = Pathname.new("hey") + repo.mkpath + + system "cd", repo + system git, "init" + system git, "remote", "add", "origin", "git@github.com:Homebrew/brew" + system "cd .." + expect(described_class.git_remote_exists("git@github.com:Homebrew/brew")).to be_truthy + + FileUtils.rm_rf(repo) end it "returns false when git remote does not exist" do @@ -166,16 +190,25 @@ describe Utils do describe "::clear_git_available_cache" do it "removes @git_path and @git_version if defined" do described_class.clear_git_available_cache + expect(@git_path).to be_nil expect(@git_version).to be_nil end it "removes @git if defined" do described_class.instance_variable_set(:@git, true) - described_class.clear_git_available_cache - expect(@git).to be_nil - expect(@git_path).to be_nil - expect(@git_version).to be_nil + + begin + described_class.clear_git_available_cache + + expect(@git).to be_nil + expect(@git_path).to be_nil + expect(@git_version).to be_nil + ensure + if described_class.instance_variable_defined?(:@git) + described_class.send(:remove_instance_variable, :@git) + end + end end end end From 372a42230510d24e539f2763ed148f7ba3ae7991 Mon Sep 17 00:00:00 2001 From: mansimarkaur Date: Sat, 12 Aug 2017 02:33:48 +0530 Subject: [PATCH 111/294] Added tests for ensure_git_installed when git is available or homebrew/core is unavailable --- Library/Homebrew/test/utils/git_spec.rb | 157 +++++++++--------------- Library/Homebrew/utils/git.rb | 2 +- 2 files changed, 60 insertions(+), 99 deletions(-) diff --git a/Library/Homebrew/test/utils/git_spec.rb b/Library/Homebrew/test/utils/git_spec.rb index 931699c1b4..994e237257 100644 --- a/Library/Homebrew/test/utils/git_spec.rb +++ b/Library/Homebrew/test/utils/git_spec.rb @@ -3,45 +3,44 @@ require "utils/git" describe Git do before(:all) do git = HOMEBREW_SHIMS_PATH/"scm/git" - file = "lib/blah.rb" - repo = Pathname.new("repo") - (repo/"lib").mkpath + @file = "lib/blah.rb" + @repo = Pathname.new("repo") + + (@repo/"lib").mkpath system git, "init" - FileUtils.touch("repo/#{file}") + FileUtils.touch(@repo/@file) - File.open(repo/file, "w") { |f| f.write("blah") } - system git, "add", repo/file + File.open(@repo/@file, "w") { |f| f.write("blah") } + system git, "add", @repo/@file system git, "commit", "-m", "'File added'" @h1 = `git rev-parse HEAD` - File.open(repo/file, "w") { |f| f.write("brew") } - system git, "add", repo/file + File.open(@repo/@file, "w") { |f| f.write("brew") } + system git, "add", @repo/@file system git, "commit", "-m", "'written to File'" @h2 = `git rev-parse HEAD` end - let(:file) { "lib/blah.rb" } - let(:repo) { Pathname.new("repo") } let(:hash1) { @h1[0..6] } let(:hash2) { @h2[0..6] } after(:all) do - FileUtils.rm_rf("repo") + FileUtils.rm_rf(@repo) end describe "#last_revision_commit_of_file" do it "gives last revision commit when before_commit is nil" do expect( - described_class.last_revision_commit_of_file(repo, file), + described_class.last_revision_commit_of_file(@repo, @file), ).to eq(hash1) end it "gives revision commit based on before_commit when it is not nil" do expect( - described_class.last_revision_commit_of_file(repo, - file, - before_commit: "0..3"), + described_class.last_revision_commit_of_file(@repo, + @file, + before_commit: hash2), ).to eq(hash2) end end @@ -49,14 +48,14 @@ describe Git do describe "#last_revision_of_file" do it "returns last revision of file" do expect( - described_class.last_revision_of_file(repo, - repo/file), + described_class.last_revision_of_file(@repo, + @repo/@file), ).to eq("blah") end it "returns last revision of file based on before_commit" do expect( - described_class.last_revision_of_file(repo, repo/file, + described_class.last_revision_of_file(@repo, @repo/@file, before_commit: "0..3"), ).to eq("brew") end @@ -72,100 +71,71 @@ describe Utils do describe "::git_available?" do it "returns true if git --version command succeeds" do - allow_any_instance_of(Process::Status).to receive(:success?).and_return(true) expect(described_class.git_available?).to be_truthy end it "returns false if git --version command does not succeed" do - allow_any_instance_of(Process::Status).to receive(:success?).and_return(false) + stub_const("HOMEBREW_SHIMS_PATH", mktmpdir/"shim") expect(described_class.git_available?).to be_falsey end - - it "returns git version if already set" do - described_class.instance_variable_set(:@git, true) - expect(described_class.git_available?).to be_truthy - described_class.instance_variable_set(:@git, nil) - end end describe "::git_path" do - context "when git is not available" do - before do - described_class.instance_variable_set(:@git, false) - end - - it "returns nil" do - expect(described_class.git_path).to eq(nil) - end + it "returns nil when git is not available" do + stub_const("HOMEBREW_SHIMS_PATH", mktmpdir/"shim") + expect(described_class.git_path).to eq(nil) end - context "when git is available" do - before do - described_class.instance_variable_set(:@git, true) - end - - it "returns path of git" do - expect(described_class.git_path).to end_with("git") - end - - it "returns git_path if already set" do - described_class.instance_variable_set(:@git_path, "git") - expect(described_class.git_path).to eq("git") - described_class.instance_variable_set(:@git_path, nil) - end + it "returns path of git when git is available" do + expect(described_class.git_path).to end_with("git") end end describe "::git_version" do - context "when git is not available" do - before do - described_class.instance_variable_set(:@git, false) - end - - it "returns nil" do - expect(described_class.git_path).to eq(nil) - end + it "returns nil when git is not available" do + stub_const("HOMEBREW_SHIMS_PATH", mktmpdir/"shim") + expect(described_class.git_path).to eq(nil) end - context "when git is available" do + it "returns version of git when git is available" do + expect(described_class.git_version).not_to be_nil + end + end + + describe "::ensure_git_installed!" do + it "returns nil if git already available" do + expect(described_class.ensure_git_installed!).to be_nil + end + + context "when git is not already available" do before do - described_class.instance_variable_set(:@git, true) + stub_const("HOMEBREW_SHIMS_PATH", mktmpdir/"shim") end - it "returns version of git" do - expect(described_class.git_version).not_to be_nil + it "can't install brewed git if homebrew/core is unavailable" do + allow_any_instance_of(Pathname).to receive(:directory?).and_return(false) + expect { described_class.ensure_git_installed! }.to raise_error("Git is unavailable") end - it "returns git_version if already set" do - described_class.instance_variable_set(:@git_version, "v1") - expect(described_class.git_version).to eq("v1") - described_class.instance_variable_set(:@git_version, nil) + it "raises error if can't install git" do + stub_const("HOMEBREW_BREW_FILE", mktmpdir/"brew") + expect { described_class.ensure_git_installed! }.to raise_error("Git is unavailable") + end + + it "installs git" do + allow(Homebrew).to receive(:_system).with(any_args).and_return(true) + described_class.ensure_git_installed! end end end describe "::git_remote_exists" do - context "when git is not available" do - before do - described_class.instance_variable_set(:@git, false) - end - - it "returns true" do - expect(described_class.git_remote_exists("blah")).to be_truthy - end + it "returns true when git is not available" do + stub_const("HOMEBREW_SHIMS_PATH", mktmpdir/"shim") + expect(described_class.git_remote_exists("blah")).to be_truthy end context "when git is available" do - before(:all) do - described_class.instance_variable_set(:@git, true) - end - - after(:all) do - if described_class.instance_variable_defined?(:@git) - described_class.send(:remove_instance_variable, :@git) - end - end - it "returns true when git remote exists", :needs_network do git = HOMEBREW_SHIMS_PATH/"scm/git" repo = Pathname.new("hey") @@ -173,10 +143,10 @@ describe Utils do system "cd", repo system git, "init" - system git, "remote", "add", "origin", "git@github.com:Homebrew/brew" + system git, "remote", "add", "origin", "http://github.com/Homebrew/homebrew.github.io" system "cd .." - expect(described_class.git_remote_exists("git@github.com:Homebrew/brew")).to be_truthy + expect(described_class.git_remote_exists("http://github.com/Homebrew/homebrew.github.io")).to be_truthy FileUtils.rm_rf(repo) end @@ -191,24 +161,15 @@ describe Utils do it "removes @git_path and @git_version if defined" do described_class.clear_git_available_cache - expect(@git_path).to be_nil - expect(@git_version).to be_nil + expect(described_class.instance_variable_get(:@git_path)).to be_nil + expect(described_class.instance_variable_get(:@git_version)).to be_nil end it "removes @git if defined" do - described_class.instance_variable_set(:@git, true) + described_class.git_available? + described_class.clear_git_available_cache - begin - described_class.clear_git_available_cache - - expect(@git).to be_nil - expect(@git_path).to be_nil - expect(@git_version).to be_nil - ensure - if described_class.instance_variable_defined?(:@git) - described_class.send(:remove_instance_variable, :@git) - end - end + expect(described_class.instance_variable_get(:@git)).to be_nil end end end diff --git a/Library/Homebrew/utils/git.rb b/Library/Homebrew/utils/git.rb index 1e2e360e67..8521929459 100644 --- a/Library/Homebrew/utils/git.rb +++ b/Library/Homebrew/utils/git.rb @@ -4,7 +4,7 @@ module Git module_function def last_revision_commit_of_file(repo, file, before_commit: nil) - args = ["--skip=#{before_commit.nil? ? 1 : before_commit.split("..").first}"] + args = [before_commit.nil? ? "--skip=1" : before_commit.split("..").first] out, = Open3.capture3( HOMEBREW_SHIMS_PATH/"scm/git", "-C", repo, From c695dffd373aefaaa84f1cf1098d23bd9f1d998d Mon Sep 17 00:00:00 2001 From: mansimarkaur Date: Fri, 25 Aug 2017 17:19:34 +0530 Subject: [PATCH 112/294] Added clear git version cache method --- Library/Homebrew/test/utils/git_spec.rb | 72 +++++++++++-------------- Library/Homebrew/utils/git.rb | 6 ++- 2 files changed, 37 insertions(+), 41 deletions(-) diff --git a/Library/Homebrew/test/utils/git_spec.rb b/Library/Homebrew/test/utils/git_spec.rb index 994e237257..65dd3bf414 100644 --- a/Library/Homebrew/test/utils/git_spec.rb +++ b/Library/Homebrew/test/utils/git_spec.rb @@ -1,44 +1,39 @@ require "utils/git" describe Git do - before(:all) do + before(:each) do git = HOMEBREW_SHIMS_PATH/"scm/git" - @file = "lib/blah.rb" - @repo = Pathname.new("repo") + @file = "blah.rb" - (@repo/"lib").mkpath - system git, "init" - FileUtils.touch(@repo/@file) + HOMEBREW_CACHE.cd do + system git, "init" - File.open(@repo/@file, "w") { |f| f.write("blah") } - system git, "add", @repo/@file - system git, "commit", "-m", "'File added'" - @h1 = `git rev-parse HEAD` + File.open(@file, "w") { |f| f.write("blah") } + system git, "add", HOMEBREW_CACHE/@file + system git, "commit", "-m", "'File added'" + @h1 = `git rev-parse HEAD` - File.open(@repo/@file, "w") { |f| f.write("brew") } - system git, "add", @repo/@file - system git, "commit", "-m", "'written to File'" - @h2 = `git rev-parse HEAD` + File.open(@file, "w") { |f| f.write("brew") } + system git, "add", HOMEBREW_CACHE/@file + system git, "commit", "-m", "'written to File'" + @h2 = `git rev-parse HEAD` + end end let(:hash1) { @h1[0..6] } let(:hash2) { @h2[0..6] } - after(:all) do - FileUtils.rm_rf(@repo) - end - describe "#last_revision_commit_of_file" do it "gives last revision commit when before_commit is nil" do expect( - described_class.last_revision_commit_of_file(@repo, @file), + described_class.last_revision_commit_of_file(HOMEBREW_CACHE, @file), ).to eq(hash1) end it "gives revision commit based on before_commit when it is not nil" do expect( - described_class.last_revision_commit_of_file(@repo, + described_class.last_revision_commit_of_file(HOMEBREW_CACHE, @file, before_commit: hash2), ).to eq(hash2) @@ -48,14 +43,14 @@ describe Git do describe "#last_revision_of_file" do it "returns last revision of file" do expect( - described_class.last_revision_of_file(@repo, - @repo/@file), + described_class.last_revision_of_file(HOMEBREW_CACHE, + HOMEBREW_CACHE/@file), ).to eq("blah") end it "returns last revision of file based on before_commit" do expect( - described_class.last_revision_of_file(@repo, @repo/@file, + described_class.last_revision_of_file(HOMEBREW_CACHE, HOMEBREW_CACHE/@file, before_commit: "0..3"), ).to eq("brew") end @@ -64,9 +59,7 @@ end describe Utils do before(:each) do - if described_class.instance_variable_defined?(:@git) - described_class.send(:remove_instance_variable, :@git) - end + described_class.clear_git_version_cache end describe "::git_available?" do @@ -75,14 +68,14 @@ describe Utils do end it "returns false if git --version command does not succeed" do - stub_const("HOMEBREW_SHIMS_PATH", mktmpdir/"shim") + stub_const("HOMEBREW_SHIMS_PATH", HOMEBREW_PREFIX/"bin/shim") expect(described_class.git_available?).to be_falsey end end describe "::git_path" do it "returns nil when git is not available" do - stub_const("HOMEBREW_SHIMS_PATH", mktmpdir/"shim") + stub_const("HOMEBREW_SHIMS_PATH", HOMEBREW_PREFIX/"bin/shim") expect(described_class.git_path).to eq(nil) end @@ -93,7 +86,7 @@ describe Utils do describe "::git_version" do it "returns nil when git is not available" do - stub_const("HOMEBREW_SHIMS_PATH", mktmpdir/"shim") + stub_const("HOMEBREW_SHIMS_PATH", HOMEBREW_PREFIX/"bin/shim") expect(described_class.git_path).to eq(nil) end @@ -109,7 +102,7 @@ describe Utils do context "when git is not already available" do before do - stub_const("HOMEBREW_SHIMS_PATH", mktmpdir/"shim") + stub_const("HOMEBREW_SHIMS_PATH", HOMEBREW_PREFIX/"bin/shim") end it "can't install brewed git if homebrew/core is unavailable" do @@ -118,7 +111,7 @@ describe Utils do end it "raises error if can't install git" do - stub_const("HOMEBREW_BREW_FILE", mktmpdir/"brew") + stub_const("HOMEBREW_BREW_FILE", HOMEBREW_PREFIX/"bin/brew") expect { described_class.ensure_git_installed! }.to raise_error("Git is unavailable") end @@ -131,24 +124,23 @@ describe Utils do describe "::git_remote_exists" do it "returns true when git is not available" do - stub_const("HOMEBREW_SHIMS_PATH", mktmpdir/"shim") + stub_const("HOMEBREW_SHIMS_PATH", HOMEBREW_PREFIX/"bin/shim") expect(described_class.git_remote_exists("blah")).to be_truthy end context "when git is available" do it "returns true when git remote exists", :needs_network do git = HOMEBREW_SHIMS_PATH/"scm/git" - repo = Pathname.new("hey") + url = "http://github.com/Homebrew/homebrew.github.io" + repo = HOMEBREW_CACHE/"hey" repo.mkpath - system "cd", repo - system git, "init" - system git, "remote", "add", "origin", "http://github.com/Homebrew/homebrew.github.io" - system "cd .." + repo.cd do + system git, "init" + system git, "remote", "add", "origin", url + end - expect(described_class.git_remote_exists("http://github.com/Homebrew/homebrew.github.io")).to be_truthy - - FileUtils.rm_rf(repo) + expect(described_class.git_remote_exists(url)).to be_truthy end it "returns false when git remote does not exist" do diff --git a/Library/Homebrew/utils/git.rb b/Library/Homebrew/utils/git.rb index 8521929459..4fdcf1a2e1 100644 --- a/Library/Homebrew/utils/git.rb +++ b/Library/Homebrew/utils/git.rb @@ -19,13 +19,17 @@ module Git commit_hash = last_revision_commit_of_file(repo, relative_file, before_commit: before_commit) out, = Open3.capture3( HOMEBREW_SHIMS_PATH/"scm/git", "-C", repo, - "show", "#{commit_hash}:#{file}" + "show", "#{commit_hash}:#{relative_file}" ) out end end module Utils + def self.clear_git_version_cache + remove_instance_variable(:@git) if instance_variable_defined?(:@git) + end + def self.git_available? return @git if instance_variable_defined?(:@git) @git = quiet_system HOMEBREW_SHIMS_PATH/"scm/git", "--version" From 923c84d4f7c4e0cf09bfb417deb83bff2364c199 Mon Sep 17 00:00:00 2001 From: Viktor Szakats Date: Sun, 27 Aug 2017 09:39:28 +0000 Subject: [PATCH 113/294] add some heuristics to https upgrade check --- Library/Homebrew/dev-cmd/audit.rb | 36 ++++++++++++++++++++++++++----- 1 file changed, 31 insertions(+), 5 deletions(-) diff --git a/Library/Homebrew/dev-cmd/audit.rb b/Library/Homebrew/dev-cmd/audit.rb index 2c93364812..4fadae1a40 100644 --- a/Library/Homebrew/dev-cmd/audit.rb +++ b/Library/Homebrew/dev-cmd/audit.rb @@ -201,7 +201,7 @@ class FormulaAuditor @specs = %w[stable devel head].map { |s| formula.send(s) }.compact end - def self.check_http_content(url, name, user_agents: [:default]) + def self.check_http_content(type, url, name, user_agents: [:default]) return unless url.start_with? "http" details = nil @@ -236,8 +236,31 @@ class FormulaAuditor details[:content_length] == secure_details[:content_length] file_match = details[:file_hash] == secure_details[:file_hash] - return if !etag_match && !content_length_match && !file_match - "The URL #{url} could use HTTPS rather than HTTP" + if etag_match || content_length_match || file_match + return "The URL #{url} could use HTTPS rather than HTTP" + end + + if type == "homepage" + + details[:file] = details[:file].gsub(/https?:\\?\/\\?\//, '/') + secure_details[:file] = secure_details[:file].gsub(/https?:\\?\/\\?\//, '/') + + # Same content after normalization + if details[:file] == secure_details[:file] + return "The URL #{url} could use HTTPS rather than HTTP" + end + + # Same size, different content after normalization + # (typical causes: Generated ID, Timestamp, Unix time) + if details[:file].length == secure_details[:file].length + return "The URL #{url} could use HTTPS rather than HTTP" + end + + lenratio = (100 * secure_details[:file].length / details[:file].length).to_i + if lenratio >= 90 && lenratio <= 120 + return "The URL #{url} may be able to use HTTPS rather than HTTP. Please verify it in a browser." + end + end end def self.http_content_headers_and_checksum(url, hash_needed: false, user_agent: :default) @@ -260,6 +283,7 @@ class FormulaAuditor etag: headers[%r{ETag: ([wW]\/)?"(([^"]|\\")*)"}, 2], content_length: headers[/Content-Length: (\d+)/, 1], file_hash: output_hash, + file: output, } end @@ -564,7 +588,8 @@ class FormulaAuditor return unless @online return unless DevelopmentTools.curl_handles_most_https_homepages? - if http_content_problem = FormulaAuditor.check_http_content(homepage, + if http_content_problem = FormulaAuditor.check_http_content("homepage", + homepage, formula.name, user_agents: [:browser, :default]) problem http_content_problem @@ -1219,7 +1244,8 @@ 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, name) + if http_content_problem = FormulaAuditor.check_http_content("url", + url, name) problem http_content_problem end elsif strategy <= GitDownloadStrategy From 11b267a7cfb3411c74c4fc21732463d543fc4fb3 Mon Sep 17 00:00:00 2001 From: Viktor Szakats Date: Sun, 27 Aug 2017 17:52:26 +0000 Subject: [PATCH 114/294] try addressing style issues --- Library/Homebrew/dev-cmd/audit.rb | 31 +++++++++++++++---------------- 1 file changed, 15 insertions(+), 16 deletions(-) diff --git a/Library/Homebrew/dev-cmd/audit.rb b/Library/Homebrew/dev-cmd/audit.rb index 4fadae1a40..97fc93db9e 100644 --- a/Library/Homebrew/dev-cmd/audit.rb +++ b/Library/Homebrew/dev-cmd/audit.rb @@ -240,26 +240,25 @@ class FormulaAuditor return "The URL #{url} could use HTTPS rather than HTTP" end - if type == "homepage" + return if type != "homepage" - details[:file] = details[:file].gsub(/https?:\\?\/\\?\//, '/') - secure_details[:file] = secure_details[:file].gsub(/https?:\\?\/\\?\//, '/') + details[:file] = details[:file].gsub(%r{https?:\\?\/\\?\/}, "/") + secure_details[:file] = secure_details[:file].gsub(%r{https?:\\?\/\\?\/}, "/") - # Same content after normalization - if details[:file] == secure_details[:file] - return "The URL #{url} could use HTTPS rather than HTTP" - end + # Same content after normalization + if details[:file] == secure_details[:file] + return "The URL #{url} could use HTTPS rather than HTTP" + end - # Same size, different content after normalization - # (typical causes: Generated ID, Timestamp, Unix time) - if details[:file].length == secure_details[:file].length - return "The URL #{url} could use HTTPS rather than HTTP" - end + # Same size, different content after normalization + # (typical causes: Generated ID, Timestamp, Unix time) + if details[:file].length == secure_details[:file].length + return "The URL #{url} could use HTTPS rather than HTTP" + end - lenratio = (100 * secure_details[:file].length / details[:file].length).to_i - if lenratio >= 90 && lenratio <= 120 - return "The URL #{url} may be able to use HTTPS rather than HTTP. Please verify it in a browser." - end + lenratio = (100 * secure_details[:file].length / details[:file].length).to_i + if lenratio >= 90 && lenratio <= 120 + return "The URL #{url} may be able to use HTTPS rather than HTTP. Please verify it in a browser." end end From 1c2c390c6fae78062c28a8ed1610936a4c2dd412 Mon Sep 17 00:00:00 2001 From: Viktor Szakats Date: Sun, 27 Aug 2017 18:00:59 +0000 Subject: [PATCH 115/294] try addressing style issues #2 --- Library/Homebrew/dev-cmd/audit.rb | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/Library/Homebrew/dev-cmd/audit.rb b/Library/Homebrew/dev-cmd/audit.rb index 97fc93db9e..d468d69cb5 100644 --- a/Library/Homebrew/dev-cmd/audit.rb +++ b/Library/Homebrew/dev-cmd/audit.rb @@ -257,9 +257,8 @@ class FormulaAuditor end lenratio = (100 * secure_details[:file].length / details[:file].length).to_i - if lenratio >= 90 && lenratio <= 120 - return "The URL #{url} may be able to use HTTPS rather than HTTP. Please verify it in a browser." - end + return if lenratio < 90 || lenratio > 120 + "The URL #{url} may be able to use HTTPS rather than HTTP. Please verify it in a browser." end def self.http_content_headers_and_checksum(url, hash_needed: false, user_agent: :default) From 18115f0639b2777e15cda9496bb729dd8246d49d Mon Sep 17 00:00:00 2001 From: William Woodruff Date: Mon, 28 Aug 2017 17:33:57 -0400 Subject: [PATCH 116/294] mach: Avoid reopening the file for relocation This commit allows the relocation code to perform install name and dylib ID changes without reopening the file separately. --- .../Homebrew/extend/os/mac/keg_relocate.rb | 8 ++--- Library/Homebrew/os/mac.rb | 1 - Library/Homebrew/os/mac/keg.rb | 29 ------------------- Library/Homebrew/os/mac/mach.rb | 28 ++++++++++++++++++ 4 files changed, 32 insertions(+), 34 deletions(-) delete mode 100644 Library/Homebrew/os/mac/keg.rb diff --git a/Library/Homebrew/extend/os/mac/keg_relocate.rb b/Library/Homebrew/extend/os/mac/keg_relocate.rb index 707710be61..7031bea1ee 100644 --- a/Library/Homebrew/extend/os/mac/keg_relocate.rb +++ b/Library/Homebrew/extend/os/mac/keg_relocate.rb @@ -2,7 +2,7 @@ class Keg def fix_dynamic_linkage mach_o_files.each do |file| file.ensure_writable do - change_dylib_id(dylib_id_for(file), file) if file.dylib? + file.change_dylib_id(dylib_id_for(file)) if file.dylib? each_install_name_for(file) do |bad_name| # Don't fix absolute paths unless they are rooted in the build directory @@ -11,7 +11,7 @@ class Keg !bad_name.start_with?(HOMEBREW_TEMP.realpath.to_s) new_name = fixed_name(file, bad_name) - change_install_name(bad_name, new_name, file) unless new_name == bad_name + file.change_install_name(bad_name, new_name, file) end end end @@ -24,7 +24,7 @@ class Keg file.ensure_writable do if file.dylib? id = dylib_id_for(file).sub(relocation.old_prefix, relocation.new_prefix) - change_dylib_id(id, file) + file.change_dylib_id(id) end each_install_name_for(file) do |old_name| @@ -34,7 +34,7 @@ class Keg new_name = old_name.sub(relocation.old_prefix, relocation.new_prefix) end - change_install_name(old_name, new_name, file) if new_name + file.change_install_name(old_name, new_name) if new_name end end end diff --git a/Library/Homebrew/os/mac.rb b/Library/Homebrew/os/mac.rb index 5074665fca..b2a3109f14 100644 --- a/Library/Homebrew/os/mac.rb +++ b/Library/Homebrew/os/mac.rb @@ -5,7 +5,6 @@ require "os/mac/xcode" require "os/mac/xquartz" require "os/mac/pathname" require "os/mac/sdk" -require "os/mac/keg" module OS module Mac diff --git a/Library/Homebrew/os/mac/keg.rb b/Library/Homebrew/os/mac/keg.rb deleted file mode 100644 index 6caadb1d7a..0000000000 --- a/Library/Homebrew/os/mac/keg.rb +++ /dev/null @@ -1,29 +0,0 @@ -class Keg - def change_dylib_id(id, file) - return if file.dylib_id == id - @require_relocation = true - puts "Changing dylib ID of #{file}\n from #{file.dylib_id}\n to #{id}" if ARGV.debug? - MachO::Tools.change_dylib_id(file, id, strict: false) - rescue MachO::MachOError - onoe <<-EOS.undent - Failed changing dylib ID of #{file} - from #{file.dylib_id} - to #{id} - EOS - raise - end - - def change_install_name(old, new, file) - return if old == new - @require_relocation = true - puts "Changing install name in #{file}\n from #{old}\n to #{new}" if ARGV.debug? - MachO::Tools.change_install_name(file, old, new, strict: false) - rescue MachO::MachOError - onoe <<-EOS.undent - Failed changing install name in #{file} - from #{old} - to #{new} - EOS - raise - end -end diff --git a/Library/Homebrew/os/mac/mach.rb b/Library/Homebrew/os/mac/mach.rb index 9b53c49797..2d066392f6 100644 --- a/Library/Homebrew/os/mac/mach.rb +++ b/Library/Homebrew/os/mac/mach.rb @@ -61,6 +61,34 @@ module MachOShim macho.dylib_id end + def change_dylib_id(id) + return if dylib_id == id + @require_relocation = true + puts "Changing dylib ID of #{self}\n from #{dylib_id}\n to #{id}" if ARGV.debug? + macho.change_dylib_id(id, strict: false) + rescue MachO::MachOError + onoe <<-EOS.undent + Failed changing dylib ID of #{self} + from #{file.dylib_id} + to #{id} + EOS + raise + end + + def change_install_name(old, new) + return if old == new + @require_relocation = true + puts "Changing install name in #{self}\n from #{old}\n to #{new}" if ARGV.debug? + macho.change_install_name(old, new, strict: false) + rescue MachO::MachOError + onoe <<-EOS.undent + Failed changing install name in #{self} + from #{old} + to #{new} + EOS + raise + end + def archs mach_data.map { |m| m.fetch :arch }.extend(ArchitectureListExtension) end From 13fb14a95f6d0c909451e94e96b14447ccabdfcb Mon Sep 17 00:00:00 2001 From: mansimarkaur Date: Thu, 27 Jul 2017 01:52:21 +0530 Subject: [PATCH 117/294] Added tests fir utils/svn --- Library/Homebrew/test/utils/svn_spec.rb | 33 +++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 Library/Homebrew/test/utils/svn_spec.rb diff --git a/Library/Homebrew/test/utils/svn_spec.rb b/Library/Homebrew/test/utils/svn_spec.rb new file mode 100644 index 0000000000..35f8917aaf --- /dev/null +++ b/Library/Homebrew/test/utils/svn_spec.rb @@ -0,0 +1,33 @@ +require "utils/svn" + +describe Utils do + describe "#self.svn_available?" do + it "processes value when @svn is not defined" do + expect(described_class.svn_available?).to be_truthy + end + + it "returns value of @svn when @svn is defined" do + described_class.instance_variable_set(:@svn, true) + expect(described_class.svn_available?).to be_truthy + end + end + + describe "#self.svn_remote_exists" do + let(:url) { "https://dl.bintray.com/homebrew/mirror/" } + + it "gives true when @svn is false" do + allow_any_instance_of(Process::Status).to receive(:success?).and_return(false) + described_class.instance_variable_set(:@svn, false) + expect(described_class.svn_remote_exists(url)).to be_truthy + end + + it "gives false when url is obscure" do + expect(described_class.svn_remote_exists(url)).to be_falsy + end + + it "gives true when quiet_system succeeds with given url" do + allow_any_instance_of(Process::Status).to receive(:success?).and_return(true) + expect(described_class.svn_remote_exists(url)).to be_truthy + end + end +end From cf96d8d9700d0869d52add879f25179509b3773c Mon Sep 17 00:00:00 2001 From: mansimarkaur Date: Thu, 27 Jul 2017 04:18:43 +0530 Subject: [PATCH 118/294] Improved tests for svn_available? --- Library/Homebrew/test/utils/svn_spec.rb | 19 ++++++++++++------- Library/Homebrew/utils/svn.rb | 3 +-- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/Library/Homebrew/test/utils/svn_spec.rb b/Library/Homebrew/test/utils/svn_spec.rb index 35f8917aaf..3ff9ac6555 100644 --- a/Library/Homebrew/test/utils/svn_spec.rb +++ b/Library/Homebrew/test/utils/svn_spec.rb @@ -2,11 +2,17 @@ require "utils/svn" describe Utils do describe "#self.svn_available?" do - it "processes value when @svn is not defined" do + it "returns true if svn --version command succeeds" do + allow_any_instance_of(Process::Status).to receive(:success?).and_return(true) expect(described_class.svn_available?).to be_truthy end - it "returns value of @svn when @svn is defined" do + it "returns false if svn --version command does not succeed" do + allow_any_instance_of(Process::Status).to receive(:success?).and_return(false) + expect(described_class.svn_available?).to be_falsey + end + + it "returns svn version if already set" do described_class.instance_variable_set(:@svn, true) expect(described_class.svn_available?).to be_truthy end @@ -15,17 +21,16 @@ describe Utils do describe "#self.svn_remote_exists" do let(:url) { "https://dl.bintray.com/homebrew/mirror/" } - it "gives true when @svn is false" do - allow_any_instance_of(Process::Status).to receive(:success?).and_return(false) + it "returns true when svn is not available" do described_class.instance_variable_set(:@svn, false) expect(described_class.svn_remote_exists(url)).to be_truthy end - it "gives false when url is obscure" do - expect(described_class.svn_remote_exists(url)).to be_falsy + it "returns false when remote does not exist" do + expect(described_class.svn_remote_exists(url)).to be_falsey end - it "gives true when quiet_system succeeds with given url" do + it "returns true when remote exists" do allow_any_instance_of(Process::Status).to receive(:success?).and_return(true) expect(described_class.svn_remote_exists(url)).to be_truthy end diff --git a/Library/Homebrew/utils/svn.rb b/Library/Homebrew/utils/svn.rb index fb49ac2e99..7a99551b33 100644 --- a/Library/Homebrew/utils/svn.rb +++ b/Library/Homebrew/utils/svn.rb @@ -1,7 +1,6 @@ module Utils def self.svn_available? - return @svn if instance_variable_defined?(:@svn) - @svn = quiet_system HOMEBREW_SHIMS_PATH/"scm/svn", "--version" + @svn ||= quiet_system HOMEBREW_SHIMS_PATH/"scm/svn", "--version" end def self.svn_remote_exists(url) From 53be6bb4bd69eaf8cc8e5c3c1ac9ecd1ddb1582c Mon Sep 17 00:00:00 2001 From: mansimarkaur Date: Thu, 27 Jul 2017 04:40:27 +0530 Subject: [PATCH 119/294] Added check for svn availability --- Library/Homebrew/dev-cmd/audit.rb | 4 ++- Library/Homebrew/test/utils/svn_spec.rb | 43 +++++++++++++------------ Library/Homebrew/utils/svn.rb | 3 +- 3 files changed, 28 insertions(+), 22 deletions(-) diff --git a/Library/Homebrew/dev-cmd/audit.rb b/Library/Homebrew/dev-cmd/audit.rb index 2c93364812..0e4500a124 100644 --- a/Library/Homebrew/dev-cmd/audit.rb +++ b/Library/Homebrew/dev-cmd/audit.rb @@ -1228,7 +1228,9 @@ class ResourceAuditor end elsif strategy <= SubversionDownloadStrategy next unless DevelopmentTools.subversion_handles_most_https_certificates? - unless Utils.svn_remote_exists url + if !Utils.svn_available? + problem "No valid version of svn found" + elsif Utils.svn_remote_exists url problem "The URL #{url} is not a valid svn URL" end end diff --git a/Library/Homebrew/test/utils/svn_spec.rb b/Library/Homebrew/test/utils/svn_spec.rb index 3ff9ac6555..6f841cc92c 100644 --- a/Library/Homebrew/test/utils/svn_spec.rb +++ b/Library/Homebrew/test/utils/svn_spec.rb @@ -2,37 +2,40 @@ require "utils/svn" describe Utils do describe "#self.svn_available?" do - it "returns true if svn --version command succeeds" do - allow_any_instance_of(Process::Status).to receive(:success?).and_return(true) - expect(described_class.svn_available?).to be_truthy + before(:each) do + if described_class.instance_variable_defined?(:@svn) + described_class.send(:remove_instance_variable, :@svn) + end end - it "returns false if svn --version command does not succeed" do - allow_any_instance_of(Process::Status).to receive(:success?).and_return(false) - expect(described_class.svn_available?).to be_falsey - end - - it "returns svn version if already set" do - described_class.instance_variable_set(:@svn, true) + it "returns svn version if svn available" do expect(described_class.svn_available?).to be_truthy end end describe "#self.svn_remote_exists" do - let(:url) { "https://dl.bintray.com/homebrew/mirror/" } - it "returns true when svn is not available" do - described_class.instance_variable_set(:@svn, false) - expect(described_class.svn_remote_exists(url)).to be_truthy + allow(Utils).to receive(:svn_available?).and_return(false) + expect(described_class.svn_remote_exists("blah")).to be_truthy end - it "returns false when remote does not exist" do - expect(described_class.svn_remote_exists(url)).to be_falsey - end + context "when svn is available" do + before do + allow(Utils).to receive(:svn_available?).and_return(true) + end - it "returns true when remote exists" do - allow_any_instance_of(Process::Status).to receive(:success?).and_return(true) - expect(described_class.svn_remote_exists(url)).to be_truthy + it "returns false when remote does not exist" do + expect(described_class.svn_remote_exists(HOMEBREW_CACHE/"install")).to be_falsey + end + + it "returns true when remote exists", :needs_network do + remote = "http://github.com/Homebrew/install" + svn = HOMEBREW_SHIMS_PATH/"scm/svn" + + HOMEBREW_CACHE.cd { system svn, "checkout", remote } + + expect(described_class.svn_remote_exists(HOMEBREW_CACHE/"install")).to be_truthy + end end end end diff --git a/Library/Homebrew/utils/svn.rb b/Library/Homebrew/utils/svn.rb index 7a99551b33..fb49ac2e99 100644 --- a/Library/Homebrew/utils/svn.rb +++ b/Library/Homebrew/utils/svn.rb @@ -1,6 +1,7 @@ module Utils def self.svn_available? - @svn ||= quiet_system HOMEBREW_SHIMS_PATH/"scm/svn", "--version" + return @svn if instance_variable_defined?(:@svn) + @svn = quiet_system HOMEBREW_SHIMS_PATH/"scm/svn", "--version" end def self.svn_remote_exists(url) From d9c0b8ce9fb65c288d2192f9db0efb93a2bd4d52 Mon Sep 17 00:00:00 2001 From: mansimarkaur Date: Thu, 24 Aug 2017 01:30:29 +0530 Subject: [PATCH 120/294] Added clear_svn_version_cache --- Library/Homebrew/utils/svn.rb | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Library/Homebrew/utils/svn.rb b/Library/Homebrew/utils/svn.rb index fb49ac2e99..150b7eee74 100644 --- a/Library/Homebrew/utils/svn.rb +++ b/Library/Homebrew/utils/svn.rb @@ -1,4 +1,8 @@ module Utils + def self.clear_svn_version_cache + remove_instance_variable(:@svn) if instance_variable_defined?(:@svn) + end + def self.svn_available? return @svn if instance_variable_defined?(:@svn) @svn = quiet_system HOMEBREW_SHIMS_PATH/"scm/svn", "--version" From d533973395e549c558c2282a46acc12df4e7d6da Mon Sep 17 00:00:00 2001 From: mansimarkaur Date: Thu, 24 Aug 2017 01:31:12 +0530 Subject: [PATCH 121/294] Used clear_svn_version_cache to remove @svn --- Library/Homebrew/test/utils/svn_spec.rb | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/Library/Homebrew/test/utils/svn_spec.rb b/Library/Homebrew/test/utils/svn_spec.rb index 6f841cc92c..4edb365a03 100644 --- a/Library/Homebrew/test/utils/svn_spec.rb +++ b/Library/Homebrew/test/utils/svn_spec.rb @@ -3,9 +3,7 @@ require "utils/svn" describe Utils do describe "#self.svn_available?" do before(:each) do - if described_class.instance_variable_defined?(:@svn) - described_class.send(:remove_instance_variable, :@svn) - end + described_class.clear_svn_version_cache end it "returns svn version if svn available" do From 3d8873ca5b6270351ac8e4260fba8a41f8c0fe04 Mon Sep 17 00:00:00 2001 From: mansimarkaur Date: Tue, 29 Aug 2017 16:14:00 +0530 Subject: [PATCH 122/294] url skipped if svn not available when auditing urls --- Library/Homebrew/dev-cmd/audit.rb | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/Library/Homebrew/dev-cmd/audit.rb b/Library/Homebrew/dev-cmd/audit.rb index 0e4500a124..be332481ca 100644 --- a/Library/Homebrew/dev-cmd/audit.rb +++ b/Library/Homebrew/dev-cmd/audit.rb @@ -1228,9 +1228,8 @@ class ResourceAuditor end elsif strategy <= SubversionDownloadStrategy next unless DevelopmentTools.subversion_handles_most_https_certificates? - if !Utils.svn_available? - problem "No valid version of svn found" - elsif Utils.svn_remote_exists url + next unless Utils.svn_available? + if Utils.svn_remote_exists url problem "The URL #{url} is not a valid svn URL" end end From a4d4da64aab707e2f39fcc32fec6418cc39e8010 Mon Sep 17 00:00:00 2001 From: mansimarkaur Date: Thu, 27 Jul 2017 04:41:49 +0530 Subject: [PATCH 123/294] Added tests for os_prefix_ci --- Library/Homebrew/test/utils/analytics_spec.rb | 34 +++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 Library/Homebrew/test/utils/analytics_spec.rb diff --git a/Library/Homebrew/test/utils/analytics_spec.rb b/Library/Homebrew/test/utils/analytics_spec.rb new file mode 100644 index 0000000000..cee09e2861 --- /dev/null +++ b/Library/Homebrew/test/utils/analytics_spec.rb @@ -0,0 +1,34 @@ +require "utils/analytics" + +describe Utils::Analytics do + describe "::os_prefix_ci" do + context "when anonymous_os_prefix_ci is not set" do + it "returns OS_VERSION and prefix when HOMEBREW_PREFIX is not /usr/local" do + expect(described_class.os_prefix_ci).to include("#{OS_VERSION}, non-/usr/local") + end + + it "includes CI when ENV['CI'] is set" do + allow(ENV).to receive(:[]).with("CI").and_return("true") + expect(described_class.os_prefix_ci).to include("CI") + end + + it "does not include prefix when HOMEBREW_PREFIX is usr/local" do + allow(HOMEBREW_PREFIX).to receive(:to_s).and_return("/usr/local") + expect(described_class.os_prefix_ci).not_to include("non-/usr/local") + end + end + + context "when anonymous_os_prefix_ci is set" do + let(:anonymous_os_prefix_ci) { "macOS 10.11.6, non-/usr/local, CI" } + + it "returns anonymous_os_prefix_ci" do + described_class.instance_variable_set(:@anonymous_os_prefix_ci, anonymous_os_prefix_ci) + expect(described_class.os_prefix_ci).to eq(anonymous_os_prefix_ci) + end + end + end + + describe "::" do + + end +end \ No newline at end of file From 2660f5ae3ea5e0ce466e6f9b3b736a12ad3a341a Mon Sep 17 00:00:00 2001 From: mansimarkaur Date: Thu, 27 Jul 2017 17:47:28 +0530 Subject: [PATCH 124/294] Added tests for report and report_event --- Library/Homebrew/test/utils/analytics_spec.rb | 50 +++++++++++++++++-- 1 file changed, 45 insertions(+), 5 deletions(-) diff --git a/Library/Homebrew/test/utils/analytics_spec.rb b/Library/Homebrew/test/utils/analytics_spec.rb index cee09e2861..96a9a4f7ff 100644 --- a/Library/Homebrew/test/utils/analytics_spec.rb +++ b/Library/Homebrew/test/utils/analytics_spec.rb @@ -1,19 +1,27 @@ require "utils/analytics" +require "formula_installer" describe Utils::Analytics do describe "::os_prefix_ci" do context "when anonymous_os_prefix_ci is not set" do + before(:each) do + if described_class.instance_variable_defined?(:@anonymous_os_prefix_ci) + described_class.send(:remove_instance_variable, :@anonymous_os_prefix_ci) + end + end + it "returns OS_VERSION and prefix when HOMEBREW_PREFIX is not /usr/local" do + stub_const("HOMEBREW_PREFIX", "blah") expect(described_class.os_prefix_ci).to include("#{OS_VERSION}, non-/usr/local") end it "includes CI when ENV['CI'] is set" do - allow(ENV).to receive(:[]).with("CI").and_return("true") + ENV["CI"] = "true" expect(described_class.os_prefix_ci).to include("CI") end it "does not include prefix when HOMEBREW_PREFIX is usr/local" do - allow(HOMEBREW_PREFIX).to receive(:to_s).and_return("/usr/local") + stub_const("HOMEBREW_PREFIX", "/usr/local") expect(described_class.os_prefix_ci).not_to include("non-/usr/local") end end @@ -28,7 +36,39 @@ describe Utils::Analytics do end end - describe "::" do - + describe "::report_event" do + let(:f) { formula { url "foo-1.0" } } + let(:options) { FormulaInstaller.new(f).display_options(f) } + let(:action) { "#{f.full_name} #{options}".strip } + + context "when ENV vars is set" do + it "returns nil when HOMEBREW_NO_ANALYTICS is true" do + ENV["HOMEBREW_NO_ANALYTICS"] = "true" + expect(described_class.report_event("install", action)).to be_nil + end + + it "returns nil when HOMEBREW_NO_ANALYTICS_THIS_RUN is true" do + ENV["HOMEBREW_NO_ANALYTICS_THIS_RUN"] = "true" + expect(described_class.report_event("install", action)).to be_nil + end + + it "returns nil when HOMEBREW_ANALYTICS_DEBUG is true" do + ENV["HOMEBREW_NO_ANALYTICS_THIS_RUN"] = nil + ENV["HOMEBREW_NO_ANALYTICS"] = nil + ENV["HOMEBREW_ANALYTICS_DEBUG"] = "true" + expect(described_class.report_event("install", action)).to be_nil + end + end + + context "when ENV vars are nil" do + before do + ENV["HOMEBREW_NO_ANALYTICS"] = nil + ENV["HOMEBREW_NO_ANALYTICS_THIS_RUN"] = nil + end + + it "returns nil when HOMEBREW_ANALYTICS_DEBUG is not set" do + expect(described_class.report_event("install", action)).to be_an_instance_of(Thread) + end + end end -end \ No newline at end of file +end From a4d8d7ba576e1418a18eb605b8eddc6c10447608 Mon Sep 17 00:00:00 2001 From: mansimarkaur Date: Tue, 15 Aug 2017 21:05:52 +0530 Subject: [PATCH 125/294] Added tests for report_build_error --- Library/Homebrew/test/utils/analytics_spec.rb | 47 +++++++++++++++---- 1 file changed, 37 insertions(+), 10 deletions(-) diff --git a/Library/Homebrew/test/utils/analytics_spec.rb b/Library/Homebrew/test/utils/analytics_spec.rb index 96a9a4f7ff..eb675b370d 100644 --- a/Library/Homebrew/test/utils/analytics_spec.rb +++ b/Library/Homebrew/test/utils/analytics_spec.rb @@ -25,15 +25,6 @@ describe Utils::Analytics do expect(described_class.os_prefix_ci).not_to include("non-/usr/local") end end - - context "when anonymous_os_prefix_ci is set" do - let(:anonymous_os_prefix_ci) { "macOS 10.11.6, non-/usr/local, CI" } - - it "returns anonymous_os_prefix_ci" do - described_class.instance_variable_set(:@anonymous_os_prefix_ci, anonymous_os_prefix_ci) - expect(described_class.os_prefix_ci).to eq(anonymous_os_prefix_ci) - end - end end describe "::report_event" do @@ -66,9 +57,45 @@ describe Utils::Analytics do ENV["HOMEBREW_NO_ANALYTICS_THIS_RUN"] = nil end - it "returns nil when HOMEBREW_ANALYTICS_DEBUG is not set" do + it "returns waiting thread when HOMEBREW_ANALYTICS_DEBUG is not set" do expect(described_class.report_event("install", action)).to be_an_instance_of(Thread) end end end + + describe "::report_build_error" do + context "when tap is installed" do + let(:err) { BuildError.new(f, "badprg", %w[arg1 arg2], {}) } + let(:f) { formula { url "foo-1.0" } } + + it "reports event if BuildError raised for a formula with a public remote repository" do + allow_any_instance_of(Tap).to receive(:custom_remote?).and_return(false) + expect(described_class).to respond_to(:report_event) + described_class.report_build_error(err) + end + + it "does not report event if BuildError raised for a formula with a private remote repository" do + expect(described_class.report_build_error(err)).to be_nil + end + end + + context "when formula does not have a tap" do + let(:err) { BuildError.new(f, "badprg", %w[arg1 arg2], {}) } + let(:f) { double(Formula, name: "foo", path: "blah", tap: nil) } + + it "does not report event if BuildError is raised" do + expect(described_class.report_build_error(err)).to be_nil + end + end + + context "when tap for a formula is not installed" do + let(:err) { BuildError.new(f, "badprg", %w[arg1 arg2], {}) } + let(:f) { double(Formula, name: "foo", path: "blah", tap: CoreTap.instance) } + + it "does not report event if BuildError is raised" do + allow_any_instance_of(Pathname).to receive(:directory?).and_return(false) + expect(described_class.report_build_error(err)).to be_nil + end + end + end end From 59f3c661a31d2d0d7f649fbe75daae171b2cfd23 Mon Sep 17 00:00:00 2001 From: mansimarkaur Date: Sun, 20 Aug 2017 22:04:09 +0530 Subject: [PATCH 126/294] Used ENV.delete to remove set ENV vars --- Library/Homebrew/test/utils/analytics_spec.rb | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Library/Homebrew/test/utils/analytics_spec.rb b/Library/Homebrew/test/utils/analytics_spec.rb index eb675b370d..228c352b4c 100644 --- a/Library/Homebrew/test/utils/analytics_spec.rb +++ b/Library/Homebrew/test/utils/analytics_spec.rb @@ -44,8 +44,8 @@ describe Utils::Analytics do end it "returns nil when HOMEBREW_ANALYTICS_DEBUG is true" do - ENV["HOMEBREW_NO_ANALYTICS_THIS_RUN"] = nil - ENV["HOMEBREW_NO_ANALYTICS"] = nil + ENV.delete("HOMEBREW_NO_ANALYTICS_THIS_RUN") + ENV.delete("HOMEBREW_NO_ANALYTICS") ENV["HOMEBREW_ANALYTICS_DEBUG"] = "true" expect(described_class.report_event("install", action)).to be_nil end @@ -53,8 +53,8 @@ describe Utils::Analytics do context "when ENV vars are nil" do before do - ENV["HOMEBREW_NO_ANALYTICS"] = nil - ENV["HOMEBREW_NO_ANALYTICS_THIS_RUN"] = nil + ENV.delete("HOMEBREW_NO_ANALYTICS_THIS_RUN") + ENV.delete("HOMEBREW_NO_ANALYTICS") end it "returns waiting thread when HOMEBREW_ANALYTICS_DEBUG is not set" do From 413d35b82fc66a6970d933a845a242b795340e44 Mon Sep 17 00:00:00 2001 From: mansimarkaur Date: Thu, 24 Aug 2017 01:44:13 +0530 Subject: [PATCH 127/294] Added clear_anonymous_os_prefix_ci_cache --- Library/Homebrew/utils/analytics.rb | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Library/Homebrew/utils/analytics.rb b/Library/Homebrew/utils/analytics.rb index a89995ba93..2e59b8f009 100644 --- a/Library/Homebrew/utils/analytics.rb +++ b/Library/Homebrew/utils/analytics.rb @@ -3,6 +3,10 @@ require "erb" module Utils module Analytics class << self + def clear_anonymous_os_prefix_ci_cache + remove_instance_variable(:@anonymous_os_prefix_ci) if instance_variable_defined?(:@anonymous_os_prefix_ci) + end + def os_prefix_ci @anonymous_os_prefix_ci ||= begin os = OS_VERSION From db28126b4a31c3d8ff910283fc50ab4de1f63db2 Mon Sep 17 00:00:00 2001 From: mansimarkaur Date: Thu, 24 Aug 2017 01:44:48 +0530 Subject: [PATCH 128/294] Used clear_anonymous_os_prefix_ci_cache to remove @anonymous_os_prefix_ci --- Library/Homebrew/test/utils/analytics_spec.rb | 17 ++--------------- 1 file changed, 2 insertions(+), 15 deletions(-) diff --git a/Library/Homebrew/test/utils/analytics_spec.rb b/Library/Homebrew/test/utils/analytics_spec.rb index 228c352b4c..bb6cda0b12 100644 --- a/Library/Homebrew/test/utils/analytics_spec.rb +++ b/Library/Homebrew/test/utils/analytics_spec.rb @@ -5,9 +5,7 @@ describe Utils::Analytics do describe "::os_prefix_ci" do context "when anonymous_os_prefix_ci is not set" do before(:each) do - if described_class.instance_variable_defined?(:@anonymous_os_prefix_ci) - described_class.send(:remove_instance_variable, :@anonymous_os_prefix_ci) - end + described_class.clear_anonymous_os_prefix_ci_cache end it "returns OS_VERSION and prefix when HOMEBREW_PREFIX is not /usr/local" do @@ -20,7 +18,7 @@ describe Utils::Analytics do expect(described_class.os_prefix_ci).to include("CI") end - it "does not include prefix when HOMEBREW_PREFIX is usr/local" do + it "does not include prefix when HOMEBREW_PREFIX is /usr/local" do stub_const("HOMEBREW_PREFIX", "/usr/local") expect(described_class.os_prefix_ci).not_to include("non-/usr/local") end @@ -50,17 +48,6 @@ describe Utils::Analytics do expect(described_class.report_event("install", action)).to be_nil end end - - context "when ENV vars are nil" do - before do - ENV.delete("HOMEBREW_NO_ANALYTICS_THIS_RUN") - ENV.delete("HOMEBREW_NO_ANALYTICS") - end - - it "returns waiting thread when HOMEBREW_ANALYTICS_DEBUG is not set" do - expect(described_class.report_event("install", action)).to be_an_instance_of(Thread) - end - end end describe "::report_build_error" do From 1dd7e9d95b55bbf352dfe7a9dd1e509fc1bc557d Mon Sep 17 00:00:00 2001 From: mansimarkaur Date: Tue, 29 Aug 2017 16:36:46 +0530 Subject: [PATCH 129/294] Modified clear_anonymous_os_prefix_ci_cache --- Library/Homebrew/utils/analytics.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Library/Homebrew/utils/analytics.rb b/Library/Homebrew/utils/analytics.rb index 2e59b8f009..9766c14db3 100644 --- a/Library/Homebrew/utils/analytics.rb +++ b/Library/Homebrew/utils/analytics.rb @@ -4,7 +4,8 @@ module Utils module Analytics class << self def clear_anonymous_os_prefix_ci_cache - remove_instance_variable(:@anonymous_os_prefix_ci) if instance_variable_defined?(:@anonymous_os_prefix_ci) + return unless instance_variable_defined?(:@anonymous_os_prefix_ci) + remove_instance_variable(:@anonymous_os_prefix_ci) end def os_prefix_ci From c6274b01df033d99d235738c58b9f3b9eadac239 Mon Sep 17 00:00:00 2001 From: Dominyk Tiller Date: Tue, 29 Aug 2017 04:22:05 +0100 Subject: [PATCH 130/294] missing_formula: update for Pillow's removal Ref: https://github.com/Homebrew/homebrew-core/pull/17341 Ref: https://github.com/Homebrew/homebrew-core/pull/17357 --- Library/Homebrew/missing_formula.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Library/Homebrew/missing_formula.rb b/Library/Homebrew/missing_formula.rb index c3625c8bb0..b507fcab17 100644 --- a/Library/Homebrew/missing_formula.rb +++ b/Library/Homebrew/missing_formula.rb @@ -31,7 +31,7 @@ module Homebrew #{Formatter.url("https://pip.readthedocs.io/en/stable/installing/")} EOS when "pil" then <<-EOS.undent - Instead of PIL, consider `pip install pillow` or `brew install Homebrew/science/pillow`. + Instead of PIL, consider `pip install pillow`. EOS when "macruby" then <<-EOS.undent MacRuby is not packaged and is on an indefinite development hiatus. From f8d5b20512700c9458c51523bda2da24f4212b0c Mon Sep 17 00:00:00 2001 From: Dominyk Tiller Date: Tue, 29 Aug 2017 12:14:05 +0100 Subject: [PATCH 131/294] missing_formula: use pip2 instead of pip --- Library/Homebrew/missing_formula.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Library/Homebrew/missing_formula.rb b/Library/Homebrew/missing_formula.rb index b507fcab17..a3d182a2bf 100644 --- a/Library/Homebrew/missing_formula.rb +++ b/Library/Homebrew/missing_formula.rb @@ -31,7 +31,7 @@ module Homebrew #{Formatter.url("https://pip.readthedocs.io/en/stable/installing/")} EOS when "pil" then <<-EOS.undent - Instead of PIL, consider `pip install pillow`. + Instead of PIL, consider `pip2 install pillow`. EOS when "macruby" then <<-EOS.undent MacRuby is not packaged and is on an indefinite development hiatus. @@ -53,7 +53,7 @@ module Homebrew ruin SSH's security. EOS when "gsutil" then <<-EOS.undent - Install gsutil with `pip install gsutil` + Install gsutil with `pip2 install gsutil` EOS when "gfortran" then <<-EOS.undent GNU Fortran is now provided as part of GCC, and can be installed with: From c30b94135853b809eda34c5c347c549bbf08a42d Mon Sep 17 00:00:00 2001 From: Viktor Szakats Date: Tue, 29 Aug 2017 12:31:07 +0000 Subject: [PATCH 132/294] review follow-up #1 --- Library/Homebrew/dev-cmd/audit.rb | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/Library/Homebrew/dev-cmd/audit.rb b/Library/Homebrew/dev-cmd/audit.rb index d468d69cb5..5a86c0adfd 100644 --- a/Library/Homebrew/dev-cmd/audit.rb +++ b/Library/Homebrew/dev-cmd/audit.rb @@ -201,7 +201,7 @@ class FormulaAuditor @specs = %w[stable devel head].map { |s| formula.send(s) }.compact end - def self.check_http_content(type, url, name, user_agents: [:default]) + def self.check_http_content(url, name, user_agents: [:default], check_content: false) return unless url.start_with? "http" details = nil @@ -237,23 +237,24 @@ class FormulaAuditor file_match = details[:file_hash] == secure_details[:file_hash] if etag_match || content_length_match || file_match - return "The URL #{url} could use HTTPS rather than HTTP" + return "The URL #{url} should use HTTPS rather than HTTP" end - return if type != "homepage" + return unless check_content - details[:file] = details[:file].gsub(%r{https?:\\?\/\\?\/}, "/") - secure_details[:file] = secure_details[:file].gsub(%r{https?:\\?\/\\?\/}, "/") + no_protocol_file_contents = %r{https?:\\?/\\?/} + details[:file] = details[:file].gsub(no_protocol_file_contents, "/") + secure_details[:file] = secure_details[:file].gsub(no_protocol_file_contents, "/") - # Same content after normalization + # Check for the same content after removing all protocols if details[:file] == secure_details[:file] - return "The URL #{url} could use HTTPS rather than HTTP" + return "The URL #{url} should use HTTPS rather than HTTP" end # Same size, different content after normalization # (typical causes: Generated ID, Timestamp, Unix time) if details[:file].length == secure_details[:file].length - return "The URL #{url} could use HTTPS rather than HTTP" + return "The URL #{url} may be able to use HTTPS rather than HTTP. Please verify it in a browser." end lenratio = (100 * secure_details[:file].length / details[:file].length).to_i @@ -586,10 +587,10 @@ class FormulaAuditor return unless @online return unless DevelopmentTools.curl_handles_most_https_homepages? - if http_content_problem = FormulaAuditor.check_http_content("homepage", - homepage, + if http_content_problem = FormulaAuditor.check_http_content(homepage, formula.name, - user_agents: [:browser, :default]) + user_agents: [:browser, :default], + check_content: true) problem http_content_problem end end @@ -1242,8 +1243,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", - url, name) + if http_content_problem = FormulaAuditor.check_http_content(url, name) problem http_content_problem end elsif strategy <= GitDownloadStrategy From 56ccf10efaac5f97bae6b2e5aef9ef87d7529328 Mon Sep 17 00:00:00 2001 From: Viktor Szakats Date: Tue, 29 Aug 2017 12:53:45 +0000 Subject: [PATCH 133/294] limit some heuristics to strict mode --- Library/Homebrew/dev-cmd/audit.rb | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/Library/Homebrew/dev-cmd/audit.rb b/Library/Homebrew/dev-cmd/audit.rb index 5a86c0adfd..17948ea2cc 100644 --- a/Library/Homebrew/dev-cmd/audit.rb +++ b/Library/Homebrew/dev-cmd/audit.rb @@ -201,7 +201,7 @@ class FormulaAuditor @specs = %w[stable devel head].map { |s| formula.send(s) }.compact end - def self.check_http_content(url, name, user_agents: [:default], check_content: false) + def self.check_http_content(url, name, user_agents: [:default], check_content: false, strict: false) return unless url.start_with? "http" details = nil @@ -251,6 +251,8 @@ class FormulaAuditor return "The URL #{url} should use HTTPS rather than HTTP" end + return unless strict + # Same size, different content after normalization # (typical causes: Generated ID, Timestamp, Unix time) if details[:file].length == secure_details[:file].length @@ -590,7 +592,8 @@ class FormulaAuditor if http_content_problem = FormulaAuditor.check_http_content(homepage, formula.name, user_agents: [:browser, :default], - check_content: true) + check_content: true, + strict: @strict) problem http_content_problem end end From 18f5b43d9001955784e235ce7f87068038175a82 Mon Sep 17 00:00:00 2001 From: Viktor Szakats Date: Tue, 29 Aug 2017 17:02:27 +0000 Subject: [PATCH 134/294] fix length ratio range --- Library/Homebrew/dev-cmd/audit.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Library/Homebrew/dev-cmd/audit.rb b/Library/Homebrew/dev-cmd/audit.rb index 17948ea2cc..93aab63841 100644 --- a/Library/Homebrew/dev-cmd/audit.rb +++ b/Library/Homebrew/dev-cmd/audit.rb @@ -260,7 +260,7 @@ class FormulaAuditor end lenratio = (100 * secure_details[:file].length / details[:file].length).to_i - return if lenratio < 90 || lenratio > 120 + return if lenratio < 90 || lenratio > 110 "The URL #{url} may be able to use HTTPS rather than HTTP. Please verify it in a browser." end From 784250d55099f16d8b9c3553a219d603c200cb6b Mon Sep 17 00:00:00 2001 From: mansimarkaur Date: Fri, 25 Aug 2017 17:55:54 +0530 Subject: [PATCH 135/294] Used already existing clear_git_available_cache to remove @git --- Library/Homebrew/test/utils/git_spec.rb | 37 +++++++------------------ Library/Homebrew/utils/git.rb | 4 --- 2 files changed, 10 insertions(+), 31 deletions(-) diff --git a/Library/Homebrew/test/utils/git_spec.rb b/Library/Homebrew/test/utils/git_spec.rb index 65dd3bf414..e511212f49 100644 --- a/Library/Homebrew/test/utils/git_spec.rb +++ b/Library/Homebrew/test/utils/git_spec.rb @@ -4,37 +4,36 @@ describe Git do before(:each) do git = HOMEBREW_SHIMS_PATH/"scm/git" - @file = "blah.rb" - HOMEBREW_CACHE.cd do system git, "init" - File.open(@file, "w") { |f| f.write("blah") } - system git, "add", HOMEBREW_CACHE/@file + File.open(file, "w") { |f| f.write("blah") } + system git, "add", HOMEBREW_CACHE/file system git, "commit", "-m", "'File added'" @h1 = `git rev-parse HEAD` - File.open(@file, "w") { |f| f.write("brew") } - system git, "add", HOMEBREW_CACHE/@file + File.open(file, "w") { |f| f.write("brew") } + system git, "add", HOMEBREW_CACHE/file system git, "commit", "-m", "'written to File'" @h2 = `git rev-parse HEAD` end end + let(:file) { "blah.rb" } let(:hash1) { @h1[0..6] } let(:hash2) { @h2[0..6] } describe "#last_revision_commit_of_file" do it "gives last revision commit when before_commit is nil" do expect( - described_class.last_revision_commit_of_file(HOMEBREW_CACHE, @file), + described_class.last_revision_commit_of_file(HOMEBREW_CACHE, file), ).to eq(hash1) end it "gives revision commit based on before_commit when it is not nil" do expect( described_class.last_revision_commit_of_file(HOMEBREW_CACHE, - @file, + file, before_commit: hash2), ).to eq(hash2) end @@ -44,13 +43,13 @@ describe Git do it "returns last revision of file" do expect( described_class.last_revision_of_file(HOMEBREW_CACHE, - HOMEBREW_CACHE/@file), + HOMEBREW_CACHE/file), ).to eq("blah") end it "returns last revision of file based on before_commit" do expect( - described_class.last_revision_of_file(HOMEBREW_CACHE, HOMEBREW_CACHE/@file, + described_class.last_revision_of_file(HOMEBREW_CACHE, HOMEBREW_CACHE/file, before_commit: "0..3"), ).to eq("brew") end @@ -59,7 +58,7 @@ end describe Utils do before(:each) do - described_class.clear_git_version_cache + described_class.clear_git_available_cache end describe "::git_available?" do @@ -148,20 +147,4 @@ describe Utils do end end end - - describe "::clear_git_available_cache" do - it "removes @git_path and @git_version if defined" do - described_class.clear_git_available_cache - - expect(described_class.instance_variable_get(:@git_path)).to be_nil - expect(described_class.instance_variable_get(:@git_version)).to be_nil - end - - it "removes @git if defined" do - described_class.git_available? - described_class.clear_git_available_cache - - expect(described_class.instance_variable_get(:@git)).to be_nil - end - end end diff --git a/Library/Homebrew/utils/git.rb b/Library/Homebrew/utils/git.rb index 4fdcf1a2e1..1fc01188cc 100644 --- a/Library/Homebrew/utils/git.rb +++ b/Library/Homebrew/utils/git.rb @@ -26,10 +26,6 @@ module Git end module Utils - def self.clear_git_version_cache - remove_instance_variable(:@git) if instance_variable_defined?(:@git) - end - def self.git_available? return @git if instance_variable_defined?(:@git) @git = quiet_system HOMEBREW_SHIMS_PATH/"scm/git", "--version" From 008eaac60da0bfaba4e54fb0febeb172b7976898 Mon Sep 17 00:00:00 2001 From: Shaun Jackman Date: Wed, 30 Aug 2017 09:24:55 -0700 Subject: [PATCH 136/294] pour_bottle?: Ensure local bottles are compatible Don't ignore f.pour_bottle? and compatible_cellar? when pouring a local bottle. --force-bottle may be used to pour a local bottle that is incompatible, as it is for remote bottles. --- Library/Homebrew/formula_installer.rb | 1 - 1 file changed, 1 deletion(-) diff --git a/Library/Homebrew/formula_installer.rb b/Library/Homebrew/formula_installer.rb index 6c5b8bdabb..5aa06e9f0c 100644 --- a/Library/Homebrew/formula_installer.rb +++ b/Library/Homebrew/formula_installer.rb @@ -91,7 +91,6 @@ class FormulaInstaller return false if ARGV.cc return false unless options.empty? return false if formula.bottle_disabled? - return true if formula.local_bottle_path unless formula.pour_bottle? if install_bottle_options[:warn] && formula.pour_bottle_check_unsatisfied_reason opoo <<-EOS.undent From 4cfd333c5a9fd32f1d9870b3e4987c7dad76a88a Mon Sep 17 00:00:00 2001 From: Shaun Jackman Date: Tue, 29 Aug 2017 11:48:47 -0700 Subject: [PATCH 137/294] pour_bottle?: Pour local bottles without sha256 Pouring a local bottle for a formula without a bottle sha256 in the formula for that OS would unexpectedly install from source instead. --- Library/Homebrew/formula_installer.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Library/Homebrew/formula_installer.rb b/Library/Homebrew/formula_installer.rb index 5aa06e9f0c..216a375ce9 100644 --- a/Library/Homebrew/formula_installer.rb +++ b/Library/Homebrew/formula_installer.rb @@ -85,7 +85,7 @@ class FormulaInstaller return false if @pour_failed bottle = formula.bottle - return false unless bottle + return false if !bottle && !formula.local_bottle_path return true if force_bottle? return false if build_from_source? || build_bottle? || interactive? return false if ARGV.cc From 775245262d02017cbc10cf842f7a09fd464d30a4 Mon Sep 17 00:00:00 2001 From: Andrew Lazarus Date: Wed, 30 Aug 2017 14:36:16 -0700 Subject: [PATCH 138/294] add zsh completion for switch --- completions/zsh/_brew | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/completions/zsh/_brew b/completions/zsh/_brew index bc88f402b5..22792860dd 100644 --- a/completions/zsh/_brew +++ b/completions/zsh/_brew @@ -592,8 +592,14 @@ _brew_style() { # brew switch name version: _brew_switch() { - _message "name version" - return 1 + local -a versions + if [[ -n ${words[2]} ]]; then + versions=(${$(brew ls "${words[2]}" --versions)#${words[2]}}) + fi + _arguments -S \ + '1::formula:__brew_formulae' \ + "2:: :(${versions[*]})" \ + && ret=0 } # brew tap: From 68dd0ac918639e6c1cbe7ba1800cda3646ba4e0b Mon Sep 17 00:00:00 2001 From: Alexey Alekhin Date: Thu, 31 Aug 2017 03:03:00 +0200 Subject: [PATCH 139/294] Changed warning message as recommended by @reitermarkus --- Library/Homebrew/cask/lib/hbc/cli/search.rb | 2 +- Library/Homebrew/test/cask/cli/search_spec.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Library/Homebrew/cask/lib/hbc/cli/search.rb b/Library/Homebrew/cask/lib/hbc/cli/search.rb index 8fb8b91ecc..d56d0c81fe 100644 --- a/Library/Homebrew/cask/lib/hbc/cli/search.rb +++ b/Library/Homebrew/cask/lib/hbc/cli/search.rb @@ -27,7 +27,7 @@ module Hbc extension: "rb", ) rescue GitHub::Error => error - opoo "Online search failed: #{error}\n" + opoo "Error searching on GitHub: #{error}\n" [] end matches.map do |match| diff --git a/Library/Homebrew/test/cask/cli/search_spec.rb b/Library/Homebrew/test/cask/cli/search_spec.rb index 06f0b4b32c..85bb42c56f 100644 --- a/Library/Homebrew/test/cask/cli/search_spec.rb +++ b/Library/Homebrew/test/cask/cli/search_spec.rb @@ -30,7 +30,7 @@ describe Hbc::CLI::Search, :cask do local-caffeine local-transmission EOS - .and output(/^Warning: Online search failed: reason/).to_stderr + .and output(/^Warning: Error searching on GitHub: reason/).to_stderr end it "shows that there are no Casks matching a search term that did not result in anything" do From 0ea4da4ef6bca28e2225f79cd0c6c9210eee8f7f Mon Sep 17 00:00:00 2001 From: Dominyk Tiller Date: Thu, 31 Aug 2017 03:59:33 +0100 Subject: [PATCH 140/294] github: limit PR search to Homebrew Not sure whether this is the way you want to handle this problem but it's really darn irritating so here's a PR that handles it one way. Fixes: https://github.com/Homebrew/brew/pull/3086#issuecomment-324519156 --- Library/Homebrew/utils/github.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Library/Homebrew/utils/github.rb b/Library/Homebrew/utils/github.rb index a1cf5fbbac..a50d6d8e58 100644 --- a/Library/Homebrew/utils/github.rb +++ b/Library/Homebrew/utils/github.rb @@ -245,7 +245,7 @@ module GitHub end def print_pull_requests_matching(query) - open_or_closed_prs = search_issues(query, type: "pr") + open_or_closed_prs = search_issues(query, type: "pr", user: "Homebrew") open_prs = open_or_closed_prs.select { |i| i["state"] == "open" } prs = if !open_prs.empty? From a6fa2f367bc4c7c6250d875b117de3ef6815a4b4 Mon Sep 17 00:00:00 2001 From: Alyssa Ross Date: Thu, 31 Aug 2017 12:17:01 +0100 Subject: [PATCH 141/294] Don't fail to migrate repo because of empty dir I just ran into an issue where a colleague's Homebrew couldn't update. It seems to have been because it failed once just after the new repo directory was created. Since there was nothing in this directory, there really isn't any reason for us to fail here, so to avoid this problem in the future, try to `rmdir` the directory before failing because it already exists. --- Library/Homebrew/cmd/update-report.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/Library/Homebrew/cmd/update-report.rb b/Library/Homebrew/cmd/update-report.rb index ea915f99cf..164413cd12 100644 --- a/Library/Homebrew/cmd/update-report.rb +++ b/Library/Homebrew/cmd/update-report.rb @@ -203,6 +203,7 @@ module Homebrew end new_homebrew_repository = Pathname.new "/usr/local/Homebrew" + new_homebrew_repository.rmdir_if_possible if new_homebrew_repository.exist? ofail <<-EOS.undent #{new_homebrew_repository} already exists. From db1054be7b2f5d59c2cb07ce9bf3ee1110885a8c Mon Sep 17 00:00:00 2001 From: Dominyk Tiller Date: Thu, 31 Aug 2017 00:04:27 +0100 Subject: [PATCH 142/294] formula: manipulate Java's home usage by default --- Library/Homebrew/formula.rb | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/Library/Homebrew/formula.rb b/Library/Homebrew/formula.rb index 8cea85a995..2f0c913c21 100644 --- a/Library/Homebrew/formula.rb +++ b/Library/Homebrew/formula.rb @@ -1613,6 +1613,7 @@ class Formula def run_test @prefix_returns_versioned_prefix = true old_home = ENV["HOME"] + old_java_opts = ENV["_JAVA_OPTIONS"] old_curl_home = ENV["CURL_HOME"] old_tmpdir = ENV["TMPDIR"] old_temp = ENV["TEMP"] @@ -1626,6 +1627,7 @@ class Formula ENV["TERM"] = "dumb" ENV["PATH"] = PATH.new(old_path).append(HOMEBREW_PREFIX/"bin") ENV["HOMEBREW_PATH"] = nil + ENV["_JAVA_OPTIONS"] = "#{old_java_opts} -Duser.home=#{HOMEBREW_CACHE}/java_cache" ENV.clear_sensitive_environment! @@ -1646,6 +1648,7 @@ class Formula ensure @testpath = nil ENV["HOME"] = old_home + ENV["_JAVA_OPTIONS"] = old_java_opts ENV["CURL_HOME"] = old_curl_home ENV["TMPDIR"] = old_tmpdir ENV["TEMP"] = old_temp @@ -1888,11 +1891,13 @@ class Formula mkdir_p env_home old_home = ENV["HOME"] + old_java_opts = ENV["_JAVA_OPTIONS"] old_curl_home = ENV["CURL_HOME"] old_path = ENV["HOMEBREW_PATH"] unless ARGV.interactive? ENV["HOME"] = env_home + ENV["_JAVA_OPTIONS"] = "#{old_java_opts} -Duser.home=#{HOMEBREW_CACHE}/java_cache" ENV["CURL_HOME"] = old_curl_home || old_home end ENV["HOMEBREW_PATH"] = nil @@ -1907,6 +1912,7 @@ class Formula @buildpath = nil unless ARGV.interactive? ENV["HOME"] = old_home + ENV["_JAVA_OPTIONS"] = old_java_opts ENV["CURL_HOME"] = old_curl_home end ENV["HOMEBREW_PATH"] = old_path From 0cb6307f2d5207c794760727df579cd8015b23e9 Mon Sep 17 00:00:00 2001 From: Dominyk Tiller Date: Thu, 31 Aug 2017 00:09:14 +0100 Subject: [PATCH 143/294] ENV: move java_cache to compat for future hard deprecation --- Library/Homebrew/compat/ENV/shared.rb | 4 ++++ Library/Homebrew/extend/ENV/shared.rb | 4 ---- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Library/Homebrew/compat/ENV/shared.rb b/Library/Homebrew/compat/ENV/shared.rb index 200e7b132b..c700b1e00a 100644 --- a/Library/Homebrew/compat/ENV/shared.rb +++ b/Library/Homebrew/compat/ENV/shared.rb @@ -3,4 +3,8 @@ module SharedEnvExtension odeprecated "ENV.j1", "ENV.deparallelize" deparallelize end + + def java_cache + # odeprecated "ENV.java_cache" + end end diff --git a/Library/Homebrew/extend/ENV/shared.rb b/Library/Homebrew/extend/ENV/shared.rb index b51ade48b9..15488ee191 100644 --- a/Library/Homebrew/extend/ENV/shared.rb +++ b/Library/Homebrew/extend/ENV/shared.rb @@ -260,10 +260,6 @@ module SharedEnvExtension set_cpu_flags(flags) end - def java_cache - append "_JAVA_OPTIONS", "-Duser.home=#{HOMEBREW_CACHE}/java_cache" - end - # ld64 is a newer linker provided for Xcode 2.5 # @private def ld64 From f301e5c4f4a3094aa9a1a1cf76a34efbd04b838d Mon Sep 17 00:00:00 2001 From: Dominyk Tiller Date: Thu, 31 Aug 2017 21:33:09 +0100 Subject: [PATCH 144/294] audit: add a nudge to remove ENV.java_cache --- Library/Homebrew/dev-cmd/audit.rb | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Library/Homebrew/dev-cmd/audit.rb b/Library/Homebrew/dev-cmd/audit.rb index be332481ca..3c6867f451 100644 --- a/Library/Homebrew/dev-cmd/audit.rb +++ b/Library/Homebrew/dev-cmd/audit.rb @@ -869,6 +869,10 @@ class FormulaAuditor problem "Use \"depends_on :x11\" instead of \"ENV.x11\"" end + if line.include?("ENV.java_cache") + problem "In-formula ENV.java_cache usage has been deprecated & should be removed." + end + # 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 \"#{Regexp.last_match(3)}\"" From b38d811673677dab387e15db58919e902299e993 Mon Sep 17 00:00:00 2001 From: Dominyk Tiller Date: Mon, 28 Aug 2017 16:41:46 +0100 Subject: [PATCH 145/294] gpg: be less strict on newer versions --- Library/Homebrew/gpg.rb | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/Library/Homebrew/gpg.rb b/Library/Homebrew/gpg.rb index f56473df3f..b9a6942ecf 100644 --- a/Library/Homebrew/gpg.rb +++ b/Library/Homebrew/gpg.rb @@ -7,8 +7,7 @@ class Gpg next unless gpg_short_version gpg_version = Version.create(gpg_short_version.to_s) @version = gpg_version - gpg_version == Version.create("2.1") || - gpg_version == Version.create("2.0") + gpg_version >= Version.create("2.0") end end From 380afe2f2df9c4b341484571dc1b2d2d54f7400b Mon Sep 17 00:00:00 2001 From: Dominyk Tiller Date: Mon, 28 Aug 2017 16:51:58 +0100 Subject: [PATCH 146/294] gpg: test usability tweaks --- Library/Homebrew/gpg.rb | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/Library/Homebrew/gpg.rb b/Library/Homebrew/gpg.rb index b9a6942ecf..a63207e6c4 100644 --- a/Library/Homebrew/gpg.rb +++ b/Library/Homebrew/gpg.rb @@ -37,12 +37,21 @@ class Gpg Key-Length: 2048 Subkey-Type: RSA Subkey-Length: 2048 - Passphrase: '' Name-Real: Testing Name-Email: testing@foo.bar Expire-Date: 1d + %no-protection %commit EOS system GPG_EXECUTABLE, "--batch", "--gen-key", "batch.gpg" end + + def self.cleanup_test_processes! + odie "No GPG present to test against!" unless available? + gpgconf = Pathname.new(GPG_EXECUTABLE).parent/"gpgconf" + + system gpgconf, "--kill", "gpg-agent" + system gpgconf, "--homedir", "keyrings/live", "--kill", + "gpg-agent" + end end From c75a8221a5115dc45634ece380266a8a63c0458d Mon Sep 17 00:00:00 2001 From: Dominyk Tiller Date: Tue, 29 Aug 2017 05:20:10 +0100 Subject: [PATCH 147/294] gpg2_requirement: update code comments --- Library/Homebrew/requirements/gpg2_requirement.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Library/Homebrew/requirements/gpg2_requirement.rb b/Library/Homebrew/requirements/gpg2_requirement.rb index d570983eb1..ebdd71f6ef 100644 --- a/Library/Homebrew/requirements/gpg2_requirement.rb +++ b/Library/Homebrew/requirements/gpg2_requirement.rb @@ -5,8 +5,8 @@ class GPG2Requirement < Requirement fatal true default_formula "gnupg" - # GPGTools installs GnuPG 2.0.x as a vanilla `gpg` symlink - # pointing to `gpg2`. Homebrew install 2.1.x as a non-symlink `gpg`. - # We support both the 2.0.x "stable" and 2.1.x "modern" series here. + # GPGTools installs GnuPG 2.0.x as a `gpg` symlink pointing + # to `gpg2`. Our `gnupg` installs only a non-symlink `gpg`. + # The aim is to retain support for any version above 2.0. satisfy(build_env: false) { Gpg.gpg || Gpg.gpg2 } end From 6d726e1bd6676d97bf41bc800942881cf8c3e78f Mon Sep 17 00:00:00 2001 From: Dominyk Tiller Date: Fri, 1 Sep 2017 01:50:26 +0100 Subject: [PATCH 148/294] gpg: create unified test helper --- Library/Homebrew/gpg.rb | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/Library/Homebrew/gpg.rb b/Library/Homebrew/gpg.rb index a63207e6c4..de2089ddad 100644 --- a/Library/Homebrew/gpg.rb +++ b/Library/Homebrew/gpg.rb @@ -54,4 +54,13 @@ class Gpg system gpgconf, "--homedir", "keyrings/live", "--kill", "gpg-agent" end + + def self.test(path) + create_test_key(path) + begin + yield + ensure + cleanup_test_processes! + end + end end From a26cde8299c998043bf7073341b029b609135e8a Mon Sep 17 00:00:00 2001 From: Misty De Meo Date: Thu, 31 Aug 2017 22:29:36 -0700 Subject: [PATCH 149/294] search_remote_tap spec: fix test offline Even though we stub the JSON response, the method being tested always returns [] immediately if HOMEBREW_NO_GITHUB_API is set. --- Library/Homebrew/test/cmd/search_remote_tap_spec.rb | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Library/Homebrew/test/cmd/search_remote_tap_spec.rb b/Library/Homebrew/test/cmd/search_remote_tap_spec.rb index b0beb122c4..eb256b9245 100644 --- a/Library/Homebrew/test/cmd/search_remote_tap_spec.rb +++ b/Library/Homebrew/test/cmd/search_remote_tap_spec.rb @@ -2,6 +2,9 @@ require "cmd/search" describe Homebrew do specify "#search_taps" do + # Otherwise the tested method returns [], regardless of our stub + ENV.delete("HOMEBREW_NO_GITHUB_API") + json_response = { "items" => [ { From 42e2c71dbc9c744fdabab70bf51dce106a76f0a6 Mon Sep 17 00:00:00 2001 From: Viktor Szakats Date: Fri, 1 Sep 2017 16:47:31 +0000 Subject: [PATCH 150/294] cleanup range check --- Library/Homebrew/dev-cmd/audit.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Library/Homebrew/dev-cmd/audit.rb b/Library/Homebrew/dev-cmd/audit.rb index 93aab63841..f6a8b10a6b 100644 --- a/Library/Homebrew/dev-cmd/audit.rb +++ b/Library/Homebrew/dev-cmd/audit.rb @@ -260,7 +260,7 @@ class FormulaAuditor end lenratio = (100 * secure_details[:file].length / details[:file].length).to_i - return if lenratio < 90 || lenratio > 110 + return unless (90..110).cover?(lenratio) "The URL #{url} may be able to use HTTPS rather than HTTP. Please verify it in a browser." end From 8e5ad9ad9be3587001fb92b4367ddb7cc4c7fc8c Mon Sep 17 00:00:00 2001 From: Alexey Alekhin Date: Sat, 2 Sep 2017 02:29:56 +0200 Subject: [PATCH 151/294] Minor tests formatting change --- Library/Homebrew/test/cask/cli/search_spec.rb | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/Library/Homebrew/test/cask/cli/search_spec.rb b/Library/Homebrew/test/cask/cli/search_spec.rb index 85bb42c56f..6dc9805903 100644 --- a/Library/Homebrew/test/cask/cli/search_spec.rb +++ b/Library/Homebrew/test/cask/cli/search_spec.rb @@ -42,18 +42,16 @@ describe Hbc::CLI::Search, :cask do end it "doesn't output anything to non-TTY stdout when there are no matches" do - expect { - Hbc::CLI::Search.run("foo-bar-baz") - }.to not_to_output.to_stdout - .and not_to_output.to_stderr + expect { Hbc::CLI::Search.run("foo-bar-baz") } + .to not_to_output.to_stdout + .and not_to_output.to_stderr end it "lists all Casks available offline with no search term" do allow(GitHub).to receive(:search_code).and_raise(GitHub::Error.new("reason")) - expect { - Hbc::CLI::Search.run - }.to output(/local-caffeine/).to_stdout.as_tty - .and not_to_output.to_stderr + expect { Hbc::CLI::Search.run } + .to output(/local-caffeine/).to_stdout.as_tty + .and not_to_output.to_stderr end it "ignores hyphens in search terms" do From 50db7db72449d48590352149d778653086b73dbb Mon Sep 17 00:00:00 2001 From: Alexey Alekhin Date: Sat, 2 Sep 2017 14:27:02 +0200 Subject: [PATCH 152/294] Updated cask search manpage --- Library/Homebrew/manpages/brew-cask.1.md | 13 +++++++------ manpages/brew-cask.1 | 2 +- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/Library/Homebrew/manpages/brew-cask.1.md b/Library/Homebrew/manpages/brew-cask.1.md index bfb9cd7a53..715d8fd770 100644 --- a/Library/Homebrew/manpages/brew-cask.1.md +++ b/Library/Homebrew/manpages/brew-cask.1.md @@ -1,5 +1,5 @@ brew-cask(1) - a friendly binary installer for macOS -======================================================== +==================================================== ## SYNOPSIS @@ -85,7 +85,7 @@ names, and other aspects of this manual are still subject to change. If is given, summarize the staged files associated with the given Cask. - + * `outdated` [--greedy] [--verbose|--quiet] [ ...]: Without token arguments, display all the installed Casks that have newer versions available in the tap; otherwise check only the tokens given @@ -101,9 +101,10 @@ names, and other aspects of this manual are still subject to change. Reinstall the given Cask. * `search` or `-S` [ | //]: - Without an argument, display all Casks available for install; otherwise - perform a substring search of known Cask tokens for or, if the - text is delimited by slashes (//), it is interpreted as a + Without an argument, display all locally available Casks for install; no + online search is performed. + Otherwise perform a substring search of known Cask tokens for or, + if the text is delimited by slashes (//), it is interpreted as a Ruby regular expression. * `style` [--fix] [ ... ]: @@ -255,7 +256,7 @@ Environment variables specific to Homebrew-Cask: export HOMEBREW_CASK_OPTS='--appdir=~/Applications --fontdir=/Library/Fonts' Other environment variables: - + * `SUDO_ASKPASS`: When this variable is set, Homebrew-Cask will call `sudo`(8) with the `-A` option. diff --git a/manpages/brew-cask.1 b/manpages/brew-cask.1 index 763d78ebe6..f8f58a123b 100644 --- a/manpages/brew-cask.1 +++ b/manpages/brew-cask.1 @@ -103,7 +103,7 @@ Reinstall the given Cask\. . .TP \fBsearch\fR or \fB\-S\fR [\fItext\fR | /\fIregexp\fR/] -Without an argument, display all Casks available for install; otherwise perform a substring search of known Cask tokens for \fItext\fR or, if the text is delimited by slashes (/\fIregexp\fR/), it is interpreted as a Ruby regular expression\. +Without an argument, display all locally available Casks for install; no online search is performed\. Otherwise perform a substring search of known Cask tokens for \fItext\fR or, if the text is delimited by slashes (/\fIregexp\fR/), it is interpreted as a Ruby regular expression\. . .TP \fBstyle\fR [\-\-fix] [ \fItoken\fR \.\.\. ] From bbf71921eb2b2cce5072bb615fac3a2bc96fcfc7 Mon Sep 17 00:00:00 2001 From: Mike McQuaid Date: Sun, 3 Sep 2017 21:42:46 +0100 Subject: [PATCH 153/294] audit: fix subversion remote check logic. Stop flagging invalid URLs as valid and vice-versa. Fixes #3118. --- Library/Homebrew/dev-cmd/audit.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Library/Homebrew/dev-cmd/audit.rb b/Library/Homebrew/dev-cmd/audit.rb index 3c6867f451..d8306609b6 100644 --- a/Library/Homebrew/dev-cmd/audit.rb +++ b/Library/Homebrew/dev-cmd/audit.rb @@ -1233,7 +1233,7 @@ class ResourceAuditor elsif strategy <= SubversionDownloadStrategy next unless DevelopmentTools.subversion_handles_most_https_certificates? next unless Utils.svn_available? - if Utils.svn_remote_exists url + unless Utils.svn_remote_exists url problem "The URL #{url} is not a valid svn URL" end end From 6e3acddc44379eb5d13c923ec08d2f51f0475af9 Mon Sep 17 00:00:00 2001 From: William Woodruff Date: Sun, 3 Sep 2017 20:46:50 -0400 Subject: [PATCH 154/294] docs: Clarify availability of analytics This commit tweaks the language in Analytics.md to make it clear that summaries of install/error data are publicly available, while only Homebrew maintainers can access the full analytics (as specified above in the document). --- docs/Analytics.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/docs/Analytics.md b/docs/Analytics.md index 15fa6fc93b..18dc7bfa62 100644 --- a/docs/Analytics.md +++ b/docs/Analytics.md @@ -37,7 +37,9 @@ As far as we can tell it would be impossible for Google to match the randomly ge Homebrew's analytics are sent throughout Homebrew's execution to Google Analytics over HTTPS. ## Who? -Homebrew's analytics are accessible to Homebrew's current maintainers. Contact @MikeMcQuaid if you are a maintainer and need access. +Homebrew's detailed analytics are accessible to Homebrew's current maintainers. Contact @MikeMcQuaid if you are a maintainer and need access. + +Summaries of installation and error analytics are publicly available [here](https://brew.sh/analytics/). ## How? The code is viewable in [analytics.rb](https://github.com/Homebrew/brew/blob/master/Library/Homebrew/utils/analytics.rb) and [analytics.sh](https://github.com/Homebrew/brew/blob/master/Library/Homebrew/utils/analytics.sh). They are done in a separate background process and fail fast to avoid delaying any execution. They will fail immediately and silently if you have no network connection. From 267def28faab69388be3bc6347c0644f6ca812e8 Mon Sep 17 00:00:00 2001 From: Gautham Goli Date: Fri, 4 Aug 2017 01:18:00 +0530 Subject: [PATCH 155/294] audit: Port rules from line_problems to rubocop part 3 --- Library/Homebrew/dev-cmd/audit.rb | 47 -------------- .../Homebrew/rubocops/extend/formula_cop.rb | 24 ++++--- Library/Homebrew/rubocops/lines_cop.rb | 64 +++++++++++++++++++ 3 files changed, 80 insertions(+), 55 deletions(-) diff --git a/Library/Homebrew/dev-cmd/audit.rb b/Library/Homebrew/dev-cmd/audit.rb index d089f308da..87377bd77c 100644 --- a/Library/Homebrew/dev-cmd/audit.rb +++ b/Library/Homebrew/dev-cmd/audit.rb @@ -892,10 +892,6 @@ class FormulaAuditor problem "Use spaces instead of tabs for indentation" if line =~ /^[ ]*\t/ - if line.include?("ENV.x11") - problem "Use \"depends_on :x11\" instead of \"ENV.x11\"" - end - if line.include?("ENV.java_cache") problem "In-formula ENV.java_cache usage has been deprecated & should be removed." end @@ -913,14 +909,6 @@ class FormulaAuditor problem "Use ENV instead of invoking '#{Regexp.last_match(1)}' to modify the environment" end - if formula.name != "wine" && line =~ /ENV\.universal_binary/ - problem "macOS has been 64-bit only since 10.6 so ENV.universal_binary is deprecated." - end - - if line =~ /build\.universal\?/ - problem "macOS has been 64-bit only so build.universal? is deprecated." - end - if line =~ /version == ['"]HEAD['"]/ problem "Use 'build.head?' instead of inspecting 'version'" end @@ -961,12 +949,6 @@ class FormulaAuditor problem "Use build instead of ARGV to check options" end - problem "Use new-style option definitions" if line.include?("def options") - - if line.end_with?("def test") - problem "Use new-style test definitions (test do)" - end - if line.include?("MACOS_VERSION") problem "Use MacOS.version instead of MACOS_VERSION" end @@ -980,11 +962,6 @@ class FormulaAuditor problem "\"#{$&}\" is deprecated, use a comparison to MacOS.version instead" end - if line =~ /skip_clean\s+:all/ - problem "`skip_clean :all` is deprecated; brew no longer strips symbols\n" \ - "\tPass explicit paths to prevent Homebrew from removing empty folders." - end - if line =~ /depends_on [A-Z][\w:]+\.new$/ problem "`depends_on` can take requirement classes instead of instances" end @@ -1023,30 +1000,6 @@ class FormulaAuditor problem "Use `assert_match` instead of `assert ...include?`" end - if line.include?('system "npm", "install"') && !line.include?("Language::Node") && - formula.name !~ /^kibana(\@\d+(\.\d+)?)?$/ - problem "Use Language::Node for npm install args" - end - - if line.include?("fails_with :llvm") - problem "'fails_with :llvm' is now a no-op so should be removed" - end - - if line =~ /system\s+['"](otool|install_name_tool|lipo)/ && formula.name != "cctools" - problem "Use ruby-macho instead of calling #{Regexp.last_match(1)}" - end - - if formula.tap.to_s == "homebrew/core" - ["OS.mac?", "OS.linux?"].each do |check| - next unless line.include?(check) - problem "Don't use #{check}; Homebrew/core only supports macOS" - end - end - - if line =~ /((revision|version_scheme)\s+0)/ - problem "'#{Regexp.last_match(1)}' should be removed" - end - return unless @strict problem "`#{Regexp.last_match(1)}` in formulae is deprecated" if line =~ /(env :(std|userpaths))/ diff --git a/Library/Homebrew/rubocops/extend/formula_cop.rb b/Library/Homebrew/rubocops/extend/formula_cop.rb index 7844f7bf23..4aec1a4c95 100644 --- a/Library/Homebrew/rubocops/extend/formula_cop.rb +++ b/Library/Homebrew/rubocops/extend/formula_cop.rb @@ -4,12 +4,13 @@ require_relative "../../extend/string" module RuboCop module Cop class FormulaCop < Cop + attr_accessor :file_path @registry = Cop.registry # This method is called by RuboCop and is the main entry point def on_class(node) - file_path = processed_source.buffer.name - return unless file_path_allowed?(file_path) + @file_path = processed_source.buffer.name + return unless file_path_allowed? return unless formula_class?(node) return unless respond_to?(:audit_formula) class_node, parent_class_node, @body = *node @@ -100,8 +101,7 @@ module RuboCop def find_method_with_args(node, method_name, *args) methods = find_every_method_call_by_name(node, method_name) methods.each do |method| - next unless parameters_passed?(method, *args) - yield method + yield method if parameters_passed?(method, *args) end end @@ -112,7 +112,9 @@ module RuboCop def find_instance_method_call(node, instance, method_name) methods = find_every_method_call_by_name(node, method_name) methods.each do |method| - next unless method.receiver && method.receiver.const_name == instance + next if method.receiver.nil? + next if method.receiver.const_name != instance && + method.receiver.method_name != instance @offense_source_range = method.source_range @offensive_node = method yield method @@ -414,6 +416,12 @@ module RuboCop method_name(component_node) if component_node.def_type? end + # Returns the formula tap + def formula_tap + return unless match_obj = @file_path.match(%r{/(homebrew-\w+)/}) + match_obj[1] + end + def problem(msg) add_offense(@offensive_node, @offense_source_range, msg) end @@ -425,11 +433,11 @@ module RuboCop class_node && string_content(class_node) == "Formula" end - def file_path_allowed?(file_path) + def file_path_allowed? paths_to_exclude = [%r{/Library/Homebrew/compat/}, %r{/Library/Homebrew/test/}] - return true if file_path.nil? # file_path is nil when source is directly passed to the cop eg., in specs - file_path !~ Regexp.union(paths_to_exclude) + return true if @file_path.nil? # file_path is nil when source is directly passed to the cop eg., in specs + @file_path !~ Regexp.union(paths_to_exclude) end end end diff --git a/Library/Homebrew/rubocops/lines_cop.rb b/Library/Homebrew/rubocops/lines_cop.rb index ed50ba49c9..241f9860e0 100644 --- a/Library/Homebrew/rubocops/lines_cop.rb +++ b/Library/Homebrew/rubocops/lines_cop.rb @@ -67,7 +67,71 @@ module RuboCop next unless block_arg.source.size>1 problem "\"inreplace do |s|\" is preferred over \"|#{block_arg.source}|\"." end + + [:rebuild, :version_scheme].each do |method_name| + find_method_with_args(body_node, method_name, 0) do + problem "'#{method_name} 0' should be removed" + end + end + + [:mac?, :linux?].each do |method_name| + next unless formula_tap == "homebrew-core" + find_instance_method_call(body_node, "OS", method_name) do |check| + problem "Don't use #{check.source}; Homebrew/core only supports macOS" + end + end + + find_method_with_args(body_node, :fails_with, :llvm) do + problem "'fails_with :llvm' is now a no-op so should be removed" + end + + find_method_with_args(body_node, :system, /^(otool|install_name_tool|lipo)$/) do + next if @formula_name == "Cctools" + problem "Use ruby-macho instead of calling #{@offensive_node.source}" + end + + find_every_method_call_by_name(body_node, :system).each do |method_node| + next if @formula_name =~ /^Kibana(\@\d+(\.\d+)?)?$/ + first_param, second_param = parameters(method_node) + next if !node_equals?(first_param, "npm") || + !node_equals?(second_param, "install") + offending_node(method_node) + problem "Use Language::Node for npm install args" unless languageNodeModule?(method_node) + end + + if find_method_def(body_node, :test) + problem "Use new-style test definitions (test do)" + end + + if find_method_def(body_node, :options) + problem "Use new-style option definitions" + end + + find_method_with_args(body_node, :skip_clean, :all) do + problem <<-EOS.undent.chomp + `skip_clean :all` is deprecated; brew no longer strips symbols + Pass explicit paths to prevent Homebrew from removing empty folders. + EOS + end + + find_instance_method_call(body_node, :build, :universal?) do + next if @formula_name == "Wine" + problem "macOS has been 64-bit only so build.universal? is deprecated." + end + + find_instance_method_call(body_node, "ENV", :universal_binary) do + problem "macOS has been 64-bit only since 10.6 so ENV.universal_binary is deprecated." + end + + find_instance_method_call(body_node, "ENV", :x11) do + problem 'Use "depends_on :x11" instead of "ENV.x11"' + end end + + # Node Pattern search for Language::Node + def_node_search :languageNodeModule?, <<-EOS.undent + (const (const nil :Language) :Node) + EOS end end end From b582ed513b3b28197369cb3cf808e9c4025ee581 Mon Sep 17 00:00:00 2001 From: Gautham Goli Date: Sat, 5 Aug 2017 14:58:09 +0530 Subject: [PATCH 156/294] audit: Add tests for rubocop methods in line_cop.rb --- .../Homebrew/rubocops/extend/formula_cop.rb | 2 + Library/Homebrew/rubocops/lines_cop.rb | 2 +- .../Homebrew/test/rubocops/lines_cop_spec.rb | 271 ++++++++++++++++++ 3 files changed, 274 insertions(+), 1 deletion(-) diff --git a/Library/Homebrew/rubocops/extend/formula_cop.rb b/Library/Homebrew/rubocops/extend/formula_cop.rb index 4aec1a4c95..c8288ef9f7 100644 --- a/Library/Homebrew/rubocops/extend/formula_cop.rb +++ b/Library/Homebrew/rubocops/extend/formula_cop.rb @@ -108,6 +108,8 @@ module RuboCop # Matches a method with a receiver, # EX: to match `Formula.factory(name)` # call `find_instance_method_call(node, "Formula", :factory)` + # EX: to match `build.head?` + # call `find_instance_method_call(node, :build, :head?)` # yields to a block with matching method node def find_instance_method_call(node, instance, method_name) methods = find_every_method_call_by_name(node, method_name) diff --git a/Library/Homebrew/rubocops/lines_cop.rb b/Library/Homebrew/rubocops/lines_cop.rb index 241f9860e0..ab10f6552a 100644 --- a/Library/Homebrew/rubocops/lines_cop.rb +++ b/Library/Homebrew/rubocops/lines_cop.rb @@ -129,7 +129,7 @@ module RuboCop end # Node Pattern search for Language::Node - def_node_search :languageNodeModule?, <<-EOS.undent + def_node_search :languageNodeModule?, <<-EOS.undent (const (const nil :Language) :Node) EOS end diff --git a/Library/Homebrew/test/rubocops/lines_cop_spec.rb b/Library/Homebrew/test/rubocops/lines_cop_spec.rb index b0ed8f4d1d..31aafbcf8e 100644 --- a/Library/Homebrew/test/rubocops/lines_cop_spec.rb +++ b/Library/Homebrew/test/rubocops/lines_cop_spec.rb @@ -200,5 +200,276 @@ describe RuboCop::Cop::FormulaAudit::Miscellaneous do expect_offense(expected, actual) end end + + it "with invalid rebuild" do + source = <<-EOS.undent + class Foo < Formula + desc "foo" + url 'http://example.com/foo-1.0.tgz' + bottle do + rebuild 0 + sha256 "fe0679b932dd43a87fd415b609a7fbac7a069d117642ae8ebaac46ae1fb9f0b3" => :sierra + end + end + EOS + + expected_offenses = [{ message: "'rebuild 0' should be removed", + severity: :convention, + line: 5, + column: 4, + source: source }] + + inspect_source(cop, source) + + expected_offenses.zip(cop.offenses).each do |expected, actual| + expect_offense(expected, actual) + end + end + + it "with OS.linux? check" do + source = <<-EOS.undent + class Foo < Formula + desc "foo" + url 'http://example.com/foo-1.0.tgz' + bottle do + if OS.linux? + nil + end + sha256 "fe0679b932dd43a87fd415b609a7fbac7a069d117642ae8ebaac46ae1fb9f0b3" => :sierra + end + end + EOS + + expected_offenses = [{ message: "Don't use OS.linux?; Homebrew/core only supports macOS", + severity: :convention, + line: 5, + column: 7, + source: source }] + + inspect_source(cop, source, "/homebrew-core/") + + expected_offenses.zip(cop.offenses).each do |expected, actual| + expect_offense(expected, actual) + end + end + + it "with fails_with :llvm" do + source = <<-EOS.undent + class Foo < Formula + desc "foo" + url 'http://example.com/foo-1.0.tgz' + bottle do + sha256 "fe0679b932dd43a87fd415b609a7fbac7a069d117642ae8ebaac46ae1fb9f0b3" => :sierra + end + fails_with :llvm do + build 2335 + cause "foo" + end + end + EOS + + expected_offenses = [{ message: "'fails_with :llvm' is now a no-op so should be removed", + severity: :convention, + line: 7, + column: 2, + source: source }] + + inspect_source(cop, source) + + expected_offenses.zip(cop.offenses).each do |expected, actual| + expect_offense(expected, actual) + end + end + + it "with def test" do + source = <<-EOS.undent + class Foo < Formula + desc "foo" + url 'http://example.com/foo-1.0.tgz' + + def test + assert_equals "1", "1" + end + end + EOS + + expected_offenses = [{ message: "Use new-style test definitions (test do)", + severity: :convention, + line: 5, + column: 2, + source: source }] + + inspect_source(cop, source) + + expected_offenses.zip(cop.offenses).each do |expected, actual| + expect_offense(expected, actual) + end + end + + it "with def options" do + source = <<-EOS.undent + class Foo < Formula + desc "foo" + url 'http://example.com/foo-1.0.tgz' + + def options + [["--bar", "desc"]] + end + end + EOS + + expected_offenses = [{ message: "Use new-style option definitions", + severity: :convention, + line: 5, + column: 2, + source: source }] + + inspect_source(cop, source) + + expected_offenses.zip(cop.offenses).each do |expected, actual| + expect_offense(expected, actual) + end + end + + it "with deprecated skip_clean call" do + source = <<-EOS.undent + class Foo < Formula + desc "foo" + url 'http://example.com/foo-1.0.tgz' + skip_clean :all + end + EOS + + expected_offenses = [{ message: <<-EOS.undent.chomp, + `skip_clean :all` is deprecated; brew no longer strips symbols + Pass explicit paths to prevent Homebrew from removing empty folders. + EOS + severity: :convention, + line: 4, + column: 2, + source: source }] + + inspect_source(cop, source) + + expected_offenses.zip(cop.offenses).each do |expected, actual| + expect_offense(expected, actual) + end + end + + it "with build.universal?" do + source = <<-EOS.undent + class Foo < Formula + desc "foo" + url 'http://example.com/foo-1.0.tgz' + if build.universal? + "foo" + end + end + EOS + + expected_offenses = [{ message: "macOS has been 64-bit only since 10.6 so build.universal? is deprecated.", + severity: :convention, + line: 4, + column: 5, + source: source }] + + inspect_source(cop, source) + + expected_offenses.zip(cop.offenses).each do |expected, actual| + expect_offense(expected, actual) + end + end + + it "with ENV.universal_binary" do + source = <<-EOS.undent + class Foo < Formula + desc "foo" + url 'http://example.com/foo-1.0.tgz' + if build? + ENV.universal_binary + end + end + EOS + + expected_offenses = [{ message: "macOS has been 64-bit only since 10.6 so ENV.universal_binary is deprecated.", + severity: :convention, + line: 5, + column: 5, + source: source }] + + inspect_source(cop, source) + + expected_offenses.zip(cop.offenses).each do |expected, actual| + expect_offense(expected, actual) + end + end + + it "with ENV.universal_binary" do + source = <<-EOS.undent + class Foo < Formula + desc "foo" + url 'http://example.com/foo-1.0.tgz' + if build? + ENV.x11 + end + end + EOS + + expected_offenses = [{ message: 'Use "depends_on :x11" instead of "ENV.x11"', + severity: :convention, + line: 5, + column: 5, + source: source }] + + inspect_source(cop, source) + + expected_offenses.zip(cop.offenses).each do |expected, actual| + expect_offense(expected, actual) + end + end + + it "with ruby-macho alternatives" do + source = <<-EOS.undent + class Foo < Formula + desc "foo" + url 'http://example.com/foo-1.0.tgz' + system "install_name_tool", "-id" + end + EOS + + expected_offenses = [{ message: 'Use ruby-macho instead of calling "install_name_tool"', + severity: :convention, + line: 4, + column: 10, + source: source }] + + inspect_source(cop, source) + + expected_offenses.zip(cop.offenses).each do |expected, actual| + expect_offense(expected, actual) + end + end + + it "with npm install without language::Node args" do + source = <<-EOS.undent + class Foo < Formula + desc "foo" + url 'http://example.com/foo-1.0.tgz' + system "npm", "install" + end + EOS + + expected_offenses = [{ message: "Use Language::Node for npm install args", + severity: :convention, + line: 4, + column: 2, + source: source }] + + inspect_source(cop, source) + + expected_offenses.zip(cop.offenses).each do |expected, actual| + expect_offense(expected, actual) + end + end end end From 337d5c64708f3ad1d7074e17b1cd5be24e0ee488 Mon Sep 17 00:00:00 2001 From: Gautham Goli Date: Wed, 30 Aug 2017 15:48:41 +0530 Subject: [PATCH 157/294] audit: Fetch formula name from file path rather than class name in cops --- Library/Homebrew/rubocops/conflicts_cop.rb | 2 +- Library/Homebrew/rubocops/extend/formula_cop.rb | 9 ++------- Library/Homebrew/rubocops/lines_cop.rb | 11 ++++++----- Library/Homebrew/test/rubocops/conflicts_cop_spec.rb | 4 ++-- .../Homebrew/test/rubocops/formula_desc_cop_spec.rb | 12 ++++++------ 5 files changed, 17 insertions(+), 21 deletions(-) diff --git a/Library/Homebrew/rubocops/conflicts_cop.rb b/Library/Homebrew/rubocops/conflicts_cop.rb index c1b8015599..6f05d05673 100644 --- a/Library/Homebrew/rubocops/conflicts_cop.rb +++ b/Library/Homebrew/rubocops/conflicts_cop.rb @@ -18,7 +18,7 @@ module RuboCop def audit_formula(_node, _class_node, _parent_class_node, body) return unless versioned_formula? - problem MSG if !formula_file_name.start_with?(*WHITELIST) && + problem MSG if !@formula_name.start_with?(*WHITELIST) && method_called_ever?(body, :conflicts_with) end end diff --git a/Library/Homebrew/rubocops/extend/formula_cop.rb b/Library/Homebrew/rubocops/extend/formula_cop.rb index c8288ef9f7..75d043f30e 100644 --- a/Library/Homebrew/rubocops/extend/formula_cop.rb +++ b/Library/Homebrew/rubocops/extend/formula_cop.rb @@ -14,7 +14,7 @@ module RuboCop return unless formula_class?(node) return unless respond_to?(:audit_formula) class_node, parent_class_node, @body = *node - @formula_name = class_name(class_node) + @formula_name = Pathname.new(@file_path).basename(".rb").to_s audit_formula(node, class_node, parent_class_node, @body) end @@ -404,12 +404,7 @@ module RuboCop # Returns true if the formula is versioned def versioned_formula? - formula_file_name.include?("@") || @formula_name.match(/AT\d+/) - end - - # Returns filename of the formula without the extension - def formula_file_name - File.basename(processed_source.buffer.name, ".rb") + @formula_name.include?("@") end # Returns printable component name diff --git a/Library/Homebrew/rubocops/lines_cop.rb b/Library/Homebrew/rubocops/lines_cop.rb index ab10f6552a..01b13585c4 100644 --- a/Library/Homebrew/rubocops/lines_cop.rb +++ b/Library/Homebrew/rubocops/lines_cop.rb @@ -21,7 +21,7 @@ module RuboCop begin_pos = start_column(parent_class_node) end_pos = end_column(class_node) return unless begin_pos-end_pos != 3 - problem "Use a space in class inheritance: class #{@formula_name} < #{class_name(parent_class_node)}" + problem "Use a space in class inheritance: class #{class_name(class_node)} < #{class_name(parent_class_node)}" end end @@ -86,12 +86,13 @@ module RuboCop end find_method_with_args(body_node, :system, /^(otool|install_name_tool|lipo)$/) do - next if @formula_name == "Cctools" + next if @formula_name == "cctools" problem "Use ruby-macho instead of calling #{@offensive_node.source}" end find_every_method_call_by_name(body_node, :system).each do |method_node| - next if @formula_name =~ /^Kibana(\@\d+(\.\d+)?)?$/ + # Skip Kibana: npm cache edge (see formula for more details) + next if @formula_name =~ /^kibana(\@\d+(\.\d+)?)?$/ first_param, second_param = parameters(method_node) next if !node_equals?(first_param, "npm") || !node_equals?(second_param, "install") @@ -115,8 +116,8 @@ module RuboCop end find_instance_method_call(body_node, :build, :universal?) do - next if @formula_name == "Wine" - problem "macOS has been 64-bit only so build.universal? is deprecated." + next if @formula_name == "wine" + problem "macOS has been 64-bit only since 10.6 so build.universal? is deprecated." end find_instance_method_call(body_node, "ENV", :universal_binary) do diff --git a/Library/Homebrew/test/rubocops/conflicts_cop_spec.rb b/Library/Homebrew/test/rubocops/conflicts_cop_spec.rb index 4fbab6c9ed..3af0f96697 100644 --- a/Library/Homebrew/test/rubocops/conflicts_cop_spec.rb +++ b/Library/Homebrew/test/rubocops/conflicts_cop_spec.rb @@ -22,7 +22,7 @@ describe RuboCop::Cop::FormulaAudit::Conflicts do column: 2, source: source }] - inspect_source(cop, source) + inspect_source(cop, source, "/homebrew-core/Formula/foo@2.0.rb") expected_offenses.zip(cop.offenses).each do |expected, actual| expect_offense(expected, actual) @@ -36,7 +36,7 @@ describe RuboCop::Cop::FormulaAudit::Conflicts do desc 'Bar' end EOS - inspect_source(cop, source) + inspect_source(cop, source, "/homebrew-core/Formula/foo@2.0.rb") expect(cop.offenses).to eq([]) 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 74ce478fb1..48342e8bca 100644 --- a/Library/Homebrew/test/rubocops/formula_desc_cop_spec.rb +++ b/Library/Homebrew/test/rubocops/formula_desc_cop_spec.rb @@ -37,7 +37,7 @@ describe RuboCop::Cop::FormulaAuditStrict::DescLength do msg = <<-EOS.undent Description is too long. "name: desc" should be less than 80 characters. - Length is calculated as Foo + desc. (currently 95) + Length is calculated as foo + desc. (currently 95) EOS expected_offenses = [{ message: msg, severity: :convention, @@ -45,7 +45,7 @@ describe RuboCop::Cop::FormulaAuditStrict::DescLength do column: 2, source: source }] - inspect_source(cop, source) + inspect_source(cop, source, "/homebrew-core/Formula/foo.rb") expected_offenses.zip(cop.offenses).each do |expected, actual| expect_offense(expected, actual) end @@ -62,7 +62,7 @@ describe RuboCop::Cop::FormulaAuditStrict::DescLength do msg = <<-EOS.undent Description is too long. "name: desc" should be less than 80 characters. - Length is calculated as Foo + desc. (currently 98) + Length is calculated as foo + desc. (currently 98) EOS expected_offenses = [{ message: msg, severity: :convention, @@ -70,7 +70,7 @@ describe RuboCop::Cop::FormulaAuditStrict::DescLength do column: 2, source: source }] - inspect_source(cop, source) + inspect_source(cop, source, "/homebrew-core/Formula/foo.rb") expected_offenses.zip(cop.offenses).each do |expected, actual| expect_offense(expected, actual) end @@ -156,7 +156,7 @@ describe RuboCop::Cop::FormulaAuditStrict::Desc do column: 8, source: source }] - inspect_source(cop, source) + inspect_source(cop, source, "/homebrew-core/Formula/foo.rb") expected_offenses.zip(cop.offenses).each do |expected, actual| expect_offense(expected, actual) end @@ -176,7 +176,7 @@ describe RuboCop::Cop::FormulaAuditStrict::Desc do end EOS - corrected_source = autocorrect_source(cop, source) + corrected_source = autocorrect_source(cop, source, "/homebrew-core/Formula/foo.rb") expect(corrected_source).to eq(correct_source) end end From 4ec26aea4025d19e70cdf59da6dfd7be3a389e44 Mon Sep 17 00:00:00 2001 From: Gautham Goli Date: Mon, 4 Sep 2017 13:47:05 +0530 Subject: [PATCH 158/294] audit: Port audit_class to rubocop, add tests and autocorrect --- Library/Homebrew/dev-cmd/audit.rb | 15 ---- Library/Homebrew/rubocops.rb | 1 + Library/Homebrew/rubocops/class_cop.rb | 41 ++++++++++ .../Homebrew/rubocops/extend/formula_cop.rb | 9 ++- Library/Homebrew/test/dev-cmd/audit_spec.rb | 64 --------------- .../Homebrew/test/rubocops/class_cop_spec.rb | 81 +++++++++++++++++++ 6 files changed, 131 insertions(+), 80 deletions(-) create mode 100644 Library/Homebrew/rubocops/class_cop.rb create mode 100644 Library/Homebrew/test/rubocops/class_cop_spec.rb diff --git a/Library/Homebrew/dev-cmd/audit.rb b/Library/Homebrew/dev-cmd/audit.rb index d089f308da..1f8acb1b93 100644 --- a/Library/Homebrew/dev-cmd/audit.rb +++ b/Library/Homebrew/dev-cmd/audit.rb @@ -381,21 +381,6 @@ class FormulaAuditor end end - def audit_class - if @strict - unless formula.test_defined? - problem "A `test do` test block should be added" - end - end - - classes = %w[GithubGistFormula ScriptFileFormula AmazonWebServicesFormula] - klass = classes.find do |c| - Object.const_defined?(c) && formula.class < Object.const_get(c) - end - - problem "#{klass} is deprecated, use Formula instead" if klass - end - # core aliases + tap alias names + tap alias full name @@aliases ||= Formula.aliases + Formula.tap_aliases diff --git a/Library/Homebrew/rubocops.rb b/Library/Homebrew/rubocops.rb index b1144e075d..8dc49bb459 100644 --- a/Library/Homebrew/rubocops.rb +++ b/Library/Homebrew/rubocops.rb @@ -11,3 +11,4 @@ require_relative "./rubocops/conflicts_cop" require_relative "./rubocops/options_cop" require_relative "./rubocops/urls_cop" require_relative "./rubocops/lines_cop" +require_relative "./rubocops/class_cop" diff --git a/Library/Homebrew/rubocops/class_cop.rb b/Library/Homebrew/rubocops/class_cop.rb new file mode 100644 index 0000000000..dad81abfc5 --- /dev/null +++ b/Library/Homebrew/rubocops/class_cop.rb @@ -0,0 +1,41 @@ +require_relative "./extend/formula_cop" + +module RuboCop + module Cop + module FormulaAudit + class ClassName < FormulaCop + DEPRECATED_CLASSES = %w[ + GithubGistFormula + ScriptFileFormula + AmazonWebServicesFormula + ].freeze + + def audit_formula(_node, _class_node, parent_class_node, _body_node) + parent_class = class_name(parent_class_node) + return unless DEPRECATED_CLASSES.include?(parent_class) + problem "#{parent_class} is deprecated, use Formula instead" + end + + private + + def autocorrect(node) + lambda do |corrector| + corrector.replace(node.source_range, "Formula") + end + end + end + end + + module FormulaAuditStrict + # - `test do ..end` should be defined in the formula + class Test < FormulaCop + MSG = "A `test do` test block should be added".freeze + + def audit_formula(_node, _class_node, _parent_class_node, body_node) + return if find_block(body_node, :test) + problem MSG + end + end + end + end +end diff --git a/Library/Homebrew/rubocops/extend/formula_cop.rb b/Library/Homebrew/rubocops/extend/formula_cop.rb index 7844f7bf23..59ad1aafbf 100644 --- a/Library/Homebrew/rubocops/extend/formula_cop.rb +++ b/Library/Homebrew/rubocops/extend/formula_cop.rb @@ -422,7 +422,14 @@ module RuboCop def formula_class?(node) _, class_node, = *node - class_node && string_content(class_node) == "Formula" + class_names = %w[ + Formula + GithubGistFormula + ScriptFileFormula + AmazonWebServicesFormula + ] + + class_node && class_names.include?(string_content(class_node)) end def file_path_allowed?(file_path) diff --git a/Library/Homebrew/test/dev-cmd/audit_spec.rb b/Library/Homebrew/test/dev-cmd/audit_spec.rb index 037865fdf1..3e99bd06bc 100644 --- a/Library/Homebrew/test/dev-cmd/audit_spec.rb +++ b/Library/Homebrew/test/dev-cmd/audit_spec.rb @@ -150,70 +150,6 @@ describe FormulaAuditor do end end - describe "#audit_class" do - specify "missing test" do - fa = formula_auditor "foo", <<-EOS.undent - class Foo < Formula - url "http://example.com/foo-1.0.tgz" - end - EOS - - fa.audit_class - expect(fa.problems).to eq([]) - - fa = formula_auditor "foo", <<-EOS.undent, strict: true - class Foo < Formula - url "http://example.com/foo-1.0.tgz" - end - EOS - - fa.audit_class - expect(fa.problems).to eq(["A `test do` test block should be added"]) - end - - specify "GithubGistFormula", :needs_compat do - ENV.delete("HOMEBREW_DEVELOPER") - - fa = formula_auditor "foo", <<-EOS.undent - class Foo < GithubGistFormula - url "http://example.com/foo-1.0.tgz" - end - EOS - - fa.audit_class - expect(fa.problems) - .to eq(["GithubGistFormula is deprecated, use Formula instead"]) - end - - specify "ScriptFileFormula", :needs_compat do - ENV.delete("HOMEBREW_DEVELOPER") - - fa = formula_auditor "foo", <<-EOS.undent - class Foo < ScriptFileFormula - url "http://example.com/foo-1.0.tgz" - end - EOS - - fa.audit_class - expect(fa.problems) - .to eq(["ScriptFileFormula is deprecated, use Formula instead"]) - end - - specify "AmazonWebServicesFormula", :needs_compat do - ENV.delete("HOMEBREW_DEVELOPER") - - fa = formula_auditor "foo", <<-EOS.undent - class Foo < AmazonWebServicesFormula - url "http://example.com/foo-1.0.tgz" - end - EOS - - fa.audit_class - expect(fa.problems) - .to eq(["AmazonWebServicesFormula is deprecated, use Formula instead"]) - end - end - describe "#line_problems" do specify "pkgshare" do fa = formula_auditor "foo", <<-EOS.undent, strict: true diff --git a/Library/Homebrew/test/rubocops/class_cop_spec.rb b/Library/Homebrew/test/rubocops/class_cop_spec.rb new file mode 100644 index 0000000000..676dd4f6e9 --- /dev/null +++ b/Library/Homebrew/test/rubocops/class_cop_spec.rb @@ -0,0 +1,81 @@ +require "rubocop" +require "rubocop/rspec/support" +require_relative "../../extend/string" +require_relative "../../rubocops/class_cop" + +describe RuboCop::Cop::FormulaAudit::ClassName do + subject(:cop) { described_class.new } + + context "When auditing formula" do + it "with deprecated inheritance" do + formulas = [{ + "class" => "GithubGistFormula", + }, { + "class" => "ScriptFileFormula", + }, { + "class" => "AmazonWebServicesFormula", + }] + + formulas.each do |formula| + source = <<-EOS.undent + class Foo < #{formula["class"]} + url 'http://example.com/foo-1.0.tgz' + end + EOS + + expected_offenses = [{ message: "#{formula["class"]} is deprecated, use Formula instead", + severity: :convention, + line: 1, + column: 12, + source: source }] + + inspect_source(cop, source) + + expected_offenses.zip(cop.offenses.reverse).each do |expected, actual| + expect_offense(expected, actual) + end + end + end + + it "with deprecated inheritance and autocorrect" do + source = <<-EOS.undent + class Foo < AmazonWebServicesFormula + url 'http://example.com/foo-1.0.tgz' + end + EOS + corrected_source = <<-EOS.undent + class Foo < Formula + url 'http://example.com/foo-1.0.tgz' + end + EOS + + new_source = autocorrect_source(cop, source) + expect(new_source).to eq(corrected_source) + end + end +end + +describe RuboCop::Cop::FormulaAuditStrict::Test do + subject(:cop) { described_class.new } + + context "When auditing formula" do + it "without a test block" do + source = <<-EOS.undent + class Foo < Formula + url 'http://example.com/foo-1.0.tgz' + end + EOS + expected_offenses = [{ message: described_class::MSG, + severity: :convention, + line: 1, + column: 0, + source: source }] + + inspect_source(cop, source) + + expected_offenses.zip(cop.offenses).each do |expected, actual| + expect_offense(expected, actual) + end + end + end +end From d45ff9c0fdfa834c55c01f9c95fe18064fabd76a Mon Sep 17 00:00:00 2001 From: Gautham Goli Date: Sat, 2 Sep 2017 12:38:18 +0530 Subject: [PATCH 159/294] audit: Add a global flag to silent warning when auditing --- Library/Homebrew/dev-cmd/audit.rb | 1 + Library/Homebrew/global.rb | 6 +++++- Library/Homebrew/utils.rb | 2 +- 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/Library/Homebrew/dev-cmd/audit.rb b/Library/Homebrew/dev-cmd/audit.rb index 1f8acb1b93..884861c87c 100644 --- a/Library/Homebrew/dev-cmd/audit.rb +++ b/Library/Homebrew/dev-cmd/audit.rb @@ -54,6 +54,7 @@ module Homebrew def audit Homebrew.inject_dump_stats!(FormulaAuditor, /^audit_/) if ARGV.switch? "D" + Homebrew.auditing = true formula_count = 0 problem_count = 0 diff --git a/Library/Homebrew/global.rb b/Library/Homebrew/global.rb index 9f79781b41..32b5377a0e 100644 --- a/Library/Homebrew/global.rb +++ b/Library/Homebrew/global.rb @@ -45,11 +45,15 @@ module Homebrew @failed == true end - attr_writer :raise_deprecation_exceptions + attr_writer :raise_deprecation_exceptions, :auditing def raise_deprecation_exceptions? @raise_deprecation_exceptions == true end + + def auditing? + @auditing == true + end end end diff --git a/Library/Homebrew/utils.rb b/Library/Homebrew/utils.rb index e3137ac49c..07e339576f 100644 --- a/Library/Homebrew/utils.rb +++ b/Library/Homebrew/utils.rb @@ -102,7 +102,7 @@ def odeprecated(method, replacement = nil, disable: false, disable_on: nil, call if ARGV.homebrew_developer? || disable || Homebrew.raise_deprecation_exceptions? raise MethodDeprecatedError, message - else + elsif !Homebrew.auditing? opoo "#{message}\n" end end From 9899a5d0a8d1651601401a5baf223263a6cfc3f6 Mon Sep 17 00:00:00 2001 From: Dominyk Tiller Date: Tue, 5 Sep 2017 03:16:18 +0100 Subject: [PATCH 160/294] mac/hardware/cpu: recognise Kaby Lake The 2017 MacBook Pro line shipped with Kaby Lake CPUs. --- Library/Homebrew/extend/os/mac/hardware/cpu.rb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Library/Homebrew/extend/os/mac/hardware/cpu.rb b/Library/Homebrew/extend/os/mac/hardware/cpu.rb index 22d118e1a5..b97c280cd2 100644 --- a/Library/Homebrew/extend/os/mac/hardware/cpu.rb +++ b/Library/Homebrew/extend/os/mac/hardware/cpu.rb @@ -50,6 +50,8 @@ module Hardware :broadwell when 0x37fc219f # Skylake :skylake + when 0x0f817246 # Kaby Lake + :kabylake else :dunno end From 9562cceef15977306c9664f4f19892992a63e44a Mon Sep 17 00:00:00 2001 From: Dominyk Tiller Date: Tue, 5 Sep 2017 03:35:44 +0100 Subject: [PATCH 161/294] audit: stop demanding a HTTP HEAD mirror for curl Not sure if this is how you want to handle it but having a HEAD mirror for `curl` is just silliness. Ref: https://github.com/Homebrew/homebrew-core/commit/e36b95849ae38ade30605155d75cf6e731b4e38f --- Library/Homebrew/dev-cmd/audit.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Library/Homebrew/dev-cmd/audit.rb b/Library/Homebrew/dev-cmd/audit.rb index d089f308da..cfc57ac923 100644 --- a/Library/Homebrew/dev-cmd/audit.rb +++ b/Library/Homebrew/dev-cmd/audit.rb @@ -1237,7 +1237,7 @@ class ResourceAuditor def audit_urls urls = [url] + mirrors - if name == "curl" && !urls.find { |u| u.start_with?("http://") } + if name == "curl" && !urls.find { |u| u.start_with?("http://") } && url != Formula["curl"].head.url problem "should always include at least one HTTP url" end From 01872506000619bd57b48e5b69593b5d42ded29e Mon Sep 17 00:00:00 2001 From: Mike McQuaid Date: Wed, 6 Sep 2017 18:01:08 +0100 Subject: [PATCH 162/294] travis.yml: fix umask for brew audit. Change the umask before we create any files to avoid `brew audit` complaining about the `chmod` of formulae. --- .travis.yml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index 9cdebda832..dfdb7fc85c 100644 --- a/.travis.yml +++ b/.travis.yml @@ -20,21 +20,22 @@ matrix: before_install: - export HOMEBREW_NO_AUTO_UPDATE=1 - export HOMEBREW_DEVELOPER=1 - - git clone --depth=1 https://github.com/Homebrew/homebrew-test-bot Library/Taps/homebrew/homebrew-test-bot - if [ "${TRAVIS_OS_NAME}" = "osx" ]; then + git clone --depth=1 https://github.com/Homebrew/homebrew-test-bot Library/Taps/homebrew/homebrew-test-bot; HOMEBREW_REPOSITORY="$(brew --repo)"; sudo chown -R "$USER" "$HOMEBREW_REPOSITORY/Library/Taps"; mv "$HOMEBREW_REPOSITORY/Library/Taps" "$PWD/Library"; sudo rm -rf "$HOMEBREW_REPOSITORY"; sudo ln -s "$PWD" "$HOMEBREW_REPOSITORY"; else + umask 022; + git clone --depth=1 https://github.com/Homebrew/homebrew-test-bot Library/Taps/homebrew/homebrew-test-bot; git fetch --unshallow; export PATH="$PWD/bin:$PATH"; HOMEBREW_CORE_TAP_DIR="$(brew --repo "homebrew/core")"; mkdir -p "$HOMEBREW_CORE_TAP_DIR"; HOMEBREW_TEST_BOT_TAP_DIR="$(brew --repo "homebrew/test-bot")"; ln -s "$HOMEBREW_TEST_BOT_TAP_DIR/.git" "$HOMEBREW_TEST_BOT_TAP_DIR/Formula" "$HOMEBREW_CORE_TAP_DIR"; - umask 022; fi script: From a6d1ddf32611109b3284b045fdc5123c40e23b9e Mon Sep 17 00:00:00 2001 From: Viktor Szakats Date: Wed, 6 Sep 2017 11:06:46 +0000 Subject: [PATCH 163/294] git_spec.rb: use HTTPS for Git remote test --- Library/Homebrew/test/utils/git_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Library/Homebrew/test/utils/git_spec.rb b/Library/Homebrew/test/utils/git_spec.rb index e511212f49..48fc1338e6 100644 --- a/Library/Homebrew/test/utils/git_spec.rb +++ b/Library/Homebrew/test/utils/git_spec.rb @@ -130,7 +130,7 @@ describe Utils do context "when git is available" do it "returns true when git remote exists", :needs_network do git = HOMEBREW_SHIMS_PATH/"scm/git" - url = "http://github.com/Homebrew/homebrew.github.io" + url = "https://github.com/Homebrew/homebrew.github.io" repo = HOMEBREW_CACHE/"hey" repo.mkpath From b6d36003b336dee36d4c11a621b4061bc0615284 Mon Sep 17 00:00:00 2001 From: Alyssa Ross Date: Thu, 7 Sep 2017 12:09:52 +0100 Subject: [PATCH 164/294] Always output when tapping core Hiding all output makes it look like Homebrew is hanging while the tap operation (which can take a long time!) is running. Closes #3053. --- Library/Homebrew/cmd/update-report.rb | 2 +- Library/Homebrew/tap.rb | 6 ++---- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/Library/Homebrew/cmd/update-report.rb b/Library/Homebrew/cmd/update-report.rb index 164413cd12..781ee88081 100644 --- a/Library/Homebrew/cmd/update-report.rb +++ b/Library/Homebrew/cmd/update-report.rb @@ -124,7 +124,7 @@ module Homebrew return if ENV["HOMEBREW_UPDATE_TEST"] core_tap = CoreTap.instance return if core_tap.installed? - CoreTap.ensure_installed! quiet: false + CoreTap.ensure_installed! revision = core_tap.git_head ENV["HOMEBREW_UPDATE_BEFORE_HOMEBREW_HOMEBREW_CORE"] = revision ENV["HOMEBREW_UPDATE_AFTER_HOMEBREW_HOMEBREW_CORE"] = revision diff --git a/Library/Homebrew/tap.rb b/Library/Homebrew/tap.rb index f232be4281..f6246aad90 100644 --- a/Library/Homebrew/tap.rb +++ b/Library/Homebrew/tap.rb @@ -551,11 +551,9 @@ class CoreTap < Tap @instance ||= new end - def self.ensure_installed!(options = {}) + def self.ensure_installed! return if instance.installed? - args = ["tap", instance.name] - args << "-q" if options.fetch(:quiet, true) - safe_system HOMEBREW_BREW_FILE, *args + safe_system HOMEBREW_BREW_FILE, "tap", instance.name end # @private From 49d2d7b94d85dd150956ea14d66a34870d2f70fd Mon Sep 17 00:00:00 2001 From: Mike McQuaid Date: Tue, 5 Sep 2017 17:44:27 +0100 Subject: [PATCH 165/294] home_spec: use different test formula. Instead of `testball` use a formula named `testballhome` to avoid this clashing with any other formula named testball. --- Library/Homebrew/test/cmd/home_spec.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Library/Homebrew/test/cmd/home_spec.rb b/Library/Homebrew/test/cmd/home_spec.rb index 5a40704929..cf9453af2d 100644 --- a/Library/Homebrew/test/cmd/home_spec.rb +++ b/Library/Homebrew/test/cmd/home_spec.rb @@ -7,10 +7,10 @@ describe "brew home", :integration_test do end it "opens the homepage for a given Formula" do - setup_test_formula "testball" + setup_test_formula "testballhome" - expect { brew "home", "testball", "HOMEBREW_BROWSER" => "echo" } - .to output("#{Formula["testball"].homepage}\n").to_stdout + expect { brew "home", "testballhome", "HOMEBREW_BROWSER" => "echo" } + .to output("#{Formula["testballhome"].homepage}\n").to_stdout .and not_to_output.to_stderr .and be_a_success end From 78d3112df2667d321748f0d250deec0fde2a5572 Mon Sep 17 00:00:00 2001 From: Shaun Jackman Date: Mon, 28 Aug 2017 10:10:05 -0700 Subject: [PATCH 166/294] popen: Do not suppress stderr unless -d or -v --- Library/Homebrew/utils/popen.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Library/Homebrew/utils/popen.rb b/Library/Homebrew/utils/popen.rb index 4e03711a16..bcdd815bba 100644 --- a/Library/Homebrew/utils/popen.rb +++ b/Library/Homebrew/utils/popen.rb @@ -13,7 +13,7 @@ module Utils return pipe.read unless block_given? yield pipe else - $stderr.reopen("/dev/null", "w") + $stderr.reopen("/dev/null", "w") if !ARGV.debug? && !ARGV.verbose? exec(*args) end end From a4c5e64da426a15e673c348e7083b6705f3875e6 Mon Sep 17 00:00:00 2001 From: ilovezfs Date: Fri, 8 Sep 2017 12:32:32 -0700 Subject: [PATCH 167/294] Revert "mach: Avoid reopening the file for relocation" --- .../Homebrew/extend/os/mac/keg_relocate.rb | 8 ++--- Library/Homebrew/os/mac.rb | 1 + Library/Homebrew/os/mac/keg.rb | 29 +++++++++++++++++++ Library/Homebrew/os/mac/mach.rb | 28 ------------------ 4 files changed, 34 insertions(+), 32 deletions(-) create mode 100644 Library/Homebrew/os/mac/keg.rb diff --git a/Library/Homebrew/extend/os/mac/keg_relocate.rb b/Library/Homebrew/extend/os/mac/keg_relocate.rb index 7031bea1ee..707710be61 100644 --- a/Library/Homebrew/extend/os/mac/keg_relocate.rb +++ b/Library/Homebrew/extend/os/mac/keg_relocate.rb @@ -2,7 +2,7 @@ class Keg def fix_dynamic_linkage mach_o_files.each do |file| file.ensure_writable do - file.change_dylib_id(dylib_id_for(file)) if file.dylib? + change_dylib_id(dylib_id_for(file), file) if file.dylib? each_install_name_for(file) do |bad_name| # Don't fix absolute paths unless they are rooted in the build directory @@ -11,7 +11,7 @@ class Keg !bad_name.start_with?(HOMEBREW_TEMP.realpath.to_s) new_name = fixed_name(file, bad_name) - file.change_install_name(bad_name, new_name, file) + change_install_name(bad_name, new_name, file) unless new_name == bad_name end end end @@ -24,7 +24,7 @@ class Keg file.ensure_writable do if file.dylib? id = dylib_id_for(file).sub(relocation.old_prefix, relocation.new_prefix) - file.change_dylib_id(id) + change_dylib_id(id, file) end each_install_name_for(file) do |old_name| @@ -34,7 +34,7 @@ class Keg new_name = old_name.sub(relocation.old_prefix, relocation.new_prefix) end - file.change_install_name(old_name, new_name) if new_name + change_install_name(old_name, new_name, file) if new_name end end end diff --git a/Library/Homebrew/os/mac.rb b/Library/Homebrew/os/mac.rb index b2a3109f14..5074665fca 100644 --- a/Library/Homebrew/os/mac.rb +++ b/Library/Homebrew/os/mac.rb @@ -5,6 +5,7 @@ require "os/mac/xcode" require "os/mac/xquartz" require "os/mac/pathname" require "os/mac/sdk" +require "os/mac/keg" module OS module Mac diff --git a/Library/Homebrew/os/mac/keg.rb b/Library/Homebrew/os/mac/keg.rb new file mode 100644 index 0000000000..6caadb1d7a --- /dev/null +++ b/Library/Homebrew/os/mac/keg.rb @@ -0,0 +1,29 @@ +class Keg + def change_dylib_id(id, file) + return if file.dylib_id == id + @require_relocation = true + puts "Changing dylib ID of #{file}\n from #{file.dylib_id}\n to #{id}" if ARGV.debug? + MachO::Tools.change_dylib_id(file, id, strict: false) + rescue MachO::MachOError + onoe <<-EOS.undent + Failed changing dylib ID of #{file} + from #{file.dylib_id} + to #{id} + EOS + raise + end + + def change_install_name(old, new, file) + return if old == new + @require_relocation = true + puts "Changing install name in #{file}\n from #{old}\n to #{new}" if ARGV.debug? + MachO::Tools.change_install_name(file, old, new, strict: false) + rescue MachO::MachOError + onoe <<-EOS.undent + Failed changing install name in #{file} + from #{old} + to #{new} + EOS + raise + end +end diff --git a/Library/Homebrew/os/mac/mach.rb b/Library/Homebrew/os/mac/mach.rb index 2d066392f6..9b53c49797 100644 --- a/Library/Homebrew/os/mac/mach.rb +++ b/Library/Homebrew/os/mac/mach.rb @@ -61,34 +61,6 @@ module MachOShim macho.dylib_id end - def change_dylib_id(id) - return if dylib_id == id - @require_relocation = true - puts "Changing dylib ID of #{self}\n from #{dylib_id}\n to #{id}" if ARGV.debug? - macho.change_dylib_id(id, strict: false) - rescue MachO::MachOError - onoe <<-EOS.undent - Failed changing dylib ID of #{self} - from #{file.dylib_id} - to #{id} - EOS - raise - end - - def change_install_name(old, new) - return if old == new - @require_relocation = true - puts "Changing install name in #{self}\n from #{old}\n to #{new}" if ARGV.debug? - macho.change_install_name(old, new, strict: false) - rescue MachO::MachOError - onoe <<-EOS.undent - Failed changing install name in #{self} - from #{old} - to #{new} - EOS - raise - end - def archs mach_data.map { |m| m.fetch :arch }.extend(ArchitectureListExtension) end From 1f66c9c9e0b678cc8f7b72d12f29ab6d25bd8eb8 Mon Sep 17 00:00:00 2001 From: Markus Reiter Date: Sun, 10 Sep 2017 07:23:18 +0200 Subject: [PATCH 168/294] Let `curl_download` handle HTTP 416 error. --- Library/Homebrew/download_strategy.rb | 12 +----------- Library/Homebrew/utils/curl.rb | 5 ++++- 2 files changed, 5 insertions(+), 12 deletions(-) diff --git a/Library/Homebrew/download_strategy.rb b/Library/Homebrew/download_strategy.rb index adeb0a02ad..7012fccc81 100644 --- a/Library/Homebrew/download_strategy.rb +++ b/Library/Homebrew/download_strategy.rb @@ -331,20 +331,10 @@ class CurlDownloadStrategy < AbstractFileDownloadStrategy if cached_location.exist? puts "Already downloaded: #{cached_location}" else - had_incomplete_download = temporary_path.exist? begin _fetch rescue ErrorDuringExecution - # 33 == range not supported - # try wiping the incomplete download and retrying once - unless $CHILD_STATUS.exitstatus == 33 && had_incomplete_download - raise CurlDownloadStrategyError, @url - end - - ohai "Trying a full download" - temporary_path.unlink - had_incomplete_download = false - retry + raise CurlDownloadStrategyError, @url end ignore_interrupts { temporary_path.rename(cached_location) } end diff --git a/Library/Homebrew/utils/curl.rb b/Library/Homebrew/utils/curl.rb index bc7055c0c3..7807d20344 100644 --- a/Library/Homebrew/utils/curl.rb +++ b/Library/Homebrew/utils/curl.rb @@ -38,11 +38,14 @@ def curl(*args) end def curl_download(*args, to: nil, continue_at: "-", **options) + had_incomplete_download ||= File.exist?(to) curl("--location", "--remote-time", "--continue-at", continue_at.to_s, "--output", to, *args, **options) rescue ErrorDuringExecution # `curl` error 33: HTTP server doesn't seem to support byte ranges. Cannot resume. - if $CHILD_STATUS.exitstatus == 33 && continue_at == "-" + # HTTP status 416: Requested range not satisfiable + if ($CHILD_STATUS.exitstatus == 33 || had_incomplete_download) && continue_at == "-" continue_at = 0 + had_incomplete_download = false retry end From 732bf2212d1d52e4f14bef82df94ba4ed537b5fb Mon Sep 17 00:00:00 2001 From: ilovezfs Date: Wed, 6 Sep 2017 01:49:10 -0700 Subject: [PATCH 169/294] build: fix HOMEBREW_FORMULA_PREFIX for head so that it includes the commit. --- Library/Homebrew/build.rb | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Library/Homebrew/build.rb b/Library/Homebrew/build.rb index 8dd4fb245f..cd2fa4c022 100644 --- a/Library/Homebrew/build.rb +++ b/Library/Homebrew/build.rb @@ -112,6 +112,10 @@ class Build formula.extend(Debrew::Formula) if ARGV.debug? formula.brew do |_formula, staging| + # For head builds, HOMEBREW_FORMULA_PREFIX should include the commit, + # which is not known until after the formula has been staged. + ENV["HOMEBREW_FORMULA_PREFIX"] = formula.prefix + staging.retain! if ARGV.keep_tmp? formula.patch From 7b1cf6df5a73b03ad87333636df627c86de50599 Mon Sep 17 00:00:00 2001 From: Josh Soref Date: Sun, 10 Sep 2017 16:30:30 +0000 Subject: [PATCH 170/294] spelling: comparison --- Library/Homebrew/test/cask/depends_on_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Library/Homebrew/test/cask/depends_on_spec.rb b/Library/Homebrew/test/cask/depends_on_spec.rb index c603cf6e14..fb92a9a24e 100644 --- a/Library/Homebrew/test/cask/depends_on_spec.rb +++ b/Library/Homebrew/test/cask/depends_on_spec.rb @@ -31,7 +31,7 @@ describe "Satisfy Dependencies and Requirements", :cask do it { is_expected.not_to raise_error } end - context "given a comparisson" do + context "given a comparison" do let(:cask) { Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/with-depends-on-macos-comparison.rb") } it { is_expected.not_to raise_error } end From 08e53870a65d272db5054d4919acead95a6869dc Mon Sep 17 00:00:00 2001 From: Josh Soref Date: Sun, 10 Sep 2017 16:31:02 +0000 Subject: [PATCH 171/294] spelling: definitions --- Library/Homebrew/extend/string.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Library/Homebrew/extend/string.rb b/Library/Homebrew/extend/string.rb index ae7a209dbf..b96f129949 100644 --- a/Library/Homebrew/extend/string.rb +++ b/Library/Homebrew/extend/string.rb @@ -60,7 +60,7 @@ module StringInreplaceExtension result end - # Looks for Makefile style variable defintions and replaces the + # Looks for Makefile style variable definitions and replaces the # value with "new_value", or removes the definition entirely. def change_make_var!(flag, new_value) return if gsub!(/^#{Regexp.escape(flag)}[ \t]*=[ \t]*(.*)$/, "#{flag}=#{new_value}", false) From 4806b35e2784e55a79b094968d195e648228a63b Mon Sep 17 00:00:00 2001 From: Josh Soref Date: Sun, 10 Sep 2017 16:31:56 +0000 Subject: [PATCH 172/294] spelling: directories --- Library/Homebrew/os/mac.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Library/Homebrew/os/mac.rb b/Library/Homebrew/os/mac.rb index 5074665fca..d6ded58ce1 100644 --- a/Library/Homebrew/os/mac.rb +++ b/Library/Homebrew/os/mac.rb @@ -129,7 +129,7 @@ module OS paths << path if path.exist? end - # Finally, some users make their MacPorts or Fink directorie + # Finally, some users make their MacPorts or Fink directories # read-only in order to try out Homebrew, but this doens't work as # some build scripts error out when trying to read from these now # unreadable paths. From fe21cfdefdc87074de6643b804b94b984814e0a1 Mon Sep 17 00:00:00 2001 From: Josh Soref Date: Sun, 10 Sep 2017 16:32:09 +0000 Subject: [PATCH 173/294] spelling: does --- Library/Homebrew/os/mac.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Library/Homebrew/os/mac.rb b/Library/Homebrew/os/mac.rb index d6ded58ce1..bc75fc3223 100644 --- a/Library/Homebrew/os/mac.rb +++ b/Library/Homebrew/os/mac.rb @@ -130,7 +130,7 @@ module OS end # Finally, some users make their MacPorts or Fink directories - # read-only in order to try out Homebrew, but this doens't work as + # read-only in order to try out Homebrew, but this doesn't work as # some build scripts error out when trying to read from these now # unreadable paths. %w[/sw /opt/local].map { |p| Pathname.new(p) }.each do |path| From 1fe2ade15c655b5f7bd2c22fac4b346fff2e434a Mon Sep 17 00:00:00 2001 From: Josh Soref Date: Sun, 10 Sep 2017 16:35:11 +0000 Subject: [PATCH 174/294] spelling: incomplete --- Library/Homebrew/cask/lib/hbc/cli/internal_dump.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Library/Homebrew/cask/lib/hbc/cli/internal_dump.rb b/Library/Homebrew/cask/lib/hbc/cli/internal_dump.rb index e21ce86b6c..46273cbe3e 100644 --- a/Library/Homebrew/cask/lib/hbc/cli/internal_dump.rb +++ b/Library/Homebrew/cask/lib/hbc/cli/internal_dump.rb @@ -7,7 +7,7 @@ module Hbc end def run - raise CaskError, "Dump incomplete." if dump_casks == :incomplet + raise CaskError, "Dump incomplete." if dump_casks == :incomplete end def dump_casks From 70ce9fe7f9b96acc62ad622a564ac41b7cad9521 Mon Sep 17 00:00:00 2001 From: Josh Soref Date: Sun, 10 Sep 2017 16:35:30 +0000 Subject: [PATCH 175/294] spelling: intermediate --- Library/Homebrew/test/pathname_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Library/Homebrew/test/pathname_spec.rb b/Library/Homebrew/test/pathname_spec.rb index 0bc19c5acf..69314e5f49 100644 --- a/Library/Homebrew/test/pathname_spec.rb +++ b/Library/Homebrew/test/pathname_spec.rb @@ -295,7 +295,7 @@ describe FileUtils do let(:dst) { mktmpdir } describe "#mkdir" do - it "creates indermediate directories" do + it "creates intermediate directories" do described_class.mkdir dst/"foo/bar/baz" do expect(dst/"foo/bar/baz").to exist, "foo/bar/baz was not created" expect(dst/"foo/bar/baz").to be_a_directory, "foo/bar/baz was not a directory structure" From a337620d97d9e3ae4575ff79768c0ef14d82fd0b Mon Sep 17 00:00:00 2001 From: Josh Soref Date: Sun, 10 Sep 2017 16:38:28 +0000 Subject: [PATCH 176/294] spelling: omitted --- Library/Homebrew/test/requirement_spec.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Library/Homebrew/test/requirement_spec.rb b/Library/Homebrew/test/requirement_spec.rb index 71372aa69e..11a3da8f4e 100644 --- a/Library/Homebrew/test/requirement_spec.rb +++ b/Library/Homebrew/test/requirement_spec.rb @@ -48,7 +48,7 @@ describe Requirement do it { is_expected.to be_fatal } end - context "#fatal is ommitted" do + context "#fatal is omitted" do it { is_expected.not_to be_fatal } end end @@ -184,7 +184,7 @@ describe Requirement do it { is_expected.to have_a_default_formula } end - context "#default_formula ommitted" do + context "#default_formula omitted" do it { is_expected.not_to have_a_default_formula } end end From ca32ece84ed17231edd7ec07af4b95bc457cee66 Mon Sep 17 00:00:00 2001 From: Josh Soref Date: Sun, 10 Sep 2017 16:39:03 +0000 Subject: [PATCH 177/294] spelling: packages --- Library/Homebrew/cask/lib/hbc/artifact/relocated.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Library/Homebrew/cask/lib/hbc/artifact/relocated.rb b/Library/Homebrew/cask/lib/hbc/artifact/relocated.rb index 4dba46c9d8..0e8e42c9be 100644 --- a/Library/Homebrew/cask/lib/hbc/artifact/relocated.rb +++ b/Library/Homebrew/cask/lib/hbc/artifact/relocated.rb @@ -34,7 +34,7 @@ module Hbc altnames.concat(%Q("#{altname}")) altnames = "(#{altnames})" - # Some packges are shipped as u=rx (e.g. Bitcoin Core) + # Some packages are shipped as u=rx (e.g. Bitcoin Core) @command.run!("/bin/chmod", args: ["--", "u+rw", file, file.realpath]) @command.run!("/usr/bin/xattr", From b9a33b03a4812e87c88dc009dc0661d4fc7d46fc Mon Sep 17 00:00:00 2001 From: Josh Soref Date: Sun, 10 Sep 2017 16:39:18 +0000 Subject: [PATCH 178/294] spelling: parameters --- Library/Homebrew/test/utils/github_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Library/Homebrew/test/utils/github_spec.rb b/Library/Homebrew/test/utils/github_spec.rb index 9322898eee..a132894f92 100644 --- a/Library/Homebrew/test/utils/github_spec.rb +++ b/Library/Homebrew/test/utils/github_spec.rb @@ -2,7 +2,7 @@ require "utils/github" describe GitHub do describe "::search_code", :needs_network do - it "queries GitHub code with the passed paramaters" do + it "queries GitHub code with the passed parameters" do results = subject.search_code(repo: "Homebrew/brew", path: "/", filename: "readme", language: "markdown") From ce45591981123c078567956a351e0d902b7c8158 Mon Sep 17 00:00:00 2001 From: Josh Soref Date: Sun, 10 Sep 2017 16:40:18 +0000 Subject: [PATCH 179/294] spelling: perform --- Library/Homebrew/compat/formula_specialties.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Library/Homebrew/compat/formula_specialties.rb b/Library/Homebrew/compat/formula_specialties.rb index ec5e91ce8a..78966625ee 100644 --- a/Library/Homebrew/compat/formula_specialties.rb +++ b/Library/Homebrew/compat/formula_specialties.rb @@ -16,7 +16,7 @@ end # This formula serves as the base class for several very similar # formulae for Amazon Web Services related tools. class AmazonWebServicesFormula < Formula - # Use this method to peform a standard install for Java-based tools, + # Use this method to perform a standard install for Java-based tools, # keeping the .jars out of HOMEBREW_PREFIX/lib def install odeprecated "AmazonWebServicesFormula#install", "Formula#install" From 130fec083166a9d29545155a26a105dcd3dfb192 Mon Sep 17 00:00:00 2001 From: Josh Soref Date: Sun, 10 Sep 2017 16:40:29 +0000 Subject: [PATCH 180/294] spelling: preserves --- Library/Homebrew/test/dependency_expansion_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Library/Homebrew/test/dependency_expansion_spec.rb b/Library/Homebrew/test/dependency_expansion_spec.rb index f955237a97..d6ecdf5527 100644 --- a/Library/Homebrew/test/dependency_expansion_spec.rb +++ b/Library/Homebrew/test/dependency_expansion_spec.rb @@ -69,7 +69,7 @@ describe Dependency do end end - it "merges dependencies and perserves env_proc" do + it "merges dependencies and preserves env_proc" do env_proc = double dep = described_class.new("foo", [], env_proc) allow(dep).to receive(:to_formula).and_return(double(deps: [], name: "foo")) From 44c56cd9a8d47acbb2e9930087a89bb1a8475038 Mon Sep 17 00:00:00 2001 From: Josh Soref Date: Sun, 10 Sep 2017 16:42:10 +0000 Subject: [PATCH 181/294] spelling: separated --- Library/Homebrew/extend/ARGV.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Library/Homebrew/extend/ARGV.rb b/Library/Homebrew/extend/ARGV.rb index c6cb54f5da..daa5306faf 100644 --- a/Library/Homebrew/extend/ARGV.rb +++ b/Library/Homebrew/extend/ARGV.rb @@ -147,7 +147,7 @@ module HomebrewArgvExtension flag_with_value.strip_prefix(arg_prefix) if flag_with_value end - # Returns an array of values that were given as a comma-seperated list. + # Returns an array of values that were given as a comma-separated list. # @see value def values(name) return unless val = value(name) From 8e4150b20b811175d4778ec73f3018b8ef878742 Mon Sep 17 00:00:00 2001 From: Josh Soref Date: Sun, 10 Sep 2017 16:42:24 +0000 Subject: [PATCH 182/294] spelling: should --- Library/Homebrew/test/cmd/commands_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Library/Homebrew/test/cmd/commands_spec.rb b/Library/Homebrew/test/cmd/commands_spec.rb index cf6f567404..46ed3ddcfe 100644 --- a/Library/Homebrew/test/cmd/commands_spec.rb +++ b/Library/Homebrew/test/cmd/commands_spec.rb @@ -68,7 +68,7 @@ describe Homebrew do expect(cmds).to include("t1"), "Executable files should be included" expect(cmds).to include("t2"), "Executable Ruby files should be included" - expect(cmds).not_to include("t3"), "Executable files with a non Ruby extension shoudn't be included" + expect(cmds).not_to include("t3"), "Executable files with a non Ruby extension shouldn't be included" expect(cmds).not_to include("t4"), "Non-executable files shouldn't be included" end end From 194a2c2adebdcd585fcff781841725b13a91d28a Mon Sep 17 00:00:00 2001 From: Markus Reiter Date: Sun, 10 Sep 2017 21:56:12 +0200 Subject: [PATCH 183/294] Make `brew cask search` spec deterministic. --- Library/Homebrew/test/cask/cli/search_spec.rb | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/Library/Homebrew/test/cask/cli/search_spec.rb b/Library/Homebrew/test/cask/cli/search_spec.rb index 6dc9805903..3d58e6a151 100644 --- a/Library/Homebrew/test/cask/cli/search_spec.rb +++ b/Library/Homebrew/test/cask/cli/search_spec.rb @@ -4,6 +4,8 @@ describe Hbc::CLI::Search, :cask do end it "lists the available Casks that match the search term" do + allow(GitHub).to receive(:search_code).and_return([]) + expect { Hbc::CLI::Search.run("local") }.to output(<<-EOS.undent).to_stdout.as_tty @@ -14,6 +16,8 @@ describe Hbc::CLI::Search, :cask do end it "outputs a plain list when stdout is not a TTY" do + allow(GitHub).to receive(:search_code).and_return([]) + expect { Hbc::CLI::Search.run("local") }.to output(<<-EOS.undent).to_stdout @@ -24,6 +28,7 @@ describe Hbc::CLI::Search, :cask do it "returns matches even when online search failed" do allow(GitHub).to receive(:search_code).and_raise(GitHub::Error.new("reason")) + expect { Hbc::CLI::Search.run("local") }.to output(<<-EOS.undent).to_stdout From 53ecdd843f6e6d6dd93e09a5394de3c31bc0e51a Mon Sep 17 00:00:00 2001 From: Markus Reiter Date: Thu, 6 Apr 2017 00:33:31 +0200 Subject: [PATCH 184/294] Treat every `Artifact` instance as a single artifact. --- Library/Homebrew/cask/lib/hbc/artifact.rb | 9 +- .../{base.rb => abstract_artifact.rb} | 43 +++--- .../lib/hbc/artifact/abstract_flight_block.rb | 42 +++--- ...ninstall_base.rb => abstract_uninstall.rb} | 132 ++++++++++-------- .../cask/lib/hbc/artifact/artifact.rb | 31 ++-- .../Homebrew/cask/lib/hbc/artifact/binary.rb | 6 +- .../cask/lib/hbc/artifact/installer.rb | 89 +++++++++--- .../Homebrew/cask/lib/hbc/artifact/moved.rb | 52 ++++--- .../cask/lib/hbc/artifact/nested_container.rb | 28 ++-- Library/Homebrew/cask/lib/hbc/artifact/pkg.rb | 61 ++++---- .../cask/lib/hbc/artifact/prefpane.rb | 2 +- .../cask/lib/hbc/artifact/qlplugin.rb | 20 +-- .../cask/lib/hbc/artifact/relocated.rb | 74 +++++----- .../cask/lib/hbc/artifact/stage_only.rb | 16 ++- .../Homebrew/cask/lib/hbc/artifact/suite.rb | 4 +- .../cask/lib/hbc/artifact/symlinked.rb | 68 +++++---- .../cask/lib/hbc/artifact/uninstall.rb | 8 +- Library/Homebrew/cask/lib/hbc/artifact/zap.rb | 8 +- Library/Homebrew/cask/lib/hbc/audit.rb | 8 +- Library/Homebrew/cask/lib/hbc/cask.rb | 2 +- Library/Homebrew/cask/lib/hbc/cli/info.rb | 12 +- .../cask/lib/hbc/cli/internal_stanza.rb | 37 +---- Library/Homebrew/cask/lib/hbc/cli/list.rb | 6 +- Library/Homebrew/cask/lib/hbc/dsl.rb | 129 ++++++++--------- .../Homebrew/cask/lib/hbc/dsl/installer.rb | 32 ----- Library/Homebrew/cask/lib/hbc/installer.rb | 20 +-- Library/Homebrew/cask/lib/hbc/staged.rb | 2 +- .../test/cask/artifact/alt_target_spec.rb | 2 +- .../Homebrew/test/cask/artifact/app_spec.rb | 21 ++- .../test/cask/artifact/binary_spec.rb | 21 ++- .../cask/artifact/generic_artifact_spec.rb | 12 +- .../cask/artifact/nested_container_spec.rb | 3 +- .../Homebrew/test/cask/artifact/pkg_spec.rb | 8 +- .../cask/artifact/postflight_block_spec.rb | 6 +- .../cask/artifact/preflight_block_spec.rb | 6 +- .../Homebrew/test/cask/artifact/suite_spec.rb | 4 +- .../cask/artifact/two_apps_correct_spec.rb | 2 +- .../cask/artifact/uninstall_no_zap_spec.rb | 2 +- .../artifact/uninstall_zap_shared_examples.rb | 26 ++-- Library/Homebrew/test/cask/audit_spec.rb | 9 +- Library/Homebrew/test/cask/cli/info_spec.rb | 10 +- Library/Homebrew/test/cask/cli/list_spec.rb | 3 +- Library/Homebrew/test/cask/dsl_spec.rb | 24 ++-- 43 files changed, 560 insertions(+), 540 deletions(-) rename Library/Homebrew/cask/lib/hbc/artifact/{base.rb => abstract_artifact.rb} (66%) rename Library/Homebrew/cask/lib/hbc/artifact/{uninstall_base.rb => abstract_uninstall.rb} (63%) delete mode 100644 Library/Homebrew/cask/lib/hbc/dsl/installer.rb diff --git a/Library/Homebrew/cask/lib/hbc/artifact.rb b/Library/Homebrew/cask/lib/hbc/artifact.rb index 074d15017a..cb15ec0513 100644 --- a/Library/Homebrew/cask/lib/hbc/artifact.rb +++ b/Library/Homebrew/cask/lib/hbc/artifact.rb @@ -33,7 +33,7 @@ module Hbc # We want to extract nested containers before we # handle any other artifacts. # - TYPES = [ + CLASSES = [ PreflightBlock, Uninstall, NestedContainer, @@ -60,12 +60,9 @@ module Hbc Zap, ].freeze - def self.for_cask(cask, options = {}) + def self.for_cask(cask) odebug "Determining which artifacts are present in Cask #{cask}" - - TYPES - .select { |klass| klass.me?(cask) } - .map { |klass| klass.new(cask, options) } + CLASSES.flat_map { |klass| klass.for_cask(cask) } end end end diff --git a/Library/Homebrew/cask/lib/hbc/artifact/base.rb b/Library/Homebrew/cask/lib/hbc/artifact/abstract_artifact.rb similarity index 66% rename from Library/Homebrew/cask/lib/hbc/artifact/base.rb rename to Library/Homebrew/cask/lib/hbc/artifact/abstract_artifact.rb index ae15552a4e..1b18cc6e7d 100644 --- a/Library/Homebrew/cask/lib/hbc/artifact/base.rb +++ b/Library/Homebrew/cask/lib/hbc/artifact/abstract_artifact.rb @@ -1,34 +1,28 @@ module Hbc module Artifact - class Base + class AbstractArtifact extend Predicable - def self.artifact_name - @artifact_name ||= name.sub(/^.*:/, "").gsub(/(.)([A-Z])/, '\1_\2').downcase + def self.english_name + @english_name ||= name.sub(/^.*:/, "").gsub(/(.)([A-Z])/, '\1 \2') end - def self.artifact_english_name - @artifact_english_name ||= name.sub(/^.*:/, "").gsub(/(.)([A-Z])/, '\1 \2') + def self.english_article + @english_article ||= (english_name =~ /^[aeiou]/i) ? "an" : "a" end - def self.artifact_english_article - @artifact_english_article ||= (artifact_english_name =~ /^[aeiou]/i) ? "an" : "a" + def self.dsl_key + @dsl_key ||= name.sub(/^.*:/, "").gsub(/(.)([A-Z])/, '\1_\2').downcase.to_sym end - def self.artifact_dsl_key - @artifact_dsl_key ||= artifact_name.to_sym + def self.dirmethod + @dirmethod ||= "#{dsl_key}dir".to_sym end - def self.artifact_dirmethod - @artifact_dirmethod ||= "#{artifact_name}dir".to_sym + def self.for_cask(cask) + cask.artifacts[dsl_key].to_a end - def self.me?(cask) - cask.artifacts[artifact_dsl_key].any? - end - - attr_reader :force - # TODO: this sort of logic would make more sense in dsl.rb, or a # constructor called from dsl.rb, so long as that isn't slow. def self.read_script_arguments(arguments, stanza, default_arguments = {}, override_arguments = {}, key = nil) @@ -63,17 +57,14 @@ module Hbc [executable, arguments] end - def summary - {} + attr_reader :cask + + def initialize(cask) + @cask = cask end - attr_predicate :force?, :verbose? - - def initialize(cask, command: SystemCommand, force: false, verbose: false) - @cask = cask - @command = command - @force = force - @verbose = verbose + def to_s + "#{summarize} (#{self.class.english_name})" end end end diff --git a/Library/Homebrew/cask/lib/hbc/artifact/abstract_flight_block.rb b/Library/Homebrew/cask/lib/hbc/artifact/abstract_flight_block.rb index be3050acb7..6670d42499 100644 --- a/Library/Homebrew/cask/lib/hbc/artifact/abstract_flight_block.rb +++ b/Library/Homebrew/cask/lib/hbc/artifact/abstract_flight_block.rb @@ -1,39 +1,47 @@ -require "hbc/artifact/base" +require "hbc/artifact/abstract_artifact" module Hbc module Artifact - class AbstractFlightBlock < Base - def self.artifact_dsl_key + class AbstractFlightBlock < AbstractArtifact + def self.dsl_key super.to_s.sub(/_block$/, "").to_sym end - def self.uninstall_artifact_dsl_key - artifact_dsl_key.to_s.prepend("uninstall_").to_sym + def self.uninstall_dsl_key + dsl_key.to_s.prepend("uninstall_").to_sym end - def self.class_for_dsl_key(dsl_key) - Object.const_get("Hbc::DSL::#{dsl_key.to_s.split("_").collect(&:capitalize).join}") + def self.for_cask(cask) + [dsl_key, uninstall_dsl_key].flat_map do |key| + [*cask.artifacts[key]].map { |block| new(cask, key => block) } + end end - def self.me?(cask) - cask.artifacts[artifact_dsl_key].any? || - cask.artifacts[uninstall_artifact_dsl_key].any? + attr_reader :directives + + def initialize(cask, **directives) + super(cask) + @directives = directives end - def install_phase - abstract_phase(self.class.artifact_dsl_key) + def install_phase(**) + abstract_phase(self.class.dsl_key) end - def uninstall_phase - abstract_phase(self.class.uninstall_artifact_dsl_key) + def uninstall_phase(**) + abstract_phase(self.class.uninstall_dsl_key) end private + def class_for_dsl_key(dsl_key) + namespace = self.class.name.to_s.sub(/::.*::.*$/, "") + self.class.const_get("#{namespace}::DSL::#{dsl_key.to_s.split("_").collect(&:capitalize).join}") + end + def abstract_phase(dsl_key) - @cask.artifacts[dsl_key].each do |block| - self.class.class_for_dsl_key(dsl_key).new(@cask).instance_eval(&block) - end + return if (block = directives[dsl_key]).nil? + class_for_dsl_key(dsl_key).new(cask).instance_eval(&block) end end end diff --git a/Library/Homebrew/cask/lib/hbc/artifact/uninstall_base.rb b/Library/Homebrew/cask/lib/hbc/artifact/abstract_uninstall.rb similarity index 63% rename from Library/Homebrew/cask/lib/hbc/artifact/uninstall_base.rb rename to Library/Homebrew/cask/lib/hbc/artifact/abstract_uninstall.rb index d926441502..9499d5c03f 100644 --- a/Library/Homebrew/cask/lib/hbc/artifact/uninstall_base.rb +++ b/Library/Homebrew/cask/lib/hbc/artifact/abstract_uninstall.rb @@ -1,11 +1,11 @@ require "pathname" require "timeout" -require "hbc/artifact/base" +require "hbc/artifact/abstract_artifact" module Hbc module Artifact - class UninstallBase < Base + class AbstractUninstall < AbstractArtifact ORDERED_DIRECTIVES = [ :early_script, :launchctl, @@ -20,26 +20,33 @@ module Hbc :rmdir, ].freeze - def dispatch_uninstall_directives - directives_set = @cask.artifacts[stanza] - ohai "Running #{stanza} process for #{@cask}; your password may be necessary" + def self.from_args(cask, **directives) + new(cask, directives) + end - directives_set.each do |directives| - warn_for_unknown_directives(directives) - end + attr_reader :directives - ORDERED_DIRECTIVES.each do |directive_sym| - directives_set.select { |h| h.key?(directive_sym) }.each do |directives| - args = directives[directive_sym] - send("uninstall_#{directive_sym}", *(args.is_a?(Hash) ? [args] : args)) - end - end + def initialize(cask, directives) + super(cask) + @directives = directives end private + def dispatch_uninstall_directives(**options) + ohai "Running #{stanza} process for #{@cask}; your password may be necessary" + + warn_for_unknown_directives(directives) + + ORDERED_DIRECTIVES.each do |directive_sym| + next unless directives.key?(directive_sym) + args = directives[directive_sym] + send("uninstall_#{directive_sym}", *(args.is_a?(Hash) ? [args] : args), **options) + end + end + def stanza - self.class.artifact_dsl_key + self.class.dsl_key end def warn_for_unknown_directives(directives) @@ -51,18 +58,18 @@ module Hbc # Preserve prior functionality of script which runs first. Should rarely be needed. # :early_script should not delete files, better defer that to :script. # If Cask writers never need :early_script it may be removed in the future. - def uninstall_early_script(directives) - uninstall_script(directives, directive_name: :early_script) + def uninstall_early_script(directives, **options) + uninstall_script(directives, directive_name: :early_script, **options) end # :launchctl must come before :quit/:signal for cases where app would instantly re-launch - def uninstall_launchctl(*services) + def uninstall_launchctl(*services, command: nil, **_) services.each do |service| ohai "Removing launchctl service #{service}" [false, true].each do |with_sudo| - plist_status = @command.run("/bin/launchctl", args: ["list", service], sudo: with_sudo, print_stderr: false).stdout + plist_status = command.run("/bin/launchctl", args: ["list", service], sudo: with_sudo, print_stderr: false).stdout if plist_status =~ /^\{/ - @command.run!("/bin/launchctl", args: ["remove", service], sudo: with_sudo) + command.run!("/bin/launchctl", args: ["remove", service], sudo: with_sudo) sleep 1 end paths = ["/Library/LaunchAgents/#{service}.plist", @@ -70,38 +77,38 @@ module Hbc paths.each { |elt| elt.prepend(ENV["HOME"]) } unless with_sudo paths = paths.map { |elt| Pathname(elt) }.select(&:exist?) paths.each do |path| - @command.run!("/bin/rm", args: ["-f", "--", path], sudo: with_sudo) + command.run!("/bin/rm", args: ["-f", "--", path], sudo: with_sudo) end # undocumented and untested: pass a path to uninstall :launchctl next unless Pathname(service).exist? - @command.run!("/bin/launchctl", args: ["unload", "-w", "--", service], sudo: with_sudo) - @command.run!("/bin/rm", args: ["-f", "--", service], sudo: with_sudo) + command.run!("/bin/launchctl", args: ["unload", "-w", "--", service], sudo: with_sudo) + command.run!("/bin/rm", args: ["-f", "--", service], sudo: with_sudo) sleep 1 end end end - def running_processes(bundle_id) - @command.run!("/bin/launchctl", args: ["list"]).stdout.lines - .map { |line| line.chomp.split("\t") } - .map { |pid, state, id| [pid.to_i, state.to_i, id] } - .select do |fields| - next if fields[0].zero? - fields[2] =~ /^#{Regexp.escape(bundle_id)}($|\.\d+)/ - end + def running_processes(bundle_id, command: nil) + command.run!("/bin/launchctl", args: ["list"]).stdout.lines + .map { |line| line.chomp.split("\t") } + .map { |pid, state, id| [pid.to_i, state.to_i, id] } + .select do |fields| + next if fields[0].zero? + fields[2] =~ /^#{Regexp.escape(bundle_id)}($|\.\d+)/ + end end # :quit/:signal must come before :kext so the kext will not be in use by a running process - def uninstall_quit(*bundle_ids) + def uninstall_quit(*bundle_ids, command: nil, **_) bundle_ids.each do |bundle_id| ohai "Quitting application ID #{bundle_id}" - next if running_processes(bundle_id).empty? - @command.run!("/usr/bin/osascript", args: ["-e", %Q(tell application id "#{bundle_id}" to quit)], sudo: true) + next if running_processes(bundle_id, command: command).empty? + command.run!("/usr/bin/osascript", args: ["-e", %Q(tell application id "#{bundle_id}" to quit)], sudo: true) begin Timeout.timeout(3) do Kernel.loop do - break if running_processes(bundle_id).empty? + break if running_processes(bundle_id, command: command).empty? end end rescue Timeout::Error @@ -111,15 +118,15 @@ module Hbc end # :signal should come after :quit so it can be used as a backup when :quit fails - def uninstall_signal(*signals) + def uninstall_signal(*signals, **options) signals.flatten.each_slice(2) do |pair| unless pair.size == 2 - raise CaskInvalidError.new(@cask, "Each #{stanza} :signal must consist of 2 elements.") + raise CaskInvalidError.new(cask, "Each #{stanza} :signal must consist of 2 elements.") end signal, bundle_id = pair ohai "Signalling '#{signal}' to application ID '#{bundle_id}'" - pids = running_processes(bundle_id).map(&:first) + pids = running_processes(bundle_id, **options).map(&:first) next unless pids.any? # Note that unlike :quit, signals are sent from the current user (not # upgraded to the superuser). This is a todo item for the future, but @@ -133,10 +140,10 @@ module Hbc end end - def uninstall_login_item(*login_items) + def uninstall_login_item(*login_items, command: nil, **_) login_items.each do |name| ohai "Removing login item #{name}" - @command.run!("/usr/bin/osascript", + command.run!("/usr/bin/osascript", args: ["-e", %Q(tell application "System Events" to delete every login item whose name is "#{name}")], sudo: false) sleep 1 @@ -144,23 +151,24 @@ module Hbc end # :kext should be unloaded before attempting to delete the relevant file - def uninstall_kext(*kexts) + def uninstall_kext(*kexts, command: nil, **_) kexts.each do |kext| ohai "Unloading kernel extension #{kext}" - is_loaded = @command.run!("/usr/sbin/kextstat", args: ["-l", "-b", kext], sudo: true).stdout + is_loaded = command.run!("/usr/sbin/kextstat", args: ["-l", "-b", kext], sudo: true).stdout if is_loaded.length > 1 - @command.run!("/sbin/kextunload", args: ["-b", kext], sudo: true) + command.run!("/sbin/kextunload", args: ["-b", kext], sudo: true) sleep 1 end - @command.run!("/usr/sbin/kextfind", args: ["-b", kext], sudo: true).stdout.chomp.lines.each do |kext_path| + command.run!("/usr/sbin/kextfind", args: ["-b", kext], sudo: true).stdout.chomp.lines.each do |kext_path| ohai "Removing kernel extension #{kext_path}" - @command.run!("/bin/rm", args: ["-rf", kext_path], sudo: true) + command.run!("/bin/rm", args: ["-rf", kext_path], sudo: true) end end end # :script must come before :pkgutil, :delete, or :trash so that the script file is not already deleted - def uninstall_script(directives, directive_name: :script) + def uninstall_script(directives, directive_name: :script, force: false, command: nil, **_) + # TODO: Create a common `Script` class to run this and Artifact::Installer. executable, script_arguments = self.class.read_script_arguments(directives, "uninstall", { must_succeed: true, sudo: false }, @@ -168,25 +176,25 @@ module Hbc directive_name) ohai "Running uninstall script #{executable}" - raise CaskInvalidError.new(@cask, "#{stanza} :#{directive_name} without :executable.") if executable.nil? - executable_path = @cask.staged_path.join(executable) + raise CaskInvalidError.new(cask, "#{stanza} :#{directive_name} without :executable.") if executable.nil? + executable_path = cask.staged_path.join(executable) unless executable_path.exist? message = "uninstall script #{executable} does not exist" - raise CaskError, "#{message}." unless force? + raise CaskError, "#{message}." unless force opoo "#{message}, skipping." return end - @command.run("/bin/chmod", args: ["--", "+x", executable_path]) - @command.run(executable_path, script_arguments) + command.run("/bin/chmod", args: ["--", "+x", executable_path]) + command.run(executable_path, script_arguments) sleep 1 end - def uninstall_pkgutil(*pkgs) + def uninstall_pkgutil(*pkgs, command: nil, **_) ohai "Uninstalling packages:" pkgs.each do |regex| - Hbc::Pkg.all_matching(regex, @command).each do |pkg| + Hbc::Pkg.all_matching(regex, command).each do |pkg| puts pkg.package_id pkg.uninstall end @@ -215,28 +223,28 @@ module Hbc end end - def uninstall_delete(*paths) + def uninstall_delete(*paths, command: nil, **_) return if paths.empty? ohai "Removing files:" each_resolved_path(:delete, paths) do |path, resolved_paths| puts path - @command.run!("/usr/bin/xargs", args: ["-0", "--", "/bin/rm", "-r", "-f", "--"], input: resolved_paths.join("\0"), sudo: true) + command.run!("/usr/bin/xargs", args: ["-0", "--", "/bin/rm", "-r", "-f", "--"], input: resolved_paths.join("\0"), sudo: true) end end - def uninstall_trash(*paths) + def uninstall_trash(*paths, **options) return if paths.empty? resolved_paths = each_resolved_path(:trash, paths).to_a ohai "Trashing files:" puts resolved_paths.map(&:first) - trash_paths(*resolved_paths.flat_map(&:last)) + trash_paths(*resolved_paths.flat_map(&:last), **options) end - def trash_paths(*paths) - @command.run!("/usr/bin/osascript", args: ["-e", <<-'EOS'.undent, *paths]) + def trash_paths(*paths, command: nil, **_) + command.run!("/usr/bin/osascript", args: ["-e", <<-'EOS'.undent, *paths]) on run argv repeat with i from 1 to (count argv) set item i of argv to (item i of argv as POSIX file) @@ -260,7 +268,7 @@ module Hbc EOS end - def uninstall_rmdir(*directories) + def uninstall_rmdir(*directories, command: nil, **_) return if directories.empty? ohai "Removing directories if empty:" @@ -268,10 +276,10 @@ module Hbc puts path resolved_paths.select(&:directory?).each do |resolved_path| if (ds_store = resolved_path.join(".DS_Store")).exist? - @command.run!("/bin/rm", args: ["-f", "--", ds_store], sudo: true, print_stderr: false) + command.run!("/bin/rm", args: ["-f", "--", ds_store], sudo: true, print_stderr: false) end - @command.run("/bin/rmdir", args: ["--", resolved_path], sudo: true, print_stderr: false) + command.run("/bin/rmdir", args: ["--", resolved_path], sudo: true, print_stderr: false) end end end diff --git a/Library/Homebrew/cask/lib/hbc/artifact/artifact.rb b/Library/Homebrew/cask/lib/hbc/artifact/artifact.rb index b42db877d0..0f37afaded 100644 --- a/Library/Homebrew/cask/lib/hbc/artifact/artifact.rb +++ b/Library/Homebrew/cask/lib/hbc/artifact/artifact.rb @@ -5,21 +5,32 @@ require "hbc/utils/hash_validator" module Hbc module Artifact class Artifact < Moved - def self.artifact_english_name + def self.english_name "Generic Artifact" end - def self.artifact_dirmethod - :appdir + def self.from_args(cask, *args) + source_string, target_hash = args + + if source_string.nil? + raise CaskInvalidError.new(cask.token, "no source given for #{english_name}") + end + + unless target_hash.is_a?(Hash) + raise CaskInvalidError.new(cask.token, "target required for #{english_name} '#{source_string}'") + end + + target_hash.extend(HashValidator).assert_valid_keys(:target) + + new(cask, source_string, **target_hash) end - def load_specification(artifact_spec) - source_string, target_hash = artifact_spec - raise CaskInvalidError.new(@cask.token, "no source given for artifact") if source_string.nil? - @source = @cask.staged_path.join(source_string) - raise CaskInvalidError.new(@cask.token, "target required for generic artifact #{source_string}") unless target_hash.is_a?(Hash) - target_hash.extend(HashValidator).assert_valid_keys(:target) - @target = Pathname.new(target_hash[:target]) + def self.resolve_target(target) + Pathname(target) + end + + def initialize(cask, source, target: nil) + super(cask, source, target: target) end end end diff --git a/Library/Homebrew/cask/lib/hbc/artifact/binary.rb b/Library/Homebrew/cask/lib/hbc/artifact/binary.rb index 7178c2af69..68f4b074da 100644 --- a/Library/Homebrew/cask/lib/hbc/artifact/binary.rb +++ b/Library/Homebrew/cask/lib/hbc/artifact/binary.rb @@ -3,13 +3,13 @@ require "hbc/artifact/symlinked" module Hbc module Artifact class Binary < Symlinked - def link - super + def link(command: nil, **options) + super(command: command, **options) return if source.executable? if source.writable? FileUtils.chmod "+x", source else - @command.run!("/bin/chmod", args: ["+x", source], sudo: true) + command.run!("/bin/chmod", args: ["+x", source], sudo: true) end end end diff --git a/Library/Homebrew/cask/lib/hbc/artifact/installer.rb b/Library/Homebrew/cask/lib/hbc/artifact/installer.rb index be857696ec..64ce2d4bc5 100644 --- a/Library/Homebrew/cask/lib/hbc/artifact/installer.rb +++ b/Library/Homebrew/cask/lib/hbc/artifact/installer.rb @@ -1,31 +1,78 @@ -require "hbc/artifact/base" +require "hbc/artifact/abstract_artifact" module Hbc module Artifact - class Installer < Base - def install_phase - @cask.artifacts[self.class.artifact_dsl_key].each do |artifact| - if artifact.manual - puts <<-EOS.undent - To complete the installation of Cask #{@cask}, you must also - run the installer at + class Installer < AbstractArtifact + VALID_KEYS = Set.new [ + :manual, + :script, + ] - '#{@cask.staged_path.join(artifact.manual)}' + module ManualInstaller + def install_phase(**) + puts <<-EOS.undent + To complete the installation of Cask #{cask}, you must also + run the installer at - EOS - else - executable, script_arguments = self.class.read_script_arguments(artifact.script, - self.class.artifact_dsl_key.to_s, - { must_succeed: true, sudo: false }, - print_stdout: true) - ohai "Running #{self.class.artifact_dsl_key} script #{executable}" - raise CaskInvalidError.new(@cask, "#{self.class.artifact_dsl_key} missing executable") if executable.nil? - executable_path = @cask.staged_path.join(executable) - @command.run("/bin/chmod", args: ["--", "+x", executable_path]) if File.exist?(executable_path) - @command.run(executable_path, script_arguments) - end + '#{path}' + EOS end end + + module ScriptInstaller + def install_phase(command: nil, **_) + ohai "Running #{self.class.dsl_key} script '#{path.relative_path_from(cask.staged_path)}'" + FileUtils.chmod "+x", path unless path.executable? + command.run(path, **args) + end + end + + def self.from_args(cask, **args) + raise CaskInvalidError.new(cask, "'installer' stanza requires an argument.") if args.empty? + + if args.key?(:script) && !args[:script].respond_to?(:key?) + if args.key?(:executable) + raise CaskInvalidError.new(cask, "'installer' stanza gave arguments for both :script and :executable.") + end + + args[:executable] = args[:script] + args.delete(:script) + args = { script: args } + end + + unless args.keys.count == 1 + raise CaskInvalidError.new(cask, "invalid 'installer' stanza: Only one of #{VALID_KEYS.inspect} is permitted.") + end + + args.extend(HashValidator).assert_valid_keys(*VALID_KEYS) + new(cask, **args) + end + + attr_reader :path, :args + + def initialize(cask, **args) + super(cask) + + if args.key?(:manual) + @path = cask.staged_path.join(args[:manual]) + @args = [] + extend(ManualInstaller) + return + end + + path, @args = self.class.read_script_arguments( + args[:script], self.class.dsl_key.to_s, { must_succeed: true, sudo: false }, print_stdout: true + ) + raise CaskInvalidError.new(cask, "#{self.class.dsl_key} missing executable") if path.nil? + + path = Pathname(path) + @path = path.absolute? ? path : cask.staged_path.join(path) + extend(ScriptInstaller) + end + + def summarize + path.relative_path_from(cask.staged_path).to_s + end end end end diff --git a/Library/Homebrew/cask/lib/hbc/artifact/moved.rb b/Library/Homebrew/cask/lib/hbc/artifact/moved.rb index 3fe969c0c2..ba1c8e9072 100644 --- a/Library/Homebrew/cask/lib/hbc/artifact/moved.rb +++ b/Library/Homebrew/cask/lib/hbc/artifact/moved.rb @@ -4,63 +4,61 @@ module Hbc module Artifact class Moved < Relocated def self.english_description - "#{artifact_english_name}s" + "#{english_name}s" end - def install_phase - each_artifact(&method(:move)) + def install_phase(**options) + move(**options) end - def uninstall_phase - each_artifact(&method(:delete)) + def uninstall_phase(**options) + delete(**options) + end + + def summarize_installed + if target.exist? + "#{printable_target} (#{target.abv})" + else + Formatter.error(printable_target, label: "Missing #{self.class.english_name}") + end end private - def move + def move(force: false, command: nil, **options) if Utils.path_occupied?(target) - message = "It seems there is already #{self.class.artifact_english_article} #{self.class.artifact_english_name} at '#{target}'" - raise CaskError, "#{message}." unless force? + message = "It seems there is already #{self.class.english_article} #{self.class.english_name} at '#{target}'" + raise CaskError, "#{message}." unless force opoo "#{message}; overwriting." - delete + delete(force: force, command: command, **options) end unless source.exist? - raise CaskError, "It seems the #{self.class.artifact_english_name} source '#{source}' is not there." + raise CaskError, "It seems the #{self.class.english_name} source '#{source}' is not there." end - ohai "Moving #{self.class.artifact_english_name} '#{source.basename}' to '#{target}'." + ohai "Moving #{self.class.english_name} '#{source.basename}' to '#{target}'." target.dirname.mkpath if target.parent.writable? FileUtils.move(source, target) else - SystemCommand.run("/bin/mv", args: [source, target], sudo: true) + command.run("/bin/mv", args: [source, target], sudo: true) end - add_altname_metadata target, source.basename.to_s + add_altname_metadata(target, source.basename, command: command) end - def delete - ohai "Removing #{self.class.artifact_english_name} '#{target}'." - raise CaskError, "Cannot remove undeletable #{self.class.artifact_english_name}." if MacOS.undeletable?(target) + def delete(force: false, command: nil, **_) + ohai "Removing #{self.class.english_name} '#{target}'." + raise CaskError, "Cannot remove undeletable #{self.class.english_name}." if MacOS.undeletable?(target) return unless Utils.path_occupied?(target) if target.parent.writable? && !force target.rmtree else - Utils.gain_permissions_remove(target, command: @command) - end - end - - def summarize_artifact(artifact_spec) - load_specification artifact_spec - - if target.exist? - "#{printable_target} (#{target.abv})" - else - Formatter.error(printable_target, label: "Missing #{self.class.artifact_english_name}") + Utils.gain_permissions_remove(target, command: command) end end end diff --git a/Library/Homebrew/cask/lib/hbc/artifact/nested_container.rb b/Library/Homebrew/cask/lib/hbc/artifact/nested_container.rb index 84253ea308..81adf90290 100644 --- a/Library/Homebrew/cask/lib/hbc/artifact/nested_container.rb +++ b/Library/Homebrew/cask/lib/hbc/artifact/nested_container.rb @@ -1,23 +1,31 @@ -require "hbc/artifact/base" +require "hbc/artifact/abstract_artifact" module Hbc module Artifact - class NestedContainer < Base - def install_phase - @cask.artifacts[:nested_container].each { |container| extract(container) } + class NestedContainer < AbstractArtifact + attr_reader :path + + def initialize(cask, path) + super(cask) + @path = cask.staged_path.join(path) end - def extract(container_relative_path) - source = @cask.staged_path.join(container_relative_path) - container = Container.for_path(source, @command) + def install_phase(**options) + extract(**options) + end + + private + + def extract(command: nil, verbose: nil, **_) + container = Container.for_path(path, command) unless container raise CaskError, "Aw dang, could not identify nested container at '#{source}'" end - ohai "Extracting nested container #{source.basename}" - container.new(@cask, source, @command, verbose: verbose?).extract - FileUtils.remove_entry_secure(source) + ohai "Extracting nested container #{path.relative_path_from(cask.staged_path)}" + container.new(cask, path, command, verbose: verbose).extract + FileUtils.remove_entry_secure(path) end end end diff --git a/Library/Homebrew/cask/lib/hbc/artifact/pkg.rb b/Library/Homebrew/cask/lib/hbc/artifact/pkg.rb index be0a6be717..0967fd99d8 100644 --- a/Library/Homebrew/cask/lib/hbc/artifact/pkg.rb +++ b/Library/Homebrew/cask/lib/hbc/artifact/pkg.rb @@ -1,4 +1,4 @@ -require "hbc/artifact/base" +require "hbc/artifact/abstract_artifact" require "hbc/utils/hash_validator" @@ -6,62 +6,57 @@ require "vendor/plist/plist" module Hbc module Artifact - class Pkg < Base + class Pkg < AbstractArtifact attr_reader :pkg_relative_path - def self.artifact_dsl_key - :pkg + def self.from_args(cask, path, **options) + options.extend(HashValidator).assert_valid_keys(:allow_untrusted, :choices) + new(cask, path, **options) end - def load_pkg_description(pkg_description) - @pkg_relative_path = pkg_description.shift - @pkg_install_opts = pkg_description.shift - begin - if @pkg_install_opts.respond_to?(:keys) - @pkg_install_opts.extend(HashValidator).assert_valid_keys(:allow_untrusted, :choices) - elsif @pkg_install_opts - raise - end - raise if pkg_description.nil? - rescue StandardError - raise CaskInvalidError.new(@cask, "Bad pkg stanza") - end + attr_reader :path, :options + + def initialize(cask, path, **options) + super(cask) + @path = cask.staged_path.join(path) + @options = options end - def pkg_install_opts(opt) - @pkg_install_opts[opt] if @pkg_install_opts.respond_to?(:keys) + def summarize + path.relative_path_from(cask.staged_path).to_s end - def install_phase - @cask.artifacts[:pkg].each { |pkg_description| run_installer(pkg_description) } + def install_phase(**options) + run_installer(**options) end - def run_installer(pkg_description) - load_pkg_description pkg_description - ohai "Running installer for #{@cask}; your password may be necessary." + private + + def run_installer(command: nil, verbose: false, **options) + ohai "Running installer for #{cask}; your password may be necessary." ohai "Package installers may write to any location; options such as --appdir are ignored." - source = @cask.staged_path.join(pkg_relative_path) - unless source.exist? - raise CaskError, "pkg source file not found: '#{source}'" + unless path.exist? + raise CaskError, "pkg source file not found: '#{path.relative_path_from(cask.staged_path)}'" end args = [ - "-pkg", source, + "-pkg", path, "-target", "/" ] - args << "-verboseR" if verbose? - args << "-allowUntrusted" if pkg_install_opts :allow_untrusted + args << "-verboseR" if verbose + args << "-allowUntrusted" if options.fetch(:allow_untrusted, false) with_choices_file do |choices_path| args << "-applyChoiceChangesXML" << choices_path if choices_path - @command.run!("/usr/sbin/installer", sudo: true, args: args, print_stdout: true) + command.run!("/usr/sbin/installer", sudo: true, args: args, print_stdout: true) end end def with_choices_file - return yield nil unless pkg_install_opts(:choices) + choices = options.fetch(:choices, {}) + return yield nil if choices.empty? Tempfile.open(["choices", ".xml"]) do |file| begin - file.write Plist::Emit.dump(pkg_install_opts(:choices)) + file.write Plist::Emit.dump(choices) file.close yield file.path ensure diff --git a/Library/Homebrew/cask/lib/hbc/artifact/prefpane.rb b/Library/Homebrew/cask/lib/hbc/artifact/prefpane.rb index a44f8ae3a3..87f120934d 100644 --- a/Library/Homebrew/cask/lib/hbc/artifact/prefpane.rb +++ b/Library/Homebrew/cask/lib/hbc/artifact/prefpane.rb @@ -3,7 +3,7 @@ require "hbc/artifact/moved" module Hbc module Artifact class Prefpane < Moved - def self.artifact_english_name + def self.english_name "Preference Pane" end end diff --git a/Library/Homebrew/cask/lib/hbc/artifact/qlplugin.rb b/Library/Homebrew/cask/lib/hbc/artifact/qlplugin.rb index ee41de2fe2..298714d894 100644 --- a/Library/Homebrew/cask/lib/hbc/artifact/qlplugin.rb +++ b/Library/Homebrew/cask/lib/hbc/artifact/qlplugin.rb @@ -3,22 +3,24 @@ require "hbc/artifact/moved" module Hbc module Artifact class Qlplugin < Moved - def self.artifact_english_name + def self.english_name "QuickLook Plugin" end - def install_phase - super - reload_quicklook + def install_phase(**options) + super(**options) + reload_quicklook(**options) end - def uninstall_phase - super - reload_quicklook + def uninstall_phase(**options) + super(**options) + reload_quicklook(**options) end - def reload_quicklook - @command.run!("/usr/bin/qlmanage", args: ["-r"]) + private + + def reload_quicklook(command: nil, **_) + command.run!("/usr/bin/qlmanage", args: ["-r"]) end end end diff --git a/Library/Homebrew/cask/lib/hbc/artifact/relocated.rb b/Library/Homebrew/cask/lib/hbc/artifact/relocated.rb index 0e8e42c9be..72a6f6bb56 100644 --- a/Library/Homebrew/cask/lib/hbc/artifact/relocated.rb +++ b/Library/Homebrew/cask/lib/hbc/artifact/relocated.rb @@ -1,33 +1,57 @@ -require "hbc/artifact/base" +require "hbc/artifact/abstract_artifact" require "hbc/utils/hash_validator" module Hbc module Artifact - class Relocated < Base - def summary - { - english_description: self.class.english_description, - contents: @cask.artifacts[self.class.artifact_dsl_key].map(&method(:summarize_artifact)).compact, - } + class Relocated < AbstractArtifact + def self.from_args(cask, *args) + source_string, target_hash = args + + if target_hash + raise CaskInvalidError unless target_hash.respond_to?(:keys) + target_hash.extend(HashValidator).assert_valid_keys(:target) + end + + target_hash ||= {} + + new(cask, source_string, **target_hash) + end + + def self.resolve_target(target) + Hbc.public_send(dirmethod).join(target) end attr_reader :source, :target - def printable_target - target.to_s.sub(/^#{ENV['HOME']}(#{File::SEPARATOR}|$)/, "~/") + def initialize(cask, source, target: nil) + super(cask) + + @source_string = source.to_s + @target_string = target.to_s + source = cask.staged_path.join(source) + @source = source + target ||= source.basename + @target = self.class.resolve_target(target) end + def summarize + target_string = @target_string.empty? ? "" : " -> #{@target_string}" + "#{@source_string}#{target_string}" + end + + private + ALT_NAME_ATTRIBUTE = "com.apple.metadata:kMDItemAlternateNames".freeze # Try to make the asset searchable under the target name. Spotlight # respects this attribute for many filetypes, but ignores it for App # bundles. Alfred 2.2 respects it even for App bundles. - def add_altname_metadata(file, altname) - return if altname.casecmp(file.basename).zero? + def add_altname_metadata(file, altname, command: nil) + return if altname.to_s.casecmp(file.basename.to_s).zero? odebug "Adding #{ALT_NAME_ATTRIBUTE} metadata" - altnames = @command.run("/usr/bin/xattr", - args: ["-p", ALT_NAME_ATTRIBUTE, file.to_s], + altnames = command.run("/usr/bin/xattr", + args: ["-p", ALT_NAME_ATTRIBUTE, file], print_stderr: false).stdout.sub(/\A\((.*)\)\Z/, '\1') odebug "Existing metadata is: '#{altnames}'" altnames.concat(", ") unless altnames.empty? @@ -35,31 +59,15 @@ module Hbc altnames = "(#{altnames})" # Some packages are shipped as u=rx (e.g. Bitcoin Core) - @command.run!("/bin/chmod", args: ["--", "u+rw", file, file.realpath]) + command.run!("/bin/chmod", args: ["--", "u+rw", file, file.realpath]) - @command.run!("/usr/bin/xattr", + command.run!("/usr/bin/xattr", args: ["-w", ALT_NAME_ATTRIBUTE, altnames, file], print_stderr: false) end - def each_artifact - @cask.artifacts[self.class.artifact_dsl_key].each do |artifact| - load_specification(artifact) - yield - end - end - - def load_specification(artifact_spec) - source_string, target_hash = artifact_spec - raise CaskInvalidError if source_string.nil? - @source = @cask.staged_path.join(source_string) - if target_hash - raise CaskInvalidError unless target_hash.respond_to?(:keys) - target_hash.extend(HashValidator).assert_valid_keys(:target) - @target = Hbc.send(self.class.artifact_dirmethod).join(target_hash[:target]) - else - @target = Hbc.send(self.class.artifact_dirmethod).join(source.basename) - end + def printable_target + target.to_s.sub(/^#{ENV['HOME']}(#{File::SEPARATOR}|$)/, "~/") end end end diff --git a/Library/Homebrew/cask/lib/hbc/artifact/stage_only.rb b/Library/Homebrew/cask/lib/hbc/artifact/stage_only.rb index 1122c1d02d..7aef664690 100644 --- a/Library/Homebrew/cask/lib/hbc/artifact/stage_only.rb +++ b/Library/Homebrew/cask/lib/hbc/artifact/stage_only.rb @@ -1,10 +1,18 @@ -require "hbc/artifact/base" +require "hbc/artifact/abstract_artifact" module Hbc module Artifact - class StageOnly < Base - def self.artifact_dsl_key - :stage_only + class StageOnly < AbstractArtifact + def self.from_args(cask, *args) + if args != [true] + raise CaskInvalidError.new(cask.token, "'stage_only' takes only a single argument: true") + end + + new(cask) + end + + def initialize(cask) + super(cask) end end end diff --git a/Library/Homebrew/cask/lib/hbc/artifact/suite.rb b/Library/Homebrew/cask/lib/hbc/artifact/suite.rb index 35251f70c1..59ae58cf13 100644 --- a/Library/Homebrew/cask/lib/hbc/artifact/suite.rb +++ b/Library/Homebrew/cask/lib/hbc/artifact/suite.rb @@ -3,11 +3,11 @@ require "hbc/artifact/moved" module Hbc module Artifact class Suite < Moved - def self.artifact_english_name + def self.english_name "App Suite" end - def self.artifact_dirmethod + def self.dirmethod :appdir end end diff --git a/Library/Homebrew/cask/lib/hbc/artifact/symlinked.rb b/Library/Homebrew/cask/lib/hbc/artifact/symlinked.rb index 16715fe81a..3726ebb5c5 100644 --- a/Library/Homebrew/cask/lib/hbc/artifact/symlinked.rb +++ b/Library/Homebrew/cask/lib/hbc/artifact/symlinked.rb @@ -8,47 +8,18 @@ module Hbc end def self.english_description - "#{artifact_english_name} #{link_type_english_name}s" + "#{english_name} #{link_type_english_name}s" end - def install_phase - each_artifact(&method(:link)) + def install_phase(**options) + link(**options) end - def uninstall_phase - each_artifact(&method(:unlink)) + def uninstall_phase(**options) + unlink(**options) end - private - - def link - unless source.exist? - raise CaskError, "It seems the #{self.class.link_type_english_name.downcase} source '#{source}' is not there." - end - - if target.exist? && !target.symlink? - raise CaskError, "It seems there is already #{self.class.artifact_english_article} #{self.class.artifact_english_name} at '#{target}'; not linking." - end - - ohai "Linking #{self.class.artifact_english_name} '#{source.basename}' to '#{target}'." - create_filesystem_link(source, target) - end - - def unlink - return unless target.symlink? - ohai "Unlinking #{self.class.artifact_english_name} '#{target}'." - target.delete - end - - def create_filesystem_link(source, target) - target.dirname.mkpath - @command.run!("/bin/ln", args: ["-h", "-f", "-s", "--", source, target]) - add_altname_metadata source, target.basename.to_s - end - - def summarize_artifact(artifact_spec) - load_specification artifact_spec - + def summarize_installed if target.symlink? && target.exist? && target.readlink.exist? "#{printable_target} -> #{target.readlink} (#{target.readlink.abv})" else @@ -61,6 +32,33 @@ module Hbc Formatter.error(string, label: "Broken Link") end end + + private + + def link(**options) + unless source.exist? + raise CaskError, "It seems the #{self.class.link_type_english_name.downcase} source '#{source}' is not there." + end + + if target.exist? && !target.symlink? + raise CaskError, "It seems there is already #{self.class.english_article} #{self.class.english_name} at '#{target}'; not linking." + end + + ohai "Linking #{self.class.english_name} '#{source.basename}' to '#{target}'." + create_filesystem_link(**options) + end + + def unlink(**) + return unless target.symlink? + ohai "Unlinking #{self.class.english_name} '#{target}'." + target.delete + end + + def create_filesystem_link(command: nil, **_) + target.dirname.mkpath + command.run!("/bin/ln", args: ["-h", "-f", "-s", "--", source, target]) + add_altname_metadata(source, target.basename, command: command) + end end end end diff --git a/Library/Homebrew/cask/lib/hbc/artifact/uninstall.rb b/Library/Homebrew/cask/lib/hbc/artifact/uninstall.rb index 5a3dc098d9..2bbf82862a 100644 --- a/Library/Homebrew/cask/lib/hbc/artifact/uninstall.rb +++ b/Library/Homebrew/cask/lib/hbc/artifact/uninstall.rb @@ -1,10 +1,10 @@ -require "hbc/artifact/uninstall_base" +require "hbc/artifact/abstract_uninstall" module Hbc module Artifact - class Uninstall < UninstallBase - def uninstall_phase - dispatch_uninstall_directives + class Uninstall < AbstractUninstall + def uninstall_phase(**options) + dispatch_uninstall_directives(**options) end end end diff --git a/Library/Homebrew/cask/lib/hbc/artifact/zap.rb b/Library/Homebrew/cask/lib/hbc/artifact/zap.rb index cdfe2531da..31ff54d201 100644 --- a/Library/Homebrew/cask/lib/hbc/artifact/zap.rb +++ b/Library/Homebrew/cask/lib/hbc/artifact/zap.rb @@ -1,10 +1,10 @@ -require "hbc/artifact/uninstall_base" +require "hbc/artifact/abstract_uninstall" module Hbc module Artifact - class Zap < UninstallBase - def zap_phase - dispatch_uninstall_directives + class Zap < AbstractUninstall + def zap_phase(**options) + dispatch_uninstall_directives(**options) end end end diff --git a/Library/Homebrew/cask/lib/hbc/audit.rb b/Library/Homebrew/cask/lib/hbc/audit.rb index b8bb6ab814..03d8cce826 100644 --- a/Library/Homebrew/cask/lib/hbc/audit.rb +++ b/Library/Homebrew/cask/lib/hbc/audit.rb @@ -214,12 +214,10 @@ module Hbc end def check_generic_artifacts - cask.artifacts[:artifact].each do |source, target_hash| - unless target_hash.is_a?(Hash) && target_hash[:target] - add_error "target required for generic artifact #{source}" - next + cask.artifacts[:artifact].each do |artifact| + unless artifact.target.absolute? + add_error "target must be absolute path for #{artifact.class.english_name} #{artifact.source}" end - add_error "target must be absolute path for generic artifact #{source}" unless Pathname.new(target_hash[:target]).absolute? end end diff --git a/Library/Homebrew/cask/lib/hbc/cask.rb b/Library/Homebrew/cask/lib/hbc/cask.rb index 6d89a997cc..27f8ae791f 100644 --- a/Library/Homebrew/cask/lib/hbc/cask.rb +++ b/Library/Homebrew/cask/lib/hbc/cask.rb @@ -17,7 +17,7 @@ module Hbc @token = token @sourcefile_path = sourcefile_path @tap = tap - @dsl = DSL.new(@token) + @dsl = DSL.new(self) return unless block_given? @dsl.instance_eval(&block) @dsl.language_eval diff --git a/Library/Homebrew/cask/lib/hbc/cli/info.rb b/Library/Homebrew/cask/lib/hbc/cli/info.rb index d26747e176..9cdada62e8 100644 --- a/Library/Homebrew/cask/lib/hbc/cli/info.rb +++ b/Library/Homebrew/cask/lib/hbc/cli/info.rb @@ -69,13 +69,11 @@ module Hbc def self.artifact_info(cask) ohai "Artifacts" - DSL::ORDINARY_ARTIFACT_TYPES.each do |type| - next if cask.artifacts[type].empty? - cask.artifacts[type].each do |artifact| - activatable_item = (type == :stage_only) ? "" : artifact.first - puts "#{activatable_item} (#{type})" - end - end + DSL::ORDINARY_ARTIFACT_CLASSES.flat_map { |klass| klass.for_cask(cask) } + .select { |artifact| artifact.respond_to?(:install_phase) } + .each do |artifact| + puts artifact.to_s + end end end end diff --git a/Library/Homebrew/cask/lib/hbc/cli/internal_stanza.rb b/Library/Homebrew/cask/lib/hbc/cli/internal_stanza.rb index 4515fe9319..2727f95b70 100644 --- a/Library/Homebrew/cask/lib/hbc/cli/internal_stanza.rb +++ b/Library/Homebrew/cask/lib/hbc/cli/internal_stanza.rb @@ -21,34 +21,9 @@ module Hbc # brew cask _stanza artifacts --table --yaml alfred google-chrome adium voicemac logisim vagrant # - # TODO: this should be retrievable from Hbc::DSL - ARTIFACTS = Set.new [ - :app, - :suite, - :artifact, - :prefpane, - :qlplugin, - :dictionary, - :font, - :service, - :colorpicker, - :binary, - :input_method, - :internet_plugin, - :audio_unit_plugin, - :vst_plugin, - :vst3_plugin, - :screen_saver, - :pkg, - :installer, - :stage_only, - :nested_container, - :uninstall, - :preflight, - :postflight, - :uninstall_preflight, - :uninstall_postflight, - ] + ARTIFACTS = + DSL::ORDINARY_ARTIFACT_CLASSES.map(&:dsl_key) + + DSL::ARTIFACT_BLOCK_CLASSES.map(&:dsl_key) option "--table", :table, false option "--quiet", :quiet, false @@ -93,7 +68,7 @@ module Hbc end begin - value = cask.send(@stanza) + value = cask.send(stanza) rescue StandardError opoo "failure calling '#{stanza}' on Cask '#{cask}'" unless quiet? puts "" @@ -108,8 +83,8 @@ module Hbc value = value.fetch(artifact_name).to_a.flatten if artifact_name - if @format - puts value.send(@format) + if format + puts value.send(format) elsif artifact_name || value.is_a?(Symbol) puts value.inspect else diff --git a/Library/Homebrew/cask/lib/hbc/cli/list.rb b/Library/Homebrew/cask/lib/hbc/cli/list.rb index 9d978360eb..4b5fcd8736 100644 --- a/Library/Homebrew/cask/lib/hbc/cli/list.rb +++ b/Library/Homebrew/cask/lib/hbc/cli/list.rb @@ -30,9 +30,9 @@ module Hbc end def self.list_artifacts(cask) - Artifact.for_cask(cask).each do |artifact| - summary = artifact.summary - ohai summary[:english_description], summary[:contents] unless summary.empty? + Artifact.for_cask(cask).group_by(&:class).each do |klass, artifacts| + next unless klass.respond_to?(:english_description) + ohai klass.english_description, artifacts.map(&:summarize_installed) end end diff --git a/Library/Homebrew/cask/lib/hbc/dsl.rb b/Library/Homebrew/cask/lib/hbc/dsl.rb index 8ad206c2f2..2dda476277 100644 --- a/Library/Homebrew/cask/lib/hbc/dsl.rb +++ b/Library/Homebrew/cask/lib/hbc/dsl.rb @@ -1,6 +1,8 @@ require "set" require "locale" +require "hbc/artifact" + require "hbc/dsl/appcast" require "hbc/dsl/base" require "hbc/dsl/caveats" @@ -8,7 +10,6 @@ require "hbc/dsl/conflicts_with" require "hbc/dsl/container" require "hbc/dsl/depends_on" require "hbc/dsl/gpg" -require "hbc/dsl/installer" require "hbc/dsl/postflight" require "hbc/dsl/preflight" require "hbc/dsl/stanza_proxy" @@ -18,39 +19,35 @@ require "hbc/dsl/version" module Hbc class DSL - ORDINARY_ARTIFACT_TYPES = [ - :app, - :artifact, - :audio_unit_plugin, - :binary, - :colorpicker, - :dictionary, - :font, - :input_method, - :internet_plugin, - :pkg, - :prefpane, - :qlplugin, - :screen_saver, - :service, - :stage_only, - :suite, - :vst_plugin, - :vst3_plugin, + ORDINARY_ARTIFACT_CLASSES = [ + Artifact::Installer, + Artifact::App, + Artifact::Artifact, + Artifact::AudioUnitPlugin, + Artifact::Binary, + Artifact::Colorpicker, + Artifact::Dictionary, + Artifact::Font, + Artifact::InputMethod, + Artifact::InternetPlugin, + Artifact::Pkg, + Artifact::Prefpane, + Artifact::Qlplugin, + Artifact::ScreenSaver, + Artifact::Service, + Artifact::StageOnly, + Artifact::Suite, + Artifact::VstPlugin, + Artifact::Vst3Plugin, + Artifact::Uninstall, + Artifact::Zap, ].freeze - ACTIVATABLE_ARTIFACT_TYPES = ([:installer, *ORDINARY_ARTIFACT_TYPES] - [:stage_only]).freeze + ACTIVATABLE_ARTIFACT_TYPES = (ORDINARY_ARTIFACT_CLASSES.map(&:dsl_key) - [:stage_only]).freeze - SPECIAL_ARTIFACT_TYPES = [ - :uninstall, - :zap, - ].freeze - - ARTIFACT_BLOCK_TYPES = [ - :preflight, - :postflight, - :uninstall_preflight, - :uninstall_postflight, + ARTIFACT_BLOCK_CLASSES = [ + Artifact::PreflightBlock, + Artifact::PostflightBlock, ].freeze DSL_METHODS = Set.new [ @@ -72,15 +69,15 @@ module Hbc :url, :version, :appdir, - *ORDINARY_ARTIFACT_TYPES, + *ORDINARY_ARTIFACT_CLASSES.map(&:dsl_key), *ACTIVATABLE_ARTIFACT_TYPES, - *SPECIAL_ARTIFACT_TYPES, - *ARTIFACT_BLOCK_TYPES, + *ARTIFACT_BLOCK_CLASSES.flat_map { |klass| [klass.dsl_key, klass.uninstall_dsl_key] }, ].freeze - attr_reader :token - def initialize(token) - @token = token + attr_reader :token, :cask + def initialize(cask) + @cask = cask + @token = cask.token end def name(*args) @@ -93,12 +90,14 @@ module Hbc return instance_variable_get("@#{stanza}") if should_return if instance_variable_defined?("@#{stanza}") - raise CaskInvalidError.new(token, "'#{stanza}' stanza may only appear once") + raise CaskInvalidError.new(cask, "'#{stanza}' stanza may only appear once.") end instance_variable_set("@#{stanza}", yield) + rescue CaskInvalidError + raise rescue StandardError => e - raise CaskInvalidError.new(token, "'#{stanza}' stanza failed with: #{e}") + raise CaskInvalidError.new(cask, "'#{stanza}' stanza failed with: #{e}") end def homepage(homepage = nil) @@ -113,7 +112,7 @@ module Hbc return unless default unless @language_blocks.default.nil? - raise CaskInvalidError.new(token, "Only one default language may be defined") + raise CaskInvalidError.new(cask, "Only one default language may be defined.") end @language_blocks.default = block @@ -163,7 +162,7 @@ module Hbc DSL::Container.new(*args).tap do |container| # TODO: remove this backward-compatibility section after removing nested_container if container && container.nested - artifacts[:nested_container] << container.nested + artifacts[:nested_container] << Artifact::NestedContainer.new(cask, container.nested) end end end @@ -173,7 +172,7 @@ module Hbc def version(arg = nil) set_unique_stanza(:version, arg.nil?) do if !arg.is_a?(String) && arg != :latest - raise CaskInvalidError.new(token, "invalid 'version' value: '#{arg.inspect}'") + raise CaskInvalidError.new(cask, "invalid 'version' value: '#{arg.inspect}'") end DSL::Version.new(arg) end @@ -182,7 +181,7 @@ module Hbc def sha256(arg = nil) set_unique_stanza(:sha256, arg.nil?) do if !arg.is_a?(String) && arg != :no_check - raise CaskInvalidError.new(token, "invalid 'sha256' value: '#{arg.inspect}'") + raise CaskInvalidError.new(cask, "invalid 'sha256' value: '#{arg.inspect}'") end arg end @@ -195,7 +194,7 @@ module Hbc begin @depends_on.load(*args) rescue RuntimeError => e - raise CaskInvalidError.new(token, e) + raise CaskInvalidError.new(cask, e) end @depends_on end @@ -237,39 +236,29 @@ module Hbc set_unique_stanza(:auto_updates, auto_updates.nil?) { auto_updates } end - ORDINARY_ARTIFACT_TYPES.each do |type| + ORDINARY_ARTIFACT_CLASSES.each do |klass| + type = klass.dsl_key + define_method(type) do |*args| - if type == :stage_only - if args != [true] - raise CaskInvalidError.new(token, "'stage_only' takes a single argument: true") + begin + if [*artifacts.keys, type].include?(:stage_only) && (artifacts.keys & ACTIVATABLE_ARTIFACT_TYPES).any? + raise CaskInvalidError.new(cask, "'stage_only' must be the only activatable artifact.") end - unless (artifacts.keys & ACTIVATABLE_ARTIFACT_TYPES).empty? - raise CaskInvalidError.new(token, "'stage_only' must be the only activatable artifact") - end + artifacts[type].add(klass.from_args(cask, *args)) + rescue CaskInvalidError + raise + rescue StandardError => e + raise CaskInvalidError.new(cask, "invalid '#{klass.dsl_key}' stanza: #{e}") end - - artifacts[type].add(args) end end - def installer(*args) - return artifacts[:installer] if args.empty? - artifacts[:installer] << DSL::Installer.new(*args) - raise "'stage_only' must be the only activatable artifact" if artifacts.key?(:stage_only) - rescue StandardError => e - raise CaskInvalidError.new(token, e) - end - - SPECIAL_ARTIFACT_TYPES.each do |type| - define_method(type) do |*args| - artifacts[type].merge(args) - end - end - - ARTIFACT_BLOCK_TYPES.each do |type| - define_method(type) do |&block| - artifacts[type] << block + ARTIFACT_BLOCK_CLASSES.each do |klass| + [klass.dsl_key, klass.uninstall_dsl_key].each do |dsl_key| + define_method(dsl_key) do |&block| + artifacts[dsl_key] << block + end end end diff --git a/Library/Homebrew/cask/lib/hbc/dsl/installer.rb b/Library/Homebrew/cask/lib/hbc/dsl/installer.rb deleted file mode 100644 index b01b28d762..0000000000 --- a/Library/Homebrew/cask/lib/hbc/dsl/installer.rb +++ /dev/null @@ -1,32 +0,0 @@ -module Hbc - class DSL - class Installer - VALID_KEYS = Set.new [ - :manual, - :script, - ] - - attr_accessor(*VALID_KEYS) - - def initialize(*parameters) - raise CaskInvalidError.new(token, "'installer' stanza requires an argument") if parameters.empty? - parameters = {}.merge(*parameters) - if parameters.key?(:script) && !parameters[:script].respond_to?(:key?) - if parameters.key?(:executable) - raise CaskInvalidError.new(token, "'installer' stanza gave arguments for both :script and :executable") - end - parameters[:executable] = parameters[:script] - parameters.delete(:script) - parameters = { script: parameters } - end - unless parameters.keys.length == 1 - raise "invalid 'installer' stanza: only one of #{VALID_KEYS.inspect} is permitted" - end - key = parameters.keys.first - raise "invalid 'installer' stanza key: '#{key.inspect}'" unless VALID_KEYS.include?(key) - writer_method = "#{key}=".to_sym - send(writer_method, parameters[key]) - end - end - end -end diff --git a/Library/Homebrew/cask/lib/hbc/installer.rb b/Library/Homebrew/cask/lib/hbc/installer.rb index 37cc4e5612..b9c34e3a1d 100644 --- a/Library/Homebrew/cask/lib/hbc/installer.rb +++ b/Library/Homebrew/cask/lib/hbc/installer.rb @@ -177,7 +177,7 @@ module Hbc already_installed_artifacts = [] odebug "Installing artifacts" - artifacts = Artifact.for_cask(@cask, command: @command, verbose: verbose?, force: force?) + artifacts = Artifact.for_cask(@cask) odebug "#{artifacts.length} artifact/s defined", artifacts artifacts.each do |artifact| @@ -188,7 +188,7 @@ module Hbc next unless binaries? end - artifact.install_phase + artifact.install_phase(command: @command, verbose: verbose?, force: force?) already_installed_artifacts.unshift(artifact) end rescue StandardError => e @@ -196,7 +196,7 @@ module Hbc already_installed_artifacts.each do |artifact| next unless artifact.respond_to?(:uninstall_phase) odebug "Reverting installation of artifact of class #{artifact.class}" - artifact.uninstall_phase + artifact.uninstall_phase(command: @command, verbose: verbose?, force: force?) end ensure purge_versioned_files @@ -374,25 +374,27 @@ module Hbc def uninstall_artifacts odebug "Un-installing artifacts" - artifacts = Artifact.for_cask(@cask, command: @command, verbose: verbose?, force: force?) + artifacts = Artifact.for_cask(@cask) odebug "#{artifacts.length} artifact/s defined", artifacts artifacts.each do |artifact| next unless artifact.respond_to?(:uninstall_phase) odebug "Un-installing artifact of class #{artifact.class}" - artifact.uninstall_phase + artifact.uninstall_phase(command: @command, verbose: verbose?, force: force?) end end def zap ohai %Q(Implied "brew cask uninstall #{@cask}") uninstall_artifacts - if Artifact::Zap.me?(@cask) - ohai "Dispatching zap stanza" - Artifact::Zap.new(@cask, command: @command).zap_phase - else + if (zap_stanzas = Artifact::Zap.for_cask(@cask)).empty? opoo "No zap stanza present for Cask '#{@cask}'" + else + ohai "Dispatching zap stanza" + zap_stanzas.each do |stanza| + stanza.zap_phase(command: @command, verbose: verbose?, force: force?) + end end ohai "Removing all staged versions of Cask '#{@cask}'" purge_caskroom_path diff --git a/Library/Homebrew/cask/lib/hbc/staged.rb b/Library/Homebrew/cask/lib/hbc/staged.rb index c1aa01b295..dc21279dee 100644 --- a/Library/Homebrew/cask/lib/hbc/staged.rb +++ b/Library/Homebrew/cask/lib/hbc/staged.rb @@ -4,7 +4,7 @@ module Hbc index = 0 if index == :first index = 1 if index == :second index = -1 if index == :last - Hbc.appdir.join(@cask.artifacts[:app].to_a.at(index).first, "Contents", "Info.plist") + @cask.artifacts[:app].to_a.at(index).target.join("Contents", "Info.plist") end def plist_exec(cmd) diff --git a/Library/Homebrew/test/cask/artifact/alt_target_spec.rb b/Library/Homebrew/test/cask/artifact/alt_target_spec.rb index 9e8d83bb4a..02be796edc 100644 --- a/Library/Homebrew/test/cask/artifact/alt_target_spec.rb +++ b/Library/Homebrew/test/cask/artifact/alt_target_spec.rb @@ -3,7 +3,7 @@ describe Hbc::Artifact::App, :cask do let(:cask) { Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/with-alt-target.rb") } let(:install_phase) { - -> { Hbc::Artifact::App.new(cask).install_phase } + -> { described_class.for_cask(cask).each { |artifact| artifact.install_phase(command: Hbc::NeverSudoSystemCommand, force: false) } } } let(:source_path) { cask.staged_path.join("Caffeine.app") } diff --git a/Library/Homebrew/test/cask/artifact/app_spec.rb b/Library/Homebrew/test/cask/artifact/app_spec.rb index 0add472e21..f67ffd31b5 100644 --- a/Library/Homebrew/test/cask/artifact/app_spec.rb +++ b/Library/Homebrew/test/cask/artifact/app_spec.rb @@ -2,13 +2,13 @@ describe Hbc::Artifact::App, :cask do let(:cask) { Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/local-caffeine.rb") } let(:command) { Hbc::SystemCommand } let(:force) { false } - let(:app) { Hbc::Artifact::App.new(cask, command: command, force: force) } + let(:app) { described_class.for_cask(cask).first } let(:source_path) { cask.staged_path.join("Caffeine.app") } let(:target_path) { Hbc.appdir.join("Caffeine.app") } - let(:install_phase) { app.install_phase } - let(:uninstall_phase) { app.uninstall_phase } + let(:install_phase) { app.install_phase(command: command, force: force) } + let(:uninstall_phase) { app.uninstall_phase(command: command, force: force) } before(:each) do InstallHelper.install_without_artifacts(cask) @@ -105,8 +105,8 @@ describe Hbc::Artifact::App, :cask do describe "target is user-owned but contains read-only files" do before(:each) do - system "/usr/bin/touch", "--", "#{target_path}/foo" - system "/bin/chmod", "--", "0555", target_path + FileUtils.touch "#{target_path}/foo" + FileUtils.chmod 0555, target_path end it "overwrites the existing app" do @@ -138,7 +138,7 @@ describe Hbc::Artifact::App, :cask do end after(:each) do - system "/bin/chmod", "--", "0755", target_path + FileUtils.chmod 0755, target_path end end end @@ -206,8 +206,8 @@ describe Hbc::Artifact::App, :cask do end describe "summary" do - let(:description) { app.summary[:english_description] } - let(:contents) { app.summary[:contents] } + let(:description) { app.class.english_description } + let(:contents) { app.summarize_installed } it "returns the correct english_description" do expect(description).to eq("Apps") @@ -217,14 +217,13 @@ describe Hbc::Artifact::App, :cask do it "returns the path to the app" do install_phase - expect(contents).to eq(["#{target_path} (#{target_path.abv})"]) + expect(contents).to eq("#{target_path} (#{target_path.abv})") end end describe "app is missing" do it "returns a warning and the supposed path to the app" do - expect(contents.size).to eq(1) - expect(contents[0]).to match(/.*Missing App.*: #{target_path}/) + expect(contents).to match(/.*Missing App.*: #{target_path}/) end end end diff --git a/Library/Homebrew/test/cask/artifact/binary_spec.rb b/Library/Homebrew/test/cask/artifact/binary_spec.rb index ce00e39357..5ffaca861f 100644 --- a/Library/Homebrew/test/cask/artifact/binary_spec.rb +++ b/Library/Homebrew/test/cask/artifact/binary_spec.rb @@ -26,7 +26,8 @@ describe Hbc::Artifact::Binary, :cask do end it "links the binary to the proper directory" do - Hbc::Artifact::Binary.new(cask).install_phase + described_class.for_cask(cask) + .each { |artifact| artifact.install_phase(command: Hbc::NeverSudoSystemCommand, force: false) } expect(expected_path).to be_a_symlink expect(expected_path.readlink).to exist @@ -45,7 +46,8 @@ describe Hbc::Artifact::Binary, :cask do expect(FileUtils).to receive(:chmod) .with("+x", cask.staged_path.join("naked_non_executable")).and_call_original - Hbc::Artifact::Binary.new(cask).install_phase + described_class.for_cask(cask) + .each { |artifact| artifact.install_phase(command: Hbc::NeverSudoSystemCommand, force: false) } expect(expected_path).to be_a_symlink expect(expected_path.readlink).to be_executable @@ -56,7 +58,8 @@ describe Hbc::Artifact::Binary, :cask do FileUtils.touch expected_path expect { - Hbc::Artifact::Binary.new(cask).install_phase + described_class.for_cask(cask) + .each { |artifact| artifact.install_phase(command: Hbc::NeverSudoSystemCommand, force: false) } }.to raise_error(Hbc::CaskError) expect(expected_path).not_to be :symlink? @@ -65,7 +68,8 @@ describe Hbc::Artifact::Binary, :cask do it "clobbers an existing symlink" do expected_path.make_symlink("/tmp") - Hbc::Artifact::Binary.new(cask).install_phase + described_class.for_cask(cask) + .each { |artifact| artifact.install_phase(command: Hbc::NeverSudoSystemCommand, force: false) } expect(File.readlink(expected_path)).not_to eq("/tmp") end @@ -73,7 +77,8 @@ describe Hbc::Artifact::Binary, :cask do it "creates parent directory if it doesn't exist" do FileUtils.rmdir Hbc.binarydir - Hbc::Artifact::Binary.new(cask).install_phase + described_class.for_cask(cask) + .each { |artifact| artifact.install_phase(command: Hbc::NeverSudoSystemCommand, force: false) } expect(expected_path.exist?).to be true end @@ -86,8 +91,10 @@ describe Hbc::Artifact::Binary, :cask do } it "links the binary to the proper directory" do - Hbc::Artifact::App.new(cask).install_phase - Hbc::Artifact::Binary.new(cask).install_phase + Hbc::Artifact::App.for_cask(cask) + .each { |artifact| artifact.install_phase(command: Hbc::NeverSudoSystemCommand, force: false) } + described_class.for_cask(cask) + .each { |artifact| artifact.install_phase(command: Hbc::NeverSudoSystemCommand, force: false) } expect(expected_path).to be_a_symlink expect(expected_path.readlink).to exist diff --git a/Library/Homebrew/test/cask/artifact/generic_artifact_spec.rb b/Library/Homebrew/test/cask/artifact/generic_artifact_spec.rb index cb2ef9850d..bec8c27428 100644 --- a/Library/Homebrew/test/cask/artifact/generic_artifact_spec.rb +++ b/Library/Homebrew/test/cask/artifact/generic_artifact_spec.rb @@ -2,7 +2,7 @@ describe Hbc::Artifact::Artifact, :cask do let(:cask) { Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/with-generic-artifact.rb") } let(:install_phase) { - -> { Hbc::Artifact::Artifact.new(cask).install_phase } + -> { described_class.for_cask(cask).each { |artifact| artifact.install_phase(command: Hbc::NeverSudoSystemCommand, force: false) } } } let(:source_path) { cask.staged_path.join("Caffeine.app") } @@ -12,11 +12,11 @@ describe Hbc::Artifact::Artifact, :cask do InstallHelper.install_without_artifacts(cask) end - describe "with no target" do - let(:cask) { Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/with-generic-artifact-no-target.rb") } - - it "fails to install with no target" do - expect(install_phase).to raise_error(Hbc::CaskInvalidError) + context "without target" do + it "fails to load" do + expect { + Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/with-generic-artifact-no-target.rb") + }.to raise_error(Hbc::CaskInvalidError, /target required for Generic Artifact/) end end diff --git a/Library/Homebrew/test/cask/artifact/nested_container_spec.rb b/Library/Homebrew/test/cask/artifact/nested_container_spec.rb index be7ba5ff87..41d143764b 100644 --- a/Library/Homebrew/test/cask/artifact/nested_container_spec.rb +++ b/Library/Homebrew/test/cask/artifact/nested_container_spec.rb @@ -5,7 +5,8 @@ describe Hbc::Artifact::NestedContainer, :cask do InstallHelper.install_without_artifacts(c) end - Hbc::Artifact::NestedContainer.new(cask).install_phase + described_class.for_cask(cask) + .each { |artifact| artifact.install_phase(command: Hbc::NeverSudoSystemCommand, force: false) } expect(cask.staged_path.join("MyNestedApp.app")).to be_a_directory end diff --git a/Library/Homebrew/test/cask/artifact/pkg_spec.rb b/Library/Homebrew/test/cask/artifact/pkg_spec.rb index 3e62616ea2..c6a45c49ab 100644 --- a/Library/Homebrew/test/cask/artifact/pkg_spec.rb +++ b/Library/Homebrew/test/cask/artifact/pkg_spec.rb @@ -8,7 +8,7 @@ describe Hbc::Artifact::Pkg, :cask do describe "install_phase" do it "runs the system installer on the specified pkgs" do - pkg = Hbc::Artifact::Pkg.new(cask, command: fake_system_command) + pkg = described_class.for_cask(cask).first expect(fake_system_command).to receive(:run!).with( "/usr/sbin/installer", @@ -17,7 +17,7 @@ describe Hbc::Artifact::Pkg, :cask do print_stdout: true, ) - pkg.install_phase + pkg.install_phase(command: fake_system_command) end end @@ -25,7 +25,7 @@ describe Hbc::Artifact::Pkg, :cask do let(:cask) { Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/with-choices.rb") } it "passes the choice changes xml to the system installer" do - pkg = Hbc::Artifact::Pkg.new(cask, command: fake_system_command) + pkg = described_class.for_cask(cask).first file = double(path: Pathname.new("/tmp/choices.xml")) @@ -57,7 +57,7 @@ describe Hbc::Artifact::Pkg, :cask do print_stdout: true, ) - pkg.install_phase + pkg.install_phase(command: fake_system_command) end end end diff --git a/Library/Homebrew/test/cask/artifact/postflight_block_spec.rb b/Library/Homebrew/test/cask/artifact/postflight_block_spec.rb index 51b1431f03..4a44bb59be 100644 --- a/Library/Homebrew/test/cask/artifact/postflight_block_spec.rb +++ b/Library/Homebrew/test/cask/artifact/postflight_block_spec.rb @@ -11,7 +11,8 @@ describe Hbc::Artifact::PostflightBlock, :cask do end end - described_class.new(cask).install_phase + described_class.for_cask(cask) + .each { |artifact| artifact.install_phase(command: Hbc::NeverSudoSystemCommand, force: false) } expect(called).to be true expect(yielded_arg).to be_kind_of(Hbc::DSL::Postflight) @@ -30,7 +31,8 @@ describe Hbc::Artifact::PostflightBlock, :cask do end end - described_class.new(cask).uninstall_phase + described_class.for_cask(cask) + .each { |artifact| artifact.uninstall_phase(command: Hbc::NeverSudoSystemCommand, force: false) } expect(called).to be true expect(yielded_arg).to be_kind_of(Hbc::DSL::UninstallPostflight) diff --git a/Library/Homebrew/test/cask/artifact/preflight_block_spec.rb b/Library/Homebrew/test/cask/artifact/preflight_block_spec.rb index b13c4ab9d3..d7d4e72d93 100644 --- a/Library/Homebrew/test/cask/artifact/preflight_block_spec.rb +++ b/Library/Homebrew/test/cask/artifact/preflight_block_spec.rb @@ -11,7 +11,8 @@ describe Hbc::Artifact::PreflightBlock, :cask do end end - described_class.new(cask).install_phase + described_class.for_cask(cask) + .each { |artifact| artifact.install_phase(command: Hbc::NeverSudoSystemCommand, force: false) } expect(called).to be true expect(yielded_arg).to be_kind_of Hbc::DSL::Preflight @@ -30,7 +31,8 @@ describe Hbc::Artifact::PreflightBlock, :cask do end end - described_class.new(cask).uninstall_phase + described_class.for_cask(cask) + .each { |artifact| artifact.uninstall_phase(command: Hbc::NeverSudoSystemCommand, force: false) } expect(called).to be true expect(yielded_arg).to be_kind_of Hbc::DSL::UninstallPreflight diff --git a/Library/Homebrew/test/cask/artifact/suite_spec.rb b/Library/Homebrew/test/cask/artifact/suite_spec.rb index 8c217a9e0c..2f913fecc7 100644 --- a/Library/Homebrew/test/cask/artifact/suite_spec.rb +++ b/Library/Homebrew/test/cask/artifact/suite_spec.rb @@ -1,7 +1,9 @@ describe Hbc::Artifact::Suite, :cask do let(:cask) { Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/with-suite.rb") } - let(:install_phase) { -> { Hbc::Artifact::Suite.new(cask).install_phase } } + let(:install_phase) { + -> { described_class.for_cask(cask).each { |artifact| artifact.install_phase(command: Hbc::NeverSudoSystemCommand, force: false) } } + } let(:target_path) { Hbc.appdir.join("Caffeine") } let(:source_path) { cask.staged_path.join("Caffeine") } diff --git a/Library/Homebrew/test/cask/artifact/two_apps_correct_spec.rb b/Library/Homebrew/test/cask/artifact/two_apps_correct_spec.rb index a1fdd3b74c..f6e0d3c97b 100644 --- a/Library/Homebrew/test/cask/artifact/two_apps_correct_spec.rb +++ b/Library/Homebrew/test/cask/artifact/two_apps_correct_spec.rb @@ -3,7 +3,7 @@ describe Hbc::Artifact::App, :cask do let(:cask) { Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/with-two-apps-correct.rb") } let(:install_phase) { - -> { Hbc::Artifact::App.new(cask).install_phase } + -> { described_class.for_cask(cask).each { |artifact| artifact.install_phase(command: Hbc::NeverSudoSystemCommand, force: false) } } } let(:source_path_mini) { cask.staged_path.join("Caffeine Mini.app") } diff --git a/Library/Homebrew/test/cask/artifact/uninstall_no_zap_spec.rb b/Library/Homebrew/test/cask/artifact/uninstall_no_zap_spec.rb index 8cd0b1e41e..d6a8393dac 100644 --- a/Library/Homebrew/test/cask/artifact/uninstall_no_zap_spec.rb +++ b/Library/Homebrew/test/cask/artifact/uninstall_no_zap_spec.rb @@ -2,7 +2,7 @@ describe Hbc::Artifact::Zap, :cask do let(:cask) { Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/with-installable.rb") } let(:zap_artifact) { - Hbc::Artifact::Zap.new(cask) + described_class.for_cask(cask).first } before(:each) do diff --git a/Library/Homebrew/test/cask/artifact/uninstall_zap_shared_examples.rb b/Library/Homebrew/test/cask/artifact/uninstall_zap_shared_examples.rb index 0e522bc210..06eec4a011 100644 --- a/Library/Homebrew/test/cask/artifact/uninstall_zap_shared_examples.rb +++ b/Library/Homebrew/test/cask/artifact/uninstall_zap_shared_examples.rb @@ -1,12 +1,12 @@ shared_examples "#uninstall_phase or #zap_phase" do - let(:artifact_name) { described_class.artifact_name } - let(:artifact) { described_class.new(cask, command: fake_system_command) } + let(:artifact_dsl_key) { described_class.dsl_key } + let(:artifact) { described_class.for_cask(cask).first } let(:fake_system_command) { Hbc::FakeSystemCommand } - subject { artifact.public_send(:"#{artifact_name}_phase") } + subject { artifact.public_send(:"#{artifact_dsl_key}_phase", command: fake_system_command) } context "using :launchctl" do - let(:cask) { Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/with-#{artifact_name}-launchctl.rb") } + let(:cask) { Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/with-#{artifact_dsl_key}-launchctl.rb") } let(:launchctl_list_cmd) { %w[/bin/launchctl list my.fancy.package.service] } let(:launchctl_remove_cmd) { %w[/bin/launchctl remove my.fancy.package.service] } let(:unknown_response) { "launchctl list returned unknown response\n" } @@ -61,7 +61,7 @@ shared_examples "#uninstall_phase or #zap_phase" do context "using :pkgutil" do let(:fake_system_command) { class_double(Hbc::SystemCommand) } - let(:cask) { Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/with-#{artifact_name}-pkgutil.rb") } + let(:cask) { Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/with-#{artifact_dsl_key}-pkgutil.rb") } let(:main_pkg_id) { "my.fancy.package.main" } let(:agent_pkg_id) { "my.fancy.package.agent" } @@ -85,7 +85,7 @@ shared_examples "#uninstall_phase or #zap_phase" do end context "using :kext" do - let(:cask) { Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/with-#{artifact_name}-kext.rb") } + let(:cask) { Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/with-#{artifact_dsl_key}-kext.rb") } let(:kext_id) { "my.fancy.package.kernelextension" } it "is supported" do @@ -110,7 +110,7 @@ shared_examples "#uninstall_phase or #zap_phase" do end context "using :quit" do - let(:cask) { Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/with-#{artifact_name}-quit.rb") } + let(:cask) { Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/with-#{artifact_dsl_key}-quit.rb") } let(:bundle_id) { "my.fancy.package.app" } let(:quit_application_script) do %Q(tell application id "#{bundle_id}" to quit) @@ -130,7 +130,7 @@ shared_examples "#uninstall_phase or #zap_phase" do end context "using :signal" do - let(:cask) { Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/with-#{artifact_name}-signal.rb") } + let(:cask) { Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/with-#{artifact_dsl_key}-signal.rb") } let(:bundle_id) { "my.fancy.package.app" } let(:signals) { %w[TERM KILL] } let(:unix_pids) { [12_345, 67_890] } @@ -170,10 +170,10 @@ shared_examples "#uninstall_phase or #zap_phase" do end let(:fake_system_command) { Hbc::NeverSudoSystemCommand } - let(:cask) { Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/with-#{artifact_name}-#{directive}.rb") } + let(:cask) { Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/with-#{artifact_dsl_key}-#{directive}.rb") } before(:each) do - allow_any_instance_of(Hbc::Artifact::UninstallBase).to receive(:trash_paths) + allow_any_instance_of(Hbc::Artifact::AbstractUninstall).to receive(:trash_paths) .and_wrap_original do |method, *args| result = method.call(*args) FileUtils.rm_rf result.stdout.split("\0") @@ -196,7 +196,7 @@ shared_examples "#uninstall_phase or #zap_phase" do context "using :rmdir" do let(:fake_system_command) { Hbc::NeverSudoSystemCommand } - let(:cask) { Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/with-#{artifact_name}-rmdir.rb") } + let(:cask) { Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/with-#{artifact_dsl_key}-rmdir.rb") } let(:empty_directory) { Pathname.new("#{TEST_TMPDIR}/empty_directory_path") } let(:ds_store) { empty_directory.join(".DS_Store") } @@ -223,7 +223,7 @@ shared_examples "#uninstall_phase or #zap_phase" do [:script, :early_script].each do |script_type| context "using #{script_type.inspect}" do let(:fake_system_command) { Hbc::NeverSudoSystemCommand } - let(:token) { "with-#{artifact_name}-#{script_type}".tr("_", "-") } + let(:token) { "with-#{artifact_dsl_key}-#{script_type}".tr("_", "-") } let(:cask) { Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/#{token}.rb") } let(:script_pathname) { cask.staged_path.join("MyFancyPkg", "FancyUninstaller.tool") } @@ -250,7 +250,7 @@ shared_examples "#uninstall_phase or #zap_phase" do end context "using :login_item" do - let(:cask) { Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/with-#{artifact_name}-login-item.rb") } + let(:cask) { Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/with-#{artifact_dsl_key}-login-item.rb") } it "is supported" do Hbc::FakeSystemCommand.expects_command( diff --git a/Library/Homebrew/test/cask/audit_spec.rb b/Library/Homebrew/test/cask/audit_spec.rb index ddc773e3e2..7e140acb24 100644 --- a/Library/Homebrew/test/cask/audit_spec.rb +++ b/Library/Homebrew/test/cask/audit_spec.rb @@ -265,19 +265,14 @@ describe Hbc::Audit, :cask do end describe "generic artifact checks" do - context "with no target" do - let(:cask_token) { "generic-artifact-no-target" } - it { is_expected.to fail_with(/target required for generic artifact/) } - end - context "with relative target" do let(:cask_token) { "generic-artifact-relative-target" } - it { is_expected.to fail_with(/target must be absolute path for generic artifact/) } + it { is_expected.to fail_with(/target must be absolute path for Generic Artifact/) } end context "with absolute target" do let(:cask_token) { "generic-artifact-absolute-target" } - it { should_not fail_with(/target required for generic artifact/) } + it { should_not fail_with(/target required for Generic Artifact/) } end end diff --git a/Library/Homebrew/test/cask/cli/info_spec.rb b/Library/Homebrew/test/cask/cli/info_spec.rb index bffe900ec4..aec7080dea 100644 --- a/Library/Homebrew/test/cask/cli/info_spec.rb +++ b/Library/Homebrew/test/cask/cli/info_spec.rb @@ -10,7 +10,7 @@ describe Hbc::CLI::Info, :cask do ==> Name None ==> Artifacts - Caffeine.app (app) + Caffeine.app (App) EOS end @@ -24,7 +24,7 @@ describe Hbc::CLI::Info, :cask do ==> Name None ==> Artifacts - Caffeine.app (app) + Caffeine.app (App) local-transmission: 2.61 http://example.com/local-transmission Not installed @@ -32,7 +32,7 @@ describe Hbc::CLI::Info, :cask do ==> Name None ==> Artifacts - Transmission.app (app) + Transmission.app (App) EOS } @@ -60,7 +60,7 @@ describe Hbc::CLI::Info, :cask do ==> Name None ==> Artifacts - Caffeine.app (app) + Caffeine.app (App) ==> Caveats Here are some things you might want to know. @@ -86,7 +86,7 @@ describe Hbc::CLI::Info, :cask do ==> Name None ==> Artifacts - Caffeine.app (app) + Caffeine.app (App) EOS end diff --git a/Library/Homebrew/test/cask/cli/list_spec.rb b/Library/Homebrew/test/cask/cli/list_spec.rb index ecca3035f5..fd6997f412 100644 --- a/Library/Homebrew/test/cask/cli/list_spec.rb +++ b/Library/Homebrew/test/cask/cli/list_spec.rb @@ -48,7 +48,8 @@ describe Hbc::CLI::List, :cask do it "lists the installed files for those Casks" do casks.each(&InstallHelper.method(:install_without_artifacts_with_caskfile)) - Hbc::Artifact::App.new(transmission).install_phase + Hbc::Artifact::App.for_cask(transmission) + .each { |artifact| artifact.install_phase(command: Hbc::NeverSudoSystemCommand, force: false) } expect { Hbc::CLI::List.run("local-transmission", "local-caffeine") diff --git a/Library/Homebrew/test/cask/dsl_spec.rb b/Library/Homebrew/test/cask/dsl_spec.rb index 7f2207a877..aec1e917f3 100644 --- a/Library/Homebrew/test/cask/dsl_spec.rb +++ b/Library/Homebrew/test/cask/dsl_spec.rb @@ -186,12 +186,12 @@ describe Hbc::DSL, :cask do app "Bar.app" end - expect(Array(cask.artifacts[:app])).to eq([["Foo.app"], ["Bar.app"]]) + expect(cask.artifacts[:app].map(&:to_s)).to eq(["Foo.app (App)", "Bar.app (App)"]) end it "allow app stanzas to be empty" do cask = Hbc::Cask.new("cask-with-no-apps") - expect(Array(cask.artifacts[:app])).to eq([]) + expect(cask.artifacts[:app]).to be_empty end end @@ -219,7 +219,7 @@ describe Hbc::DSL, :cask do pkg "Bar.pkg" end - expect(Array(cask.artifacts[:pkg])).to eq([["Foo.pkg"], ["Bar.pkg"]]) + expect(cask.artifacts[:pkg].map(&:to_s)).to eq(["Foo.pkg (Pkg)", "Bar.pkg (Pkg)"]) end end @@ -471,10 +471,10 @@ describe Hbc::DSL, :cask do let(:token) { "with-installer-script" } it "allows installer script to be specified" do - expect(cask.artifacts[:installer].first.script[:executable]).to eq("/usr/bin/true") - expect(cask.artifacts[:installer].first.script[:args]).to eq(["--flag"]) - expect(cask.artifacts[:installer].to_a[1].script[:executable]).to eq("/usr/bin/false") - expect(cask.artifacts[:installer].to_a[1].script[:args]).to eq(["--flag"]) + expect(cask.artifacts[:installer].first.path).to eq(Pathname("/usr/bin/true")) + expect(cask.artifacts[:installer].first.args[:args]).to eq(["--flag"]) + expect(cask.artifacts[:installer].to_a[1].path).to eq(Pathname("/usr/bin/false")) + expect(cask.artifacts[:installer].to_a[1].args[:args]).to eq(["--flag"]) end end @@ -482,7 +482,9 @@ describe Hbc::DSL, :cask do let(:token) { "with-installer-manual" } it "allows installer manual to be specified" do - expect(cask.artifacts[:installer].first.manual).to eq("Caffeine.app") + installer = cask.artifacts[:installer].first + expect(installer).to be_a(Hbc::Artifact::Installer::ManualInstaller) + expect(installer.path).to eq(cask.staged_path.join("Caffeine.app")) end end end @@ -492,7 +494,7 @@ describe Hbc::DSL, :cask do let(:token) { "stage-only" } it "allows stage_only stanza to be specified" do - expect(cask.artifacts[:stage_only].first).to eq([true]) + expect(cask.artifacts[:stage_only]).not_to be_empty end end @@ -518,7 +520,7 @@ describe Hbc::DSL, :cask do let(:token) { "appdir-interpolation" } it "is allowed" do - expect(cask.artifacts[:binary].first).to eq(["#{Hbc.appdir}/some/path"]) + expect(cask.artifacts[:binary].first.source).to eq(Hbc.appdir/"some/path") end end @@ -531,7 +533,7 @@ describe Hbc::DSL, :cask do binary "#{appdir}/some/path" end - expect(cask.artifacts[:binary].first).to eq(["#{original_appdir}/some/path"]) + expect(cask.artifacts[:binary].first.source).to eq(original_appdir/"some/path") ensure Hbc.appdir = original_appdir end From b0c98ba6319e0e53cc0a262dd08bbb339d4bd7b5 Mon Sep 17 00:00:00 2001 From: Markus Reiter Date: Fri, 4 Aug 2017 14:59:18 +0200 Subject: [PATCH 185/294] Fix `_stanza`. --- .../lib/hbc/artifact/abstract_uninstall.rb | 4 +++ .../cask/lib/hbc/artifact/installer.rb | 6 ++++ .../cask/lib/hbc/artifact/relocated.rb | 6 ++++ .../cask/lib/hbc/artifact/stage_only.rb | 4 +++ .../cask/lib/hbc/cli/internal_stanza.rb | 31 +++++++++++++------ .../Homebrew/test/cask/conflicts_with_spec.rb | 2 +- 6 files changed, 43 insertions(+), 10 deletions(-) diff --git a/Library/Homebrew/cask/lib/hbc/artifact/abstract_uninstall.rb b/Library/Homebrew/cask/lib/hbc/artifact/abstract_uninstall.rb index 9499d5c03f..2ce4f399dd 100644 --- a/Library/Homebrew/cask/lib/hbc/artifact/abstract_uninstall.rb +++ b/Library/Homebrew/cask/lib/hbc/artifact/abstract_uninstall.rb @@ -31,6 +31,10 @@ module Hbc @directives = directives end + def to_h + directives.to_h + end + private def dispatch_uninstall_directives(**options) diff --git a/Library/Homebrew/cask/lib/hbc/artifact/installer.rb b/Library/Homebrew/cask/lib/hbc/artifact/installer.rb index 64ce2d4bc5..588bcabd54 100644 --- a/Library/Homebrew/cask/lib/hbc/artifact/installer.rb +++ b/Library/Homebrew/cask/lib/hbc/artifact/installer.rb @@ -73,6 +73,12 @@ module Hbc def summarize path.relative_path_from(cask.staged_path).to_s end + + def to_h + { path: path.relative_path_from(cask.staged_path).to_s }.tap do |h| + h[:args] = args unless is_a?(ManualInstaller) + end + end end end end diff --git a/Library/Homebrew/cask/lib/hbc/artifact/relocated.rb b/Library/Homebrew/cask/lib/hbc/artifact/relocated.rb index 72a6f6bb56..540699630e 100644 --- a/Library/Homebrew/cask/lib/hbc/artifact/relocated.rb +++ b/Library/Homebrew/cask/lib/hbc/artifact/relocated.rb @@ -35,6 +35,12 @@ module Hbc @target = self.class.resolve_target(target) end + def to_a + [@source_string].tap do |ary| + ary << { target: @target_string } unless @target_string.empty? + end + end + def summarize target_string = @target_string.empty? ? "" : " -> #{@target_string}" "#{@source_string}#{target_string}" diff --git a/Library/Homebrew/cask/lib/hbc/artifact/stage_only.rb b/Library/Homebrew/cask/lib/hbc/artifact/stage_only.rb index 7aef664690..8c32a52d08 100644 --- a/Library/Homebrew/cask/lib/hbc/artifact/stage_only.rb +++ b/Library/Homebrew/cask/lib/hbc/artifact/stage_only.rb @@ -14,6 +14,10 @@ module Hbc def initialize(cask) super(cask) end + + def to_a + [true] + end end end end diff --git a/Library/Homebrew/cask/lib/hbc/cli/internal_stanza.rb b/Library/Homebrew/cask/lib/hbc/cli/internal_stanza.rb index 2727f95b70..018b4e9cae 100644 --- a/Library/Homebrew/cask/lib/hbc/cli/internal_stanza.rb +++ b/Library/Homebrew/cask/lib/hbc/cli/internal_stanza.rb @@ -3,7 +3,7 @@ module Hbc class InternalStanza < AbstractInternalCommand # Syntax # - # brew cask _stanza [ --table | --yaml | --inspect | --quiet ] [ ... ] + # brew cask _stanza [ --quiet ] [ --table | --yaml ] [ ... ] # # If no tokens are given, then data for all Casks is returned. # @@ -14,11 +14,11 @@ module Hbc # Examples # # brew cask _stanza appcast --table - # brew cask _stanza app --table alfred google-chrome adium voicemac logisim vagrant - # brew cask _stanza url --table alfred google-chrome adium voicemac logisim vagrant - # brew cask _stanza version --table alfred google-chrome adium voicemac logisim vagrant - # brew cask _stanza artifacts --table --inspect alfred google-chrome adium voicemac logisim vagrant - # brew cask _stanza artifacts --table --yaml alfred google-chrome adium voicemac logisim vagrant + # brew cask _stanza app --table alfred google-chrome adium vagrant + # brew cask _stanza url --table alfred google-chrome adium vagrant + # brew cask _stanza version --table alfred google-chrome adium vagrant + # brew cask _stanza artifacts --table alfred google-chrome adium vagrant + # brew cask _stanza artifacts --table --yaml alfred google-chrome adium vagrant # ARTIFACTS = @@ -43,7 +43,6 @@ module Hbc @stanza = args.shift.to_sym @format = :to_yaml if yaml? - @format = :inspect if inspect? end def run @@ -81,11 +80,25 @@ module Hbc next end - value = value.fetch(artifact_name).to_a.flatten if artifact_name + if stanza == :artifacts + value = Hash[ + value.map do |k, v| + v = v.map do |a| + next a.to_a if a.respond_to?(:to_a) + next a.to_h if a.respond_to?(:to_h) + a + end + + [k, v] + end + ] + + value = value.fetch(artifact_name) if artifact_name + end if format puts value.send(format) - elsif artifact_name || value.is_a?(Symbol) + elsif value.is_a?(Symbol) puts value.inspect else puts value.to_s diff --git a/Library/Homebrew/test/cask/conflicts_with_spec.rb b/Library/Homebrew/test/cask/conflicts_with_spec.rb index 0dc51cb2d7..00dc252fe4 100644 --- a/Library/Homebrew/test/cask/conflicts_with_spec.rb +++ b/Library/Homebrew/test/cask/conflicts_with_spec.rb @@ -8,7 +8,7 @@ describe "conflicts_with", :cask do Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/with-conflicts-with.rb") } - it "installs the dependency of a Cask and the Cask itself", :focus do + it "installs the dependency of a Cask and the Cask itself" do Hbc::Installer.new(local_caffeine).install expect(local_caffeine).to be_installed From ef67b77d95c6cad9e1ba027189a44876119d1739 Mon Sep 17 00:00:00 2001 From: Markus Reiter Date: Mon, 11 Sep 2017 08:37:15 +0200 Subject: [PATCH 186/294] Make Cask commands fail early if a Cask is not found. --- Library/Homebrew/cask/lib/hbc/cask_loader.rb | 17 +++++++ .../cask/lib/hbc/cli/abstract_command.rb | 47 ++++++++----------- Library/Homebrew/cask/lib/hbc/cli/cat.rb | 4 -- Library/Homebrew/cask/lib/hbc/cli/edit.rb | 19 ++++---- Library/Homebrew/cask/lib/hbc/cli/fetch.rb | 4 -- Library/Homebrew/cask/lib/hbc/cli/install.rb | 4 -- .../hbc/cli/internal_appcast_checkpoint.rb | 26 ++++------ .../cask/lib/hbc/cli/internal_dump.rb | 4 -- .../cask/lib/hbc/cli/internal_stanza.rb | 6 --- Library/Homebrew/cask/lib/hbc/cli/list.rb | 5 +- .../Homebrew/cask/lib/hbc/cli/reinstall.rb | 2 +- .../Homebrew/cask/lib/hbc/cli/uninstall.rb | 4 -- Library/Homebrew/cask/lib/hbc/cli/zap.rb | 4 -- Library/Homebrew/test/cask/cli/audit_spec.rb | 4 +- Library/Homebrew/test/cask/cli/cat_spec.rb | 3 +- Library/Homebrew/test/cask/cli/create_spec.rb | 2 +- Library/Homebrew/test/cask/cli/edit_spec.rb | 2 +- Library/Homebrew/test/cask/cli/fetch_spec.rb | 2 +- .../Homebrew/test/cask/cli/install_spec.rb | 18 ++----- .../Homebrew/test/cask/cli/uninstall_spec.rb | 9 ++-- Library/Homebrew/test/cask/cli/zap_spec.rb | 3 +- 21 files changed, 72 insertions(+), 117 deletions(-) diff --git a/Library/Homebrew/cask/lib/hbc/cask_loader.rb b/Library/Homebrew/cask/lib/hbc/cask_loader.rb index dd9c610899..532d9f3c3c 100644 --- a/Library/Homebrew/cask/lib/hbc/cask_loader.rb +++ b/Library/Homebrew/cask/lib/hbc/cask_loader.rb @@ -116,6 +116,22 @@ module Hbc end end + class FromInstanceLoader + attr_reader :cask + + def self.can_load?(ref) + ref.is_a?(Cask) + end + + def initialize(cask) + @cask = cask + end + + def load + cask + end + end + class NullLoader < FromPathLoader def self.can_load?(*) true @@ -149,6 +165,7 @@ module Hbc def self.for(ref) [ + FromInstanceLoader, FromURILoader, FromTapLoader, FromTapPathLoader, diff --git a/Library/Homebrew/cask/lib/hbc/cli/abstract_command.rb b/Library/Homebrew/cask/lib/hbc/cli/abstract_command.rb index 77f85301eb..001a9623b2 100644 --- a/Library/Homebrew/cask/lib/hbc/cli/abstract_command.rb +++ b/Library/Homebrew/cask/lib/hbc/cli/abstract_command.rb @@ -42,41 +42,32 @@ module Hbc @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 - + return @casks if defined?(@casks) casks = args.empty? ? alternative.call : args + @casks = casks.map { |cask| CaskLoader.load(cask) } + rescue CaskUnavailableError => e + reason = [e.reason, suggestion_message(e.token)].join(" ") + raise e.class.new(e.token, reason) + end - 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 + def suggestion_message(cask_token) + exact_match, partial_matches = Search.search(cask_token) + + if exact_match.nil? && partial_matches.count == 1 + exact_match = partial_matches.first end - return :empty if casks.length.zero? - (count == casks.length) ? :complete : :incomplete + if exact_match + "Did you mean “#{exact_match}”?" + elsif !partial_matches.empty? + "Did you mean one of these?\n" + .concat(Formatter.columns(partial_matches.take(20))) + else + "" + end end end end diff --git a/Library/Homebrew/cask/lib/hbc/cli/cat.rb b/Library/Homebrew/cask/lib/hbc/cli/cat.rb index d08c87bea2..0430805561 100644 --- a/Library/Homebrew/cask/lib/hbc/cli/cat.rb +++ b/Library/Homebrew/cask/lib/hbc/cli/cat.rb @@ -7,10 +7,6 @@ module Hbc end def run - raise CaskError, "Cat incomplete." if cat_casks == :incomplete - end - - def cat_casks casks.each do |cask| puts File.open(cask.sourcefile_path, &:read) end diff --git a/Library/Homebrew/cask/lib/hbc/cli/edit.rb b/Library/Homebrew/cask/lib/hbc/cli/edit.rb index b9485886c9..8bce81c523 100644 --- a/Library/Homebrew/cask/lib/hbc/cli/edit.rb +++ b/Library/Homebrew/cask/lib/hbc/cli/edit.rb @@ -4,21 +4,18 @@ module Hbc def initialize(*) super raise CaskUnspecifiedError if args.empty? - raise ArgumentError, "Only one Cask can be created at a time." if args.count > 1 + raise ArgumentError, "Only one Cask can be edited at a time." if args.count > 1 end def run - cask_token = args.first - 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}" + cask = casks.first + cask_path = cask.sourcefile_path + odebug "Opening editor for Cask #{cask.token}" exec_editor cask_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 def self.help diff --git a/Library/Homebrew/cask/lib/hbc/cli/fetch.rb b/Library/Homebrew/cask/lib/hbc/cli/fetch.rb index e31b1a17c1..12c794f5f6 100644 --- a/Library/Homebrew/cask/lib/hbc/cli/fetch.rb +++ b/Library/Homebrew/cask/lib/hbc/cli/fetch.rb @@ -9,10 +9,6 @@ module Hbc end def run - 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 diff --git a/Library/Homebrew/cask/lib/hbc/cli/install.rb b/Library/Homebrew/cask/lib/hbc/cli/install.rb index 0f1a5dd34c..9a2116e6ac 100644 --- a/Library/Homebrew/cask/lib/hbc/cli/install.rb +++ b/Library/Homebrew/cask/lib/hbc/cli/install.rb @@ -10,10 +10,6 @@ module Hbc end def run - raise CaskError, "Install incomplete." if install_casks == :incomplete - end - - def install_casks casks.each do |cask| begin Installer.new(cask, binaries: binaries?, diff --git a/Library/Homebrew/cask/lib/hbc/cli/internal_appcast_checkpoint.rb b/Library/Homebrew/cask/lib/hbc/cli/internal_appcast_checkpoint.rb index cd26797821..56f6d3c737 100644 --- a/Library/Homebrew/cask/lib/hbc/cli/internal_appcast_checkpoint.rb +++ b/Library/Homebrew/cask/lib/hbc/cli/internal_appcast_checkpoint.rb @@ -12,7 +12,7 @@ module Hbc if args.all? { |t| t =~ %r{^https?://} && t !~ /\.rb$/ } self.class.appcask_checkpoint_for_url(args) else - self.class.appcask_checkpoint(args, calculate?) + self.class.appcask_checkpoint(load_casks, calculate?) end end @@ -23,33 +23,27 @@ module Hbc end end - def self.appcask_checkpoint(cask_tokens, calculate) - count = 0 - - cask_tokens.each do |cask_token| - cask = CaskLoader.load(cask_token) - + def self.appcask_checkpoint(casks, calculate) + casks.each do |cask| if cask.appcast.nil? opoo "Cask '#{cask}' is missing an `appcast` stanza." else - if calculate + checkpoint = if calculate result = cask.appcast.calculate_checkpoint - - checkpoint = result[:checkpoint] + result[:checkpoint] else - checkpoint = cask.appcast.checkpoint + cask.appcast.checkpoint end - if checkpoint.nil? + if calculate && checkpoint.nil? onoe "Could not retrieve `appcast` checkpoint for cask '#{cask}': #{result[:command_result].stderr}" + elsif casks.count > 1 + puts "#{checkpoint} #{cask}" else - puts((cask_tokens.count > 1) ? "#{checkpoint} #{cask}" : checkpoint) - count += 1 + puts checkpoint end end end - - count == cask_tokens.count 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 46273cbe3e..8a38ce1bed 100644 --- a/Library/Homebrew/cask/lib/hbc/cli/internal_dump.rb +++ b/Library/Homebrew/cask/lib/hbc/cli/internal_dump.rb @@ -7,10 +7,6 @@ module Hbc end def run - raise CaskError, "Dump incomplete." if dump_casks == :incomplete - end - - def dump_casks casks.each(&:dumpcask) end diff --git a/Library/Homebrew/cask/lib/hbc/cli/internal_stanza.rb b/Library/Homebrew/cask/lib/hbc/cli/internal_stanza.rb index 018b4e9cae..c046197989 100644 --- a/Library/Homebrew/cask/lib/hbc/cli/internal_stanza.rb +++ b/Library/Homebrew/cask/lib/hbc/cli/internal_stanza.rb @@ -46,12 +46,6 @@ module Hbc end def run - return unless print_stanzas == :incomplete - exit 1 if quiet? - raise CaskError, "Print incomplete." - end - - def print_stanzas if ARTIFACTS.include?(stanza) artifact_name = stanza @stanza = :artifacts diff --git a/Library/Homebrew/cask/lib/hbc/cli/list.rb b/Library/Homebrew/cask/lib/hbc/cli/list.rb index 4b5fcd8736..faa1160a19 100644 --- a/Library/Homebrew/cask/lib/hbc/cli/list.rb +++ b/Library/Homebrew/cask/lib/hbc/cli/list.rb @@ -10,8 +10,7 @@ module Hbc end) def run - retval = args.any? ? list : list_installed - raise CaskError, "Listing incomplete." if retval == :incomplete + args.any? ? list : list_installed end def list @@ -46,8 +45,6 @@ module Hbc elsif !installed_casks.empty? puts Formatter.columns(installed_casks.map(&:to_s)) end - - installed_casks.empty? ? :empty : :complete end def self.format_versioned(cask) diff --git a/Library/Homebrew/cask/lib/hbc/cli/reinstall.rb b/Library/Homebrew/cask/lib/hbc/cli/reinstall.rb index 337a2eb9d6..408be134da 100644 --- a/Library/Homebrew/cask/lib/hbc/cli/reinstall.rb +++ b/Library/Homebrew/cask/lib/hbc/cli/reinstall.rb @@ -1,7 +1,7 @@ module Hbc class CLI class Reinstall < Install - def install_casks + def run casks.each do |cask| Installer.new(cask, binaries: binaries?, verbose: verbose?, diff --git a/Library/Homebrew/cask/lib/hbc/cli/uninstall.rb b/Library/Homebrew/cask/lib/hbc/cli/uninstall.rb index c0697c8080..7e55db5f18 100644 --- a/Library/Homebrew/cask/lib/hbc/cli/uninstall.rb +++ b/Library/Homebrew/cask/lib/hbc/cli/uninstall.rb @@ -9,10 +9,6 @@ module Hbc end def run - raise CaskError, "Uninstall incomplete." if uninstall_casks == :incomplete - end - - def uninstall_casks casks.each do |cask| odebug "Uninstalling Cask #{cask}" diff --git a/Library/Homebrew/cask/lib/hbc/cli/zap.rb b/Library/Homebrew/cask/lib/hbc/cli/zap.rb index e709f41914..7f5e6785dc 100644 --- a/Library/Homebrew/cask/lib/hbc/cli/zap.rb +++ b/Library/Homebrew/cask/lib/hbc/cli/zap.rb @@ -9,10 +9,6 @@ module Hbc end def run - 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?, force: force?).zap diff --git a/Library/Homebrew/test/cask/cli/audit_spec.rb b/Library/Homebrew/test/cask/cli/audit_spec.rb index 01f506c8c4..30ab437cbf 100644 --- a/Library/Homebrew/test/cask/cli/audit_spec.rb +++ b/Library/Homebrew/test/cask/cli/audit_spec.rb @@ -1,8 +1,10 @@ describe Hbc::CLI::Audit, :cask do - let(:cask) { double("cask", token: nil) } + let(:cask) { Hbc::Cask.new(nil) } describe "selection of Casks to audit" do it "audits all Casks if no tokens are given" do + expect(cask).to be_a Hbc::Cask + allow(Hbc).to receive(:all).and_return([cask, cask]) expect(Hbc::Auditor).to receive(:audit).twice.and_return(true) diff --git a/Library/Homebrew/test/cask/cli/cat_spec.rb b/Library/Homebrew/test/cask/cli/cat_spec.rb index b726a0b366..5a4b29c6f5 100644 --- a/Library/Homebrew/test/cask/cli/cat_spec.rb +++ b/Library/Homebrew/test/cask/cli/cat_spec.rb @@ -35,8 +35,7 @@ describe Hbc::CLI::Cat, :cask do it "raises an exception when the Cask does not exist" do expect { Hbc::CLI::Cat.run("notacask") } - .to output(/is unavailable/).to_stderr - .and raise_error(Hbc::CaskError, "Cat incomplete.") + .to raise_error(Hbc::CaskUnavailableError, /is unavailable/) end describe "when no Cask is specified" do diff --git a/Library/Homebrew/test/cask/cli/create_spec.rb b/Library/Homebrew/test/cask/cli/create_spec.rb index d77b0a2aac..17d426f78c 100644 --- a/Library/Homebrew/test/cask/cli/create_spec.rb +++ b/Library/Homebrew/test/cask/cli/create_spec.rb @@ -39,7 +39,7 @@ describe Hbc::CLI::Create, :cask do it "raises an exception when more than one Cask is given" do expect { described_class.run("additional-cask", "another-cask") - }.to raise_error(/Only one Cask can be created at a time./) + }.to raise_error(/Only one Cask can be created at a time\./) end it "raises an exception when the Cask already exists" do diff --git a/Library/Homebrew/test/cask/cli/edit_spec.rb b/Library/Homebrew/test/cask/cli/edit_spec.rb index 5d5cbf4b93..51542807f9 100644 --- a/Library/Homebrew/test/cask/cli/edit_spec.rb +++ b/Library/Homebrew/test/cask/cli/edit_spec.rb @@ -12,7 +12,7 @@ describe Hbc::CLI::Edit, :cask do it "raises an error when given more than one argument" do expect { described_class.new("local-caffeine", "local-transmission") - }.to raise_error(/Only one Cask can be created at a time./) + }.to raise_error(/Only one Cask can be edited at a time\./) end it "raises an exception when the Cask doesnt exist" do diff --git a/Library/Homebrew/test/cask/cli/fetch_spec.rb b/Library/Homebrew/test/cask/cli/fetch_spec.rb index f71c23fb67..faaa69b35b 100644 --- a/Library/Homebrew/test/cask/cli/fetch_spec.rb +++ b/Library/Homebrew/test/cask/cli/fetch_spec.rb @@ -42,7 +42,7 @@ describe Hbc::CLI::Fetch, :cask do it "properly handles Casks that are not present" do expect { Hbc::CLI::Fetch.run("notacask") - }.to raise_error(Hbc::CaskError, "Fetch incomplete.") + }.to raise_error(Hbc::CaskUnavailableError) 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 64feacce91..e30489789e 100644 --- a/Library/Homebrew/test/cask/cli/install_spec.rb +++ b/Library/Homebrew/test/cask/cli/install_spec.rb @@ -56,27 +56,19 @@ describe Hbc::CLI::Install, :cask do it "properly handles Casks that are not present" do expect { Hbc::CLI::Install.run("notacask") - }.to raise_error(Hbc::CaskError, "Install incomplete.") + }.to raise_error(Hbc::CaskUnavailableError) end it "returns a suggestion for a misspelled Cask" do expect { - begin - Hbc::CLI::Install.run("localcaffeine") - rescue Hbc::CaskError - nil - end - }.to output(/Cask 'localcaffeine' is unavailable: No Cask with this name exists\. Did you mean:\nlocal-caffeine/).to_stderr + Hbc::CLI::Install.run("localcaffeine") + }.to raise_error(Hbc::CaskUnavailableError, /Cask 'localcaffeine' is unavailable: No Cask with this name exists\. Did you mean “local-caffeine”?/) end it "returns multiple suggestions for a Cask fragment" do expect { - begin - Hbc::CLI::Install.run("local-caf") - rescue Hbc::CaskError - nil - end - }.to output(/Cask 'local-caf' is unavailable: No Cask with this name exists\. Did you mean one of:\nlocal-caffeine/).to_stderr + Hbc::CLI::Install.run("local") + }.to raise_error(Hbc::CaskUnavailableError, /Cask 'local' is unavailable: No Cask with this name exists\. Did you mean one of these\?\nlocal-caffeine\nlocal-transmission/) end describe "when no Cask is specified" do diff --git a/Library/Homebrew/test/cask/cli/uninstall_spec.rb b/Library/Homebrew/test/cask/cli/uninstall_spec.rb index 1a1c57e88b..2ec506839b 100644 --- a/Library/Homebrew/test/cask/cli/uninstall_spec.rb +++ b/Library/Homebrew/test/cask/cli/uninstall_spec.rb @@ -16,14 +16,12 @@ describe Hbc::CLI::Uninstall, :cask do it "shows an error when a bad Cask is provided" do expect { Hbc::CLI::Uninstall.run("notacask") } - .to output(/is unavailable/).to_stderr - .and raise_error(Hbc::CaskError, "Uninstall incomplete.") + .to raise_error(Hbc::CaskUnavailableError, /is unavailable/) end it "shows an error when a Cask is provided that's not installed" do expect { Hbc::CLI::Uninstall.run("local-caffeine") } - .to output(/is not installed/).to_stderr - .and raise_error(Hbc::CaskError, "Uninstall incomplete.") + .to raise_error(Hbc::CaskNotInstalledError, /is not installed/) end it "tries anyway on a non-present Cask when --force is given" do @@ -76,8 +74,7 @@ describe Hbc::CLI::Uninstall, :cask do Hbc.appdir.join("MyFancyApp.app").rmtree expect { Hbc::CLI::Uninstall.run("with-uninstall-script-app") } - .to output(/does not exist/).to_stderr - .and raise_error(Hbc::CaskError, "Uninstall incomplete.") + .to raise_error(Hbc::CaskError, /uninstall script .* does not exist/) 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 fdc5b41250..502bf8e697 100644 --- a/Library/Homebrew/test/cask/cli/zap_spec.rb +++ b/Library/Homebrew/test/cask/cli/zap_spec.rb @@ -1,8 +1,7 @@ describe Hbc::CLI::Zap, :cask do it "shows an error when a bad Cask is provided" do expect { Hbc::CLI::Zap.run("notacask") } - .to output(/is unavailable/).to_stderr - .and raise_error(Hbc::CaskError, "Zap incomplete.") + .to raise_error(Hbc::CaskUnavailableError, /is unavailable/) end it "can zap and unlink multiple Casks at once" do From ae27cd7f79dfce8bc4806d9786ec6bbbf1846a3a Mon Sep 17 00:00:00 2001 From: Markus Reiter Date: Mon, 11 Sep 2017 09:09:05 +0200 Subject: [PATCH 187/294] Always load Cask in `brew irb`. --- Library/Homebrew/cmd/irb.rb | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/Library/Homebrew/cmd/irb.rb b/Library/Homebrew/cmd/irb.rb index cba8a5b82b..4cd3d4c9ec 100644 --- a/Library/Homebrew/cmd/irb.rb +++ b/Library/Homebrew/cmd/irb.rb @@ -19,15 +19,13 @@ class String end end -def cask - $LOAD_PATH.unshift("#{HOMEBREW_LIBRARY_PATH}/cask/lib") - require "hbc" -end - module Homebrew module_function def irb + $LOAD_PATH.unshift("#{HOMEBREW_LIBRARY_PATH}/cask/lib") + require "hbc" + if ARGV.include? "--examples" puts "'v8'.f # => instance of the v8 formula" puts ":hub.f.installed?" From 6c962c2a5b67554e57e06ddf6838f092b8626efa Mon Sep 17 00:00:00 2001 From: Maxim Belkin Date: Tue, 29 Aug 2017 11:04:00 -0500 Subject: [PATCH 188/294] linkage_checker: check for extraneous dependencies --- Library/Homebrew/os/mac/linkage_checker.rb | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/Library/Homebrew/os/mac/linkage_checker.rb b/Library/Homebrew/os/mac/linkage_checker.rb index 7868278523..ded3a5ff3c 100644 --- a/Library/Homebrew/os/mac/linkage_checker.rb +++ b/Library/Homebrew/os/mac/linkage_checker.rb @@ -5,7 +5,7 @@ require "formula" class LinkageChecker attr_reader :keg, :formula attr_reader :brewed_dylibs, :system_dylibs, :broken_dylibs, :variable_dylibs - attr_reader :undeclared_deps, :reverse_links + attr_reader :undeclared_deps, :extraneous_deps, :reverse_links def initialize(keg, formula = nil) @keg = keg @@ -16,6 +16,7 @@ class LinkageChecker @variable_dylibs = Set.new @undeclared_deps = [] @reverse_links = Hash.new { |h, k| h[k] = Set.new } + @extraneous_deps = [] check_dylibs end @@ -51,7 +52,7 @@ class LinkageChecker end end - @undeclared_deps = check_undeclared_deps if formula + @undeclared_deps, @extraneous_deps = check_undeclared_deps if formula end def check_undeclared_deps @@ -77,6 +78,11 @@ class LinkageChecker a <=> b end end + extraneous_deps = declared_dep_names.reject do |full_name| + name = full_name.split("/").last + @brewed_dylibs.keys.map{ |x| x.split("/").last }.include? name + end + return undeclared_deps, extraneous_deps end def display_normal_output @@ -85,6 +91,7 @@ class LinkageChecker display_items "Variable-referenced libraries", @variable_dylibs display_items "Missing libraries", @broken_dylibs display_items "Possible undeclared dependencies", @undeclared_deps + display_items "Possible extraneous dependencies", @extraneous_deps end def display_reverse_output @@ -113,6 +120,10 @@ class LinkageChecker !@undeclared_deps.empty? end + def extraneous_deps? + !@extraneous_deps.empty? + end + private # Whether or not dylib is a harmless broken link, meaning that it's From 0037d5e2b383a0c3b0272c9481cd9020397d1fc2 Mon Sep 17 00:00:00 2001 From: Maxim Belkin Date: Tue, 29 Aug 2017 11:26:02 -0500 Subject: [PATCH 189/294] linkage_checker: fix style --- Library/Homebrew/os/mac/linkage_checker.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Library/Homebrew/os/mac/linkage_checker.rb b/Library/Homebrew/os/mac/linkage_checker.rb index ded3a5ff3c..95a48b1957 100644 --- a/Library/Homebrew/os/mac/linkage_checker.rb +++ b/Library/Homebrew/os/mac/linkage_checker.rb @@ -79,10 +79,10 @@ class LinkageChecker end end extraneous_deps = declared_dep_names.reject do |full_name| - name = full_name.split("/").last - @brewed_dylibs.keys.map{ |x| x.split("/").last }.include? name + name = full_name.split("/").last + @brewed_dylibs.keys.map { |x| x.split("/").last }.include? name end - return undeclared_deps, extraneous_deps + [undeclared_deps, extraneous_deps] end def display_normal_output From 049a453b460a5580991e5ca0f8c77fcd1f86eea1 Mon Sep 17 00:00:00 2001 From: Maxim Belkin Date: Tue, 29 Aug 2017 12:41:27 -0500 Subject: [PATCH 190/294] linkage_checker: avoid some false positives --- Library/Homebrew/os/mac/linkage_checker.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Library/Homebrew/os/mac/linkage_checker.rb b/Library/Homebrew/os/mac/linkage_checker.rb index 95a48b1957..11d8ab5674 100644 --- a/Library/Homebrew/os/mac/linkage_checker.rb +++ b/Library/Homebrew/os/mac/linkage_checker.rb @@ -80,7 +80,7 @@ class LinkageChecker end extraneous_deps = declared_dep_names.reject do |full_name| name = full_name.split("/").last - @brewed_dylibs.keys.map { |x| x.split("/").last }.include? name + Formula[name].bin.directory? || @brewed_dylibs.keys.map { |x| x.split("/").last }.include?(name) end [undeclared_deps, extraneous_deps] end From f2531d129069a1ffc0d8a273a5aeb8871eb4530c Mon Sep 17 00:00:00 2001 From: Maxim Belkin Date: Tue, 5 Sep 2017 15:59:26 -0500 Subject: [PATCH 191/294] linkage_checker: unnecessary dependencies - rename 'extraneous' to 'unnecessary' - add the report under `linkage --test` --- Library/Homebrew/os/mac/linkage_checker.rb | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/Library/Homebrew/os/mac/linkage_checker.rb b/Library/Homebrew/os/mac/linkage_checker.rb index 11d8ab5674..2e8256ce4a 100644 --- a/Library/Homebrew/os/mac/linkage_checker.rb +++ b/Library/Homebrew/os/mac/linkage_checker.rb @@ -5,7 +5,7 @@ require "formula" class LinkageChecker attr_reader :keg, :formula attr_reader :brewed_dylibs, :system_dylibs, :broken_dylibs, :variable_dylibs - attr_reader :undeclared_deps, :extraneous_deps, :reverse_links + attr_reader :undeclared_deps, :unnecessary_deps, :reverse_links def initialize(keg, formula = nil) @keg = keg @@ -16,7 +16,7 @@ class LinkageChecker @variable_dylibs = Set.new @undeclared_deps = [] @reverse_links = Hash.new { |h, k| h[k] = Set.new } - @extraneous_deps = [] + @unnecessary_deps = [] check_dylibs end @@ -52,7 +52,7 @@ class LinkageChecker end end - @undeclared_deps, @extraneous_deps = check_undeclared_deps if formula + @undeclared_deps, @unnecessary_deps = check_undeclared_deps if formula end def check_undeclared_deps @@ -78,11 +78,12 @@ class LinkageChecker a <=> b end end - extraneous_deps = declared_dep_names.reject do |full_name| + unnecessary_deps = declared_dep_names.reject do |full_name| name = full_name.split("/").last - Formula[name].bin.directory? || @brewed_dylibs.keys.map { |x| x.split("/").last }.include?(name) + next true if Formula[name].bin.directory? + @brewed_dylibs.keys.map { |x| x.split("/").last }.include?(name) end - [undeclared_deps, extraneous_deps] + [undeclared_deps, unnecessary_deps] end def display_normal_output @@ -91,7 +92,7 @@ class LinkageChecker display_items "Variable-referenced libraries", @variable_dylibs display_items "Missing libraries", @broken_dylibs display_items "Possible undeclared dependencies", @undeclared_deps - display_items "Possible extraneous dependencies", @extraneous_deps + display_items "Possible unnecessary dependencies", @unnecessary_deps end def display_reverse_output @@ -109,6 +110,7 @@ class LinkageChecker def display_test_output display_items "Missing libraries", @broken_dylibs + display_items "Possible unnecessary dependencies", @unnecessary_deps puts "No broken dylib links" if @broken_dylibs.empty? end @@ -120,8 +122,8 @@ class LinkageChecker !@undeclared_deps.empty? end - def extraneous_deps? - !@extraneous_deps.empty? + def unnecessary_deps? + !@unnecessary_deps.empty? end private From 76cb1462d45e4be8b37354bfea2187bf23dcf124 Mon Sep 17 00:00:00 2001 From: Markus Reiter Date: Mon, 11 Sep 2017 23:29:38 +0200 Subject: [PATCH 192/294] Fix uninstall with `:signal`. --- .../cask/lib/hbc/artifact/abstract_uninstall.rb | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/Library/Homebrew/cask/lib/hbc/artifact/abstract_uninstall.rb b/Library/Homebrew/cask/lib/hbc/artifact/abstract_uninstall.rb index 2ce4f399dd..badd549ce7 100644 --- a/Library/Homebrew/cask/lib/hbc/artifact/abstract_uninstall.rb +++ b/Library/Homebrew/cask/lib/hbc/artifact/abstract_uninstall.rb @@ -28,6 +28,7 @@ module Hbc def initialize(cask, directives) super(cask) + directives[:signal] = [*directives[:signal]].flatten.each_slice(2).to_a @directives = directives end @@ -35,6 +36,10 @@ module Hbc directives.to_h end + def summarize + to_h.map { |key, val| [*val].map { |v| "#{key.inspect} => #{v.inspect}" }.join(", ") }.join(", ") + end + private def dispatch_uninstall_directives(**options) @@ -122,15 +127,15 @@ module Hbc end # :signal should come after :quit so it can be used as a backup when :quit fails - def uninstall_signal(*signals, **options) - signals.flatten.each_slice(2) do |pair| + def uninstall_signal(*signals, command: nil, **_) + signals.each do |pair| unless pair.size == 2 raise CaskInvalidError.new(cask, "Each #{stanza} :signal must consist of 2 elements.") end signal, bundle_id = pair ohai "Signalling '#{signal}' to application ID '#{bundle_id}'" - pids = running_processes(bundle_id, **options).map(&:first) + pids = running_processes(bundle_id, command: command).map(&:first) next unless pids.any? # Note that unlike :quit, signals are sent from the current user (not # upgraded to the superuser). This is a todo item for the future, but From 57608170b266e625d6112236d048a1603925e8fb Mon Sep 17 00:00:00 2001 From: Markus Reiter Date: Tue, 12 Sep 2017 09:36:07 +0200 Subject: [PATCH 193/294] Fix method name. --- .../Homebrew/cask/lib/hbc/cli/internal_appcast_checkpoint.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Library/Homebrew/cask/lib/hbc/cli/internal_appcast_checkpoint.rb b/Library/Homebrew/cask/lib/hbc/cli/internal_appcast_checkpoint.rb index 56f6d3c737..a538ffd8c3 100644 --- a/Library/Homebrew/cask/lib/hbc/cli/internal_appcast_checkpoint.rb +++ b/Library/Homebrew/cask/lib/hbc/cli/internal_appcast_checkpoint.rb @@ -12,7 +12,7 @@ module Hbc if args.all? { |t| t =~ %r{^https?://} && t !~ /\.rb$/ } self.class.appcask_checkpoint_for_url(args) else - self.class.appcask_checkpoint(load_casks, calculate?) + self.class.appcask_checkpoint(casks, calculate?) end end From 1dfde95cb66416877152e3a1444f8c8be46e7436 Mon Sep 17 00:00:00 2001 From: Dominyk Tiller Date: Wed, 13 Sep 2017 02:34:23 +0100 Subject: [PATCH 194/294] mac/xcode: update expected Clang on 10.13 --- Library/Homebrew/os/mac/xcode.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Library/Homebrew/os/mac/xcode.rb b/Library/Homebrew/os/mac/xcode.rb index 37bc55a2fd..59e7026bdc 100644 --- a/Library/Homebrew/os/mac/xcode.rb +++ b/Library/Homebrew/os/mac/xcode.rb @@ -216,7 +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.35" + when "10.13" then "900.0.37" when "10.12" then "802.0.42" when "10.11" then "800.0.42.1" when "10.10" then "700.1.81" From 03ace9b1104f1ddc2adc75a68531167d7e3ea7e0 Mon Sep 17 00:00:00 2001 From: Mike McQuaid Date: Thu, 14 Sep 2017 19:58:37 +0100 Subject: [PATCH 195/294] Require more HTTP mirrors for old OS X versions. This allows the bootstrap of `curl` and `git` on versions of Mac OS X that cannot reliably download from HTTPS servers any longer. Once these are both installed users are able to update Homebrew and download files securely. Also, as we're doing this, don't point 10.5 users to Tigerbrew as they are already given caveats for using Homebrew itself. --- Library/Homebrew/dev-cmd/audit.rb | 47 +++++++++++++++++++++---------- docs/Installation.md | 2 +- 2 files changed, 33 insertions(+), 16 deletions(-) diff --git a/Library/Homebrew/dev-cmd/audit.rb b/Library/Homebrew/dev-cmd/audit.rb index bec0355671..7832378265 100644 --- a/Library/Homebrew/dev-cmd/audit.rb +++ b/Library/Homebrew/dev-cmd/audit.rb @@ -202,12 +202,12 @@ class FormulaAuditor @specs = %w[stable devel head].map { |s| formula.send(s) }.compact end - def self.check_http_content(url, name, user_agents: [:default], check_content: false, strict: false) + def self.check_http_content(url, user_agents: [:default], check_content: false, strict: false, require_http: false) return unless url.start_with? "http" details = nil user_agent = nil - hash_needed = url.start_with?("http:") && name != "curl" + hash_needed = url.start_with?("http:") && !require_http user_agents.each do |ua| details = http_content_headers_and_checksum(url, hash_needed: hash_needed, user_agent: ua) user_agent = ua @@ -576,7 +576,6 @@ class FormulaAuditor return unless DevelopmentTools.curl_handles_most_https_homepages? if http_content_problem = FormulaAuditor.check_http_content(homepage, - formula.name, user_agents: [:browser, :default], check_content: true, strict: @strict) @@ -629,13 +628,14 @@ class FormulaAuditor end %w[Stable Devel HEAD].each do |name| - next unless spec = formula.send(name.downcase) + spec_name = name.downcase.to_sym + next unless spec = formula.send(spec_name) - ra = ResourceAuditor.new(spec, online: @online, strict: @strict).audit + ra = ResourceAuditor.new(spec, spec_name, online: @online, strict: @strict).audit problems.concat ra.problems.map { |problem| "#{name}: #{problem}" } spec.resources.each_value do |resource| - ra = ResourceAuditor.new(resource, online: @online, strict: @strict).audit + ra = ResourceAuditor.new(resource, spec_name, online: @online, strict: @strict).audit problems.concat ra.problems.map { |problem| "#{name} resource #{resource.name.inspect}: #{problem}" } @@ -1086,10 +1086,10 @@ class FormulaAuditor end class ResourceAuditor - attr_reader :problems - attr_reader :version, :checksum, :using, :specs, :url, :mirrors, :name + attr_reader :name, :version, :checksum, :url, :mirrors, :using, :specs, :owner + attr_reader :spec_name, :problems - def initialize(resource, options = {}) + def initialize(resource, spec_name, options = {}) @name = resource.name @version = resource.version @checksum = resource.checksum @@ -1097,9 +1097,11 @@ class ResourceAuditor @mirrors = resource.mirrors @using = resource.using @specs = resource.specs - @online = options[:online] - @strict = options[:strict] - @problems = [] + @owner = resource.owner + @spec_name = spec_name + @online = options[:online] + @strict = options[:strict] + @problems = [] end def audit @@ -1173,11 +1175,26 @@ class ResourceAuditor problem "Redundant :using value in URL" end + def self.curl_git_openssl_and_deps + @curl_git_openssl_and_deps ||= begin + formulae_names = ["curl", "git", "openssl"] + formulae_names += formulae_names.flat_map do |f| + Formula[f].recursive_dependencies.map(&:name) + end + formulae_names.uniq + rescue FormulaUnavailableError + [] + end + end + def audit_urls urls = [url] + mirrors - if name == "curl" && !urls.find { |u| u.start_with?("http://") } && url != Formula["curl"].head.url - problem "should always include at least one HTTP url" + require_http = ResourceAuditor.curl_git_openssl_and_deps.include?(owner.name) + + if spec_name == :stable && require_http && + !urls.find { |u| u.start_with?("http://") } + problem "should always include at least one HTTP mirror" end return unless @online @@ -1189,7 +1206,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, name) + if http_content_problem = FormulaAuditor.check_http_content(url, name, require_http: require_http) problem http_content_problem end elsif strategy <= GitDownloadStrategy diff --git a/docs/Installation.md b/docs/Installation.md index e36ed3efa2..9f091d2e58 100644 --- a/docs/Installation.md +++ b/docs/Installation.md @@ -47,7 +47,7 @@ PowerPC and Tiger branches from other users in the fork network. See [Interesting Taps and Forks](Interesting-Taps-and-Forks.md). 2 10.10 or higher is recommended. 10.5–10.9 are -supported on a best-effort basis. For 10.4 and 10.5, see +supported on a best-effort basis. For 10.4 see [Tigerbrew](https://github.com/mistydemeo/tigerbrew). 3 Most formulae require a compiler. A handful From e12d2746b65d46f07e3ecc737d07926118dfb278 Mon Sep 17 00:00:00 2001 From: Mike McQuaid Date: Fri, 15 Sep 2017 08:06:58 +0100 Subject: [PATCH 196/294] os/mac/diagnostic: allow custom Ruby for devs. This avoids `brew doctor` warnings on High Sierra but in general this is a good idea for future versions and to allow Homebrew developers to test things out with different versions of Ruby. --- Library/Homebrew/extend/os/mac/diagnostic.rb | 1 + Library/Homebrew/test/os/mac/diagnostic_spec.rb | 11 +++-------- 2 files changed, 4 insertions(+), 8 deletions(-) diff --git a/Library/Homebrew/extend/os/mac/diagnostic.rb b/Library/Homebrew/extend/os/mac/diagnostic.rb index 0cdd7b1156..ab54335650 100644 --- a/Library/Homebrew/extend/os/mac/diagnostic.rb +++ b/Library/Homebrew/extend/os/mac/diagnostic.rb @@ -197,6 +197,7 @@ module Homebrew def check_ruby_version ruby_version = "2.0" return if RUBY_VERSION[/\d\.\d/] == ruby_version + return if ARGV.homebrew_developer? && OS::Mac.prerelease? <<-EOS.undent Ruby version #{RUBY_VERSION} is unsupported on #{MacOS.version}. Homebrew diff --git a/Library/Homebrew/test/os/mac/diagnostic_spec.rb b/Library/Homebrew/test/os/mac/diagnostic_spec.rb index d6186e46bb..83d95c2ef1 100644 --- a/Library/Homebrew/test/os/mac/diagnostic_spec.rb +++ b/Library/Homebrew/test/os/mac/diagnostic_spec.rb @@ -47,15 +47,10 @@ describe Homebrew::Diagnostic::Checks do 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") + allow(MacOS).to receive(:version).and_return(OS::Mac::Version.new("10.12")) + stub_const("RUBY_VERSION", "1.8.6") 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 + .to match "Ruby version 1.8.6 is unsupported on 10.12" end end From 2e43d95498eedd3c61f7c013a0a419c2c0aac098 Mon Sep 17 00:00:00 2001 From: Mike McQuaid Date: Fri, 15 Sep 2017 10:17:40 +0100 Subject: [PATCH 197/294] audit: fix check_http_content args. --- Library/Homebrew/dev-cmd/audit.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Library/Homebrew/dev-cmd/audit.rb b/Library/Homebrew/dev-cmd/audit.rb index 7832378265..4220fce471 100644 --- a/Library/Homebrew/dev-cmd/audit.rb +++ b/Library/Homebrew/dev-cmd/audit.rb @@ -1206,7 +1206,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, name, require_http: require_http) + if http_content_problem = FormulaAuditor.check_http_content(url, require_http: require_http) problem http_content_problem end elsif strategy <= GitDownloadStrategy From e33623982962612fa7d1737477ba6c60700abdf4 Mon Sep 17 00:00:00 2001 From: Markus Reiter Date: Sat, 16 Sep 2017 00:26:15 +0200 Subject: [PATCH 198/294] Add missing `summarize` method. --- .../Homebrew/cask/lib/hbc/artifact/abstract_flight_block.rb | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Library/Homebrew/cask/lib/hbc/artifact/abstract_flight_block.rb b/Library/Homebrew/cask/lib/hbc/artifact/abstract_flight_block.rb index 6670d42499..4e8edbc11c 100644 --- a/Library/Homebrew/cask/lib/hbc/artifact/abstract_flight_block.rb +++ b/Library/Homebrew/cask/lib/hbc/artifact/abstract_flight_block.rb @@ -43,6 +43,10 @@ module Hbc return if (block = directives[dsl_key]).nil? class_for_dsl_key(dsl_key).new(cask).instance_eval(&block) end + + def summarize + directives.keys.map(&:to_s).join(", ") + end end end end From ffdda0eb9f4a2e56366e8c665d147d9be637f6f4 Mon Sep 17 00:00:00 2001 From: Mike McQuaid Date: Sat, 16 Sep 2017 12:41:08 +0100 Subject: [PATCH 199/294] Tweaks for older Mac OS X versions. - `brew update` should try to install `curl` before `git` on older versions of Mac OS X where it is needed for accessing modern SSL certificates. - We don't need an HTTP mirror for `git` because `curl` will already be installed before it is downloaded. - Don't recommend GCC on Mac OS X versions where it can't be built with the default system compiler. - Start using the Homebrew `curl` on Mac OS X versions where it is needed as soon as it is installed. --- Library/Homebrew/brew.sh | 9 +++++++- Library/Homebrew/cmd/update.sh | 6 ++++++ Library/Homebrew/dev-cmd/audit.rb | 21 +++++++++++-------- Library/Homebrew/development_tools.rb | 2 +- .../extend/os/mac/development_tools.rb | 15 ++++++++----- Library/Homebrew/formula_installer.rb | 6 ++++++ 6 files changed, 43 insertions(+), 16 deletions(-) diff --git a/Library/Homebrew/brew.sh b/Library/Homebrew/brew.sh index c40ce8bf72..66908925c8 100644 --- a/Library/Homebrew/brew.sh +++ b/Library/Homebrew/brew.sh @@ -105,7 +105,14 @@ then HOMEBREW_OS_USER_AGENT_VERSION="Mac OS X $HOMEBREW_MACOS_VERSION" printf -v HOMEBREW_MACOS_VERSION_NUMERIC "%02d%02d%02d" ${HOMEBREW_MACOS_VERSION//./ } - if [[ "$HOMEBREW_MACOS_VERSION_NUMERIC" -lt "100900" && + if [[ "$HOMEBREW_MACOS_VERSION_NUMERIC" -lt "101000" ]] + then + HOMEBREW_SYSTEM_CURL_TOO_OLD="1" + fi + + # The system Curl is too old for some modern HTTPS certificates on + # older macOS versions. + if [[ -n "$HOMEBREW_SYSTEM_CURL_TOO_OLD" && -x "$HOMEBREW_PREFIX/opt/curl/bin/curl" ]] then HOMEBREW_CURL="$HOMEBREW_PREFIX/opt/curl/bin/curl" diff --git a/Library/Homebrew/cmd/update.sh b/Library/Homebrew/cmd/update.sh index fb6a3459c1..e8211e4ddf 100644 --- a/Library/Homebrew/cmd/update.sh +++ b/Library/Homebrew/cmd/update.sh @@ -385,6 +385,12 @@ EOS if ! git --version >/dev/null 2>&1 then + # we need a new enough curl to install git + if [[ -n "$HOMEBREW_SYSTEM_CURL_TOO_OLD" && + ! -x "$HOMEBREW_PREFIX/opt/curl/bin/curl" ]] + then + brew install curl + fi # we cannot install brewed git if homebrew/core is unavailable. [[ -d "$HOMEBREW_LIBRARY/Taps/homebrew/homebrew-core" ]] && brew install git unset GIT_EXECUTABLE diff --git a/Library/Homebrew/dev-cmd/audit.rb b/Library/Homebrew/dev-cmd/audit.rb index 4220fce471..e2a288fdb5 100644 --- a/Library/Homebrew/dev-cmd/audit.rb +++ b/Library/Homebrew/dev-cmd/audit.rb @@ -574,7 +574,7 @@ class FormulaAuditor return unless @online - return unless DevelopmentTools.curl_handles_most_https_homepages? + return unless DevelopmentTools.curl_handles_most_https_certificates? if http_content_problem = FormulaAuditor.check_http_content(homepage, user_agents: [:browser, :default], check_content: true, @@ -1175,9 +1175,9 @@ class ResourceAuditor problem "Redundant :using value in URL" end - def self.curl_git_openssl_and_deps - @curl_git_openssl_and_deps ||= begin - formulae_names = ["curl", "git", "openssl"] + def self.curl_openssl_and_deps + @curl_openssl_and_deps ||= begin + formulae_names = ["curl", "openssl"] formulae_names += formulae_names.flat_map do |f| Formula[f].recursive_dependencies.map(&:name) end @@ -1190,11 +1190,14 @@ class ResourceAuditor def audit_urls urls = [url] + mirrors - require_http = ResourceAuditor.curl_git_openssl_and_deps.include?(owner.name) + curl_openssl_or_deps = ResourceAuditor.curl_openssl_and_deps.include?(owner.name) - if spec_name == :stable && require_http && - !urls.find { |u| u.start_with?("http://") } - problem "should always include at least one HTTP mirror" + if spec_name == :stable && curl_openssl_or_deps + problem "should not use xz tarballs" if url.end_with?(".xz") + + unless urls.find { |u| u.start_with?("http://") } + problem "should always include at least one HTTP mirror" + end end return unless @online @@ -1206,7 +1209,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, require_http: require_http) + if http_content_problem = FormulaAuditor.check_http_content(url, require_http: curl_openssl_or_deps) problem http_content_problem end elsif strategy <= GitDownloadStrategy diff --git a/Library/Homebrew/development_tools.rb b/Library/Homebrew/development_tools.rb index 996dea87cc..b7787d8493 100644 --- a/Library/Homebrew/development_tools.rb +++ b/Library/Homebrew/development_tools.rb @@ -114,7 +114,7 @@ class DevelopmentTools @non_apple_gcc_version = {} end - def curl_handles_most_https_homepages? + def curl_handles_most_https_certificates? true end diff --git a/Library/Homebrew/extend/os/mac/development_tools.rb b/Library/Homebrew/extend/os/mac/development_tools.rb index caa85ffca5..66b3bf9d29 100644 --- a/Library/Homebrew/extend/os/mac/development_tools.rb +++ b/Library/Homebrew/extend/os/mac/development_tools.rb @@ -43,11 +43,16 @@ class DevelopmentTools end def custom_installation_instructions - if MacOS.version > :tiger + if MacOS.version > :leopard <<-EOS.undent Install GNU's GCC brew install gcc EOS + elsif MacOS.version > :tiger + <<-EOS.undent + Install GNU's GCC + brew install gcc@4.6 + EOS else # Tiger doesn't ship with apple-gcc42, and this is required to build # some software that doesn't build properly with FSF GCC. @@ -55,7 +60,7 @@ class DevelopmentTools Install Apple's GCC brew install apple-gcc42 or GNU's GCC - brew install gcc + brew install gcc@4.6 EOS end end @@ -77,10 +82,10 @@ class DevelopmentTools end end - def curl_handles_most_https_homepages? - # The system Curl is too old for some modern HTTPS homepages on + def curl_handles_most_https_certificates? + # The system Curl is too old for some modern HTTPS certificates on # older macOS versions. - MacOS.version >= :el_capitan + !ENV["HOMEBREW_SYSTEM_CURL_TOO_OLD"].nil? end def subversion_handles_most_https_certificates? diff --git a/Library/Homebrew/formula_installer.rb b/Library/Homebrew/formula_installer.rb index 216a375ce9..e955dcf074 100644 --- a/Library/Homebrew/formula_installer.rb +++ b/Library/Homebrew/formula_installer.rb @@ -603,6 +603,12 @@ class FormulaInstaller # let's reset Utils.git_available? if we just installed git Utils.clear_git_available_cache if formula.name == "git" + + # use installed curl when it's needed and available + if formula.name == "curl" && + !DevelopmentTools.curl_handles_most_https_certificates? + ENV["HOMEBREW_CURL"] = formula.opt_bin/"curl" + end ensure unlock end From 01f52f54e34ce5368c5df64cbe9784be54107f73 Mon Sep 17 00:00:00 2001 From: ilovezfs Date: Sat, 16 Sep 2017 07:04:26 -0700 Subject: [PATCH 200/294] keg_relocate: treat .lai files as libtool files. Previously .lai files only had their locations replaced with placeholders if /usr/bin/file recognized them as ASCII files, which is only the case on macOS Sierra and above. --- Library/Homebrew/keg_relocate.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Library/Homebrew/keg_relocate.rb b/Library/Homebrew/keg_relocate.rb index ad4c010210..0857486326 100644 --- a/Library/Homebrew/keg_relocate.rb +++ b/Library/Homebrew/keg_relocate.rb @@ -156,7 +156,7 @@ class Keg libtool_files = [] path.find do |pn| - next if pn.symlink? || pn.directory? || pn.extname != ".la" + next if pn.symlink? || pn.directory? || ![".la", ".lai"].include?(pn.extname) libtool_files << pn end libtool_files From acf1b278ae0c27f19e7d20a9d23c005201dc818c Mon Sep 17 00:00:00 2001 From: Dan Wendorf Date: Sat, 8 Jul 2017 19:33:44 -0700 Subject: [PATCH 201/294] List cask full-names `brew cask list` supports the `--full-name` flag which will include the tap name for casks not part of the core caskroom/cask tap. For example, if cask "foo-beta" is installed from the caskroom/versions cask, `brew cask list --full-name` will report the name as "caskroom/versions/foo-beta". --- Library/Homebrew/cask/lib/hbc/cask.rb | 8 +++++ Library/Homebrew/cask/lib/hbc/cli/list.rb | 3 ++ Library/Homebrew/cmd/list.rb | 10 +----- Library/Homebrew/test/cask/cask_spec.rb | 34 +++++++++++++++++++ Library/Homebrew/test/cask/cli/list_spec.rb | 20 +++++++++++ .../third-party/Casks/third-party-cask.rb | 9 +++++ .../spec/shared_context/homebrew_cask.rb | 8 +++++ Library/Homebrew/test/utils_spec.rb | 29 ++++++++++++++++ Library/Homebrew/utils.rb | 12 +++++++ 9 files changed, 124 insertions(+), 9 deletions(-) create mode 100644 Library/Homebrew/test/support/fixtures/third-party/Casks/third-party-cask.rb diff --git a/Library/Homebrew/cask/lib/hbc/cask.rb b/Library/Homebrew/cask/lib/hbc/cask.rb index 27f8ae791f..72a23066f8 100644 --- a/Library/Homebrew/cask/lib/hbc/cask.rb +++ b/Library/Homebrew/cask/lib/hbc/cask.rb @@ -41,6 +41,14 @@ module Hbc .reverse end + def full_name + if @tap.nil? || @tap == Hbc.default_tap + token + else + "#{@tap}/#{token}" + end + end + def installed? !versions.empty? end diff --git a/Library/Homebrew/cask/lib/hbc/cli/list.rb b/Library/Homebrew/cask/lib/hbc/cli/list.rb index faa1160a19..32415af8a5 100644 --- a/Library/Homebrew/cask/lib/hbc/cli/list.rb +++ b/Library/Homebrew/cask/lib/hbc/cli/list.rb @@ -3,6 +3,7 @@ module Hbc class List < AbstractCommand option "-1", :one, false option "--versions", :versions, false + option "--full-name", :full_name, false option "-l", (lambda do |*| one = true # rubocop:disable Lint/UselessAssignment @@ -42,6 +43,8 @@ module Hbc puts installed_casks.map(&:to_s) elsif versions? puts installed_casks.map(&self.class.method(:format_versioned)) + elsif full_name? + puts installed_casks.map(&:full_name).sort &tap_and_name_comparison elsif !installed_casks.empty? puts Formatter.columns(installed_casks.map(&:to_s)) end diff --git a/Library/Homebrew/cmd/list.rb b/Library/Homebrew/cmd/list.rb index f5c4e68acf..436fc1f976 100644 --- a/Library/Homebrew/cmd/list.rb +++ b/Library/Homebrew/cmd/list.rb @@ -39,15 +39,7 @@ module Homebrew filtered_list elsif ARGV.named.empty? if ARGV.include? "--full-name" - full_names = Formula.installed.map(&:full_name).sort do |a, b| - if a.include?("/") && !b.include?("/") - 1 - elsif !a.include?("/") && b.include?("/") - -1 - else - a <=> b - end - end + full_names = Formula.installed.map(&:full_name).sort &tap_and_name_comparison return if full_names.empty? puts Formatter.columns(full_names) else diff --git a/Library/Homebrew/test/cask/cask_spec.rb b/Library/Homebrew/test/cask/cask_spec.rb index a6ecc207f7..5858a7c6db 100644 --- a/Library/Homebrew/test/cask/cask_spec.rb +++ b/Library/Homebrew/test/cask/cask_spec.rb @@ -171,4 +171,38 @@ describe Hbc::Cask, :cask do end end end + + describe "full_name" do + context "when it is a core cask" do + it "is the cask token" do + c = Hbc::CaskLoader.load("local-caffeine") + expect(c.full_name).to eq("local-caffeine") + end + end + + context "when it is from a non-core tap" do + it "returns the fully-qualified name of the cask" do + c = Hbc::CaskLoader.load("third-party/tap/third-party-cask") + expect(c.full_name).to eq("third-party/tap/third-party-cask") + end + end + + context "when it is from no known tap" do + it "retuns the cask token" do + file = Tempfile.new(%w[tapless-cask .rb]) + + begin + cask_name = File.basename(file.path, ".rb") + file.write "cask '#{cask_name}'" + file.close + + c = Hbc::CaskLoader.load(file.path) + expect(c.full_name).to eq(cask_name) + ensure + file.close + file.unlink + end + end + end + end end diff --git a/Library/Homebrew/test/cask/cli/list_spec.rb b/Library/Homebrew/test/cask/cli/list_spec.rb index fd6997f412..d2d7efd3b6 100644 --- a/Library/Homebrew/test/cask/cli/list_spec.rb +++ b/Library/Homebrew/test/cask/cli/list_spec.rb @@ -14,6 +14,26 @@ describe Hbc::CLI::List, :cask do EOS end + it "lists full names" do + casks = %w[ + local-caffeine + third-party/tap/third-party-cask + local-transmission + ].map { |c| Hbc::CaskLoader.load(c) } + + casks.each do |c| + InstallHelper.install_with_caskfile(c) + end + + expect { + Hbc::CLI::List.run("--full-name") + }.to output(<<-EOS.undent).to_stdout + local-caffeine + local-transmission + third-party/tap/third-party-cask + EOS + end + describe "lists versions" do let(:casks) { ["local-caffeine", "local-transmission"] } let(:expected_output) { diff --git a/Library/Homebrew/test/support/fixtures/third-party/Casks/third-party-cask.rb b/Library/Homebrew/test/support/fixtures/third-party/Casks/third-party-cask.rb new file mode 100644 index 0000000000..d7add05229 --- /dev/null +++ b/Library/Homebrew/test/support/fixtures/third-party/Casks/third-party-cask.rb @@ -0,0 +1,9 @@ +cask 'third-party-cask' do + version '1.2.3' + sha256 '8c62a2b791cf5f0da6066a0a4b6e85f62949cd60975da062df44adf887f4370b' + + url 'http://example.com/ThirdParty.dmg' + homepage 'http://example.com/' + + app 'ThirdParty.app' +end diff --git a/Library/Homebrew/test/support/helper/spec/shared_context/homebrew_cask.rb b/Library/Homebrew/test/support/helper/spec/shared_context/homebrew_cask.rb index c51d339a7c..fc83149d01 100644 --- a/Library/Homebrew/test/support/helper/spec/shared_context/homebrew_cask.rb +++ b/Library/Homebrew/test/support/helper/spec/shared_context/homebrew_cask.rb @@ -18,6 +18,7 @@ HOMEBREW_CASK_DIRS = [ RSpec.shared_context "Homebrew-Cask" do around(:each) do |example| + third_party_tap = Tap.fetch("third-party", "tap") begin dirs = HOMEBREW_CASK_DIRS.map do |dir| Pathname.new(TEST_TMPDIR).join("cask-#{dir}").tap do |path| @@ -31,11 +32,18 @@ RSpec.shared_context "Homebrew-Cask" do FileUtils.ln_sf TEST_FIXTURE_DIR.join("cask"), tap.path end + third_party_tap.tap do |tap| + FileUtils.mkdir_p tap.path.dirname + FileUtils.ln_sf TEST_FIXTURE_DIR.join("third-party"), tap.path + end + example.run ensure FileUtils.rm_rf dirs Hbc.default_tap.path.unlink FileUtils.rm_rf Hbc.default_tap.path.parent + third_party_tap.path.unlink + FileUtils.rm_rf third_party_tap.path.parent end end end diff --git a/Library/Homebrew/test/utils_spec.rb b/Library/Homebrew/test/utils_spec.rb index 37bd83c4f3..3b5355b151 100644 --- a/Library/Homebrew/test/utils_spec.rb +++ b/Library/Homebrew/test/utils_spec.rb @@ -296,4 +296,33 @@ describe "globally-scoped helper methods" do expect(ENV["PATH"]).not_to eq("/bin") end end + + describe "#tap_and_name_comparison" do + describe "both strings are only names" do + it "alphabetizes the strings" do + expect(%w[a b].sort(&tap_and_name_comparison)).to eq(%w[a b]) + expect(%w[b a].sort(&tap_and_name_comparison)).to eq(%w[a b]) + end + end + + describe "both strings include tap" do + it "alphabetizes the strings" do + expect(%w[a/z/z b/z/z].sort(&tap_and_name_comparison)).to eq(%w[a/z/z b/z/z]) + expect(%w[b/z/z a/z/z].sort(&tap_and_name_comparison)).to eq(%w[a/z/z b/z/z]) + + expect(%w[z/a/z z/b/z].sort(&tap_and_name_comparison)).to eq(%w[z/a/z z/b/z]) + expect(%w[z/b/z z/a/z].sort(&tap_and_name_comparison)).to eq(%w[z/a/z z/b/z]) + + expect(%w[z/z/a z/z/b].sort(&tap_and_name_comparison)).to eq(%w[z/z/a z/z/b]) + expect(%w[z/z/b z/z/a].sort(&tap_and_name_comparison)).to eq(%w[z/z/a z/z/b]) + end + end + + describe "only one string includes tap" do + it "prefers the string without tap" do + expect(%w[a/z/z z].sort(&tap_and_name_comparison)).to eq(%w[z a/z/z]) + expect(%w[z a/z/z].sort(&tap_and_name_comparison)).to eq(%w[z a/z/z]) + end + end + end end diff --git a/Library/Homebrew/utils.rb b/Library/Homebrew/utils.rb index 07e339576f..3033eb4ddf 100644 --- a/Library/Homebrew/utils.rb +++ b/Library/Homebrew/utils.rb @@ -560,3 +560,15 @@ end def shell_profile Utils::Shell.profile end + +def tap_and_name_comparison + proc do |a, b| + if a.include?("/") && !b.include?("/") + 1 + elsif !a.include?("/") && b.include?("/") + -1 + else + a <=> b + end + end +end From 626cb6ca91f99df6f7c646d95cb5e82d0dd6532d Mon Sep 17 00:00:00 2001 From: Gautham Goli Date: Sun, 10 Sep 2017 18:55:01 +0000 Subject: [PATCH 202/294] audit: Add more tests for FormulaAudit/Miscellaneous cop --- .../Homebrew/test/rubocops/lines_cop_spec.rb | 41 +++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/Library/Homebrew/test/rubocops/lines_cop_spec.rb b/Library/Homebrew/test/rubocops/lines_cop_spec.rb index 31aafbcf8e..d939626883 100644 --- a/Library/Homebrew/test/rubocops/lines_cop_spec.rb +++ b/Library/Homebrew/test/rubocops/lines_cop_spec.rb @@ -380,6 +380,21 @@ describe RuboCop::Cop::FormulaAudit::Miscellaneous do end end + it "with build.universal? exempted formula" do + source = <<-EOS.undent + class Wine < Formula + desc "foo" + url 'http://example.com/foo-1.0.tgz' + if build.universal? + "foo" + end + end + EOS + + inspect_source(cop, source, "/homebrew-core/Formula/wine.rb") + expect(cop.offenses).to eq([]) + end + it "with ENV.universal_binary" do source = <<-EOS.undent class Foo < Formula @@ -450,6 +465,19 @@ describe RuboCop::Cop::FormulaAudit::Miscellaneous do end end + it "with ruby-macho alternatives audit exempted formula" do + source = <<-EOS.undent + class Cctools < Formula + desc "foo" + url 'http://example.com/foo-1.0.tgz' + system "install_name_tool", "-id" + end + EOS + + inspect_source(cop, source, "/homebrew-core/Formula/cctools.rb") + expect(cop.offenses).to eq([]) + end + it "with npm install without language::Node args" do source = <<-EOS.undent class Foo < Formula @@ -471,5 +499,18 @@ describe RuboCop::Cop::FormulaAudit::Miscellaneous do expect_offense(expected, actual) end end + + it "with npm install without language::Node args in kibana" do + source = <<-EOS.undent + class KibanaAT44 < Formula + desc "foo" + url 'http://example.com/foo-1.0.tgz' + system "npm", "install" + end + EOS + + inspect_source(cop, source, "/homebrew-core/Formula/kibana@4.4.rb") + expect(cop.offenses).to eq([]) + end end end From c8f3b1d37c13fc227a6062c9d0ee98fc5ebaaf6a Mon Sep 17 00:00:00 2001 From: Mike McQuaid Date: Tue, 19 Sep 2017 10:54:50 +0100 Subject: [PATCH 203/294] linkage_checker: tweak headers wording. It's helpful to note that the undeclared/unnecessary dependencies are done based on linkage alone. --- Library/Homebrew/os/mac/linkage_checker.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Library/Homebrew/os/mac/linkage_checker.rb b/Library/Homebrew/os/mac/linkage_checker.rb index 2e8256ce4a..f6aa4c2f33 100644 --- a/Library/Homebrew/os/mac/linkage_checker.rb +++ b/Library/Homebrew/os/mac/linkage_checker.rb @@ -91,8 +91,8 @@ class LinkageChecker display_items "Homebrew libraries", @brewed_dylibs display_items "Variable-referenced libraries", @variable_dylibs display_items "Missing libraries", @broken_dylibs - display_items "Possible undeclared dependencies", @undeclared_deps - display_items "Possible unnecessary dependencies", @unnecessary_deps + display_items "Undeclared dependencies with linkage", @undeclared_deps + display_items "Dependencies with no linkage", @unnecessary_deps end def display_reverse_output From 6fb9fed6935f31192613605b3f234bc3999839c1 Mon Sep 17 00:00:00 2001 From: ilovezfs Date: Tue, 19 Sep 2017 07:40:29 -0700 Subject: [PATCH 204/294] Revert "popen: Do not suppress stderr" --- Library/Homebrew/utils/popen.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Library/Homebrew/utils/popen.rb b/Library/Homebrew/utils/popen.rb index bcdd815bba..4e03711a16 100644 --- a/Library/Homebrew/utils/popen.rb +++ b/Library/Homebrew/utils/popen.rb @@ -13,7 +13,7 @@ module Utils return pipe.read unless block_given? yield pipe else - $stderr.reopen("/dev/null", "w") if !ARGV.debug? && !ARGV.verbose? + $stderr.reopen("/dev/null", "w") exec(*args) end end From 17e275305397af78efddd6f4442ad14595cbcd0a Mon Sep 17 00:00:00 2001 From: Gautham Goli Date: Wed, 20 Sep 2017 13:26:50 +0530 Subject: [PATCH 205/294] audit: Use version pinned by brew while executing rubocop cli --- Library/Homebrew/cmd/style.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Library/Homebrew/cmd/style.rb b/Library/Homebrew/cmd/style.rb index b0f46fadc4..e816db5dc6 100644 --- a/Library/Homebrew/cmd/style.rb +++ b/Library/Homebrew/cmd/style.rb @@ -119,10 +119,10 @@ module Homebrew when :print args << "--display-cop-names" if ARGV.include? "--display-cop-names" args << "--format" << "simple" if files - system(cache_env, "rubocop", *args) + system(cache_env, "rubocop", "_#{HOMEBREW_RUBOCOP_VERSION}_", *args) !$CHILD_STATUS.success? when :json - json, _, status = Open3.capture3(cache_env, "rubocop", "--format", "json", *args) + json, _, status = Open3.capture3(cache_env, "rubocop", "_#{HOMEBREW_RUBOCOP_VERSION}_", "--format", "json", *args) # exit status of 1 just means violations were found; other numbers mean # execution errors. # exitstatus can also be nil if RuboCop process crashes, e.g. due to From 8bf28477a3da58ea5c6113d9ce3228c08c4c0ec0 Mon Sep 17 00:00:00 2001 From: Shaun Jackman Date: Tue, 19 Sep 2017 10:18:04 -0700 Subject: [PATCH 206/294] popen: Add an options argument Useful for selectively enabling or silencing stderr, for example. popen_read("foo", err: :err) --- Library/Homebrew/utils/popen.rb | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/Library/Homebrew/utils/popen.rb b/Library/Homebrew/utils/popen.rb index 4e03711a16..f30a2a0fed 100644 --- a/Library/Homebrew/utils/popen.rb +++ b/Library/Homebrew/utils/popen.rb @@ -1,20 +1,20 @@ module Utils - def self.popen_read(*args, &block) - popen(args, "rb", &block) + def self.popen_read(*args, **options, &block) + popen(args, "rb", options, &block) end - def self.popen_write(*args, &block) - popen(args, "wb", &block) + def self.popen_write(*args, **options, &block) + popen(args, "wb", options, &block) end - def self.popen(args, mode) + def self.popen(args, mode, options = {}) IO.popen("-", mode) do |pipe| if pipe return pipe.read unless block_given? yield pipe else - $stderr.reopen("/dev/null", "w") - exec(*args) + options[:err] ||= :close + exec(*args, options) end end end From 58a1bd6dbf0b041b3c5c23dc190680e82bf64ae0 Mon Sep 17 00:00:00 2001 From: Shaun Jackman Date: Wed, 20 Sep 2017 11:58:52 -0700 Subject: [PATCH 207/294] popen: Do not suppress stderr when HOMEBREW_STDERR --- Library/Homebrew/utils/popen.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Library/Homebrew/utils/popen.rb b/Library/Homebrew/utils/popen.rb index f30a2a0fed..2fa3ade462 100644 --- a/Library/Homebrew/utils/popen.rb +++ b/Library/Homebrew/utils/popen.rb @@ -13,7 +13,7 @@ module Utils return pipe.read unless block_given? yield pipe else - options[:err] ||= :close + options[:err] ||= :close unless ENV["HOMEBREW_STDERR"] exec(*args, options) end end From 8bb57187ab57bc10027e55ea2d4cfd141e896286 Mon Sep 17 00:00:00 2001 From: Shaun Jackman Date: Tue, 19 Sep 2017 10:19:56 -0700 Subject: [PATCH 208/294] locate: Suppress stderr Suppress the error message: xcrun: error: unable to find utility "gcc-4.0", not a developer tool or in PATH --- Library/Homebrew/extend/os/mac/development_tools.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Library/Homebrew/extend/os/mac/development_tools.rb b/Library/Homebrew/extend/os/mac/development_tools.rb index 66b3bf9d29..ed2a1fc9e8 100644 --- a/Library/Homebrew/extend/os/mac/development_tools.rb +++ b/Library/Homebrew/extend/os/mac/development_tools.rb @@ -9,7 +9,7 @@ class DevelopmentTools @locate[key] = if (located_tool = original_locate(tool)) located_tool elsif MacOS.version > :tiger - path = Utils.popen_read("/usr/bin/xcrun", "-no-cache", "-find", tool).chomp + path = Utils.popen_read("/usr/bin/xcrun", "-no-cache", "-find", tool, err: :close).chomp Pathname.new(path) if File.executable?(path) end end From 2f6b8dcf687d99fed1a9eb64c07472cc7ea2c838 Mon Sep 17 00:00:00 2001 From: Shaun Jackman Date: Wed, 20 Sep 2017 12:03:45 -0700 Subject: [PATCH 209/294] describe_java: Suppress stderr Suppress the error message: Unable to find any JVMs matching version "(null)". --- Library/Homebrew/system_config.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Library/Homebrew/system_config.rb b/Library/Homebrew/system_config.rb index 5663295c28..3e1acd4ff2 100644 --- a/Library/Homebrew/system_config.rb +++ b/Library/Homebrew/system_config.rb @@ -134,7 +134,7 @@ class SystemConfig # java_home doesn't exist on all macOSs; it might be missing on older versions. return "N/A" unless File.executable? "/usr/libexec/java_home" - java_xml = Utils.popen_read("/usr/libexec/java_home", "--xml", "--failfast") + java_xml = Utils.popen_read("/usr/libexec/java_home", "--xml", "--failfast", err: :close) return "N/A" unless $CHILD_STATUS.success? javas = [] REXML::XPath.each(REXML::Document.new(java_xml), "//key[text()='JVMVersion']/following-sibling::string") do |item| From 733d485065e55ad1cf159eec89927c4990bbdfaf Mon Sep 17 00:00:00 2001 From: ilovezfs Date: Thu, 21 Sep 2017 03:43:15 -0700 Subject: [PATCH 210/294] superenv: help Autotools with 10.13 SDK on 10.12 The GNU Autotools tests for whether futimens and utimensat are available reliably come to incorrect conclusions on 10.12 with the 10.13 SDK in Xcode 9. This overrides its decisions by forcing the right answer in superenv using ac_cv_func_* environment variables and setting them to "no" on 10.12. --- Library/Homebrew/extend/os/mac/extend/ENV/super.rb | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/Library/Homebrew/extend/os/mac/extend/ENV/super.rb b/Library/Homebrew/extend/os/mac/extend/ENV/super.rb index 9c20cc7c6f..0f6bdb8343 100644 --- a/Library/Homebrew/extend/os/mac/extend/ENV/super.rb +++ b/Library/Homebrew/extend/os/mac/extend/ENV/super.rb @@ -96,9 +96,12 @@ module Superenv self["SDKROOT"] = MacOS.sdk_path end - # Filter out symbols known not to be defined on 10.11 since GNU Autotools - # can't reliably figure this out with Xcode 8 on its own yet. - if MacOS.version == "10.11" && MacOS::Xcode.installed? && MacOS::Xcode.version >= "8.0" + # Filter out symbols known not to be defined since GNU Autotools can't + # reliably figure this out with Xcode 8 and above. + if MacOS.version == "10.12" && MacOS::Xcode.installed? && MacOS::Xcode.version >= "9.0" + ENV["ac_cv_func_futimens"] = "no" + ENV["ac_cv_func_utimensat"] = "no" + elsif MacOS.version == "10.11" && MacOS::Xcode.installed? && MacOS::Xcode.version >= "8.0" %w[basename_r clock_getres clock_gettime clock_settime dirname_r getentropy mkostemp mkostemps timingsafe_bcmp].each do |s| ENV["ac_cv_func_#{s}"] = "no" From b2b413165f3553c48c8e060dd97ccde9c13cae80 Mon Sep 17 00:00:00 2001 From: Mike McQuaid Date: Thu, 21 Sep 2017 14:27:17 +0100 Subject: [PATCH 211/294] Upgrade vendored Ruby to 2.3.3. Use this version whenever 2.3.3 isn't installed. Also, remove the Linux portable Ruby for now until it's built to be the same version. --- .travis.yml | 2 +- Library/Homebrew/cmd/vendor-install.sh | 4 ++-- Library/Homebrew/extend/os/mac/diagnostic.rb | 4 ++-- Library/Homebrew/utils/ruby.sh | 9 ++++----- Library/Homebrew/vendor/portable-ruby-version | 2 +- 5 files changed, 10 insertions(+), 11 deletions(-) diff --git a/.travis.yml b/.travis.yml index dfdb7fc85c..94b83fc116 100644 --- a/.travis.yml +++ b/.travis.yml @@ -15,7 +15,7 @@ matrix: rvm: system - os: linux sudo: false - rvm: 2.0.0 + rvm: 2.3.3 before_install: - export HOMEBREW_NO_AUTO_UPDATE=1 diff --git a/Library/Homebrew/cmd/vendor-install.sh b/Library/Homebrew/cmd/vendor-install.sh index fe7e26dd44..a040221e9b 100644 --- a/Library/Homebrew/cmd/vendor-install.sh +++ b/Library/Homebrew/cmd/vendor-install.sh @@ -13,8 +13,8 @@ if [[ -n "$HOMEBREW_MACOS" ]] then if [[ "$HOMEBREW_PROCESSOR" = "Intel" ]] then - ruby_URL="https://homebrew.bintray.com/bottles-portable/portable-ruby-2.0.0-p648.leopard_64.bottle.tar.gz" - ruby_SHA="5c1240abe4be91c9774a0089c2a38a8ccfff87c009e8e5786730c659d5e633f7" + ruby_URL="https://homebrew.bintray.com/bottles-portable/portable-ruby-2.3.3.leopard_64.bottle.tar.gz" + ruby_SHA="9060cdddbc5b5a0cc7188a251c40b2845e9d8b8ce346c83c585a965a111cab54" else ruby_URL="" ruby_SHA="" diff --git a/Library/Homebrew/extend/os/mac/diagnostic.rb b/Library/Homebrew/extend/os/mac/diagnostic.rb index ab54335650..9f7b18b492 100644 --- a/Library/Homebrew/extend/os/mac/diagnostic.rb +++ b/Library/Homebrew/extend/os/mac/diagnostic.rb @@ -195,8 +195,8 @@ module Homebrew end def check_ruby_version - ruby_version = "2.0" - return if RUBY_VERSION[/\d\.\d/] == ruby_version + ruby_version = "2.3.3" + return if RUBY_VERSION == ruby_version return if ARGV.homebrew_developer? && OS::Mac.prerelease? <<-EOS.undent diff --git a/Library/Homebrew/utils/ruby.sh b/Library/Homebrew/utils/ruby.sh index 6945c068bb..0303da6005 100644 --- a/Library/Homebrew/utils/ruby.sh +++ b/Library/Homebrew/utils/ruby.sh @@ -2,7 +2,8 @@ setup-ruby-path() { local vendor_dir local vendor_ruby_current_version local vendor_ruby_path - local ruby_version_major + local ruby_old_version + local minimum_ruby_version="2.3.3" vendor_dir="$HOMEBREW_LIBRARY/Homebrew/vendor" vendor_ruby_current_version="$vendor_dir/portable-ruby/current" @@ -36,12 +37,10 @@ setup-ruby-path() { if [[ -n "$HOMEBREW_RUBY_PATH" ]] then - ruby_version_major="$("$HOMEBREW_RUBY_PATH" --version)" - ruby_version_major="${ruby_version_major#ruby }" - ruby_version_major="${ruby_version_major%%.*}" + ruby_old_version="$("$HOMEBREW_RUBY_PATH" -e "puts Gem::Version.new('$minimum_ruby_version') > Gem::Version.new(RUBY_VERSION)")" fi - if [[ "$ruby_version_major" != "2" || -n "$HOMEBREW_FORCE_VENDOR_RUBY" ]] + if [[ "$ruby_old_version" == "true" || -n "$HOMEBREW_FORCE_VENDOR_RUBY" ]] then brew vendor-install ruby --quiet if [[ ! -x "$vendor_ruby_path" ]] diff --git a/Library/Homebrew/vendor/portable-ruby-version b/Library/Homebrew/vendor/portable-ruby-version index 633c00da36..0bee604df7 100644 --- a/Library/Homebrew/vendor/portable-ruby-version +++ b/Library/Homebrew/vendor/portable-ruby-version @@ -1 +1 @@ -2.0.0-p648 +2.3.3 From fcb6b5c7aa1c8c76aa7e31b5ca280d7435dc8280 Mon Sep 17 00:00:00 2001 From: FX Coudert Date: Mon, 4 Sep 2017 11:29:37 +0200 Subject: [PATCH 212/294] os/mac: support macOS High Sierra (10.13). --- Library/Homebrew/os/mac.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Library/Homebrew/os/mac.rb b/Library/Homebrew/os/mac.rb index bc75fc3223..52fa2a1873 100644 --- a/Library/Homebrew/os/mac.rb +++ b/Library/Homebrew/os/mac.rb @@ -34,12 +34,12 @@ module OS def prerelease? # TODO: bump version when new OS is released - version >= "10.13" + version >= "10.14" end def outdated_release? # TODO: bump version when new OS is released - version < "10.10" + version < "10.11" end def cat From 353810d934ad807449ed360d950662a5cc92e94b Mon Sep 17 00:00:00 2001 From: Shaun Jackman Date: Thu, 21 Sep 2017 17:02:42 -0700 Subject: [PATCH 213/294] Upgrade vendored Ruby to 2.3.3 for Linux. --- Library/Homebrew/cmd/vendor-install.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Library/Homebrew/cmd/vendor-install.sh b/Library/Homebrew/cmd/vendor-install.sh index a040221e9b..5cad7541e7 100644 --- a/Library/Homebrew/cmd/vendor-install.sh +++ b/Library/Homebrew/cmd/vendor-install.sh @@ -21,8 +21,8 @@ then fi elif [[ -n "$HOMEBREW_LINUX" ]] then - ruby_URL="https://homebrew.bintray.com/bottles-portable/portable-ruby-2.0.0-p648.x86_64_linux.bottle.tar.gz" - ruby_SHA="dbb5118a22a6a75cc77e62544a3d8786d383fab1bdaf8c154951268807357bf0" + ruby_URL="https://homebrew.bintray.com/bottles-portable/portable-ruby-2.3.3.x86_64_linux.bottle.tar.gz" + ruby_SHA="543c18bd33a300e6c16671437b1e0f17b03bb64e6a485fc15ff7de1eb1a0bc2a" fi fetch() { From 557105640b5154e3fe1299aa31abdc106aa71df5 Mon Sep 17 00:00:00 2001 From: Naoto Kaneko Date: Fri, 22 Sep 2017 16:57:27 +0900 Subject: [PATCH 214/294] Add a failure message to be_detected_from matcher --- Library/Homebrew/test/version_spec.rb | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/Library/Homebrew/test/version_spec.rb b/Library/Homebrew/test/version_spec.rb index cee57e9352..6d69963169 100644 --- a/Library/Homebrew/test/version_spec.rb +++ b/Library/Homebrew/test/version_spec.rb @@ -241,8 +241,18 @@ describe Version do describe "::detect" do matcher :be_detected_from do |url, specs = {}| - match do |version| - Version.detect(url, specs) == version + detected = Version.detect(url, specs) + + match do |expected| + detected == expected + end + + failure_message do |expected| + format = <<-EOS + expected: %s + detected: %s + EOS + format % [expected, detected] end end From 5fa4d60c7b6c6d0e8488ad3a7d6649233af4fb2e Mon Sep 17 00:00:00 2001 From: Naoto Kaneko Date: Fri, 22 Sep 2017 17:53:48 +0900 Subject: [PATCH 215/294] Replace String#% with Kernel.#format --- Library/Homebrew/test/version_spec.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Library/Homebrew/test/version_spec.rb b/Library/Homebrew/test/version_spec.rb index 6d69963169..d670d79c80 100644 --- a/Library/Homebrew/test/version_spec.rb +++ b/Library/Homebrew/test/version_spec.rb @@ -248,11 +248,11 @@ describe Version do end failure_message do |expected| - format = <<-EOS + message = <<-EOS expected: %s detected: %s EOS - format % [expected, detected] + format(message, expected, detected) end end From df7fb212c264e0ebe92b1e312f783d20e3e6fbe3 Mon Sep 17 00:00:00 2001 From: Mike McQuaid Date: Fri, 22 Sep 2017 15:50:09 +0100 Subject: [PATCH 216/294] brew.sh: update no git repository message. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Clarify that this message doesn’t only trigger when there’s no Git repository but also when there’s no tags that `git describe` can use. --- Library/Homebrew/brew.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Library/Homebrew/brew.sh b/Library/Homebrew/brew.sh index 66908925c8..b2859c9277 100644 --- a/Library/Homebrew/brew.sh +++ b/Library/Homebrew/brew.sh @@ -23,7 +23,7 @@ HOMEBREW_VERSION="$(git -C "$HOMEBREW_REPOSITORY" describe --tags --dirty --abbr HOMEBREW_USER_AGENT_VERSION="$HOMEBREW_VERSION" if [[ -z "$HOMEBREW_VERSION" ]] then - HOMEBREW_VERSION=">1.2.0 (no git repository)" + HOMEBREW_VERSION=">1.2.0 (shallow or no git repository)" HOMEBREW_USER_AGENT_VERSION="1.X.Y" fi From aa665b94587ee7b0d69e783a669269a9954e8428 Mon Sep 17 00:00:00 2001 From: Mike McQuaid Date: Fri, 22 Sep 2017 15:54:29 +0100 Subject: [PATCH 217/294] portable-ruby: improve installation messaging. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Use “Pouring” to be more consistent with our normal messaging. - Don’t be silent by default. --- Library/Homebrew/cmd/vendor-install.sh | 2 +- Library/Homebrew/utils/ruby.sh | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Library/Homebrew/cmd/vendor-install.sh b/Library/Homebrew/cmd/vendor-install.sh index a040221e9b..a21601760d 100644 --- a/Library/Homebrew/cmd/vendor-install.sh +++ b/Library/Homebrew/cmd/vendor-install.sh @@ -135,7 +135,7 @@ install() { fi safe_cd "$VENDOR_DIR" - [[ -n "$HOMEBREW_QUIET" ]] || echo "==> Unpacking $(basename "$VENDOR_URL")" + [[ -n "$HOMEBREW_QUIET" ]] || echo "==> Pouring $(basename "$VENDOR_URL")" tar "$tar_args" "$CACHED_LOCATION" safe_cd "$VENDOR_DIR/portable-$VENDOR_NAME" diff --git a/Library/Homebrew/utils/ruby.sh b/Library/Homebrew/utils/ruby.sh index 0303da6005..813bb09999 100644 --- a/Library/Homebrew/utils/ruby.sh +++ b/Library/Homebrew/utils/ruby.sh @@ -22,7 +22,7 @@ setup-ruby-path() { if [[ $(readlink "$vendor_ruby_current_version") != "$(<"$vendor_dir/portable-ruby-version")" ]] then - if ! brew vendor-install ruby --quiet + if ! brew vendor-install ruby then onoe "Failed to upgrade vendor Ruby." fi @@ -42,7 +42,7 @@ setup-ruby-path() { if [[ "$ruby_old_version" == "true" || -n "$HOMEBREW_FORCE_VENDOR_RUBY" ]] then - brew vendor-install ruby --quiet + brew vendor-install ruby if [[ ! -x "$vendor_ruby_path" ]] then odie "Failed to install vendor Ruby." From 0e766d00a5dd89e25a523e2018f03e5487bef183 Mon Sep 17 00:00:00 2001 From: Mike McQuaid Date: Fri, 22 Sep 2017 16:02:09 +0100 Subject: [PATCH 218/294] development_tools: fix curl https handling. `curl` can handle modern certificates _unless_ it is too old. This broke `brew audit`'s HTTPS detection code. --- Library/Homebrew/extend/os/mac/development_tools.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Library/Homebrew/extend/os/mac/development_tools.rb b/Library/Homebrew/extend/os/mac/development_tools.rb index 66b3bf9d29..b0d78f45b8 100644 --- a/Library/Homebrew/extend/os/mac/development_tools.rb +++ b/Library/Homebrew/extend/os/mac/development_tools.rb @@ -85,7 +85,7 @@ class DevelopmentTools def curl_handles_most_https_certificates? # The system Curl is too old for some modern HTTPS certificates on # older macOS versions. - !ENV["HOMEBREW_SYSTEM_CURL_TOO_OLD"].nil? + ENV["HOMEBREW_SYSTEM_CURL_TOO_OLD"].nil? end def subversion_handles_most_https_certificates? From 352a8817e9e576ca8f2e50949a33904e9da283b7 Mon Sep 17 00:00:00 2001 From: ilovezfs Date: Fri, 22 Sep 2017 17:10:40 -0700 Subject: [PATCH 219/294] superenv: more help for Autotools with 10.13 SDK on 10.12 Add fmemopen and open_memstream to the list of ac_cv_func_*=no symbols for 10.12 with the 10.13 SDK. --- Library/Homebrew/extend/os/mac/extend/ENV/super.rb | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Library/Homebrew/extend/os/mac/extend/ENV/super.rb b/Library/Homebrew/extend/os/mac/extend/ENV/super.rb index 0f6bdb8343..5872c2264f 100644 --- a/Library/Homebrew/extend/os/mac/extend/ENV/super.rb +++ b/Library/Homebrew/extend/os/mac/extend/ENV/super.rb @@ -99,8 +99,9 @@ module Superenv # Filter out symbols known not to be defined since GNU Autotools can't # reliably figure this out with Xcode 8 and above. if MacOS.version == "10.12" && MacOS::Xcode.installed? && MacOS::Xcode.version >= "9.0" - ENV["ac_cv_func_futimens"] = "no" - ENV["ac_cv_func_utimensat"] = "no" + %w[fmemopen futimens open_memstream utimensat].each do |s| + ENV["ac_cv_func_#{s}"] = "no" + end elsif MacOS.version == "10.11" && MacOS::Xcode.installed? && MacOS::Xcode.version >= "8.0" %w[basename_r clock_getres clock_gettime clock_settime dirname_r getentropy mkostemp mkostemps timingsafe_bcmp].each do |s| From 56ab1ef5a860beb2f180bbf26bfc74a0d569dce9 Mon Sep 17 00:00:00 2001 From: Mike McQuaid Date: Sat, 23 Sep 2017 21:10:25 +0100 Subject: [PATCH 220/294] audit: hack around El Capitan audit failure. --- Library/Homebrew/dev-cmd/audit.rb | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/Library/Homebrew/dev-cmd/audit.rb b/Library/Homebrew/dev-cmd/audit.rb index e2a288fdb5..5d1871f542 100644 --- a/Library/Homebrew/dev-cmd/audit.rb +++ b/Library/Homebrew/dev-cmd/audit.rb @@ -214,7 +214,12 @@ class FormulaAuditor break if details[:status].to_s.start_with?("2") end - return "The URL #{url} is not reachable" unless details[:status] + unless details[:status] + # Hack around https://github.com/Homebrew/brew/issues/3199 + return if MacOS.version == :el_capitan + return "The URL #{url} is not reachable" + end + unless details[:status].start_with? "2" return "The URL #{url} is not reachable (HTTP status code #{details[:status]})" end From 7f93d816a384f750a8c914ff52fb7728f4466309 Mon Sep 17 00:00:00 2001 From: Mike McQuaid Date: Sat, 23 Sep 2017 21:53:20 +0100 Subject: [PATCH 221/294] utils/git: don't fail when CoreTap is untapped. This produces test failures on Linux where we intentionally avoid having it tapped. --- Library/Homebrew/utils/git.rb | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/Library/Homebrew/utils/git.rb b/Library/Homebrew/utils/git.rb index 1fc01188cc..28884ba5b3 100644 --- a/Library/Homebrew/utils/git.rb +++ b/Library/Homebrew/utils/git.rb @@ -49,13 +49,13 @@ module Utils return if git_available? # we cannot install brewed git if homebrew/core is unavailable. - raise "Git is unavailable" unless CoreTap.instance.installed? - - begin - oh1 "Installing git" - safe_system HOMEBREW_BREW_FILE, "install", "git" - rescue - raise "Git is unavailable" + if CoreTap.instance.installed? + begin + oh1 "Installing git" + safe_system HOMEBREW_BREW_FILE, "install", "git" + rescue + raise "Git is unavailable" + end end clear_git_available_cache From e984623214d2a55d30c342e0a4607eb2fe56d017 Mon Sep 17 00:00:00 2001 From: ilovezfs Date: Sat, 23 Sep 2017 23:00:29 -0700 Subject: [PATCH 222/294] audit: don't check for homebrew/science duplicates It's just noise to turn the migration PRs red over expected duplicates. --- Library/Homebrew/dev-cmd/audit.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/Library/Homebrew/dev-cmd/audit.rb b/Library/Homebrew/dev-cmd/audit.rb index 5d1871f542..a9768c8565 100644 --- a/Library/Homebrew/dev-cmd/audit.rb +++ b/Library/Homebrew/dev-cmd/audit.rb @@ -419,6 +419,7 @@ class FormulaAuditor @@local_official_taps_name_map ||= Tap.select(&:official?).flat_map(&:formula_names) .each_with_object({}) do |tap_formula_full_name, name_map| + next if tap_formula_full_name.start_with?("homebrew/science/") tap_formula_name = tap_formula_full_name.split("/").last name_map[tap_formula_name] ||= [] name_map[tap_formula_name] << tap_formula_full_name From 28c78384501e159ecb45e0ffa29ff419a22701d8 Mon Sep 17 00:00:00 2001 From: ilovezfs Date: Sun, 24 Sep 2017 00:29:34 -0700 Subject: [PATCH 223/294] audit: also skip homebrew/science duplicates found by search_taps Follow-up to #3202. --- Library/Homebrew/dev-cmd/audit.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/Library/Homebrew/dev-cmd/audit.rb b/Library/Homebrew/dev-cmd/audit.rb index a9768c8565..743b9484ef 100644 --- a/Library/Homebrew/dev-cmd/audit.rb +++ b/Library/Homebrew/dev-cmd/audit.rb @@ -430,6 +430,7 @@ class FormulaAuditor if @online Homebrew.search_taps(name, silent: true).each do |tap_formula_full_name| + next if tap_formula_full_name.start_with?("homebrew/science/") tap_formula_name = tap_formula_full_name.split("/").last next if tap_formula_name != name same_name_tap_formulae << tap_formula_full_name From 3d876f7d70eb3bebf5267f6794a1d5a5456c2798 Mon Sep 17 00:00:00 2001 From: Mike McQuaid Date: Sun, 24 Sep 2017 20:39:06 +0100 Subject: [PATCH 224/294] utils/git: cache less aggressively. This should avoid weird test ordering failures with specs on Linux (but there's no real reason this can't occur on macOS too). --- Library/Homebrew/utils/git.rb | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/Library/Homebrew/utils/git.rb b/Library/Homebrew/utils/git.rb index 28884ba5b3..f1113af661 100644 --- a/Library/Homebrew/utils/git.rb +++ b/Library/Homebrew/utils/git.rb @@ -27,8 +27,7 @@ end module Utils def self.git_available? - return @git if instance_variable_defined?(:@git) - @git = quiet_system HOMEBREW_SHIMS_PATH/"scm/git", "--version" + @git ||= quiet_system HOMEBREW_SHIMS_PATH/"scm/git", "--version" end def self.git_path @@ -58,12 +57,11 @@ module Utils end end - clear_git_available_cache raise "Git is unavailable" unless git_available? end def self.clear_git_available_cache - remove_instance_variable(:@git) if instance_variable_defined?(:@git) + @git = nil @git_path = nil @git_version = nil end From 9eb51db400261545822c8c03c2e9d587d70e8ad0 Mon Sep 17 00:00:00 2001 From: Mike McQuaid Date: Sun, 24 Sep 2017 19:10:57 +0100 Subject: [PATCH 225/294] Rubocop 0.50 and target 2.3. --- Library/.rubocop.yml | 23 ++++++++++++++++++++--- Library/Homebrew/.rubocop.yml | 4 ++-- Library/Homebrew/.rubocop_todo.yml | 9 +-------- Library/Homebrew/constants.rb | 6 ++++-- Library/Homebrew/os/mac.rb | 2 +- 5 files changed, 28 insertions(+), 16 deletions(-) diff --git a/Library/.rubocop.yml b/Library/.rubocop.yml index cb065a1a4b..dd6e039b09 100644 --- a/Library/.rubocop.yml +++ b/Library/.rubocop.yml @@ -1,5 +1,5 @@ AllCops: - TargetRubyVersion: 2.0 + TargetRubyVersion: 2.3 Exclude: - '**/Casks/**/*' - '**/vendor/**/*' @@ -119,7 +119,7 @@ Style/Encoding: Enabled: true # dashes in filenames are typical -Style/FileName: +Naming/FileName: Regex: !ruby/regexp /^[\w\@\-\+\.]+(\.rb)?$/ # falsely flags e.g. curl formatting arguments as format strings @@ -189,8 +189,25 @@ Style/TrailingCommaInArguments: EnforcedStyleForMultiline: comma # we have too many variables like sha256 where this harms readability -Style/VariableNumber: +Naming/VariableNumber: Enabled: false Style/WordArray: MinSize: 4 + +# we want to add this slowly and manually +Style/FrozenStringLiteralComment: + Enabled: false + +# generally rescuing StandardError is fine +Lint/RescueWithoutErrorClass: + Enabled: false + +# implicitly allow EOS as we use it everywhere +Naming/HeredocDelimiterNaming: + Blacklist: + - END, EOD, EOF + +# we output how to use interpolated strings too often +Lint/InterpolationCheck: + Enabled: false diff --git a/Library/Homebrew/.rubocop.yml b/Library/Homebrew/.rubocop.yml index 26c9445294..dc44065277 100644 --- a/Library/Homebrew/.rubocop.yml +++ b/Library/Homebrew/.rubocop.yml @@ -42,12 +42,12 @@ Style/HashSyntax: EnforcedStyle: ruby19_no_mixed_keys # we won't change backward compatible method names -Style/MethodName: +Naming/MethodName: Exclude: - 'compat/**/*' # we won't change backward compatible predicate names -Style/PredicateName: +Naming/PredicateName: Exclude: - 'compat/**/*' NameWhitelist: is_32_bit?, is_64_bit? diff --git a/Library/Homebrew/.rubocop_todo.yml b/Library/Homebrew/.rubocop_todo.yml index 37518a5f0a..96c2f3676c 100644 --- a/Library/Homebrew/.rubocop_todo.yml +++ b/Library/Homebrew/.rubocop_todo.yml @@ -81,7 +81,7 @@ Security/MarshalLoad: - 'utils/fork.rb' # Offense count: 1 -Style/AccessorMethodName: +Naming/AccessorMethodName: Exclude: - 'extend/ENV/super.rb' @@ -136,10 +136,3 @@ Style/MutableConstant: - 'formulary.rb' - 'tab.rb' - 'tap.rb' - -# Offense count: 8 -Style/OpMethod: - Exclude: - - 'dependencies.rb' - - 'install_renamed.rb' - - 'options.rb' diff --git a/Library/Homebrew/constants.rb b/Library/Homebrew/constants.rb index 23be70bccf..b122946c8f 100644 --- a/Library/Homebrew/constants.rb +++ b/Library/Homebrew/constants.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # RuboCop version used for `brew style` and `brew cask style` -HOMEBREW_RUBOCOP_VERSION = "0.49.1".freeze -HOMEBREW_RUBOCOP_CASK_VERSION = "~> 0.13.1".freeze # has to be updated when RuboCop version changes +HOMEBREW_RUBOCOP_VERSION = "0.50.0" +HOMEBREW_RUBOCOP_CASK_VERSION = "~> 0.14.2" # has to be updated when RuboCop version changes diff --git a/Library/Homebrew/os/mac.rb b/Library/Homebrew/os/mac.rb index 52fa2a1873..d3e5cb38ca 100644 --- a/Library/Homebrew/os/mac.rb +++ b/Library/Homebrew/os/mac.rb @@ -11,7 +11,7 @@ module OS module Mac module_function - ::MacOS = self # rubocop:disable Style/ConstantName + ::MacOS = self # rubocop:disable Naming/ConstantName raise "Loaded OS::Mac on generic OS!" if ENV["HOMEBREW_TEST_GENERIC_OS"] From 01e9ec9a9f723b2ef89c7adfaea39f9e4db9aede Mon Sep 17 00:00:00 2001 From: Mike McQuaid Date: Sun, 24 Sep 2017 19:24:46 +0100 Subject: [PATCH 226/294] Rubocop: automatic rule fixes. --- Library/Homebrew/cask/lib/hbc/cask_loader.rb | 2 +- Library/Homebrew/cask/lib/hbc/dsl.rb | 2 +- Library/Homebrew/cask/lib/hbc/installer.rb | 4 ++-- Library/Homebrew/cask/lib/hbc/system_command.rb | 2 +- Library/Homebrew/caveats.rb | 2 +- Library/Homebrew/cmd/unlinkapps.rb | 2 +- Library/Homebrew/debrew/irb.rb | 2 +- Library/Homebrew/dependency.rb | 2 +- Library/Homebrew/dev-cmd/audit.rb | 4 ++-- Library/Homebrew/dev-cmd/bottle.rb | 2 +- Library/Homebrew/dev-cmd/bump-formula-pr.rb | 2 +- Library/Homebrew/dev-cmd/pull.rb | 4 ++-- Library/Homebrew/dev-cmd/release-notes.rb | 4 +--- Library/Homebrew/diagnostic.rb | 4 ++-- Library/Homebrew/extend/ARGV.rb | 4 ++-- Library/Homebrew/formula.rb | 14 +++++++------- Library/Homebrew/formula_installer.rb | 2 +- Library/Homebrew/keg.rb | 2 +- Library/Homebrew/language/python.rb | 2 +- Library/Homebrew/os/mac.rb | 2 +- Library/Homebrew/requirements/java_requirement.rb | 4 ++-- Library/Homebrew/requirements/ruby_requirement.rb | 4 +--- Library/Homebrew/sandbox.rb | 2 +- Library/Homebrew/tab.rb | 2 +- 24 files changed, 36 insertions(+), 40 deletions(-) diff --git a/Library/Homebrew/cask/lib/hbc/cask_loader.rb b/Library/Homebrew/cask/lib/hbc/cask_loader.rb index 532d9f3c3c..8fce9636ad 100644 --- a/Library/Homebrew/cask/lib/hbc/cask_loader.rb +++ b/Library/Homebrew/cask/lib/hbc/cask_loader.rb @@ -56,7 +56,7 @@ module Hbc class FromURILoader < FromPathLoader def self.can_load?(ref) - ref.to_s.match?(::URI.regexp) + ref.to_s.match?(::URI::DEFAULT_PARSER.make_regexp) end attr_reader :url diff --git a/Library/Homebrew/cask/lib/hbc/dsl.rb b/Library/Homebrew/cask/lib/hbc/dsl.rb index 2dda476277..3824b9761f 100644 --- a/Library/Homebrew/cask/lib/hbc/dsl.rb +++ b/Library/Homebrew/cask/lib/hbc/dsl.rb @@ -161,7 +161,7 @@ module Hbc begin DSL::Container.new(*args).tap do |container| # TODO: remove this backward-compatibility section after removing nested_container - if container && container.nested + if container&.nested artifacts[:nested_container] << Artifact::NestedContainer.new(cask, container.nested) end end diff --git a/Library/Homebrew/cask/lib/hbc/installer.rb b/Library/Homebrew/cask/lib/hbc/installer.rb index b9c34e3a1d..01aae935df 100644 --- a/Library/Homebrew/cask/lib/hbc/installer.rb +++ b/Library/Homebrew/cask/lib/hbc/installer.rb @@ -159,7 +159,7 @@ module Hbc odebug "Extracting primary container" FileUtils.mkdir_p @cask.staged_path - container = if @cask.container && @cask.container.type + container = if @cask.container&.type Container.from_type(@cask.container.type) else Container.for_path(@downloaded_path, @command) @@ -361,7 +361,7 @@ module Hbc savedir = @cask.metadata_subdir("Casks", timestamp: :now, create: true) FileUtils.copy @cask.sourcefile_path, savedir - old_savedir.rmtree unless old_savedir.nil? + old_savedir&.rmtree end def uninstall diff --git a/Library/Homebrew/cask/lib/hbc/system_command.rb b/Library/Homebrew/cask/lib/hbc/system_command.rb index b735ae4f9c..be083c29ef 100644 --- a/Library/Homebrew/cask/lib/hbc/system_command.rb +++ b/Library/Homebrew/cask/lib/hbc/system_command.rb @@ -61,7 +61,7 @@ module Hbc end def assert_success - return if processed_status && processed_status.success? + return if processed_status&.success? raise CaskCommandFailedError.new(command, processed_output[:stdout], processed_output[:stderr], processed_status) end diff --git a/Library/Homebrew/caveats.rb b/Library/Homebrew/caveats.rb index 578b292fab..1849ea79b3 100644 --- a/Library/Homebrew/caveats.rb +++ b/Library/Homebrew/caveats.rb @@ -163,7 +163,7 @@ class Caveats def plist_caveats s = [] - if f.plist || (keg && keg.plist_installed?) + if f.plist || (keg&.plist_installed?) plist_domain = f.plist_path.basename(".plist") # we readlink because this path probably doesn't exist since caveats diff --git a/Library/Homebrew/cmd/unlinkapps.rb b/Library/Homebrew/cmd/unlinkapps.rb index 7cae97e27c..56dba3603c 100644 --- a/Library/Homebrew/cmd/unlinkapps.rb +++ b/Library/Homebrew/cmd/unlinkapps.rb @@ -77,7 +77,7 @@ module Homebrew def unlinkapps_unlink?(target_app, opts = {}) # Skip non-symlinks and symlinks that don't point into the Homebrew prefix. app = target_app.readlink.to_s if target_app.symlink? - return false unless app && app.start_with?(*UNLINKAPPS_PREFIXES) + return false unless app&.start_with?(*UNLINKAPPS_PREFIXES) if opts.fetch(:prune, false) !File.exist?(app) # Remove only broken symlinks in prune mode. diff --git a/Library/Homebrew/debrew/irb.rb b/Library/Homebrew/debrew/irb.rb index f974037820..069dbe6760 100644 --- a/Library/Homebrew/debrew/irb.rb +++ b/Library/Homebrew/debrew/irb.rb @@ -16,7 +16,7 @@ module IRB workspace = WorkSpace.new(binding) irb = Irb.new(workspace) - @CONF[:IRB_RC].call(irb.context) if @CONF[:IRB_RC] + @CONF[:IRB_RC]&.call(irb.context) @CONF[:MAIN_CONTEXT] = irb.context trap("SIGINT") do diff --git a/Library/Homebrew/dependency.rb b/Library/Homebrew/dependency.rb index d7d5ec59c0..0fbc2625b1 100644 --- a/Library/Homebrew/dependency.rb +++ b/Library/Homebrew/dependency.rb @@ -51,7 +51,7 @@ class Dependency end def modify_build_environment - env_proc.call unless env_proc.nil? + env_proc&.call end def inspect diff --git a/Library/Homebrew/dev-cmd/audit.rb b/Library/Homebrew/dev-cmd/audit.rb index 743b9484ef..1fb89c3a4b 100644 --- a/Library/Homebrew/dev-cmd/audit.rb +++ b/Library/Homebrew/dev-cmd/audit.rb @@ -707,7 +707,7 @@ class FormulaAuditor end stable = formula.stable - case stable && stable.url + case stable&.url when /[\d\._-](alpha|beta|rc\d)/ matched = Regexp.last_match(1) version_prefix = stable.version.to_s.sub(/\d+$/, "") @@ -1018,7 +1018,7 @@ class FormulaAuditor def audit_reverse_migration # Only enforce for new formula being re-added to core and official taps return unless @strict - return unless formula.tap && formula.tap.official? + return unless formula.tap&.official? return unless formula.tap.tap_migrations.key?(formula.name) problem <<-EOS.undent diff --git a/Library/Homebrew/dev-cmd/bottle.rb b/Library/Homebrew/dev-cmd/bottle.rb index d8aefc4c0d..577924a340 100644 --- a/Library/Homebrew/dev-cmd/bottle.rb +++ b/Library/Homebrew/dev-cmd/bottle.rb @@ -283,7 +283,7 @@ module Homebrew raise ensure ignore_interrupts do - original_tab.write if original_tab + original_tab&.write unless ARGV.include? "--skip-relocation" keg.replace_placeholders_with_locations changed_files end diff --git a/Library/Homebrew/dev-cmd/bump-formula-pr.rb b/Library/Homebrew/dev-cmd/bump-formula-pr.rb index 521c763023..87a239b986 100644 --- a/Library/Homebrew/dev-cmd/bump-formula-pr.rb +++ b/Library/Homebrew/dev-cmd/bump-formula-pr.rb @@ -124,7 +124,7 @@ module Homebrew Formula.each do |f| if is_devel && f.devel && f.devel.url && f.devel.url.match(base_url) guesses << f - elsif f.stable && f.stable.url && f.stable.url.match(base_url) + elsif f.stable&.url && f.stable.url.match(base_url) guesses << f end end diff --git a/Library/Homebrew/dev-cmd/pull.rb b/Library/Homebrew/dev-cmd/pull.rb index a8f35531f9..931cba07f5 100644 --- a/Library/Homebrew/dev-cmd/pull.rb +++ b/Library/Homebrew/dev-cmd/pull.rb @@ -75,7 +75,7 @@ module Homebrew tap = CoreTap.instance elsif (testing_match = arg.match %r{/job/Homebrew.*Testing/(\d+)/}) tap = ARGV.value("tap") - tap = if tap && tap.start_with?("homebrew/") + tap = if tap&.start_with?("homebrew/") Tap.fetch("homebrew", tap.strip_prefix("homebrew/")) elsif tap odie "Tap option did not start with \"homebrew/\": #{tap}" @@ -350,7 +350,7 @@ module Homebrew files << Regexp.last_match(1) if line =~ %r{^\+\+\+ b/(.*)} end files.each do |file| - if tap && tap.formula_file?(file) + if tap&.formula_file?(file) formula_name = File.basename(file, ".rb") formulae << formula_name unless formulae.include?(formula_name) else diff --git a/Library/Homebrew/dev-cmd/release-notes.rb b/Library/Homebrew/dev-cmd/release-notes.rb index e578869bf7..4960239565 100644 --- a/Library/Homebrew/dev-cmd/release-notes.rb +++ b/Library/Homebrew/dev-cmd/release-notes.rb @@ -10,10 +10,8 @@ module Homebrew def release_notes previous_tag = ARGV.named.first - unless previous_tag - previous_tag = Utils.popen_read("git tag --list --sort=-version:refname") + previous_tag ||= Utils.popen_read("git tag --list --sort=-version:refname") .lines.first.chomp - end odie "Could not find any previous tags!" unless previous_tag end_ref = ARGV.named[1] || "origin/master" diff --git a/Library/Homebrew/diagnostic.rb b/Library/Homebrew/diagnostic.rb index ceb6ad4d1d..88aa4dbc90 100644 --- a/Library/Homebrew/diagnostic.rb +++ b/Library/Homebrew/diagnostic.rb @@ -522,7 +522,7 @@ module Homebrew homebrew_owned = @found.all? do |path| Pathname.new(path).realpath.to_s.start_with? "#{HOMEBREW_CELLAR}/gettext" end - return if gettext && gettext.linked_keg.directory? && homebrew_owned + return if gettext&.linked_keg&.directory? && homebrew_owned inject_file_list @found, <<-EOS.undent gettext files detected at a system prefix. @@ -540,7 +540,7 @@ module Homebrew rescue nil end - if libiconv && libiconv.linked_keg.directory? + if libiconv&.linked_keg&.directory? unless libiconv.keg_only? <<-EOS.undent A libiconv formula is installed and linked. diff --git a/Library/Homebrew/extend/ARGV.rb b/Library/Homebrew/extend/ARGV.rb index daa5306faf..63a0f3e40b 100644 --- a/Library/Homebrew/extend/ARGV.rb +++ b/Library/Homebrew/extend/ARGV.rb @@ -144,7 +144,7 @@ module HomebrewArgvExtension def value(name) arg_prefix = "--#{name}=" flag_with_value = find { |arg| arg.start_with?(arg_prefix) } - flag_with_value.strip_prefix(arg_prefix) if flag_with_value + flag_with_value&.strip_prefix(arg_prefix) end # Returns an array of values that were given as a comma-separated list. @@ -236,7 +236,7 @@ module HomebrewArgvExtension def bottle_arch arch = value "bottle-arch" - arch.to_sym if arch + arch&.to_sym end def build_from_source? diff --git a/Library/Homebrew/formula.rb b/Library/Homebrew/formula.rb index 2f0c913c21..69a4cd5aaf 100644 --- a/Library/Homebrew/formula.rb +++ b/Library/Homebrew/formula.rb @@ -472,7 +472,7 @@ class Formula return true if devel && tab.devel_version && tab.devel_version < devel.version if options[:fetch_head] - return false unless head && head.downloader.is_a?(VCSDownloadStrategy) + return false unless head&.downloader.is_a?(VCSDownloadStrategy) downloader = head.downloader downloader.shutup! unless ARGV.verbose? downloader.commit_outdated?(version.version.commit) @@ -1115,8 +1115,8 @@ class Formula # @private def unlock - @lock.unlock unless @lock.nil? - @oldname_lock.unlock unless @oldname_lock.nil? + @lock&.unlock + @oldname_lock&.unlock end def migration_needed? @@ -1440,7 +1440,7 @@ class Formula # True if this formula is provided by Homebrew itself # @private def core_formula? - tap && tap.core_tap? + tap&.core_tap? end # True if this formula is provided by external Tap @@ -1525,10 +1525,10 @@ class Formula "oldname" => oldname, "aliases" => aliases, "versions" => { - "stable" => (stable.version.to_s if stable), + "stable" => stable&.version.to_s, "bottle" => bottle ? true : false, - "devel" => (devel.version.to_s if devel), - "head" => (head.version.to_s if head), + "devel" => devel&.version.to_s, + "head" => head&.version.to_s, }, "revision" => revision, "version_scheme" => version_scheme, diff --git a/Library/Homebrew/formula_installer.rb b/Library/Homebrew/formula_installer.rb index e955dcf074..68816a7824 100644 --- a/Library/Homebrew/formula_installer.rb +++ b/Library/Homebrew/formula_installer.rb @@ -560,7 +560,7 @@ class FormulaInstaller end raise else - ignore_interrupts { tmp_keg.rmtree if tmp_keg && tmp_keg.directory? } + ignore_interrupts { tmp_keg.rmtree if tmp_keg&.directory? } end def caveats diff --git a/Library/Homebrew/keg.rb b/Library/Homebrew/keg.rb index 92eab7ad31..677a97c85b 100644 --- a/Library/Homebrew/keg.rb +++ b/Library/Homebrew/keg.rb @@ -338,7 +338,7 @@ class Keg dir if dir.directory? && dir.children.any? { |f| f.basename.to_s.start_with?("_") } when :fish then path/"share/fish/vendor_completions.d" end - dir && dir.directory? && !dir.children.empty? + dir&.directory? && !dir.children.empty? end def functions_installed?(shell) diff --git a/Library/Homebrew/language/python.rb b/Library/Homebrew/language/python.rb index 0f8e3a4e62..bfec556d03 100644 --- a/Library/Homebrew/language/python.rb +++ b/Library/Homebrew/language/python.rb @@ -23,7 +23,7 @@ module Language else homebrew_site_packages(version) end - block.call python, version if block + block&.call python, version end ENV["PYTHONPATH"] = original_pythonpath end diff --git a/Library/Homebrew/os/mac.rb b/Library/Homebrew/os/mac.rb index d3e5cb38ca..15c301f994 100644 --- a/Library/Homebrew/os/mac.rb +++ b/Library/Homebrew/os/mac.rb @@ -104,7 +104,7 @@ module OS # Returns the path to an SDK or nil, following the rules set by #sdk. def sdk_path(v = nil) s = sdk(v) - s.path unless s.nil? + s&.path end # See these issues for some history: diff --git a/Library/Homebrew/requirements/java_requirement.rb b/Library/Homebrew/requirements/java_requirement.rb index ab6dca51df..de3a33eb45 100644 --- a/Library/Homebrew/requirements/java_requirement.rb +++ b/Library/Homebrew/requirements/java_requirement.rb @@ -69,14 +69,14 @@ class JavaRequirement < Requirement rescue FormulaUnavailableError nil end - javas << jdk.bin/"java" if jdk && jdk.installed? + javas << jdk.bin/"java" if jdk&.installed? javas << which("java") javas end def preferred_java possible_javas.detect do |java| - next false unless java && java.executable? + next false unless java&.executable? next true unless @version next true if satisfies_version(java) end diff --git a/Library/Homebrew/requirements/ruby_requirement.rb b/Library/Homebrew/requirements/ruby_requirement.rb index acc6559248..a9ec8c42d2 100644 --- a/Library/Homebrew/requirements/ruby_requirement.rb +++ b/Library/Homebrew/requirements/ruby_requirement.rb @@ -41,9 +41,7 @@ class RubyRequirement < Requirement def rubies rubies = which_all("ruby") ruby_formula = Formula["ruby"] - if ruby_formula && ruby_formula.installed? - rubies.unshift ruby_formula.bin/"ruby" - end + rubies.unshift ruby_formula.bin/"ruby" if ruby_formula&.installed? rubies.uniq end diff --git a/Library/Homebrew/sandbox.rb b/Library/Homebrew/sandbox.rb index 8c662857e3..7d23e59664 100644 --- a/Library/Homebrew/sandbox.rb +++ b/Library/Homebrew/sandbox.rb @@ -167,7 +167,7 @@ class Sandbox def add_rule(rule) s = "(" - s << ((rule[:allow]) ? "allow" : "deny") + s << (rule[:allow] ? "allow" : "deny") s << " #{rule[:operation]}" s << " (#{rule[:filter]})" if rule[:filter] s << " (with #{rule[:modifier]})" if rule[:modifier] diff --git a/Library/Homebrew/tab.rb b/Library/Homebrew/tab.rb index e7df883561..af19cabe67 100644 --- a/Library/Homebrew/tab.rb +++ b/Library/Homebrew/tab.rb @@ -324,7 +324,7 @@ class Tab < OpenStruct "poured_from_bottle" => poured_from_bottle, "installed_as_dependency" => installed_as_dependency, "installed_on_request" => installed_on_request, - "changed_files" => changed_files && changed_files.map(&:to_s), + "changed_files" => changed_files&.map(&:to_s), "time" => time, "source_modified_time" => source_modified_time.to_i, "HEAD" => self.HEAD, From cf5fdeef1d8e9fd053121145882835b87eec2a43 Mon Sep 17 00:00:00 2001 From: Mike McQuaid Date: Sun, 24 Sep 2017 20:12:58 +0100 Subject: [PATCH 227/294] Rubocop: manual rule fixes. --- Library/Homebrew/brew.rb | 20 +++++++--------- .../Homebrew/cask/lib/hbc/container/naked.rb | 2 +- Library/Homebrew/cask/lib/hbc/dsl/version.rb | 2 +- Library/Homebrew/cmd/prune.rb | 2 +- Library/Homebrew/cmd/search.rb | 2 +- Library/Homebrew/cmd/tap-info.rb | 4 ++-- Library/Homebrew/debrew.rb | 2 +- Library/Homebrew/dev-cmd/audit.rb | 2 +- Library/Homebrew/dev-cmd/bottle.rb | 4 ++-- Library/Homebrew/dev-cmd/bump-formula-pr.rb | 2 +- Library/Homebrew/dev-cmd/pull.rb | 2 +- Library/Homebrew/exceptions.rb | 2 +- Library/Homebrew/extend/ENV.rb | 2 +- Library/Homebrew/extend/ENV/std.rb | 4 ++-- Library/Homebrew/formula.rb | 8 ++++--- Library/Homebrew/formula_installer.rb | 2 +- Library/Homebrew/install_renamed.rb | 8 +++---- Library/Homebrew/locale.rb | 2 -- Library/Homebrew/options.rb | 24 +++++++++---------- Library/Homebrew/pkg_version.rb | 2 +- .../Homebrew/rubocops/components_order_cop.rb | 4 ++-- Library/Homebrew/software_spec.rb | 2 +- Library/Homebrew/tap.rb | 1 - Library/Homebrew/utils/github.rb | 12 +++------- Library/Homebrew/utils/shell.rb | 4 ---- 25 files changed, 54 insertions(+), 67 deletions(-) diff --git a/Library/Homebrew/brew.rb b/Library/Homebrew/brew.rb index ec86bd7941..2906fd93d8 100644 --- a/Library/Homebrew/brew.rb +++ b/Library/Homebrew/brew.rb @@ -105,18 +105,16 @@ begin possible_tap = OFFICIAL_CMD_TAPS.find { |_, cmds| cmds.include?(cmd) } possible_tap = Tap.fetch(possible_tap.first) if possible_tap - if possible_tap && !possible_tap.installed? - brew_uid = HOMEBREW_BREW_FILE.stat.uid - tap_commands = [] - if Process.uid.zero? && !brew_uid.zero? - tap_commands += %W[/usr/bin/sudo -u ##{brew_uid}] - end - tap_commands += %W[#{HOMEBREW_BREW_FILE} tap #{possible_tap}] - safe_system(*tap_commands) - exec HOMEBREW_BREW_FILE, cmd, *ARGV - else - odie "Unknown command: #{cmd}" + odie "Unknown command: #{cmd}" if !possible_tap || possible_tap.installed? + + brew_uid = HOMEBREW_BREW_FILE.stat.uid + tap_commands = [] + if Process.uid.zero? && !brew_uid.zero? + tap_commands += %W[/usr/bin/sudo -u ##{brew_uid}] end + tap_commands += %W[#{HOMEBREW_BREW_FILE} tap #{possible_tap}] + safe_system(*tap_commands) + exec HOMEBREW_BREW_FILE, cmd, *ARGV end rescue UsageError => e require "cmd/help" diff --git a/Library/Homebrew/cask/lib/hbc/container/naked.rb b/Library/Homebrew/cask/lib/hbc/container/naked.rb index 375d62f7ae..dc265c4025 100644 --- a/Library/Homebrew/cask/lib/hbc/container/naked.rb +++ b/Library/Homebrew/cask/lib/hbc/container/naked.rb @@ -16,7 +16,7 @@ module Hbc def target_file return @path.basename if @nested - URI.decode(File.basename(@cask.url.path)) + CGI.unescape(File.basename(@cask.url.path)) end end end diff --git a/Library/Homebrew/cask/lib/hbc/dsl/version.rb b/Library/Homebrew/cask/lib/hbc/dsl/version.rb index d73205f528..9605feb579 100644 --- a/Library/Homebrew/cask/lib/hbc/dsl/version.rb +++ b/Library/Homebrew/cask/lib/hbc/dsl/version.rb @@ -49,7 +49,7 @@ module Hbc end end - DIVIDERS.keys.each do |divider| + DIVIDERS.each_key do |divider| define_divider_methods(divider) end diff --git a/Library/Homebrew/cmd/prune.rb b/Library/Homebrew/cmd/prune.rb index 9fc6dbcd97..7ec2838bae 100644 --- a/Library/Homebrew/cmd/prune.rb +++ b/Library/Homebrew/cmd/prune.rb @@ -55,7 +55,7 @@ module Homebrew else n, d = ObserverPathnameExtension.counts print "Pruned #{n} symbolic links " - print "and #{d} directories " if d > 0 + print "and #{d} directories " if d.positive? puts "from #{HOMEBREW_PREFIX}" end end diff --git a/Library/Homebrew/cmd/search.rb b/Library/Homebrew/cmd/search.rb index acee9817fd..c01a11c104 100644 --- a/Library/Homebrew/cmd/search.rb +++ b/Library/Homebrew/cmd/search.rb @@ -67,7 +67,7 @@ module Homebrew ohai "Searching blacklisted, migrated and deleted formulae..." if reason = Homebrew::MissingFormula.reason(query, silent: true) - if count > 0 + if count.positive? puts puts "If you meant #{query.inspect} specifically:" end diff --git a/Library/Homebrew/cmd/tap-info.rb b/Library/Homebrew/cmd/tap-info.rb index af087645d2..cb0e0b387e 100644 --- a/Library/Homebrew/cmd/tap-info.rb +++ b/Library/Homebrew/cmd/tap-info.rb @@ -64,10 +64,10 @@ module Homebrew if tap.installed? info += tap.pinned? ? "pinned" : "unpinned" info += ", private" if tap.private? - if (formula_count = tap.formula_files.size) > 0 + if (formula_count = tap.formula_files.size).positive? info += ", #{Formatter.pluralize(formula_count, "formula")}" end - if (command_count = tap.command_files.size) > 0 + if (command_count = tap.command_files.size).positive? info += ", #{Formatter.pluralize(command_count, "command")}" end info += ", no formulae/commands" if (formula_count + command_count).zero? diff --git a/Library/Homebrew/debrew.rb b/Library/Homebrew/debrew.rb index c2662c9eee..5bc3d2daad 100644 --- a/Library/Homebrew/debrew.rb +++ b/Library/Homebrew/debrew.rb @@ -57,7 +57,7 @@ module Debrew input.chomp! i = input.to_i - if i > 0 + if i.positive? choice = menu.entries[i - 1] else possible = menu.entries.find_all { |e| e.name.start_with?(input) } diff --git a/Library/Homebrew/dev-cmd/audit.rb b/Library/Homebrew/dev-cmd/audit.rb index 1fb89c3a4b..a7d498c0d5 100644 --- a/Library/Homebrew/dev-cmd/audit.rb +++ b/Library/Homebrew/dev-cmd/audit.rb @@ -358,7 +358,7 @@ class FormulaAuditor end valid_alias_names = [alias_name_major, alias_name_major_minor] - if formula.tap && !formula.tap.core_tap? + unless formula.tap&.core_tap? versioned_aliases.map! { |a| "#{formula.tap}/#{a}" } valid_alias_names.map! { |a| "#{formula.tap}/#{a}" } end diff --git a/Library/Homebrew/dev-cmd/bottle.rb b/Library/Homebrew/dev-cmd/bottle.rb index 577924a340..8dfd0d12c6 100644 --- a/Library/Homebrew/dev-cmd/bottle.rb +++ b/Library/Homebrew/dev-cmd/bottle.rb @@ -47,7 +47,7 @@ BOTTLE_ERB = <<-EOS.freeze <% elsif cellar != BottleSpecification::DEFAULT_CELLAR %> cellar "<%= cellar %>" <% end %> - <% if rebuild > 0 %> + <% if rebuild.positive? %> rebuild <%= rebuild %> <% end %> <% checksums.each do |checksum_type, checksum_values| %> @@ -186,7 +186,7 @@ module Homebrew ohai "Determining #{f.full_name} bottle rebuild..." versions = FormulaVersions.new(f) rebuilds = versions.bottle_version_map("origin/master")[f.pkg_version] - rebuilds.pop if rebuilds.last.to_i > 0 + rebuilds.pop if rebuilds.last.to_i.positive? rebuild = rebuilds.empty? ? 0 : rebuilds.max.to_i + 1 end diff --git a/Library/Homebrew/dev-cmd/bump-formula-pr.rb b/Library/Homebrew/dev-cmd/bump-formula-pr.rb index 87a239b986..21abed7d91 100644 --- a/Library/Homebrew/dev-cmd/bump-formula-pr.rb +++ b/Library/Homebrew/dev-cmd/bump-formula-pr.rb @@ -89,7 +89,7 @@ module Homebrew def check_for_duplicate_pull_requests(formula) pull_requests = fetch_pull_requests(formula) - return unless pull_requests && !pull_requests.empty? + return unless pull_requests&.empty? duplicates_message = <<-EOS.undent These open pull requests may be duplicates: #{pull_requests.map { |pr| "#{pr["title"]} #{pr["html_url"]}" }.join("\n")} diff --git a/Library/Homebrew/dev-cmd/pull.rb b/Library/Homebrew/dev-cmd/pull.rb index 931cba07f5..cd0d6fbd06 100644 --- a/Library/Homebrew/dev-cmd/pull.rb +++ b/Library/Homebrew/dev-cmd/pull.rb @@ -69,7 +69,7 @@ module Homebrew tap = nil ARGV.named.each do |arg| - if arg.to_i > 0 + if arg.to_i.positive? issue = arg url = "https://github.com/Homebrew/homebrew-core/pull/#{arg}" tap = CoreTap.instance diff --git a/Library/Homebrew/exceptions.rb b/Library/Homebrew/exceptions.rb index 8b4cddc591..5418f93310 100644 --- a/Library/Homebrew/exceptions.rb +++ b/Library/Homebrew/exceptions.rb @@ -416,7 +416,7 @@ class BuildError < RuntimeError puts - if issues && !issues.empty? + unless issues&.empty? puts "These open issues may also help:" puts issues.map { |i| "#{i["title"]} #{i["html_url"]}" }.join("\n") end diff --git a/Library/Homebrew/extend/ENV.rb b/Library/Homebrew/extend/ENV.rb index 283e90b696..ea1b995011 100644 --- a/Library/Homebrew/extend/ENV.rb +++ b/Library/Homebrew/extend/ENV.rb @@ -28,7 +28,7 @@ module EnvActivation end def clear_sensitive_environment! - ENV.keys.each do |key| + ENV.each_key do |key| next unless /(cookie|key|token)/i =~ key ENV.delete key end diff --git a/Library/Homebrew/extend/ENV/std.rb b/Library/Homebrew/extend/ENV/std.rb index a2e800803f..4e5d0683ae 100644 --- a/Library/Homebrew/extend/ENV/std.rb +++ b/Library/Homebrew/extend/ENV/std.rb @@ -233,8 +233,8 @@ module Stdenv def make_jobs # '-j' requires a positive integral argument - if self["HOMEBREW_MAKE_JOBS"].to_i > 0 - self["HOMEBREW_MAKE_JOBS"].to_i + if (jobs = self["HOMEBREW_MAKE_JOBS"].to_i).positive? + jobs else Hardware::CPU.cores end diff --git a/Library/Homebrew/formula.rb b/Library/Homebrew/formula.rb index 69a4cd5aaf..d999b9c5fe 100644 --- a/Library/Homebrew/formula.rb +++ b/Library/Homebrew/formula.rb @@ -1182,7 +1182,8 @@ class Formula # Returns false if the formula wasn't installed with an alias. def installed_alias_target_changed? target = current_installed_alias_target - target && target.name != name + return false unless target + target.name != name end # Is this formula the target of an alias used to install an old formula? @@ -1446,7 +1447,8 @@ class Formula # True if this formula is provided by external Tap # @private def tap? - tap && !tap.core_tap? + return false unless tap + !tap.core_tap? end # @private @@ -1570,7 +1572,7 @@ class Formula "root_url" => bottle_spec.root_url, } bottle_info["files"] = {} - bottle_spec.collector.keys.each do |os| + bottle_spec.collector.keys.each do |os| # rubocop:disable Performance/HashEachMethods checksum = bottle_spec.collector[os] bottle_info["files"][os] = { "url" => "#{bottle_spec.root_url}/#{Bottle::Filename.create(self, os, bottle_spec.rebuild)}", diff --git a/Library/Homebrew/formula_installer.rb b/Library/Homebrew/formula_installer.rb index 68816a7824..b4f9db8458 100644 --- a/Library/Homebrew/formula_installer.rb +++ b/Library/Homebrew/formula_installer.rb @@ -269,7 +269,7 @@ class FormulaInstaller oh1 "Installing #{Formatter.identifier(formula.full_name)} #{options}".strip end - if formula.tap && !formula.tap.private? + unless formula.tap&.private? action = "#{formula.full_name} #{options}".strip Utils::Analytics.report_event("install", action) diff --git a/Library/Homebrew/install_renamed.rb b/Library/Homebrew/install_renamed.rb index 5e200244f3..dc5d4cda8b 100644 --- a/Library/Homebrew/install_renamed.rb +++ b/Library/Homebrew/install_renamed.rb @@ -16,12 +16,12 @@ module InstallRenamed end end - def +(path) - super(path).extend(InstallRenamed) + def +(other) + super(other).extend(InstallRenamed) end - def /(path) - super(path).extend(InstallRenamed) + def /(other) + super(other).extend(InstallRenamed) end private diff --git a/Library/Homebrew/locale.rb b/Library/Homebrew/locale.rb index 5e778f3b4d..d918e2a2a4 100644 --- a/Library/Homebrew/locale.rb +++ b/Library/Homebrew/locale.rb @@ -44,8 +44,6 @@ class Locale raise ParserError, "'#{value}' does not match #{regex}" unless value =~ regex instance_variable_set(:"@#{key}", value) end - - self end def include?(other) diff --git a/Library/Homebrew/options.rb b/Library/Homebrew/options.rb index 9f12535317..05dd643ffe 100644 --- a/Library/Homebrew/options.rb +++ b/Library/Homebrew/options.rb @@ -69,29 +69,29 @@ class Options @options.each(*args, &block) end - def <<(o) - @options << o + def <<(other) + @options << other self end - def +(o) - self.class.new(@options + o) + def +(other) + self.class.new(@options + other) end - def -(o) - self.class.new(@options - o) + def -(other) + self.class.new(@options - other) end - def &(o) - self.class.new(@options & o) + def &(other) + self.class.new(@options & other) end - def |(o) - self.class.new(@options | o) + def |(other) + self.class.new(@options | other) end - def *(arg) - @options.to_a * arg + def *(other) + @options.to_a * other end def empty? diff --git a/Library/Homebrew/pkg_version.rb b/Library/Homebrew/pkg_version.rb index 761a349fda..b68d78cf8e 100644 --- a/Library/Homebrew/pkg_version.rb +++ b/Library/Homebrew/pkg_version.rb @@ -23,7 +23,7 @@ class PkgVersion end def to_s - if revision > 0 + if revision.positive? "#{version}_#{revision}" else version.to_s diff --git a/Library/Homebrew/rubocops/components_order_cop.rb b/Library/Homebrew/rubocops/components_order_cop.rb index f1179d9a4d..3bf2ede160 100644 --- a/Library/Homebrew/rubocops/components_order_cop.rb +++ b/Library/Homebrew/rubocops/components_order_cop.rb @@ -87,8 +87,8 @@ module RuboCop # preceding_comp_arr: array containing components of same type order_idx, curr_p_idx, preceding_comp_arr = get_state(node1) - # curr_p_idx > 0 means node1 needs to be grouped with its own kind - if curr_p_idx > 0 + # curr_p_idx.positive? means node1 needs to be grouped with its own kind + if curr_p_idx.positive? node2 = preceding_comp_arr[curr_p_idx - 1] indentation = " " * (start_column(node2) - line_start_column(node2)) line_breaks = node2.multiline? ? "\n\n" : "\n" diff --git a/Library/Homebrew/software_spec.rb b/Library/Homebrew/software_spec.rb index 49d818f0fa..dd6026fcf4 100644 --- a/Library/Homebrew/software_spec.rb +++ b/Library/Homebrew/software_spec.rb @@ -267,7 +267,7 @@ class Bottle end def suffix - s = (rebuild > 0) ? ".#{rebuild}" : "" + s = rebuild.positive? ? ".#{rebuild}" : "" ".bottle#{s}.tar.gz" end end diff --git a/Library/Homebrew/tap.rb b/Library/Homebrew/tap.rb index f6246aad90..f4e7631b49 100644 --- a/Library/Homebrew/tap.rb +++ b/Library/Homebrew/tap.rb @@ -648,6 +648,5 @@ class TapConfig tap.path.cd do safe_system "git", "config", "--local", "--replace-all", "homebrew.#{key}", value.to_s end - value end end diff --git a/Library/Homebrew/utils/github.rb b/Library/Homebrew/utils/github.rb index a50d6d8e58..df0811e954 100644 --- a/Library/Homebrew/utils/github.rb +++ b/Library/Homebrew/utils/github.rb @@ -86,15 +86,9 @@ module GitHub def api_credentials_type token, username = api_credentials - if token && !token.empty? - if username && !username.empty? - :keychain - else - :environment - end - else - :none - end + return :none if !token || token.empty? + return :keychain if !username || username.empty? + :environment end def api_credentials_error_message(response_headers, needed_scopes) diff --git a/Library/Homebrew/utils/shell.rb b/Library/Homebrew/utils/shell.rb index 5327f6ecf6..8c1c5f984b 100644 --- a/Library/Homebrew/utils/shell.rb +++ b/Library/Homebrew/utils/shell.rb @@ -51,8 +51,6 @@ module Utils end end - private - SHELL_PROFILE_MAP = { bash: "~/.bash_profile", csh: "~/.cshrc", @@ -65,8 +63,6 @@ module Utils UNSAFE_SHELL_CHAR = %r{([^A-Za-z0-9_\-.,:/@\n])} - module_function - def csh_quote(str) # ruby's implementation of shell_escape str = str.to_s From 9697c8638cc11b8eace4b783d8d3114c24871007 Mon Sep 17 00:00:00 2001 From: Mike McQuaid Date: Mon, 25 Sep 2017 06:53:23 +0100 Subject: [PATCH 228/294] vendor-install: output only to stderr. This avoids causing errors in scripts that call e.g. `brew --prefix`. --- Library/Homebrew/cmd/vendor-install.sh | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Library/Homebrew/cmd/vendor-install.sh b/Library/Homebrew/cmd/vendor-install.sh index 4ffa176594..2277312443 100644 --- a/Library/Homebrew/cmd/vendor-install.sh +++ b/Library/Homebrew/cmd/vendor-install.sh @@ -48,17 +48,17 @@ fetch() { temporary_path="$CACHED_LOCATION.incomplete" mkdir -p "$HOMEBREW_CACHE" - [[ -n "$HOMEBREW_QUIET" ]] || echo "==> Downloading $VENDOR_URL" + [[ -n "$HOMEBREW_QUIET" ]] || echo "==> Downloading $VENDOR_URL" >&2 if [[ -f "$CACHED_LOCATION" ]] then - [[ -n "$HOMEBREW_QUIET" ]] || echo "Already downloaded: $CACHED_LOCATION" + [[ -n "$HOMEBREW_QUIET" ]] || echo "Already downloaded: $CACHED_LOCATION" >&2 else if [[ -f "$temporary_path" ]] then "$HOMEBREW_CURL" "${curl_args[@]}" -C - "$VENDOR_URL" -o "$temporary_path" if [[ $? -eq 33 ]] then - [[ -n "$HOMEBREW_QUIET" ]] || echo "Trying a full download" + [[ -n "$HOMEBREW_QUIET" ]] || echo "Trying a full download" >&2 rm -f "$temporary_path" "$HOMEBREW_CURL" "${curl_args[@]}" "$VENDOR_URL" -o "$temporary_path" fi @@ -135,7 +135,7 @@ install() { fi safe_cd "$VENDOR_DIR" - [[ -n "$HOMEBREW_QUIET" ]] || echo "==> Pouring $(basename "$VENDOR_URL")" + [[ -n "$HOMEBREW_QUIET" ]] || echo "==> Pouring $(basename "$VENDOR_URL")" >&2 tar "$tar_args" "$CACHED_LOCATION" safe_cd "$VENDOR_DIR/portable-$VENDOR_NAME" From 598ea0cdece3646ce1c202862e01a4464180ed88 Mon Sep 17 00:00:00 2001 From: Mike McQuaid Date: Mon, 25 Sep 2017 15:46:58 +0100 Subject: [PATCH 229/294] portable-ruby: fix installation on Leopard. Download it insecurely there and require `rubygems` for `Gem::Version`. --- Library/Homebrew/cmd/vendor-install.sh | 5 +++++ Library/Homebrew/utils/ruby.sh | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/Library/Homebrew/cmd/vendor-install.sh b/Library/Homebrew/cmd/vendor-install.sh index 2277312443..2e99c3b466 100644 --- a/Library/Homebrew/cmd/vendor-install.sh +++ b/Library/Homebrew/cmd/vendor-install.sh @@ -45,6 +45,11 @@ fetch() { curl_args[${#curl_args[*]}]="--progress-bar" fi + if [[ "$HOMEBREW_MACOS_VERSION_NUMERIC" -lt "100600" ]] + then + curl_args[${#curl_args[*]}]="--insecure" + fi + temporary_path="$CACHED_LOCATION.incomplete" mkdir -p "$HOMEBREW_CACHE" diff --git a/Library/Homebrew/utils/ruby.sh b/Library/Homebrew/utils/ruby.sh index 813bb09999..9a3ab2e818 100644 --- a/Library/Homebrew/utils/ruby.sh +++ b/Library/Homebrew/utils/ruby.sh @@ -37,7 +37,7 @@ setup-ruby-path() { if [[ -n "$HOMEBREW_RUBY_PATH" ]] then - ruby_old_version="$("$HOMEBREW_RUBY_PATH" -e "puts Gem::Version.new('$minimum_ruby_version') > Gem::Version.new(RUBY_VERSION)")" + ruby_old_version="$("$HOMEBREW_RUBY_PATH" -rrubygems -e "puts Gem::Version.new('$minimum_ruby_version') > Gem::Version.new(RUBY_VERSION)")" fi if [[ "$ruby_old_version" == "true" || -n "$HOMEBREW_FORCE_VENDOR_RUBY" ]] From dd75dd8a25b6e60b4f87c2220335e5bd37b9cc0f Mon Sep 17 00:00:00 2001 From: Mike McQuaid Date: Mon, 25 Sep 2017 18:35:18 +0100 Subject: [PATCH 230/294] os/mac/version: allow leopard_64_or_later bottles. --- Library/Homebrew/os/mac/version.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/Library/Homebrew/os/mac/version.rb b/Library/Homebrew/os/mac/version.rb index 89016bb4d1..db6dfcb1a6 100644 --- a/Library/Homebrew/os/mac/version.rb +++ b/Library/Homebrew/os/mac/version.rb @@ -12,6 +12,7 @@ module OS mountain_lion: "10.8", lion: "10.7", snow_leopard: "10.6", + leopard_64: "10.5", leopard: "10.5", tiger: "10.4", }.freeze From 745f5abc55fccdf7fb27b7ac4889bf8c8bcb5187 Mon Sep 17 00:00:00 2001 From: Mike McQuaid Date: Mon, 25 Sep 2017 18:50:07 +0100 Subject: [PATCH 231/294] README: add Commsworld logo. They host our physical hardware. --- README.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/README.md b/README.md index 4d63942ae2..a9684b5bba 100644 --- a/README.md +++ b/README.md @@ -65,6 +65,10 @@ Our Jenkins CI installation is hosted by [DigitalOcean](https://m.do.co/c/7e39c3 ![DigitalOcean](https://cloud.githubusercontent.com/assets/125011/26827038/4b7b5ade-4ab3-11e7-811b-fed3ab0e934d.png) +Our physical hardware is hosted by [Commsworld](https://www.commsworld.com). + +![Commsworld powered by Fluency](https://user-images.githubusercontent.com/125011/30822845-1716bc2c-a222-11e7-843e-ea7c7b6a1503.png) + Our bottles (binary packages) are hosted by [Bintray](https://bintray.com/homebrew). [![Downloads by Bintray](https://bintray.com/docs/images/downloads_by_bintray_96.png)](https://bintray.com/homebrew) From 222da9de1ce1b75433458a79a76e747408202cf9 Mon Sep 17 00:00:00 2001 From: Mike McQuaid Date: Mon, 25 Sep 2017 19:15:58 +0100 Subject: [PATCH 232/294] portable-ruby: use rebuild with coverage support. This will allow `simplecov` to generate coverage by rebuilding portable Ruby with coverage support. --- Library/Homebrew/cmd/vendor-install.sh | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/Library/Homebrew/cmd/vendor-install.sh b/Library/Homebrew/cmd/vendor-install.sh index 2277312443..6d16a297d5 100644 --- a/Library/Homebrew/cmd/vendor-install.sh +++ b/Library/Homebrew/cmd/vendor-install.sh @@ -13,8 +13,8 @@ if [[ -n "$HOMEBREW_MACOS" ]] then if [[ "$HOMEBREW_PROCESSOR" = "Intel" ]] then - ruby_URL="https://homebrew.bintray.com/bottles-portable/portable-ruby-2.3.3.leopard_64.bottle.tar.gz" - ruby_SHA="9060cdddbc5b5a0cc7188a251c40b2845e9d8b8ce346c83c585a965a111cab54" + ruby_URL="https://homebrew.bintray.com/bottles-portable/portable-ruby-2.3.3.leopard_64.bottle.1.tar.gz" + ruby_SHA="34ce9e4c9c1be28db564d744165aa29291426f8a3d2ef806ba4f0b9175aedb2b" else ruby_URL="" ruby_SHA="" @@ -45,6 +45,11 @@ fetch() { curl_args[${#curl_args[*]}]="--progress-bar" fi + if [[ "$HOMEBREW_MACOS_VERSION_NUMERIC" -lt "100600" ]] + then + curl_args[${#curl_args[*]}]="--insecure" + fi + temporary_path="$CACHED_LOCATION.incomplete" mkdir -p "$HOMEBREW_CACHE" From d618e574fb641de7d820208dec51bebe460cf32f Mon Sep 17 00:00:00 2001 From: William Woodruff Date: Mon, 28 Aug 2017 17:33:57 -0400 Subject: [PATCH 233/294] mach: Avoid reopening the file for relocation This commit allows the relocation code to perform install name and dylib ID changes without reopening the file separately. --- .../Homebrew/extend/os/mac/keg_relocate.rb | 15 +++++++--- Library/Homebrew/os/mac.rb | 1 - Library/Homebrew/os/mac/keg.rb | 29 ------------------- Library/Homebrew/os/mac/mach.rb | 28 ++++++++++++++++++ 4 files changed, 39 insertions(+), 34 deletions(-) delete mode 100644 Library/Homebrew/os/mac/keg.rb diff --git a/Library/Homebrew/extend/os/mac/keg_relocate.rb b/Library/Homebrew/extend/os/mac/keg_relocate.rb index 707710be61..7a1f42f8b5 100644 --- a/Library/Homebrew/extend/os/mac/keg_relocate.rb +++ b/Library/Homebrew/extend/os/mac/keg_relocate.rb @@ -2,7 +2,10 @@ class Keg def fix_dynamic_linkage mach_o_files.each do |file| file.ensure_writable do - change_dylib_id(dylib_id_for(file), file) if file.dylib? + if file.dylib? + @require_relocation = true + file.change_dylib_id(dylib_id_for(file)) + end each_install_name_for(file) do |bad_name| # Don't fix absolute paths unless they are rooted in the build directory @@ -11,7 +14,9 @@ class Keg !bad_name.start_with?(HOMEBREW_TEMP.realpath.to_s) new_name = fixed_name(file, bad_name) - change_install_name(bad_name, new_name, file) unless new_name == bad_name + + @require_relocation = true + file.change_install_name(bad_name, new_name, file) end end end @@ -23,8 +28,9 @@ class Keg mach_o_files.each do |file| file.ensure_writable do if file.dylib? + @require_relocation = true id = dylib_id_for(file).sub(relocation.old_prefix, relocation.new_prefix) - change_dylib_id(id, file) + file.change_dylib_id(id) end each_install_name_for(file) do |old_name| @@ -34,7 +40,8 @@ class Keg new_name = old_name.sub(relocation.old_prefix, relocation.new_prefix) end - change_install_name(old_name, new_name, file) if new_name + @require_relocation = true + file.change_install_name(old_name, new_name) if new_name end end end diff --git a/Library/Homebrew/os/mac.rb b/Library/Homebrew/os/mac.rb index 5074665fca..b2a3109f14 100644 --- a/Library/Homebrew/os/mac.rb +++ b/Library/Homebrew/os/mac.rb @@ -5,7 +5,6 @@ require "os/mac/xcode" require "os/mac/xquartz" require "os/mac/pathname" require "os/mac/sdk" -require "os/mac/keg" module OS module Mac diff --git a/Library/Homebrew/os/mac/keg.rb b/Library/Homebrew/os/mac/keg.rb deleted file mode 100644 index 6caadb1d7a..0000000000 --- a/Library/Homebrew/os/mac/keg.rb +++ /dev/null @@ -1,29 +0,0 @@ -class Keg - def change_dylib_id(id, file) - return if file.dylib_id == id - @require_relocation = true - puts "Changing dylib ID of #{file}\n from #{file.dylib_id}\n to #{id}" if ARGV.debug? - MachO::Tools.change_dylib_id(file, id, strict: false) - rescue MachO::MachOError - onoe <<-EOS.undent - Failed changing dylib ID of #{file} - from #{file.dylib_id} - to #{id} - EOS - raise - end - - def change_install_name(old, new, file) - return if old == new - @require_relocation = true - puts "Changing install name in #{file}\n from #{old}\n to #{new}" if ARGV.debug? - MachO::Tools.change_install_name(file, old, new, strict: false) - rescue MachO::MachOError - onoe <<-EOS.undent - Failed changing install name in #{file} - from #{old} - to #{new} - EOS - raise - end -end diff --git a/Library/Homebrew/os/mac/mach.rb b/Library/Homebrew/os/mac/mach.rb index 9b53c49797..29273cbaab 100644 --- a/Library/Homebrew/os/mac/mach.rb +++ b/Library/Homebrew/os/mac/mach.rb @@ -61,6 +61,34 @@ module MachOShim macho.dylib_id end + def change_dylib_id(id) + return if dylib_id == id + puts "Changing dylib ID of #{self}\n from #{dylib_id}\n to #{id}" if ARGV.debug? + macho.change_dylib_id(id, strict: false) + macho.write! + rescue MachO::MachOError + odie <<-EOS.undent + Failed changing dylib ID of #{self} + from #{file.dylib_id} + to #{id} + EOS + raise + end + + def change_install_name(old, new) + return if old == new + puts "Changing install name in #{self}\n from #{old}\n to #{new}" if ARGV.debug? + macho.change_install_name(old, new, strict: false) + macho.write! + rescue MachO::MachOError + odie <<-EOS.undent + Failed changing install name in #{self} + from #{old} + to #{new} + EOS + raise + end + def archs mach_data.map { |m| m.fetch :arch }.extend(ArchitectureListExtension) end From feda0242be174c63925a7e982cc05d6e9748acd8 Mon Sep 17 00:00:00 2001 From: ilovezfs Date: Mon, 25 Sep 2017 23:01:36 -0700 Subject: [PATCH 234/294] bump-formula-pr: fix duplicates check `return unless pull_requests && !pull_requests.empty?` and `return unless pull_requests&.empty?` are not equivalent. --- Library/Homebrew/dev-cmd/bump-formula-pr.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Library/Homebrew/dev-cmd/bump-formula-pr.rb b/Library/Homebrew/dev-cmd/bump-formula-pr.rb index 21abed7d91..87d8274ccb 100644 --- a/Library/Homebrew/dev-cmd/bump-formula-pr.rb +++ b/Library/Homebrew/dev-cmd/bump-formula-pr.rb @@ -89,7 +89,8 @@ module Homebrew def check_for_duplicate_pull_requests(formula) pull_requests = fetch_pull_requests(formula) - return unless pull_requests&.empty? + return unless pull_requests + return if pull_requests.empty? duplicates_message = <<-EOS.undent These open pull requests may be duplicates: #{pull_requests.map { |pr| "#{pr["title"]} #{pr["html_url"]}" }.join("\n")} From 9f57840486b764eb1f637deb972ea33939b40d01 Mon Sep 17 00:00:00 2001 From: mansimarkaur Date: Tue, 22 Aug 2017 17:03:22 +0530 Subject: [PATCH 235/294] test: Tests for os/mac/keg --- Library/Homebrew/test/os/mac/keg_spec.rb | 56 +++++++++++++++++------- 1 file changed, 41 insertions(+), 15 deletions(-) diff --git a/Library/Homebrew/test/os/mac/keg_spec.rb b/Library/Homebrew/test/os/mac/keg_spec.rb index 562c2ba6a6..4321c61cd2 100644 --- a/Library/Homebrew/test/os/mac/keg_spec.rb +++ b/Library/Homebrew/test/os/mac/keg_spec.rb @@ -5,28 +5,54 @@ describe Keg do subject { described_class.new(keg_path) } - describe "#mach_o_files" do - let(:keg_path) { HOMEBREW_CELLAR/"a/1.0" } + let(:keg_path) { HOMEBREW_CELLAR/"a/1.0" } + let(:file) { keg_path/"lib/i386.dylib" } - before(:each) { (keg_path/"lib").mkpath } + before(:each) do + (keg_path/"lib").mkpath + cp dylib_path("i386"), file + subject.link + end - after(:each) { subject.unlink } + after(:each) { subject.unlink } - it "skips hardlinks" do - cp dylib_path("i386"), keg_path/"lib/i386.dylib" - ln keg_path/"lib/i386.dylib", keg_path/"lib/i386_hardlink.dylib" + describe "#change_dylib_id" do + it "does nothing if given id is same as file's dylib id" do + id = file.dylib_id + file.change_dylib_id(id) + expect(file.dylib_id).to eq(id) + end + end - subject.link - expect(subject.mach_o_files.count).to eq(1) + describe "#change_install_name" do + it "does nothing if given name is same as file's install name" do + file.ensure_writable do + subject.each_install_name_for(file) do |name| + file.change_install_name(name, name) + expect(name).to eq(name) + end + end end - it "isn't confused by symlinks" do - cp dylib_path("i386"), keg_path/"lib/i386.dylib" - ln keg_path/"lib/i386.dylib", keg_path/"lib/i386_hardlink.dylib" - ln_s keg_path/"lib/i386.dylib", keg_path/"lib/i386_symlink.dylib" + it "does nothing when install name start with '/'" do + file.ensure_writable do + subject.each_install_name_for(file) do |name| + new_name = subject.fixed_name(file, name) + file.change_install_name(name, new_name) + expect(name).not_to eq(new_name) + end + end + end + end - subject.link - expect(subject.mach_o_files.count).to eq(1) + describe "#require_relocation?" do + it "is set to false at initialization" do + expect(subject.require_relocation?).to be false + end + + it "is set to true after linkage is fixed" do + subject.fix_dynamic_linkage + expect(subject.require_relocation?).to be true end end end From fc5b3778cb970e70444fe39aaa35d7baf19dc30b Mon Sep 17 00:00:00 2001 From: Steven Peters Date: Tue, 26 Sep 2017 17:30:28 -0700 Subject: [PATCH 236/294] keg_relocate: fix call to change_install_name During the changes to macho file relocation refactoring in #3101, #3138, and #3139, the number of arguments to the mach::change_install_name function changed from 3 to 2, but there was still an instance of the function being called with the wrong number of arguments. --- Library/Homebrew/extend/os/mac/keg_relocate.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Library/Homebrew/extend/os/mac/keg_relocate.rb b/Library/Homebrew/extend/os/mac/keg_relocate.rb index 7a1f42f8b5..2c27912cf8 100644 --- a/Library/Homebrew/extend/os/mac/keg_relocate.rb +++ b/Library/Homebrew/extend/os/mac/keg_relocate.rb @@ -16,7 +16,7 @@ class Keg new_name = fixed_name(file, bad_name) @require_relocation = true - file.change_install_name(bad_name, new_name, file) + file.change_install_name(bad_name, new_name) end end end From 0831f31e44d0ff6162eb85952197918025d5365a Mon Sep 17 00:00:00 2001 From: ilovezfs Date: Wed, 27 Sep 2017 02:07:22 -0700 Subject: [PATCH 237/294] Revert "keg_relocate: use correct number of arguments in call to change_install_name" --- Library/Homebrew/extend/os/mac/keg_relocate.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Library/Homebrew/extend/os/mac/keg_relocate.rb b/Library/Homebrew/extend/os/mac/keg_relocate.rb index 2c27912cf8..7a1f42f8b5 100644 --- a/Library/Homebrew/extend/os/mac/keg_relocate.rb +++ b/Library/Homebrew/extend/os/mac/keg_relocate.rb @@ -16,7 +16,7 @@ class Keg new_name = fixed_name(file, bad_name) @require_relocation = true - file.change_install_name(bad_name, new_name) + file.change_install_name(bad_name, new_name, file) end end end From e8da9613fbe21a409e85af56319ce13c33daffcf Mon Sep 17 00:00:00 2001 From: ilovezfs Date: Wed, 27 Sep 2017 02:08:23 -0700 Subject: [PATCH 238/294] Revert "mach: Avoid reopening the file for relocation" --- .../Homebrew/extend/os/mac/keg_relocate.rb | 15 +++------- Library/Homebrew/os/mac.rb | 1 + Library/Homebrew/os/mac/keg.rb | 29 +++++++++++++++++++ Library/Homebrew/os/mac/mach.rb | 28 ------------------ 4 files changed, 34 insertions(+), 39 deletions(-) create mode 100644 Library/Homebrew/os/mac/keg.rb diff --git a/Library/Homebrew/extend/os/mac/keg_relocate.rb b/Library/Homebrew/extend/os/mac/keg_relocate.rb index 7a1f42f8b5..707710be61 100644 --- a/Library/Homebrew/extend/os/mac/keg_relocate.rb +++ b/Library/Homebrew/extend/os/mac/keg_relocate.rb @@ -2,10 +2,7 @@ class Keg def fix_dynamic_linkage mach_o_files.each do |file| file.ensure_writable do - if file.dylib? - @require_relocation = true - file.change_dylib_id(dylib_id_for(file)) - end + change_dylib_id(dylib_id_for(file), file) if file.dylib? each_install_name_for(file) do |bad_name| # Don't fix absolute paths unless they are rooted in the build directory @@ -14,9 +11,7 @@ class Keg !bad_name.start_with?(HOMEBREW_TEMP.realpath.to_s) new_name = fixed_name(file, bad_name) - - @require_relocation = true - file.change_install_name(bad_name, new_name, file) + change_install_name(bad_name, new_name, file) unless new_name == bad_name end end end @@ -28,9 +23,8 @@ class Keg mach_o_files.each do |file| file.ensure_writable do if file.dylib? - @require_relocation = true id = dylib_id_for(file).sub(relocation.old_prefix, relocation.new_prefix) - file.change_dylib_id(id) + change_dylib_id(id, file) end each_install_name_for(file) do |old_name| @@ -40,8 +34,7 @@ class Keg new_name = old_name.sub(relocation.old_prefix, relocation.new_prefix) end - @require_relocation = true - file.change_install_name(old_name, new_name) if new_name + change_install_name(old_name, new_name, file) if new_name end end end diff --git a/Library/Homebrew/os/mac.rb b/Library/Homebrew/os/mac.rb index e8c92a6074..15c301f994 100644 --- a/Library/Homebrew/os/mac.rb +++ b/Library/Homebrew/os/mac.rb @@ -5,6 +5,7 @@ require "os/mac/xcode" require "os/mac/xquartz" require "os/mac/pathname" require "os/mac/sdk" +require "os/mac/keg" module OS module Mac diff --git a/Library/Homebrew/os/mac/keg.rb b/Library/Homebrew/os/mac/keg.rb new file mode 100644 index 0000000000..6caadb1d7a --- /dev/null +++ b/Library/Homebrew/os/mac/keg.rb @@ -0,0 +1,29 @@ +class Keg + def change_dylib_id(id, file) + return if file.dylib_id == id + @require_relocation = true + puts "Changing dylib ID of #{file}\n from #{file.dylib_id}\n to #{id}" if ARGV.debug? + MachO::Tools.change_dylib_id(file, id, strict: false) + rescue MachO::MachOError + onoe <<-EOS.undent + Failed changing dylib ID of #{file} + from #{file.dylib_id} + to #{id} + EOS + raise + end + + def change_install_name(old, new, file) + return if old == new + @require_relocation = true + puts "Changing install name in #{file}\n from #{old}\n to #{new}" if ARGV.debug? + MachO::Tools.change_install_name(file, old, new, strict: false) + rescue MachO::MachOError + onoe <<-EOS.undent + Failed changing install name in #{file} + from #{old} + to #{new} + EOS + raise + end +end diff --git a/Library/Homebrew/os/mac/mach.rb b/Library/Homebrew/os/mac/mach.rb index 29273cbaab..9b53c49797 100644 --- a/Library/Homebrew/os/mac/mach.rb +++ b/Library/Homebrew/os/mac/mach.rb @@ -61,34 +61,6 @@ module MachOShim macho.dylib_id end - def change_dylib_id(id) - return if dylib_id == id - puts "Changing dylib ID of #{self}\n from #{dylib_id}\n to #{id}" if ARGV.debug? - macho.change_dylib_id(id, strict: false) - macho.write! - rescue MachO::MachOError - odie <<-EOS.undent - Failed changing dylib ID of #{self} - from #{file.dylib_id} - to #{id} - EOS - raise - end - - def change_install_name(old, new) - return if old == new - puts "Changing install name in #{self}\n from #{old}\n to #{new}" if ARGV.debug? - macho.change_install_name(old, new, strict: false) - macho.write! - rescue MachO::MachOError - odie <<-EOS.undent - Failed changing install name in #{self} - from #{old} - to #{new} - EOS - raise - end - def archs mach_data.map { |m| m.fetch :arch }.extend(ArchitectureListExtension) end From 5377a42f7f3c3b561b011c75f0a386e5b64d3f58 Mon Sep 17 00:00:00 2001 From: ilovezfs Date: Wed, 27 Sep 2017 02:57:12 -0700 Subject: [PATCH 239/294] Revert "Added tests for os/mac/keg" --- Library/Homebrew/test/os/mac/keg_spec.rb | 56 +++++++----------------- 1 file changed, 15 insertions(+), 41 deletions(-) diff --git a/Library/Homebrew/test/os/mac/keg_spec.rb b/Library/Homebrew/test/os/mac/keg_spec.rb index 4321c61cd2..562c2ba6a6 100644 --- a/Library/Homebrew/test/os/mac/keg_spec.rb +++ b/Library/Homebrew/test/os/mac/keg_spec.rb @@ -5,54 +5,28 @@ describe Keg do subject { described_class.new(keg_path) } - let(:keg_path) { HOMEBREW_CELLAR/"a/1.0" } - let(:file) { keg_path/"lib/i386.dylib" } + describe "#mach_o_files" do + let(:keg_path) { HOMEBREW_CELLAR/"a/1.0" } - before(:each) do - (keg_path/"lib").mkpath - cp dylib_path("i386"), file - subject.link - end + before(:each) { (keg_path/"lib").mkpath } - after(:each) { subject.unlink } + after(:each) { subject.unlink } - describe "#change_dylib_id" do - it "does nothing if given id is same as file's dylib id" do - id = file.dylib_id - file.change_dylib_id(id) - expect(file.dylib_id).to eq(id) - end - end + it "skips hardlinks" do + cp dylib_path("i386"), keg_path/"lib/i386.dylib" + ln keg_path/"lib/i386.dylib", keg_path/"lib/i386_hardlink.dylib" - describe "#change_install_name" do - it "does nothing if given name is same as file's install name" do - file.ensure_writable do - subject.each_install_name_for(file) do |name| - file.change_install_name(name, name) - expect(name).to eq(name) - end - end + subject.link + expect(subject.mach_o_files.count).to eq(1) end - it "does nothing when install name start with '/'" do - file.ensure_writable do - subject.each_install_name_for(file) do |name| - new_name = subject.fixed_name(file, name) - file.change_install_name(name, new_name) - expect(name).not_to eq(new_name) - end - end - end - end + it "isn't confused by symlinks" do + cp dylib_path("i386"), keg_path/"lib/i386.dylib" + ln keg_path/"lib/i386.dylib", keg_path/"lib/i386_hardlink.dylib" + ln_s keg_path/"lib/i386.dylib", keg_path/"lib/i386_symlink.dylib" - describe "#require_relocation?" do - it "is set to false at initialization" do - expect(subject.require_relocation?).to be false - end - - it "is set to true after linkage is fixed" do - subject.fix_dynamic_linkage - expect(subject.require_relocation?).to be true + subject.link + expect(subject.mach_o_files.count).to eq(1) end end end From 208135f59f7a02bd9329c0995a4aa74166c0b2d0 Mon Sep 17 00:00:00 2001 From: commitay Date: Sat, 23 Sep 2017 12:52:57 +1000 Subject: [PATCH 240/294] Cask dsl caveats: bump java version to 9 --- Library/Homebrew/cask/lib/hbc/dsl/caveats.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Library/Homebrew/cask/lib/hbc/dsl/caveats.rb b/Library/Homebrew/cask/lib/hbc/dsl/caveats.rb index 402574456a..7d373b5f33 100644 --- a/Library/Homebrew/cask/lib/hbc/dsl/caveats.rb +++ b/Library/Homebrew/cask/lib/hbc/dsl/caveats.rb @@ -48,7 +48,7 @@ module Hbc brew cask install java EOS - elsif java_version.include?("8") || java_version.include?("+") + elsif java_version.include?("9") || java_version.include?("+") puts <<-EOS.undent #{@cask} requires Java #{java_version}. You can install the latest version with From 1e57445eca12e45896010aead6226f0f4c1df473 Mon Sep 17 00:00:00 2001 From: Shaun Jackman Date: Mon, 25 Sep 2017 11:10:36 -0700 Subject: [PATCH 241/294] receipt_path: Ensure the bottle contains INSTALL_RECEIPT.json --- Library/Homebrew/utils/bottles.rb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Library/Homebrew/utils/bottles.rb b/Library/Homebrew/utils/bottles.rb index 927963bc1e..73353496a8 100644 --- a/Library/Homebrew/utils/bottles.rb +++ b/Library/Homebrew/utils/bottles.rb @@ -29,9 +29,11 @@ module Utils end def receipt_path(bottle_file) - Utils.popen_read("tar", "-tzf", bottle_file).lines.map(&:chomp).find do |line| + path = Utils.popen_read("tar", "-tzf", bottle_file).lines.map(&:chomp).find do |line| line =~ %r{.+/.+/INSTALL_RECEIPT.json} end + raise "This bottle does not contain the file INSTALL_RECEIPT.json: #{bottle_file}" unless path + path end def resolve_formula_names(bottle_file) From b8d8049f70277efe9a8cbc496df11d48f62b86a7 Mon Sep 17 00:00:00 2001 From: Maxim Belkin Date: Thu, 28 Sep 2017 14:16:21 -0500 Subject: [PATCH 242/294] install.rb: stop early if there are no formulae to be installed --- Library/Homebrew/cmd/install.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/Library/Homebrew/cmd/install.rb b/Library/Homebrew/cmd/install.rb index c000877058..732e96b004 100644 --- a/Library/Homebrew/cmd/install.rb +++ b/Library/Homebrew/cmd/install.rb @@ -219,6 +219,7 @@ module Homebrew end end + return if formulae.empty? perform_preinstall_checks formulae.each do |f| From 3ebf282269b62722ceff61df0335b5ee305e9f3c Mon Sep 17 00:00:00 2001 From: Shaun Jackman Date: Mon, 25 Sep 2017 11:37:07 -0700 Subject: [PATCH 243/294] pour_bottle?: Fix when formula.bottle is nil formula.bottle is nil when bottle.compatible_cellar? is false. Use formula.bottle_specification.compatible_cellar? rather than formula.bottle.compatible_cellar?. --- Library/Homebrew/formula_installer.rb | 7 +++---- Library/Homebrew/test/bottle_hooks_spec.rb | 2 +- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/Library/Homebrew/formula_installer.rb b/Library/Homebrew/formula_installer.rb index b4f9db8458..4966151a36 100644 --- a/Library/Homebrew/formula_installer.rb +++ b/Library/Homebrew/formula_installer.rb @@ -84,8 +84,7 @@ class FormulaInstaller return false if @pour_failed - bottle = formula.bottle - return false if !bottle && !formula.local_bottle_path + return false if !formula.bottled? && !formula.local_bottle_path return true if force_bottle? return false if build_from_source? || build_bottle? || interactive? return false if ARGV.cc @@ -101,11 +100,11 @@ class FormulaInstaller return false end - unless bottle.compatible_cellar? + unless formula.bottled? if install_bottle_options[:warn] opoo <<-EOS.undent Building #{formula.full_name} from source: - The bottle needs a #{bottle.cellar} Cellar (yours is #{HOMEBREW_CELLAR}). + The bottle needs a #{formula.bottle_specification.cellar} Cellar (yours is #{HOMEBREW_CELLAR}). EOS end return false diff --git a/Library/Homebrew/test/bottle_hooks_spec.rb b/Library/Homebrew/test/bottle_hooks_spec.rb index e70b558a18..eb66173805 100644 --- a/Library/Homebrew/test/bottle_hooks_spec.rb +++ b/Library/Homebrew/test/bottle_hooks_spec.rb @@ -8,7 +8,7 @@ describe Homebrew::Hooks::Bottles do let(:formula) do double( - bottle: nil, + bottled?: false, local_bottle_path: nil, bottle_disabled?: false, some_random_method: true, From 9642ec769e6b187c375964e4206e5ac4014d37fa Mon Sep 17 00:00:00 2001 From: Shaun Jackman Date: Mon, 25 Sep 2017 11:28:45 -0700 Subject: [PATCH 244/294] testball_bottle-0.1: Add the formula to the bottle Update the SHA-256. --- Library/Homebrew/test/formulary_spec.rb | 2 +- ...testball_bottle-0.1.yosemite.bottle.tar.gz | Bin 1379 -> 1731 bytes .../test/support/fixtures/testball_bottle.rb | 2 +- 3 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Library/Homebrew/test/formulary_spec.rb b/Library/Homebrew/test/formulary_spec.rb index 234ebc93c3..3180ad9a7b 100644 --- a/Library/Homebrew/test/formulary_spec.rb +++ b/Library/Homebrew/test/formulary_spec.rb @@ -14,7 +14,7 @@ describe Formulary do bottle do cellar :any_skip_relocation root_url "file://#{bottle_dir}" - sha256 "9abc8ce779067e26556002c4ca6b9427b9874d25f0cafa7028e05b5c5c410cb4" => :#{Utils::Bottles.tag} + sha256 "d48bbbe583dcfbfa608579724fc6f0328b3cd316935c6ea22f134610aaf2952f" => :#{Utils::Bottles.tag} end def install diff --git a/Library/Homebrew/test/support/fixtures/bottles/testball_bottle-0.1.yosemite.bottle.tar.gz b/Library/Homebrew/test/support/fixtures/bottles/testball_bottle-0.1.yosemite.bottle.tar.gz index d88838a94d8f0c62ab5e2a0b776aacf795f34604..62ea6c264b94f8b22389d7ff0bdaf5914698136a 100644 GIT binary patch literal 1731 zcmV;!20Zy6iwFQRO37IO1MQsMZ`)K9z@4>YRX4Uu^Z@~4cU~Wc6cRg$lePlUmS(h~ zU8^?JI<{fi&Q0Uiu`Pde?Z(8UY7$j7J|rag6Oee}5g{H1;{}iqf5Ie~)Q2JMVGO85QLm05vWr_Hp^;3 z%w&Rk9U`X1Y$}z>q|zxOh}n#o;fS;s!ED8MJ;i}g+&M*?uPA0CIoYr+n>vbTId%J^ zOEjr*S`o?z9>q$tjO{Y0|E2j3hL#5^vrZ&aBNJT%D+Dz)h{D?Fsd+e>mlIk!nr*4cOiNKbr{)M!F z&;Ko9r~IFpn3!yak4NS|C9VJdXF&q;FA6OGc>mvfPM!!J_f*9#cT%lvk!B?wc_L`^ z{6A}1MRkeF8vM)~@@300ijVDMSMPt(^Pd2Ma6gbT@cfr5Q^TRlwbdi^54u; z59dQ_oPYSKmonA&zigJ}AKnA;`M)Ln^4A}KAA-6K$^j@xpxlCu8&Jof^g@y4$-%es z@8qW@Y81N~+hlsT0=+_hrm#h)YopEl9*q2QfxJf-y$$iL`sL#s_W`SqZRiBFbJsU? zG}m)C;A^LBoCbX|KO@(niPvCV!N>{y~pM5xZFp43@?KteW z!NzMnnD0#FD~vG~lxjRsW;IQA6Ji2F)73gU?J;Yc&h(P&(Mn>ds)Qg2f*=TjAjrNj z$F1C5{{8;)y{^?u?JF01xSQi0D`P$F%eQ0S{dOSsGwkYEZCk$Ge&d$^Cu|&9i-Xq6 za1Xb39^N?~tT7`q55Ll&TD{KRZXezW_pM$(7i^tfxjVgluRGXz;pXxSOufBljez#o zY~S(^-4}kmJ;MI4L(Z{(?3}0@Xz*@(=c5iNtbK&Q`yG^aD8YLpf*=TjAP9mW2!bF_ z91p7OcO(dcAP9mW2!bF8g6tJ+F7eATj{D+xIRBZozlC-J+DF?su8V|Iw~w`ja{)%8 zHk%VL8MWEGfQuZPo81-6AF!kSY|g+EYlF?7z~=i=o6U<3*B8Ws>CdY*Z8op_aA1;6 z%9dTvS7lWCz>KJmwZ!`4a=JM?NC;(C|VhWlp+&4Gc)MSYEiuaO0w-( zv!+s^(5{qaw!+c(XjPt?3%X;O99Yp!jx7rDVCSL^e{J7$Tb7U(({TNd-n?~JJFoxQ z{QZY;{ZB5PlQ<%_VsX+_zW%52_g}WJkAGYr?E4R4zU${dn~^qu|0R{qWYW0)s}*R5 z;<}^|<$5ScHF=Gkww#J@D4m29X^H5j?&*r5U!kYi4V1i2_${M@j}!I*2I!fDiU}o5 zdij(rpB^2{%knD;x@aqAQD#DM!al74qW$5w72*U;D{j!&PfXo-1>6$iQlpdz!b|8T zNSYdz>4IXAq80RmM4+DV9fR;C-Jt!+legscT8dFN@Tzj_6lm zkS9F#3cuNoTUJt1mM{ZD?DHqnBZIIV$!Lp<;m0UstxUCfh<#qSgFb2&!+3od9-ZNK z^}K;;!w9-(o1MQsKZ`)KDz)#kURbAOC(FX*Gd8Ut1;!EtbeW4i*w4#@& zD_X}kEZaFvJRCdnr5BBfNzo*#YFs2F_!E$L;SnJo2IB>g5P!lXnAC?M?O_rU4~*|P zUXotY4lT_z?fXfm=h!~q#r}?+IQqT@)DH~Zwl%{I0-I*YAs`4sE~jwNi#bJT@0)O< zq^L?(Q3OTd1X0O~3gMK)aAqf=ALt&qvTE73rB^%7JLq_P9?kwKA=nXrAuV=&4Y2qN z!lT7slw}rwHJ8Qs_kz9RZ&*%O*T5siUzB7?6qTGRLj2XNEMfe6L8tgvtX0>uOI@)6 z*F#Y{KL2GQt7Mz;S5>iEnl4yQF*Mipco${4agnY#MlP#Hu zB)Qg-G5x@^oN@;p_dv(40bLr#x~d*{1W=lp+63-7|-d8 z8Cl zDp^vt<_Dpn8J1JBoU&G-c8z**ioCWQI;Lj3?)zb_F;}bVW(6kcB{pepDesldxL*Mw zt>(F9N3T*CS1TG_qh=V;=6vd`Sf1+;&|*1+6@>(_bIpRkwJ`8|7LXp(vHpkUiFBz1 zX#e`3?e$-c`X5zRa)c9mQJnOQ*Z*|7#AVkl8S7Lty^z}4<6Z8k{x|nO>VKuIA`66* zy158Df$`rJf7>$H)3IwcppRDnsmd@-6eNj*!;-3E{bw)OFaC4$^TmTT9L$07mz0Ok ze^nAx7XKWJKh}R9KChjQ9`}asR|cqAak*{<9eFC)>;9jfJG+>lnb8&sZxp7Bi|NZg zd@p_s;C@i|yZ_HZLPH5XH-gK)q%cdUaFm2r_vk73| z1T$ConjTc(z{JGV{A}UOLgAcNTqwLby)-eAnXwE{_trC0Zj~AyUCppXpV_hU)1CqP l0=@RonqQ+PDD Utils::Bottles.tag + sha256 "d48bbbe583dcfbfa608579724fc6f0328b3cd316935c6ea22f134610aaf2952f" => Utils::Bottles.tag end cxxstdlib_check :skip end From 3ed832d4f0465aa9d938d3f4867ad12aaf394710 Mon Sep 17 00:00:00 2001 From: Shaun Jackman Date: Tue, 19 Sep 2017 12:22:32 -0700 Subject: [PATCH 245/294] BottleLoader: Use the formula stored in the bottle --- Library/Homebrew/exceptions.rb | 10 +++++----- Library/Homebrew/formulary.rb | 10 +++------- Library/Homebrew/test/exceptions_spec.rb | 6 +++--- 3 files changed, 11 insertions(+), 15 deletions(-) diff --git a/Library/Homebrew/exceptions.rb b/Library/Homebrew/exceptions.rb index 5418f93310..22a7fe0232 100644 --- a/Library/Homebrew/exceptions.rb +++ b/Library/Homebrew/exceptions.rb @@ -555,12 +555,12 @@ end # raised when a single patch file is not found and apply hasn't been specified class MissingApplyError < RuntimeError; end -class BottleVersionMismatchError < RuntimeError - def initialize(bottle_file, bottle_version, formula, formula_version) +class BottleFormulaUnavailableError < RuntimeError + def initialize(bottle_path, formula_path) super <<-EOS.undent - Bottle version mismatch - Bottle: #{bottle_file} (#{bottle_version}) - Formula: #{formula.full_name} (#{formula_version}) + This bottle does not contain the formula file: + #{bottle_path} + #{formula_path} EOS end end diff --git a/Library/Homebrew/formulary.rb b/Library/Homebrew/formulary.rb index dd67b4f243..c8ab8a9228 100644 --- a/Library/Homebrew/formulary.rb +++ b/Library/Homebrew/formulary.rb @@ -122,14 +122,10 @@ module Formulary super name, Formulary.path(full_name) end - def get_formula(spec, alias_path: nil) - formula = super + def get_formula(spec, **) + contents = Utils::Bottles.formula_contents @bottle_filename, name: name + formula = Formulary.from_contents name, @bottle_filename, contents, spec formula.local_bottle_path = @bottle_filename - formula_version = formula.pkg_version - bottle_version = Utils::Bottles.resolve_version(@bottle_filename) - unless formula_version == bottle_version - raise BottleVersionMismatchError.new(@bottle_filename, bottle_version, formula, formula_version) - end formula end end diff --git a/Library/Homebrew/test/exceptions_spec.rb b/Library/Homebrew/test/exceptions_spec.rb index 33547ea32e..0a8313355f 100644 --- a/Library/Homebrew/test/exceptions_spec.rb +++ b/Library/Homebrew/test/exceptions_spec.rb @@ -181,8 +181,8 @@ describe DuplicateResourceError do its(:to_s) { is_expected.to eq("Resource is defined more than once") } end -describe BottleVersionMismatchError do - subject { described_class.new("/foo.bottle.tar.gz", "1.0", formula, "1.1") } +describe BottleFormulaUnavailableError do + subject { described_class.new("/foo.bottle.tar.gz", "foo/1.0/.brew/foo.rb") } let(:formula) { double(Formula, full_name: "foo") } - its(:to_s) { is_expected.to match(/Bottle version mismatch/) } + its(:to_s) { is_expected.to match(/This bottle does not contain the formula file/) } end From 2e77de3b58043cb8acc1e28070ae7e24fbf596fb Mon Sep 17 00:00:00 2001 From: Shaun Jackman Date: Mon, 25 Sep 2017 22:46:51 -0700 Subject: [PATCH 246/294] Fix installing a local bottle from source Factor Utils::Bottles.formula_contents out of BottleLoader. --- Library/Homebrew/formula_installer.rb | 7 ++++++- Library/Homebrew/utils/bottles.rb | 9 +++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/Library/Homebrew/formula_installer.rb b/Library/Homebrew/formula_installer.rb index 4966151a36..ea4415796b 100644 --- a/Library/Homebrew/formula_installer.rb +++ b/Library/Homebrew/formula_installer.rb @@ -308,7 +308,12 @@ class FormulaInstaller clean # Store the formula used to build the keg in the keg. - s = formula.path.read.gsub(/ bottle do.+?end\n\n?/m, "") + formula_contents = if formula.local_bottle_path + Utils::Bottles.formula_contents formula.local_bottle_path, name: formula.name + else + formula.path.read + end + s = formula_contents.gsub(/ bottle do.+?end\n\n?/m, "") brew_prefix = formula.prefix/".brew" brew_prefix.mkdir Pathname(brew_prefix/"#{formula.name}.rb").atomic_write(s) diff --git a/Library/Homebrew/utils/bottles.rb b/Library/Homebrew/utils/bottles.rb index 73353496a8..66b5fb640d 100644 --- a/Library/Homebrew/utils/bottles.rb +++ b/Library/Homebrew/utils/bottles.rb @@ -54,6 +54,15 @@ module Utils def resolve_version(bottle_file) PkgVersion.parse receipt_path(bottle_file).split("/")[1] end + + def formula_contents(bottle_file, + name: resolve_formula_names(bottle_file)[0]) + bottle_version = resolve_version bottle_file + formula_path = "#{name}/#{bottle_version}/.brew/#{name}.rb" + contents = Utils.popen_read "tar", "-xOzf", bottle_file, formula_path + raise BottleFormulaUnavailableError.new(bottle_file, formula_path) unless $CHILD_STATUS.success? + contents + end end class Bintray From c19cc70ac8b87bfe93d2b94e5693584139238e23 Mon Sep 17 00:00:00 2001 From: Shaun Jackman Date: Thu, 28 Sep 2017 11:36:56 -0700 Subject: [PATCH 247/294] FormulaInstaller: Warn when tap version is newer Warn if a more recent version of this formula is available in the tap. --- Library/Homebrew/formula_installer.rb | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/Library/Homebrew/formula_installer.rb b/Library/Homebrew/formula_installer.rb index ea4415796b..845152e24d 100644 --- a/Library/Homebrew/formula_installer.rb +++ b/Library/Homebrew/formula_installer.rb @@ -235,6 +235,15 @@ class FormulaInstaller raise CannotInstallFormulaError, message end + # Warn if a more recent version of this formula is available in the tap. + begin + if formula.pkg_version < (v = Formulary.factory(formula.full_name).pkg_version) + opoo "#{formula.full_name} #{v} is available and more recent than version #{formula.pkg_version}." + end + rescue FormulaUnavailableError + nil + end + check_conflicts if !pour_bottle? && !formula.bottle_unneeded? && !DevelopmentTools.installed? From 9383063216ea9567e1e06adfef83955215aae2ef Mon Sep 17 00:00:00 2001 From: Adam Smith Date: Wed, 27 Sep 2017 00:56:57 -0700 Subject: [PATCH 248/294] add --language to brew-cask manpage --- Library/Homebrew/manpages/brew-cask.1.md | 7 +++++-- manpages/brew-cask.1 | 10 +++++++--- manpages/brew.1 | 2 +- 3 files changed, 13 insertions(+), 6 deletions(-) diff --git a/Library/Homebrew/manpages/brew-cask.1.md b/Library/Homebrew/manpages/brew-cask.1.md index 715d8fd770..1c7c198b07 100644 --- a/Library/Homebrew/manpages/brew-cask.1.md +++ b/Library/Homebrew/manpages/brew-cask.1.md @@ -19,7 +19,7 @@ names, and other aspects of this manual are still subject to change. ## FREQUENTLY USED COMMANDS - * `install` [--force] [--skip-cask-deps] [--require-sha] [ ... ]: + * `install` [--force] [--skip-cask-deps] [--require-sha] [--language=[, ... ]] [ ... ]: Install Cask identified by . * `uninstall` [--force] [ ... ]: @@ -34,7 +34,7 @@ names, and other aspects of this manual are still subject to change. ## COMMANDS - * `audit` [ ... ]: + * `audit` [--language=[, ... ]] [ ... ]: Check the given Casks for installability. If no tokens are given on the command line, all Casks are audited. @@ -167,6 +167,9 @@ in a future version. * `--appdir=`: Target location for Applications. The default value is `/Applications`. + * `--language=[, ... ]]`: + Set language of the Cask to install. The first matching language is used, otherwise the default language on the Cask. The default value is the `language of your system`. + * `--colorpickerdir=`: Target location for Color Pickers. The default value is `~/Library/ColorPickers`. diff --git a/manpages/brew-cask.1 b/manpages/brew-cask.1 index f8f58a123b..f2acf1842c 100644 --- a/manpages/brew-cask.1 +++ b/manpages/brew-cask.1 @@ -1,7 +1,7 @@ .\" generated with Ronn/v0.7.3 .\" http://github.com/rtomayko/ronn/tree/0.7.3 . -.TH "BREW\-CASK" "1" "August 2017" "Homebrew" "brew-cask" +.TH "BREW\-CASK" "1" "September 2017" "Homebrew" "brew-cask" . .SH "NAME" \fBbrew\-cask\fR \- a friendly binary installer for macOS @@ -18,7 +18,7 @@ Homebrew\-Cask works robustly enough that we welcome new users, but the project .SH "FREQUENTLY USED COMMANDS" . .TP -\fBinstall\fR [\-\-force] [\-\-skip\-cask\-deps] [\-\-require\-sha] \fItoken\fR [ \fItoken\fR \.\.\. ] +\fBinstall\fR [\-\-force] [\-\-skip\-cask\-deps] [\-\-require\-sha] [\-\-language=\fIiso\-language\fR[,\fIiso\-language\fR \.\.\. ]] \fItoken\fR [ \fItoken\fR \.\.\. ] Install Cask identified by \fItoken\fR\. . .TP @@ -35,7 +35,7 @@ The tokens returned by \fBsearch\fR are suitable as arguments for most other com .SH "COMMANDS" . .TP -\fBaudit\fR [ \fItoken\fR \.\.\. ] +\fBaudit\fR [\-\-language=\fIiso\-language\fR[,\fIiso\-language\fR \.\.\. ]] [ \fItoken\fR \.\.\. ] Check the given Casks for installability\. If no tokens are given on the command line, all Casks are audited\. . .TP @@ -169,6 +169,10 @@ Give additional feedback during installation\. Target location for Applications\. The default value is \fB/Applications\fR\. . .TP +\fB\-\-language=[, \.\.\. ]]\fR +Set language of the Cask to install\. The first matching language is used, otherwise the default language on the Cask\. The default value is the \fBlanguage of your system\fR\. +. +.TP \fB\-\-colorpickerdir=\fR Target location for Color Pickers\. The default value is \fB~/Library/ColorPickers\fR\. . diff --git a/manpages/brew.1 b/manpages/brew.1 index 362e884ed4..b3d8402752 100644 --- a/manpages/brew.1 +++ b/manpages/brew.1 @@ -1,7 +1,7 @@ .\" generated with Ronn/v0.7.3 .\" http://github.com/rtomayko/ronn/tree/0.7.3 . -.TH "BREW" "1" "August 2017" "Homebrew" "brew" +.TH "BREW" "1" "September 2017" "Homebrew" "brew" . .SH "NAME" \fBbrew\fR \- The missing package manager for macOS From 479544665b9e6edf66c7add1eb6b3c98d98de384 Mon Sep 17 00:00:00 2001 From: Markus Reiter Date: Fri, 29 Sep 2017 11:37:44 +0200 Subject: [PATCH 249/294] Support UN M.49 region codes. --- Library/Homebrew/locale.rb | 6 +++--- Library/Homebrew/test/locale_spec.rb | 4 ++++ 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/Library/Homebrew/locale.rb b/Library/Homebrew/locale.rb index d918e2a2a4..c430d11b64 100644 --- a/Library/Homebrew/locale.rb +++ b/Library/Homebrew/locale.rb @@ -2,9 +2,9 @@ class Locale class ParserError < StandardError end - LANGUAGE_REGEX = /(?:[a-z]{2,3})/ # ISO 639-1 or ISO 639-2 - REGION_REGEX = /(?:[A-Z]{2})/ # ISO 3166-1 - SCRIPT_REGEX = /(?:[A-Z][a-z]{3})/ # ISO 15924 + LANGUAGE_REGEX = /(?:[a-z]{2,3})/ # ISO 639-1 or ISO 639-2 + REGION_REGEX = /(?:[A-Z]{2}|\d{3})/ # ISO 3166-1 or UN M.49 + SCRIPT_REGEX = /(?:[A-Z][a-z]{3})/ # ISO 15924 LOCALE_REGEX = /\A((?:#{LANGUAGE_REGEX}|#{REGION_REGEX}|#{SCRIPT_REGEX})(?:\-|$)){1,3}\Z/ diff --git a/Library/Homebrew/test/locale_spec.rb b/Library/Homebrew/test/locale_spec.rb index 9e4d09e837..9c684f0e7f 100644 --- a/Library/Homebrew/test/locale_spec.rb +++ b/Library/Homebrew/test/locale_spec.rb @@ -9,6 +9,10 @@ describe Locale do expect(described_class.parse("zh-CN-Hans")).to eql(described_class.new("zh", "CN", "Hans")) end + it "correctly parses a string with a UN M.49 region code" do + expect(described_class.parse("es-419")).to eql(described_class.new("es", "419", nil)) + end + context "raises a ParserError when given" do it "an empty string" do expect { described_class.parse("") }.to raise_error(Locale::ParserError) From a750644b9218267116af07c4832f7a5cccad415d Mon Sep 17 00:00:00 2001 From: Markus Reiter Date: Sat, 23 Sep 2017 01:40:14 +0200 Subject: [PATCH 250/294] Fail if no default language is specified. --- Library/Homebrew/cask/lib/hbc/dsl.rb | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/Library/Homebrew/cask/lib/hbc/dsl.rb b/Library/Homebrew/cask/lib/hbc/dsl.rb index 3824b9761f..1d048bffd9 100644 --- a/Library/Homebrew/cask/lib/hbc/dsl.rb +++ b/Library/Homebrew/cask/lib/hbc/dsl.rb @@ -105,7 +105,9 @@ module Hbc end def language(*args, default: false, &block) - if !args.empty? && block_given? + if args.empty? + language_eval + elsif block_given? @language_blocks ||= {} @language_blocks[args] = block @@ -117,7 +119,7 @@ module Hbc @language_blocks.default = block else - language_eval + raise CaskInvalidError.new(cask, "No block given to language stanza.") end end @@ -126,6 +128,10 @@ module Hbc return @language = nil if @language_blocks.nil? || @language_blocks.empty? + if @language_blocks.default.nil? + raise CaskInvalidError.new(cask, "No default language specified.") + end + MacOS.languages.map(&Locale.method(:parse)).each do |locale| key = @language_blocks.keys.detect do |strings| strings.any? { |string| locale.include?(string) } From 134bd00d10a8feef63bd2583e117dc51be230db3 Mon Sep 17 00:00:00 2001 From: Mike McQuaid Date: Fri, 29 Sep 2017 16:23:02 +0100 Subject: [PATCH 251/294] audit: don't care about shadowing official taps. We're trying to import all of these formulae anyway. --- Library/Homebrew/dev-cmd/audit.rb | 32 +++---------------------------- 1 file changed, 3 insertions(+), 29 deletions(-) diff --git a/Library/Homebrew/dev-cmd/audit.rb b/Library/Homebrew/dev-cmd/audit.rb index a7d498c0d5..49e7969af0 100644 --- a/Library/Homebrew/dev-cmd/audit.rb +++ b/Library/Homebrew/dev-cmd/audit.rb @@ -396,7 +396,6 @@ class FormulaAuditor return if formula.tap.nil? || !formula.tap.official? name = formula.name - full_name = formula.full_name if Homebrew::MissingFormula.blacklisted_reason(name) problem "'#{name}' is blacklisted." @@ -412,35 +411,10 @@ class FormulaAuditor return end - if !formula.core_formula? && Formula.core_names.include?(name) - problem "Formula name conflicts with existing core formula." - return - end + return if formula.core_formula? + return unless Formula.core_names.include?(name) - @@local_official_taps_name_map ||= Tap.select(&:official?).flat_map(&:formula_names) - .each_with_object({}) do |tap_formula_full_name, name_map| - next if tap_formula_full_name.start_with?("homebrew/science/") - tap_formula_name = tap_formula_full_name.split("/").last - name_map[tap_formula_name] ||= [] - name_map[tap_formula_name] << tap_formula_full_name - name_map - end - - same_name_tap_formulae = @@local_official_taps_name_map[name] || [] - - if @online - Homebrew.search_taps(name, silent: true).each do |tap_formula_full_name| - next if tap_formula_full_name.start_with?("homebrew/science/") - tap_formula_name = tap_formula_full_name.split("/").last - next if tap_formula_name != name - same_name_tap_formulae << tap_formula_full_name - end - end - - same_name_tap_formulae.delete(full_name) - - return if same_name_tap_formulae.empty? - problem "Formula name conflicts with #{same_name_tap_formulae.join ", "}" + problem "Formula name conflicts with existing core formula." end def audit_deps From 56149c725a97280396e74c4afa948fbe7e554e3d Mon Sep 17 00:00:00 2001 From: Mike McQuaid Date: Fri, 29 Sep 2017 16:47:46 +0100 Subject: [PATCH 252/294] travis.yml: update Xcode version. --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 94b83fc116..721dda89dd 100644 --- a/.travis.yml +++ b/.travis.yml @@ -11,7 +11,7 @@ matrix: fast_finish: true include: - os: osx - osx_image: xcode8.3 + osx_image: xcode9 rvm: system - os: linux sudo: false From bcca2a7c6b80a6450bd8261af987a8da260b6b89 Mon Sep 17 00:00:00 2001 From: Mike McQuaid Date: Fri, 29 Sep 2017 19:53:15 +0100 Subject: [PATCH 253/294] brew: handle Ruby 2.3 more gracefully. - `brew.rb` needed updated to fail unless on Ruby 2.3 - `brew update` should unset `HOMEBREW_RUBY_PATH` to ensure that this doesn't "stick" on a Ruby 2.0 version after a portable Ruby has been installed. --- Library/Homebrew/brew.rb | 8 ++++++-- Library/Homebrew/cmd/update.sh | 1 + Library/Homebrew/dev-cmd/update-test.rb | 2 +- 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/Library/Homebrew/brew.rb b/Library/Homebrew/brew.rb index 2906fd93d8..41955e60e0 100644 --- a/Library/Homebrew/brew.rb +++ b/Library/Homebrew/brew.rb @@ -5,8 +5,12 @@ end std_trap = trap("INT") { exit! 130 } # no backtrace thanks # check ruby version before requiring any modules. -RUBY_TWO = RUBY_VERSION.split(".").first.to_i >= 2 -raise "Homebrew must be run under Ruby 2!" unless RUBY_TWO +RUBY_VERSION_SPLIT = RUBY_VERSION.split "." +RUBY_X = RUBY_VERSION_SPLIT[0].to_i +RUBY_Y = RUBY_VERSION_SPLIT[1].to_i +if RUBY_X < 2 || (RUBY_X == 2 && RUBY_Y < 3) + raise "Homebrew must be run under Ruby 2.3!" +end require "pathname" HOMEBREW_LIBRARY_PATH = Pathname.new(__FILE__).realpath.parent diff --git a/Library/Homebrew/cmd/update.sh b/Library/Homebrew/cmd/update.sh index e8211e4ddf..3507fa92b5 100644 --- a/Library/Homebrew/cmd/update.sh +++ b/Library/Homebrew/cmd/update.sh @@ -570,6 +570,7 @@ EOS -d "$HOMEBREW_LIBRARY/LinkedKegs" || (-n "$HOMEBREW_DEVELOPER" && -z "$HOMEBREW_UPDATE_PREINSTALL") ]] then + unset HOMEBREW_RUBY_PATH brew update-report "$@" return $? elif [[ -z "$HOMEBREW_UPDATE_PREINSTALL" ]] diff --git a/Library/Homebrew/dev-cmd/update-test.rb b/Library/Homebrew/dev-cmd/update-test.rb index aa7fe6a924..a66704917f 100644 --- a/Library/Homebrew/dev-cmd/update-test.rb +++ b/Library/Homebrew/dev-cmd/update-test.rb @@ -81,7 +81,7 @@ module Homebrew safe_system "git", "reset", "--hard", start_commit # update ENV["PATH"] - ENV["PATH"] = "#{curdir}/bin:/usr/local/bin:/usr/bin:/bin" + ENV["PATH"] = "#{curdir}/bin:#{ENV["PATH"]}" # run brew update oh1 "Running brew update..." From 7cadff0a33d062b526d2ac246bd1d9e6cc689f53 Mon Sep 17 00:00:00 2001 From: Markus Reiter Date: Fri, 29 Sep 2017 22:10:44 +0200 Subject: [PATCH 254/294] Use `PATH` where possible. --- Library/Homebrew/dev-cmd/update-test.rb | 2 +- Library/Homebrew/utils.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Library/Homebrew/dev-cmd/update-test.rb b/Library/Homebrew/dev-cmd/update-test.rb index a66704917f..1f1cdbeed1 100644 --- a/Library/Homebrew/dev-cmd/update-test.rb +++ b/Library/Homebrew/dev-cmd/update-test.rb @@ -81,7 +81,7 @@ module Homebrew safe_system "git", "reset", "--hard", start_commit # update ENV["PATH"] - ENV["PATH"] = "#{curdir}/bin:#{ENV["PATH"]}" + ENV["PATH"] = PATH.new(ENV["PATH"]).prepend(curdir/"bin") # run brew update oh1 "Running brew update..." diff --git a/Library/Homebrew/utils.rb b/Library/Homebrew/utils.rb index 3033eb4ddf..d293b2a6fa 100644 --- a/Library/Homebrew/utils.rb +++ b/Library/Homebrew/utils.rb @@ -264,7 +264,7 @@ end def with_system_path old_path = ENV["PATH"] - ENV["PATH"] = "/usr/bin:/bin" + ENV["PATH"] = PATH.new("/usr/bin", "/bin") yield ensure ENV["PATH"] = old_path From d9a474ed0e4967f6b9906bfec5fe9ac1bca0c535 Mon Sep 17 00:00:00 2001 From: Markus Reiter Date: Sun, 1 Oct 2017 02:13:53 +0200 Subject: [PATCH 255/294] Add audit warning if previous Cask version cannot be read. --- Library/Homebrew/cask/lib/hbc/audit.rb | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/Library/Homebrew/cask/lib/hbc/audit.rb b/Library/Homebrew/cask/lib/hbc/audit.rb index 03d8cce826..9ab93a67f0 100644 --- a/Library/Homebrew/cask/lib/hbc/audit.rb +++ b/Library/Homebrew/cask/lib/hbc/audit.rb @@ -70,12 +70,16 @@ module Hbc previous_cask_contents = Git.last_revision_of_file(tap.path, @cask.sourcefile_path, before_commit: commit_range) return if previous_cask_contents.empty? - previous_cask = CaskLoader.load_from_string(previous_cask_contents) + begin + previous_cask = CaskLoader.load_from_string(previous_cask_contents) - return unless previous_cask.version == cask.version - return if previous_cask.sha256 == cask.sha256 + return unless previous_cask.version == cask.version + return if previous_cask.sha256 == cask.sha256 - add_error "only sha256 changed (see: https://github.com/caskroom/homebrew-cask/blob/master/doc/cask_language_reference/stanzas/sha256.md)" + add_error "only sha256 changed (see: https://github.com/caskroom/homebrew-cask/blob/master/doc/cask_language_reference/stanzas/sha256.md)" + rescue CaskError => e + add_warning "Skipped version and checksum comparison. Reading previous version failed: #{e}" + end end def check_version From 92311901c9d85e0e43147386535118b66ca718cd Mon Sep 17 00:00:00 2001 From: Adam Smith Date: Wed, 27 Sep 2017 00:17:47 -0700 Subject: [PATCH 256/294] add available languages to cask info command add language tests for dsl add fixtures, tests for languages info output add extra lines --- Library/Homebrew/cask/lib/hbc/cli/info.rb | 8 +++++ Library/Homebrew/cask/lib/hbc/dsl.rb | 7 ++++ Library/Homebrew/test/cask/cli/info_spec.rb | 32 +++++++++++++++++++ Library/Homebrew/test/cask/dsl_spec.rb | 30 +++++++++++++++++ .../cask/Casks/with-conditional-languages.rb | 9 ++++++ .../fixtures/cask/Casks/with-languages.rb | 18 +++++++++++ 6 files changed, 104 insertions(+) create mode 100644 Library/Homebrew/test/support/fixtures/cask/Casks/with-conditional-languages.rb create mode 100644 Library/Homebrew/test/support/fixtures/cask/Casks/with-languages.rb diff --git a/Library/Homebrew/cask/lib/hbc/cli/info.rb b/Library/Homebrew/cask/lib/hbc/cli/info.rb index 9cdada62e8..2b4db95309 100644 --- a/Library/Homebrew/cask/lib/hbc/cli/info.rb +++ b/Library/Homebrew/cask/lib/hbc/cli/info.rb @@ -23,6 +23,7 @@ module Hbc installation_info(cask) repo_info(cask) name_info(cask) + language_info(cask) artifact_info(cask) Installer.print_caveats(cask) end @@ -51,6 +52,13 @@ module Hbc puts cask.name.empty? ? Formatter.error("None") : cask.name end + def self.language_info(cask) + return if cask.languages.empty? + + ohai "Languages" + puts cask.languages.join(", ") + end + def self.repo_info(cask) user, repo, token = QualifiedToken.parse(Hbc.all_tokens.detect { |t| t.split("/").last == cask.token }) diff --git a/Library/Homebrew/cask/lib/hbc/dsl.rb b/Library/Homebrew/cask/lib/hbc/dsl.rb index 3824b9761f..3822c532c4 100644 --- a/Library/Homebrew/cask/lib/hbc/dsl.rb +++ b/Library/Homebrew/cask/lib/hbc/dsl.rb @@ -63,6 +63,7 @@ module Hbc :gpg, :homepage, :language, + :languages, :name, :sha256, :staged_path, @@ -139,6 +140,12 @@ module Hbc @language = @language_blocks.default.call end + def languages + return [] if @language_blocks.nil? + + @language_blocks.keys.flatten + end + def url(*args, &block) set_unique_stanza(:url, args.empty? && !block_given?) do begin diff --git a/Library/Homebrew/test/cask/cli/info_spec.rb b/Library/Homebrew/test/cask/cli/info_spec.rb index aec7080dea..7d6dfd76d4 100644 --- a/Library/Homebrew/test/cask/cli/info_spec.rb +++ b/Library/Homebrew/test/cask/cli/info_spec.rb @@ -90,6 +90,38 @@ describe Hbc::CLI::Info, :cask do EOS end + it "should print languages if the Cask provided any" do + expect { + Hbc::CLI::Info.run("with-languages") + }.to output(<<-EOS.undent).to_stdout + with-languages: 1.2.3 + http://example.com/local-caffeine + Not installed + From: https://github.com/caskroom/homebrew-spec/blob/master/Casks/with-languages.rb + ==> Name + None + ==> Languages + zh, en-US + ==> Artifacts + Caffeine.app (App) + EOS + end + + it 'should not print "Languages" section divider if the languages block has no output' do + expect { + Hbc::CLI::Info.run("with-conditional-languages") + }.to output(<<-EOS.undent).to_stdout + with-conditional-languages: 1.2.3 + http://example.com/local-caffeine + Not installed + From: https://github.com/caskroom/homebrew-spec/blob/master/Casks/with-conditional-languages.rb + ==> Name + None + ==> Artifacts + Caffeine.app (App) + EOS + end + describe "when no Cask is specified" do it "raises an exception" do expect { diff --git a/Library/Homebrew/test/cask/dsl_spec.rb b/Library/Homebrew/test/cask/dsl_spec.rb index aec1e917f3..c2a7b2367e 100644 --- a/Library/Homebrew/test/cask/dsl_spec.rb +++ b/Library/Homebrew/test/cask/dsl_spec.rb @@ -177,6 +177,36 @@ describe Hbc::DSL, :cask do expect(cask.call.sha256).to eq("xyz789") expect(cask.call.url.to_s).to eq("https://example.org/en-US.zip") end + + it "returns empty array if no languages specified" do + cask = lambda do + Hbc::Cask.new("cask-with-apps") do + url "https://example.org/file.zip" + end + end + + expect(cask.call.languages).to be_empty + end + + it "returns an array of available languages" do + cask = lambda do + Hbc::Cask.new("cask-with-apps") do + language "zh" do + sha256 "abc123" + "zh-CN" + end + + language "en-US", default: true do + sha256 "xyz789" + "en-US" + end + + url "https://example.org/file.zip" + end + end + + expect(cask.call.languages).to eq(["zh", "en-US"]) + end end describe "app stanza" do diff --git a/Library/Homebrew/test/support/fixtures/cask/Casks/with-conditional-languages.rb b/Library/Homebrew/test/support/fixtures/cask/Casks/with-conditional-languages.rb new file mode 100644 index 0000000000..bf3b9b1c40 --- /dev/null +++ b/Library/Homebrew/test/support/fixtures/cask/Casks/with-conditional-languages.rb @@ -0,0 +1,9 @@ +cask 'with-conditional-languages' do + version '1.2.3' + sha256 '67cdb8a02803ef37fdbf7e0be205863172e41a561ca446cd84f0d7ab35a99d94' + + url "file://#{TEST_FIXTURE_DIR}/cask/caffeine.zip" + homepage 'http://example.com/local-caffeine' + + app 'Caffeine.app' +end diff --git a/Library/Homebrew/test/support/fixtures/cask/Casks/with-languages.rb b/Library/Homebrew/test/support/fixtures/cask/Casks/with-languages.rb new file mode 100644 index 0000000000..90ff638468 --- /dev/null +++ b/Library/Homebrew/test/support/fixtures/cask/Casks/with-languages.rb @@ -0,0 +1,18 @@ +cask 'with-languages' do + version '1.2.3' + + language "zh" do + sha256 "abc123" + "zh-CN" + end + + language "en-US", default: true do + sha256 "xyz789" + "en-US" + end + + url "file://#{TEST_FIXTURE_DIR}/cask/caffeine.zip" + homepage 'http://example.com/local-caffeine' + + app 'Caffeine.app' +end From a4838d22f4cd9b078a6cf641753caef562071386 Mon Sep 17 00:00:00 2001 From: Shaun Jackman Date: Sat, 30 Sep 2017 18:23:48 -0700 Subject: [PATCH 257/294] pour_bottle?: Check bottle.compatible_cellar? formula.bottled? is false when the bottle has no sha256, as with a local bottle. --- Library/Homebrew/formula_installer.rb | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Library/Homebrew/formula_installer.rb b/Library/Homebrew/formula_installer.rb index 845152e24d..56238ad734 100644 --- a/Library/Homebrew/formula_installer.rb +++ b/Library/Homebrew/formula_installer.rb @@ -100,11 +100,12 @@ class FormulaInstaller return false end - unless formula.bottled? + bottle = formula.bottle_specification + unless bottle.compatible_cellar? if install_bottle_options[:warn] opoo <<-EOS.undent Building #{formula.full_name} from source: - The bottle needs a #{formula.bottle_specification.cellar} Cellar (yours is #{HOMEBREW_CELLAR}). + The bottle needs a #{bottle.cellar} Cellar (yours is #{HOMEBREW_CELLAR}). EOS end return false From 3343d79b9fbc71984d08f4dec05542e55430c7bc Mon Sep 17 00:00:00 2001 From: Mike McQuaid Date: Sun, 1 Oct 2017 12:36:13 +0100 Subject: [PATCH 258/294] shims/super/make: don't export MAKE=make. This is redundant and breaks Handbrake: https://github.com/HandBrake/HandBrake/issues/872 --- Library/Homebrew/shims/super/make | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/Library/Homebrew/shims/super/make b/Library/Homebrew/shims/super/make index 7b49e56c0b..46de531310 100755 --- a/Library/Homebrew/shims/super/make +++ b/Library/Homebrew/shims/super/make @@ -1,5 +1,10 @@ #!/bin/bash -export MAKE=${HOMEBREW_MAKE:-make} +if [[ -n "$HOMEBREW_MAKE" && "$HOMEBREW_MAKE" != "make" ]] +then + export MAKE="$HOMEBREW_MAKE" +else + MAKE="make" +fi export HOMEBREW_CCCFG="O$HOMEBREW_CCCFG" -exec xcrun $MAKE "$@" +exec xcrun "$MAKE" "$@" From fe5674d943057f4b9cc61c1ffac934a0d0b11d3c Mon Sep 17 00:00:00 2001 From: Mike McQuaid Date: Sun, 1 Oct 2017 19:53:19 +0100 Subject: [PATCH 259/294] travis.yml: avoid cloning Homebrew/homebrew-core. Rearrange the test-bot clones so that the Homebrew/homebrew-core move can be successful to avoid the later clone. --- .travis.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index 721dda89dd..670e69ad09 100644 --- a/.travis.yml +++ b/.travis.yml @@ -21,19 +21,19 @@ before_install: - export HOMEBREW_NO_AUTO_UPDATE=1 - export HOMEBREW_DEVELOPER=1 - if [ "${TRAVIS_OS_NAME}" = "osx" ]; then - git clone --depth=1 https://github.com/Homebrew/homebrew-test-bot Library/Taps/homebrew/homebrew-test-bot; HOMEBREW_REPOSITORY="$(brew --repo)"; sudo chown -R "$USER" "$HOMEBREW_REPOSITORY/Library/Taps"; mv "$HOMEBREW_REPOSITORY/Library/Taps" "$PWD/Library"; sudo rm -rf "$HOMEBREW_REPOSITORY"; sudo ln -s "$PWD" "$HOMEBREW_REPOSITORY"; + git clone --depth=1 https://github.com/Homebrew/homebrew-test-bot Library/Taps/homebrew/homebrew-test-bot; else umask 022; - git clone --depth=1 https://github.com/Homebrew/homebrew-test-bot Library/Taps/homebrew/homebrew-test-bot; git fetch --unshallow; export PATH="$PWD/bin:$PATH"; HOMEBREW_CORE_TAP_DIR="$(brew --repo "homebrew/core")"; mkdir -p "$HOMEBREW_CORE_TAP_DIR"; + git clone --depth=1 https://github.com/Homebrew/homebrew-test-bot Library/Taps/homebrew/homebrew-test-bot; HOMEBREW_TEST_BOT_TAP_DIR="$(brew --repo "homebrew/test-bot")"; ln -s "$HOMEBREW_TEST_BOT_TAP_DIR/.git" "$HOMEBREW_TEST_BOT_TAP_DIR/Formula" "$HOMEBREW_CORE_TAP_DIR"; fi From 965ca015965bfb376cb20e40c2c534f9572edb37 Mon Sep 17 00:00:00 2001 From: Markus Reiter Date: Sun, 1 Oct 2017 01:47:08 +0200 Subject: [PATCH 260/294] Fix `brew tests` leaving last file in trash. --- .../Homebrew/cask/lib/hbc/artifact/abstract_uninstall.rb | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/Library/Homebrew/cask/lib/hbc/artifact/abstract_uninstall.rb b/Library/Homebrew/cask/lib/hbc/artifact/abstract_uninstall.rb index badd549ce7..d0b2eb6ef7 100644 --- a/Library/Homebrew/cask/lib/hbc/artifact/abstract_uninstall.rb +++ b/Library/Homebrew/cask/lib/hbc/artifact/abstract_uninstall.rb @@ -253,7 +253,7 @@ module Hbc end def trash_paths(*paths, command: nil, **_) - command.run!("/usr/bin/osascript", args: ["-e", <<-'EOS'.undent, *paths]) + result = command.run!("/usr/bin/osascript", args: ["-e", <<-'EOS'.undent, *paths]) on run argv repeat with i from 1 to (count argv) set item i of argv to (item i of argv as POSIX file) @@ -267,7 +267,7 @@ module Hbc set trashedItem to POSIX path of (item i of trashedItems as string) set output to output & trashedItem if i < count trashedItems then - set output to output & (do shell script "printf \"\\0\"") + set output to output & character id 0 end if end repeat @@ -275,6 +275,9 @@ module Hbc end tell end run EOS + + # Remove AppleScript's automatic newline. + result.tap { |r| r.stdout.sub!(/\n$/, "") } end def uninstall_rmdir(*directories, command: nil, **_) From 3bb89f5440c030e06819affe3b821a771e86a671 Mon Sep 17 00:00:00 2001 From: Markus Reiter Date: Sun, 1 Oct 2017 22:26:04 +0200 Subject: [PATCH 261/294] Only run trash test when collecting coverage. --- .../test/cask/artifact/uninstall_zap_shared_examples.rb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Library/Homebrew/test/cask/artifact/uninstall_zap_shared_examples.rb b/Library/Homebrew/test/cask/artifact/uninstall_zap_shared_examples.rb index 06eec4a011..4fdab60d00 100644 --- a/Library/Homebrew/test/cask/artifact/uninstall_zap_shared_examples.rb +++ b/Library/Homebrew/test/cask/artifact/uninstall_zap_shared_examples.rb @@ -149,6 +149,8 @@ shared_examples "#uninstall_phase or #zap_phase" do end [:delete, :trash].each do |directive| + next if directive == :trash && ENV["HOMEBREW_TESTS_COVERAGE"].nil? + context "using :#{directive}" do let(:dir) { TEST_TMPDIR } let(:absolute_path) { Pathname.new("#{dir}/absolute_path") } From da66e06068e73ea212feaf6657c37e96f6bcde2c Mon Sep 17 00:00:00 2001 From: Markus Reiter Date: Sun, 1 Oct 2017 23:33:52 +0200 Subject: [PATCH 262/294] Add missing `summarize` method. --- Library/Homebrew/cask/lib/hbc/artifact/abstract_uninstall.rb | 2 +- Library/Homebrew/cask/lib/hbc/artifact/nested_container.rb | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/Library/Homebrew/cask/lib/hbc/artifact/abstract_uninstall.rb b/Library/Homebrew/cask/lib/hbc/artifact/abstract_uninstall.rb index badd549ce7..19b83b69bb 100644 --- a/Library/Homebrew/cask/lib/hbc/artifact/abstract_uninstall.rb +++ b/Library/Homebrew/cask/lib/hbc/artifact/abstract_uninstall.rb @@ -37,7 +37,7 @@ module Hbc end def summarize - to_h.map { |key, val| [*val].map { |v| "#{key.inspect} => #{v.inspect}" }.join(", ") }.join(", ") + to_h.flat_map { |key, val| [*val].map { |v| "#{key.inspect} => #{v.inspect}" } }.join(", ") end private diff --git a/Library/Homebrew/cask/lib/hbc/artifact/nested_container.rb b/Library/Homebrew/cask/lib/hbc/artifact/nested_container.rb index 81adf90290..c9fd3dc271 100644 --- a/Library/Homebrew/cask/lib/hbc/artifact/nested_container.rb +++ b/Library/Homebrew/cask/lib/hbc/artifact/nested_container.rb @@ -16,6 +16,10 @@ module Hbc private + def summarize + path.relative_path_from(cask.staged_path).to_s + end + def extract(command: nil, verbose: nil, **_) container = Container.for_path(path, command) From 03ae6aae3b95447bc79398b3c58a9fcee67e98ef Mon Sep 17 00:00:00 2001 From: Shaun Jackman Date: Sun, 1 Oct 2017 09:52:29 -0700 Subject: [PATCH 263/294] text_files: Skip the formula in .brew/formula.rb --- Library/Homebrew/keg_relocate.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/Library/Homebrew/keg_relocate.rb b/Library/Homebrew/keg_relocate.rb index 0857486326..71773db816 100644 --- a/Library/Homebrew/keg_relocate.rb +++ b/Library/Homebrew/keg_relocate.rb @@ -124,6 +124,7 @@ class Keg next true if pn.symlink? next true if pn.directory? next false if pn.basename.to_s == "orig-prefix.txt" # for python virtualenvs + next true if pn == self/".brew/#{name}.rb" next true if Metafiles::EXTENSIONS.include?(pn.extname) if pn.text_executable? text_files << pn From fbd526ffe6a619d538193fbc7eb93b6e74c44b00 Mon Sep 17 00:00:00 2001 From: Claudia Date: Mon, 2 Oct 2017 00:26:58 +0200 Subject: [PATCH 264/294] Unshadow `allow_untrusted` option for pkg artifact The pkg stanza has an option called `allow_untrusted`, which is supposed to cause `/usr/sbin/installer` to be called with the `-allowUntrusted` switch. PR #3141 seems to have renamed the `pkg_install_opts` field to `options`. At the same time, it introduces an `options` parameter for the `run_installer` method, which shadows the `options` getter method, causing the `allow_untrusted` option to be silently ignored. The issue affects just the `pkg` stanza because `Hbc::Artifact::Pkg` is the only artifact class that has an `options` method. This commit removes the shadowing by renaming the field to `stanza_options`; in one case, it uses `_options` for a parameter name (instead of the more canonical `_`) for the sake of clarity. --- Library/Homebrew/cask/lib/hbc/artifact/pkg.rb | 22 +++++++++++-------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/Library/Homebrew/cask/lib/hbc/artifact/pkg.rb b/Library/Homebrew/cask/lib/hbc/artifact/pkg.rb index 0967fd99d8..b4bdf3de66 100644 --- a/Library/Homebrew/cask/lib/hbc/artifact/pkg.rb +++ b/Library/Homebrew/cask/lib/hbc/artifact/pkg.rb @@ -9,17 +9,19 @@ module Hbc class Pkg < AbstractArtifact attr_reader :pkg_relative_path - def self.from_args(cask, path, **options) - options.extend(HashValidator).assert_valid_keys(:allow_untrusted, :choices) - new(cask, path, **options) + def self.from_args(cask, path, **stanza_options) + stanza_options.extend(HashValidator).assert_valid_keys( + :allow_untrusted, :choices + ) + new(cask, path, **stanza_options) end - attr_reader :path, :options + attr_reader :path, :stanza_options - def initialize(cask, path, **options) + def initialize(cask, path, **stanza_options) super(cask) @path = cask.staged_path.join(path) - @options = options + @stanza_options = stanza_options end def summarize @@ -32,7 +34,7 @@ module Hbc private - def run_installer(command: nil, verbose: false, **options) + def run_installer(command: nil, verbose: false, **_options) ohai "Running installer for #{cask}; your password may be necessary." ohai "Package installers may write to any location; options such as --appdir are ignored." unless path.exist? @@ -43,7 +45,9 @@ module Hbc "-target", "/" ] args << "-verboseR" if verbose - args << "-allowUntrusted" if options.fetch(:allow_untrusted, false) + if stanza_options.fetch(:allow_untrusted, false) + args << "-allowUntrusted" + end with_choices_file do |choices_path| args << "-applyChoiceChangesXML" << choices_path if choices_path command.run!("/usr/sbin/installer", sudo: true, args: args, print_stdout: true) @@ -51,7 +55,7 @@ module Hbc end def with_choices_file - choices = options.fetch(:choices, {}) + choices = stanza_options.fetch(:choices, {}) return yield nil if choices.empty? Tempfile.open(["choices", ".xml"]) do |file| From 270bf0506a851af4748355791d1875207213466b Mon Sep 17 00:00:00 2001 From: Adam Smith Date: Mon, 2 Oct 2017 11:34:50 -0700 Subject: [PATCH 265/294] stylistic changes for cask info tests --- Library/Homebrew/test/cask/cli/info_spec.rb | 10 +++++----- Library/Homebrew/test/cask/dsl_spec.rb | 2 +- ...h-conditional-languages.rb => without-languages.rb} | 2 +- 3 files changed, 7 insertions(+), 7 deletions(-) rename Library/Homebrew/test/support/fixtures/cask/Casks/{with-conditional-languages.rb => without-languages.rb} (85%) diff --git a/Library/Homebrew/test/cask/cli/info_spec.rb b/Library/Homebrew/test/cask/cli/info_spec.rb index 7d6dfd76d4..df02bb1e5d 100644 --- a/Library/Homebrew/test/cask/cli/info_spec.rb +++ b/Library/Homebrew/test/cask/cli/info_spec.rb @@ -90,7 +90,7 @@ describe Hbc::CLI::Info, :cask do EOS end - it "should print languages if the Cask provided any" do + it "prints languages specified in the Cask" do expect { Hbc::CLI::Info.run("with-languages") }.to output(<<-EOS.undent).to_stdout @@ -107,14 +107,14 @@ describe Hbc::CLI::Info, :cask do EOS end - it 'should not print "Languages" section divider if the languages block has no output' do + it 'does not print "Languages" section divider if the languages block has no output' do expect { - Hbc::CLI::Info.run("with-conditional-languages") + Hbc::CLI::Info.run("without-languages") }.to output(<<-EOS.undent).to_stdout - with-conditional-languages: 1.2.3 + without-languages: 1.2.3 http://example.com/local-caffeine Not installed - From: https://github.com/caskroom/homebrew-spec/blob/master/Casks/with-conditional-languages.rb + From: https://github.com/caskroom/homebrew-spec/blob/master/Casks/without-languages.rb ==> Name None ==> Artifacts diff --git a/Library/Homebrew/test/cask/dsl_spec.rb b/Library/Homebrew/test/cask/dsl_spec.rb index c2a7b2367e..7df8de6f81 100644 --- a/Library/Homebrew/test/cask/dsl_spec.rb +++ b/Library/Homebrew/test/cask/dsl_spec.rb @@ -178,7 +178,7 @@ describe Hbc::DSL, :cask do expect(cask.call.url.to_s).to eq("https://example.org/en-US.zip") end - it "returns empty array if no languages specified" do + it "returns an empty array if no languages are specified" do cask = lambda do Hbc::Cask.new("cask-with-apps") do url "https://example.org/file.zip" diff --git a/Library/Homebrew/test/support/fixtures/cask/Casks/with-conditional-languages.rb b/Library/Homebrew/test/support/fixtures/cask/Casks/without-languages.rb similarity index 85% rename from Library/Homebrew/test/support/fixtures/cask/Casks/with-conditional-languages.rb rename to Library/Homebrew/test/support/fixtures/cask/Casks/without-languages.rb index bf3b9b1c40..4c0ce955ab 100644 --- a/Library/Homebrew/test/support/fixtures/cask/Casks/with-conditional-languages.rb +++ b/Library/Homebrew/test/support/fixtures/cask/Casks/without-languages.rb @@ -1,4 +1,4 @@ -cask 'with-conditional-languages' do +cask 'without-languages' do version '1.2.3' sha256 '67cdb8a02803ef37fdbf7e0be205863172e41a561ca446cd84f0d7ab35a99d94' From a92b6318eb9895ed962612c26abbf0c3f25ce09a Mon Sep 17 00:00:00 2001 From: Markus Reiter Date: Tue, 3 Oct 2017 08:29:20 +0200 Subject: [PATCH 266/294] Remove `UnderscoreSupportingURI`. --- Library/Homebrew/cask/lib/hbc.rb | 1 - Library/Homebrew/cask/lib/hbc/dsl/appcast.rb | 2 +- Library/Homebrew/cask/lib/hbc/dsl/gpg.rb | 6 ++-- .../cask/lib/hbc/underscore_supporting_uri.rb | 28 ------------------- Library/Homebrew/cask/lib/hbc/url.rb | 2 +- .../Homebrew/test/cask/dsl/appcast_spec.rb | 2 +- .../cask/underscore_supporting_uri_spec.rb | 14 ---------- 7 files changed, 6 insertions(+), 49 deletions(-) delete mode 100644 Library/Homebrew/cask/lib/hbc/underscore_supporting_uri.rb delete mode 100644 Library/Homebrew/test/cask/underscore_supporting_uri_spec.rb diff --git a/Library/Homebrew/cask/lib/hbc.rb b/Library/Homebrew/cask/lib/hbc.rb index 780acedf57..01a0850192 100644 --- a/Library/Homebrew/cask/lib/hbc.rb +++ b/Library/Homebrew/cask/lib/hbc.rb @@ -25,7 +25,6 @@ require "hbc/scopes" require "hbc/staged" require "hbc/system_command" require "hbc/topological_hash" -require "hbc/underscore_supporting_uri" require "hbc/url" require "hbc/utils" require "hbc/verify" diff --git a/Library/Homebrew/cask/lib/hbc/dsl/appcast.rb b/Library/Homebrew/cask/lib/hbc/dsl/appcast.rb index fc7e83a20d..f984ac088c 100644 --- a/Library/Homebrew/cask/lib/hbc/dsl/appcast.rb +++ b/Library/Homebrew/cask/lib/hbc/dsl/appcast.rb @@ -7,7 +7,7 @@ module Hbc def initialize(uri, parameters = {}) @parameters = parameters - @uri = UnderscoreSupportingURI.parse(uri) + @uri = URI(uri) @checkpoint = @parameters[:checkpoint] end diff --git a/Library/Homebrew/cask/lib/hbc/dsl/gpg.rb b/Library/Homebrew/cask/lib/hbc/dsl/gpg.rb index b49ebb97cd..99b39d43fd 100644 --- a/Library/Homebrew/cask/lib/hbc/dsl/gpg.rb +++ b/Library/Homebrew/cask/lib/hbc/dsl/gpg.rb @@ -14,11 +14,11 @@ module Hbc def initialize(signature, parameters = {}) @parameters = parameters - @signature = UnderscoreSupportingURI.parse(signature) + @signature = URI(signature) parameters.each do |hkey, hvalue| raise "invalid 'gpg' parameter: '#{hkey.inspect}'" unless VALID_PARAMETERS.include?(hkey) writer_method = "#{hkey}=".to_sym - hvalue = UnderscoreSupportingURI.parse(hvalue) if hkey == :key_url + hvalue = URI(hvalue) if hkey == :key_url valid_id?(hvalue) if hkey == :key_id send(writer_method, hvalue) end @@ -35,7 +35,7 @@ module Hbc end def to_yaml - # bug, :key_url value is not represented as an instance of Hbc::UnderscoreSupportingURI + # bug, :key_url value is not represented as an instance of URI [@signature, @parameters].to_yaml end diff --git a/Library/Homebrew/cask/lib/hbc/underscore_supporting_uri.rb b/Library/Homebrew/cask/lib/hbc/underscore_supporting_uri.rb deleted file mode 100644 index 8f8f66f43e..0000000000 --- a/Library/Homebrew/cask/lib/hbc/underscore_supporting_uri.rb +++ /dev/null @@ -1,28 +0,0 @@ -require "uri" - -module Hbc - module UnderscoreSupportingURI - def self.parse(maybe_uri) - return nil if maybe_uri.nil? - URI.parse(maybe_uri) - rescue URI::InvalidURIError => e - scheme, host, path = simple_parse(maybe_uri) - raise e unless path && host.include?("_") - URI.parse(without_host_underscores(scheme, host, path)).tap do |uri| - uri.instance_variable_set("@host", host) - end - end - - def self.simple_parse(maybe_uri) - scheme, host_and_path = maybe_uri.split("://") - host, path = host_and_path.split("/", 2) - [scheme, host, path] - rescue StandardError - nil - end - - def self.without_host_underscores(scheme, host, path) - ["#{scheme}:/", host.tr("_", "-"), path].join("/") - end - end -end diff --git a/Library/Homebrew/cask/lib/hbc/url.rb b/Library/Homebrew/cask/lib/hbc/url.rb index 8c652657b6..35020c5db3 100644 --- a/Library/Homebrew/cask/lib/hbc/url.rb +++ b/Library/Homebrew/cask/lib/hbc/url.rb @@ -14,7 +14,7 @@ module Hbc end def initialize(uri, options = {}) - @uri = Hbc::UnderscoreSupportingURI.parse(uri) + @uri = URI(uri) @user_agent = options.fetch(:user_agent, :default) @cookies = options[:cookies] @referer = options[:referer] diff --git a/Library/Homebrew/test/cask/dsl/appcast_spec.rb b/Library/Homebrew/test/cask/dsl/appcast_spec.rb index ccc6a46338..bf703eba2d 100644 --- a/Library/Homebrew/test/cask/dsl/appcast_spec.rb +++ b/Library/Homebrew/test/cask/dsl/appcast_spec.rb @@ -4,7 +4,7 @@ describe Hbc::DSL::Appcast do subject { described_class.new(url, params) } let(:url) { "http://example.com" } - let(:uri) { Hbc::UnderscoreSupportingURI.parse(url) } + let(:uri) { URI(url) } let(:params) { {} } describe "#to_s" do diff --git a/Library/Homebrew/test/cask/underscore_supporting_uri_spec.rb b/Library/Homebrew/test/cask/underscore_supporting_uri_spec.rb deleted file mode 100644 index 49d3ea63f7..0000000000 --- a/Library/Homebrew/test/cask/underscore_supporting_uri_spec.rb +++ /dev/null @@ -1,14 +0,0 @@ -describe Hbc::UnderscoreSupportingURI, :cask do - describe "parse" do - it "works like normal on normal URLs" do - uri = Hbc::UnderscoreSupportingURI.parse("http://example.com/TestCask.dmg") - expect(uri).to eq(URI("http://example.com/TestCask.dmg")) - end - - it "works just fine on URIs with underscores" do - uri = Hbc::UnderscoreSupportingURI.parse("http://dl_dir.qq.com/qqfile/qq/QQforMac/QQ_V3.0.0.dmg") - expect(uri.host).to include("_") - expect(uri.to_s).to eq("http://dl_dir.qq.com/qqfile/qq/QQforMac/QQ_V3.0.0.dmg") - end - end -end From 643b2a168c6c5b2f21b141ec385fc49d29c41718 Mon Sep 17 00:00:00 2001 From: Markus Reiter Date: Tue, 3 Oct 2017 10:49:58 +0200 Subject: [PATCH 267/294] Refactor `cask/cli` specs. --- Library/Homebrew/.rubocop.yml | 1 + Library/Homebrew/test/cask/cli/audit_spec.rb | 16 +++-- Library/Homebrew/test/cask/cli/cat_spec.rb | 34 +++-------- .../Homebrew/test/cask/cli/cleanup_spec.rb | 4 ++ Library/Homebrew/test/cask/cli/create_spec.rb | 28 ++------- Library/Homebrew/test/cask/cli/doctor_spec.rb | 4 ++ Library/Homebrew/test/cask/cli/edit_spec.rb | 22 ++----- Library/Homebrew/test/cask/cli/fetch_spec.rb | 30 ++++------ Library/Homebrew/test/cask/cli/home_spec.rb | 4 ++ Library/Homebrew/test/cask/cli/info_spec.rb | 40 ++++--------- .../Homebrew/test/cask/cli/install_spec.rb | 60 ++++++------------- Library/Homebrew/test/cask/cli/list_spec.rb | 14 +++-- .../Homebrew/test/cask/cli/options_spec.rb | 32 +++++----- .../Homebrew/test/cask/cli/outdated_spec.rb | 4 ++ .../Homebrew/test/cask/cli/reinstall_spec.rb | 4 ++ Library/Homebrew/test/cask/cli/search_spec.rb | 4 ++ .../cli/shared_examples/invalid_option.rb | 15 +++++ .../shared_examples/requires_cask_token.rb | 9 +++ Library/Homebrew/test/cask/cli/style_spec.rb | 4 +- .../Homebrew/test/cask/cli/uninstall_spec.rb | 46 ++++++-------- Library/Homebrew/test/cask/cli/zap_spec.rb | 26 +++----- Library/Homebrew/test/cask/depends_on_spec.rb | 5 +- 22 files changed, 178 insertions(+), 228 deletions(-) create mode 100644 Library/Homebrew/test/cask/cli/shared_examples/invalid_option.rb create mode 100644 Library/Homebrew/test/cask/cli/shared_examples/requires_cask_token.rb diff --git a/Library/Homebrew/.rubocop.yml b/Library/Homebrew/.rubocop.yml index dc44065277..3b440c33c8 100644 --- a/Library/Homebrew/.rubocop.yml +++ b/Library/Homebrew/.rubocop.yml @@ -32,6 +32,7 @@ Metrics/ParameterLists: Style/BlockDelimiters: Exclude: - '**/*_spec.rb' + - '**/shared_examples/**/*.rb' # so many of these in formulae but none in here Style/GuardClause: diff --git a/Library/Homebrew/test/cask/cli/audit_spec.rb b/Library/Homebrew/test/cask/cli/audit_spec.rb index 30ab437cbf..da8bf12737 100644 --- a/Library/Homebrew/test/cask/cli/audit_spec.rb +++ b/Library/Homebrew/test/cask/cli/audit_spec.rb @@ -1,6 +1,10 @@ +require_relative "shared_examples/invalid_option" + describe Hbc::CLI::Audit, :cask do let(:cask) { Hbc::Cask.new(nil) } + it_behaves_like "a command that handles invalid options" + describe "selection of Casks to audit" do it "audits all Casks if no tokens are given" do expect(cask).to be_a Hbc::Cask @@ -9,7 +13,7 @@ describe Hbc::CLI::Audit, :cask do expect(Hbc::Auditor).to receive(:audit).twice.and_return(true) - Hbc::CLI::Audit.run + described_class.run end it "audits specified Casks if tokens are given" do @@ -20,7 +24,7 @@ describe Hbc::CLI::Audit, :cask do .with(cask, audit_download: false, check_token_conflicts: false) .and_return(true) - Hbc::CLI::Audit.run(cask_token) + described_class.run(cask_token) end end @@ -31,7 +35,7 @@ describe Hbc::CLI::Audit, :cask do .with(cask, audit_download: false, check_token_conflicts: false) .and_return(true) - Hbc::CLI::Audit.run("casktoken") + described_class.run("casktoken") end it "download a Cask if --download flag is set" do @@ -40,7 +44,7 @@ describe Hbc::CLI::Audit, :cask do .with(cask, audit_download: true, check_token_conflicts: false) .and_return(true) - Hbc::CLI::Audit.run("casktoken", "--download") + described_class.run("casktoken", "--download") end end @@ -51,7 +55,7 @@ describe Hbc::CLI::Audit, :cask do .with(cask, audit_download: false, check_token_conflicts: false) .and_return(true) - Hbc::CLI::Audit.run("casktoken") + described_class.run("casktoken") end it "checks for token conflicts if --token-conflicts flag is set" do @@ -60,7 +64,7 @@ describe Hbc::CLI::Audit, :cask do .with(cask, audit_download: false, check_token_conflicts: true) .and_return(true) - Hbc::CLI::Audit.run("casktoken", "--token-conflicts") + described_class.run("casktoken", "--token-conflicts") end end end diff --git a/Library/Homebrew/test/cask/cli/cat_spec.rb b/Library/Homebrew/test/cask/cli/cat_spec.rb index 5a4b29c6f5..6b54a2e4b0 100644 --- a/Library/Homebrew/test/cask/cli/cat_spec.rb +++ b/Library/Homebrew/test/cask/cli/cat_spec.rb @@ -1,4 +1,10 @@ +require_relative "shared_examples/requires_cask_token" +require_relative "shared_examples/invalid_option" + describe Hbc::CLI::Cat, :cask do + it_behaves_like "a command that requires a Cask token" + it_behaves_like "a command that handles invalid options" + describe "given a basic Cask" do let(:basic_cask_content) { <<-EOS.undent @@ -16,41 +22,19 @@ describe Hbc::CLI::Cat, :cask do it "displays the Cask file content about the specified Cask" do expect { - Hbc::CLI::Cat.run("basic-cask") + described_class.run("basic-cask") }.to output(basic_cask_content).to_stdout end it "can display multiple Casks" do expect { - Hbc::CLI::Cat.run("basic-cask", "basic-cask") + described_class.run("basic-cask", "basic-cask") }.to output(basic_cask_content * 2).to_stdout end - - it "fails when option is unknown" do - expect { - Hbc::CLI::Cat.run("--notavalidoption", "basic-cask") - }.to raise_error(/invalid option/) - end end it "raises an exception when the Cask does not exist" do - expect { Hbc::CLI::Cat.run("notacask") } + expect { described_class.run("notacask") } .to raise_error(Hbc::CaskUnavailableError, /is unavailable/) end - - describe "when no Cask is specified" do - it "raises an exception" do - expect { - Hbc::CLI::Cat.run - }.to raise_error(Hbc::CaskUnspecifiedError) - end - end - - describe "when no Cask is specified, but an invalid option" do - it "raises an exception" do - expect { - Hbc::CLI::Cat.run("--notavalidoption") - }.to raise_error(/invalid option/) - end - end end diff --git a/Library/Homebrew/test/cask/cli/cleanup_spec.rb b/Library/Homebrew/test/cask/cli/cleanup_spec.rb index 64e3ef49fe..7cf00352d3 100644 --- a/Library/Homebrew/test/cask/cli/cleanup_spec.rb +++ b/Library/Homebrew/test/cask/cli/cleanup_spec.rb @@ -1,3 +1,5 @@ +require_relative "shared_examples/invalid_option" + describe Hbc::CLI::Cleanup, :cask do let(:cache_location) { Pathname.new(Dir.mktmpdir).realpath } let(:outdated_only) { false } @@ -12,6 +14,8 @@ describe Hbc::CLI::Cleanup, :cask do cache_location.rmtree end + it_behaves_like "a command that handles invalid options" + describe "cleanup" do let(:cask_token) { "caffeine" } let(:cask_tokens) { [cask_token] } diff --git a/Library/Homebrew/test/cask/cli/create_spec.rb b/Library/Homebrew/test/cask/cli/create_spec.rb index 17d426f78c..60c03db752 100644 --- a/Library/Homebrew/test/cask/cli/create_spec.rb +++ b/Library/Homebrew/test/cask/cli/create_spec.rb @@ -1,3 +1,6 @@ +require_relative "shared_examples/requires_cask_token" +require_relative "shared_examples/invalid_option" + describe Hbc::CLI::Create, :cask do around(:each) do |example| begin @@ -13,6 +16,9 @@ describe Hbc::CLI::Create, :cask do allow_any_instance_of(described_class).to receive(:exec_editor) end + it_behaves_like "a command that requires a Cask token" + it_behaves_like "a command that handles invalid options" + it "opens the editor for the specified Cask" do command = described_class.new("new-cask") expect(command).to receive(:exec_editor).with(Hbc::CaskLoader.path("new-cask")) @@ -53,26 +59,4 @@ describe Hbc::CLI::Create, :cask do expect(command).to receive(:exec_editor).with(Hbc::CaskLoader.path("local-caff")) command.run end - - describe "when no Cask is specified" do - it "raises an exception" do - expect { - described_class.run - }.to raise_error(Hbc::CaskUnspecifiedError) - end - end - - context "when an invalid option is specified" do - it "raises an exception when no Cask is specified" do - expect { - described_class.run("--notavalidoption") - }.to raise_error(/invalid option/) - end - - it "raises an exception" do - expect { - described_class.run("--notavalidoption", "yet-another-cask") - }.to raise_error(/invalid option/) - end - end end diff --git a/Library/Homebrew/test/cask/cli/doctor_spec.rb b/Library/Homebrew/test/cask/cli/doctor_spec.rb index b24c777eb7..e3967060ed 100644 --- a/Library/Homebrew/test/cask/cli/doctor_spec.rb +++ b/Library/Homebrew/test/cask/cli/doctor_spec.rb @@ -1,4 +1,8 @@ +require_relative "shared_examples/invalid_option" + describe Hbc::CLI::Doctor, :cask do + it_behaves_like "a command that handles invalid options" + it "displays some nice info about the environment" do expect { Hbc::CLI::Doctor.run diff --git a/Library/Homebrew/test/cask/cli/edit_spec.rb b/Library/Homebrew/test/cask/cli/edit_spec.rb index 51542807f9..3475220205 100644 --- a/Library/Homebrew/test/cask/cli/edit_spec.rb +++ b/Library/Homebrew/test/cask/cli/edit_spec.rb @@ -1,8 +1,14 @@ +require_relative "shared_examples/requires_cask_token" +require_relative "shared_examples/invalid_option" + describe Hbc::CLI::Edit, :cask do before(:each) do allow_any_instance_of(described_class).to receive(:exec_editor) end + it_behaves_like "a command that requires a Cask token" + it_behaves_like "a command that handles invalid options" + it "opens the editor for the specified Cask" do command = described_class.new("local-caffeine") expect(command).to receive(:exec_editor).with(Hbc::CaskLoader.path("local-caffeine")) @@ -20,20 +26,4 @@ describe Hbc::CLI::Edit, :cask do described_class.run("notacask") }.to raise_error(Hbc::CaskUnavailableError) end - - describe "when no Cask is specified" do - it "raises an exception" do - expect { - described_class.run - }.to raise_error(Hbc::CaskUnspecifiedError) - end - end - - describe "when no Cask is specified, but an invalid option" do - it "raises an exception" do - expect { - described_class.run("--notavalidoption") - }.to raise_error(/invalid option/) - end - end end diff --git a/Library/Homebrew/test/cask/cli/fetch_spec.rb b/Library/Homebrew/test/cask/cli/fetch_spec.rb index faaa69b35b..087a30f50b 100644 --- a/Library/Homebrew/test/cask/cli/fetch_spec.rb +++ b/Library/Homebrew/test/cask/cli/fetch_spec.rb @@ -1,3 +1,6 @@ +require_relative "shared_examples/requires_cask_token" +require_relative "shared_examples/invalid_option" + describe Hbc::CLI::Fetch, :cask do let(:local_transmission) { Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/local-transmission.rb") @@ -7,8 +10,11 @@ describe Hbc::CLI::Fetch, :cask do Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/local-caffeine.rb") } + it_behaves_like "a command that requires a Cask token" + it_behaves_like "a command that handles invalid options" + it "allows download the installer of a Cask" do - Hbc::CLI::Fetch.run("local-transmission", "local-caffeine") + described_class.run("local-transmission", "local-caffeine") expect(Hbc::CurlDownloadStrategy.new(local_transmission).cached_location).to exist expect(Hbc::CurlDownloadStrategy.new(local_caffeine).cached_location).to exist end @@ -19,7 +25,7 @@ describe Hbc::CLI::Fetch, :cask do Hbc::Download.new(local_transmission).perform old_ctime = File.stat(download_stategy.cached_location).ctime - Hbc::CLI::Fetch.run("local-transmission") + described_class.run("local-transmission") new_ctime = File.stat(download_stategy.cached_location).ctime expect(old_ctime.to_i).to eq(new_ctime.to_i) @@ -32,7 +38,7 @@ describe Hbc::CLI::Fetch, :cask do old_ctime = File.stat(download_stategy.cached_location).ctime sleep(1) - Hbc::CLI::Fetch.run("local-transmission", "--force") + described_class.run("local-transmission", "--force") download_stategy = Hbc::CurlDownloadStrategy.new(local_transmission) new_ctime = File.stat(download_stategy.cached_location).ctime @@ -41,23 +47,7 @@ describe Hbc::CLI::Fetch, :cask do it "properly handles Casks that are not present" do expect { - Hbc::CLI::Fetch.run("notacask") + described_class.run("notacask") }.to raise_error(Hbc::CaskUnavailableError) end - - describe "when no Cask is specified" do - it "raises an exception" do - expect { - Hbc::CLI::Fetch.run - }.to raise_error(Hbc::CaskUnspecifiedError) - end - end - - describe "when no Cask is specified, but an invalid option" do - it "raises an exception" do - expect { - Hbc::CLI::Fetch.run("--notavalidoption") - }.to raise_error(/invalid option/) - end - end end diff --git a/Library/Homebrew/test/cask/cli/home_spec.rb b/Library/Homebrew/test/cask/cli/home_spec.rb index e985fb6cd8..8960d2acc0 100644 --- a/Library/Homebrew/test/cask/cli/home_spec.rb +++ b/Library/Homebrew/test/cask/cli/home_spec.rb @@ -1,8 +1,12 @@ +require_relative "shared_examples/invalid_option" + describe Hbc::CLI::Home, :cask do before do allow(described_class).to receive(:open_url) end + it_behaves_like "a command that handles invalid options" + it "opens the homepage for the specified Cask" do expect(described_class).to receive(:open_url).with("http://example.com/local-caffeine") described_class.run("local-caffeine") diff --git a/Library/Homebrew/test/cask/cli/info_spec.rb b/Library/Homebrew/test/cask/cli/info_spec.rb index df02bb1e5d..e24eead118 100644 --- a/Library/Homebrew/test/cask/cli/info_spec.rb +++ b/Library/Homebrew/test/cask/cli/info_spec.rb @@ -1,7 +1,13 @@ +require_relative "shared_examples/requires_cask_token" +require_relative "shared_examples/invalid_option" + describe Hbc::CLI::Info, :cask do + it_behaves_like "a command that requires a Cask token" + it_behaves_like "a command that handles invalid options" + it "displays some nice info about the specified Cask" do expect { - Hbc::CLI::Info.run("local-caffeine") + described_class.run("local-caffeine") }.to output(<<-EOS.undent).to_stdout local-caffeine: 1.2.3 http://example.com/local-caffeine @@ -38,20 +44,14 @@ describe Hbc::CLI::Info, :cask do it "displays the info" do expect { - Hbc::CLI::Info.run("local-caffeine", "local-transmission") + described_class.run("local-caffeine", "local-transmission") }.to output(expected_output).to_stdout end - - it "throws away stray options" do - expect { - Hbc::CLI::Info.run("--notavalidoption", "local-caffeine", "local-transmission") - }.to raise_error(/invalid option/) - end end it "should print caveats if the Cask provided one" do expect { - Hbc::CLI::Info.run("with-caveats") + described_class.run("with-caveats") }.to output(<<-EOS.undent).to_stdout with-caveats: 1.2.3 http://example.com/local-caffeine @@ -77,7 +77,7 @@ describe Hbc::CLI::Info, :cask do it 'should not print "Caveats" section divider if the caveats block has no output' do expect { - Hbc::CLI::Info.run("with-conditional-caveats") + described_class.run("with-conditional-caveats") }.to output(<<-EOS.undent).to_stdout with-conditional-caveats: 1.2.3 http://example.com/local-caffeine @@ -92,7 +92,7 @@ describe Hbc::CLI::Info, :cask do it "prints languages specified in the Cask" do expect { - Hbc::CLI::Info.run("with-languages") + described_class.run("with-languages") }.to output(<<-EOS.undent).to_stdout with-languages: 1.2.3 http://example.com/local-caffeine @@ -109,7 +109,7 @@ describe Hbc::CLI::Info, :cask do it 'does not print "Languages" section divider if the languages block has no output' do expect { - Hbc::CLI::Info.run("without-languages") + described_class.run("without-languages") }.to output(<<-EOS.undent).to_stdout without-languages: 1.2.3 http://example.com/local-caffeine @@ -121,20 +121,4 @@ describe Hbc::CLI::Info, :cask do Caffeine.app (App) EOS end - - describe "when no Cask is specified" do - it "raises an exception" do - expect { - Hbc::CLI::Info.run - }.to raise_error(Hbc::CaskUnspecifiedError) - end - end - - describe "when no Cask is specified, but an invalid option" do - it "raises an exception" do - expect { - Hbc::CLI::Info.run("--notavalidoption") - }.to raise_error(/invalid option/) - end - end end diff --git a/Library/Homebrew/test/cask/cli/install_spec.rb b/Library/Homebrew/test/cask/cli/install_spec.rb index e30489789e..17a7b9f99c 100644 --- a/Library/Homebrew/test/cask/cli/install_spec.rb +++ b/Library/Homebrew/test/cask/cli/install_spec.rb @@ -1,4 +1,10 @@ +require_relative "shared_examples/requires_cask_token" +require_relative "shared_examples/invalid_option" + describe Hbc::CLI::Install, :cask do + it_behaves_like "a command that requires a Cask token" + it_behaves_like "a command that handles invalid options" + it "displays the installation progress" do output = Regexp.new <<-EOS.undent ==> Downloading file:.*caffeine.zip @@ -9,12 +15,12 @@ describe Hbc::CLI::Install, :cask do EOS expect { - Hbc::CLI::Install.run("local-caffeine") + described_class.run("local-caffeine") }.to output(output).to_stdout end it "allows staging and activation of multiple Casks at once" do - Hbc::CLI::Install.run("local-transmission", "local-caffeine") + described_class.run("local-transmission", "local-caffeine") expect(Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/local-transmission.rb")).to be_installed expect(Hbc.appdir.join("Transmission.app")).to be_a_directory @@ -23,31 +29,31 @@ describe Hbc::CLI::Install, :cask do end it "skips double install (without nuking existing installation)" do - Hbc::CLI::Install.run("local-transmission") - Hbc::CLI::Install.run("local-transmission") + described_class.run("local-transmission") + described_class.run("local-transmission") expect(Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/local-transmission.rb")).to be_installed end it "prints a warning message on double install" do - Hbc::CLI::Install.run("local-transmission") + described_class.run("local-transmission") expect { - Hbc::CLI::Install.run("local-transmission") + described_class.run("local-transmission") }.to output(/Warning: Cask 'local-transmission' is already installed./).to_stderr end it "allows double install with --force" do - Hbc::CLI::Install.run("local-transmission") + described_class.run("local-transmission") expect { expect { - Hbc::CLI::Install.run("local-transmission", "--force") + described_class.run("local-transmission", "--force") }.to output(/It seems there is already an App at.*overwriting\./).to_stderr }.to output(/local-transmission was successfully installed!/).to_stdout end it "skips dependencies with --skip-cask-deps" do - Hbc::CLI::Install.run("with-depends-on-cask-multiple", "--skip-cask-deps") + described_class.run("with-depends-on-cask-multiple", "--skip-cask-deps") expect(Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/with-depends-on-cask-multiple.rb")).to be_installed expect(Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/local-caffeine.rb")).not_to be_installed expect(Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/local-transmission.rb")).not_to be_installed @@ -55,49 +61,19 @@ describe Hbc::CLI::Install, :cask do it "properly handles Casks that are not present" do expect { - Hbc::CLI::Install.run("notacask") + described_class.run("notacask") }.to raise_error(Hbc::CaskUnavailableError) end it "returns a suggestion for a misspelled Cask" do expect { - Hbc::CLI::Install.run("localcaffeine") + described_class.run("localcaffeine") }.to raise_error(Hbc::CaskUnavailableError, /Cask 'localcaffeine' is unavailable: No Cask with this name exists\. Did you mean “local-caffeine”?/) end it "returns multiple suggestions for a Cask fragment" do expect { - Hbc::CLI::Install.run("local") + described_class.run("local") }.to raise_error(Hbc::CaskUnavailableError, /Cask 'local' is unavailable: No Cask with this name exists\. Did you mean one of these\?\nlocal-caffeine\nlocal-transmission/) end - - describe "when no Cask is specified" do - with_options = lambda do |options| - it "raises an exception" do - expect { - Hbc::CLI::Install.run(*options) - }.to raise_error(Hbc::CaskUnspecifiedError) - end - end - - describe "without options" do - with_options.call([]) - end - - describe "with --force" do - with_options.call(["--force"]) - end - - describe "with --skip-cask-deps" do - with_options.call(["--skip-cask-deps"]) - end - - describe "with an invalid option" do - it "raises an error" do - expect { - Hbc::CLI::Install.run("--notavalidoption") - }.to raise_error(/invalid option/) - end - end - end end diff --git a/Library/Homebrew/test/cask/cli/list_spec.rb b/Library/Homebrew/test/cask/cli/list_spec.rb index d2d7efd3b6..75da827621 100644 --- a/Library/Homebrew/test/cask/cli/list_spec.rb +++ b/Library/Homebrew/test/cask/cli/list_spec.rb @@ -1,4 +1,8 @@ +require_relative "shared_examples/invalid_option" + describe Hbc::CLI::List, :cask do + it_behaves_like "a command that handles invalid options" + it "lists the installed Casks in a pretty fashion" do casks = %w[local-caffeine local-transmission].map { |c| Hbc::CaskLoader.load(c) } @@ -7,7 +11,7 @@ describe Hbc::CLI::List, :cask do end expect { - Hbc::CLI::List.run + described_class.run }.to output(<<-EOS.undent).to_stdout local-caffeine local-transmission @@ -26,7 +30,7 @@ describe Hbc::CLI::List, :cask do end expect { - Hbc::CLI::List.run("--full-name") + described_class.run("--full-name") }.to output(<<-EOS.undent).to_stdout local-caffeine local-transmission @@ -49,13 +53,13 @@ describe Hbc::CLI::List, :cask do it "of all installed Casks" do expect { - Hbc::CLI::List.run("--versions") + described_class.run("--versions") }.to output(expected_output).to_stdout end it "of given Casks" do expect { - Hbc::CLI::List.run("--versions", "local-caffeine", "local-transmission") + described_class.run("--versions", "local-caffeine", "local-transmission") }.to output(expected_output).to_stdout end end @@ -72,7 +76,7 @@ describe Hbc::CLI::List, :cask do .each { |artifact| artifact.install_phase(command: Hbc::NeverSudoSystemCommand, force: false) } expect { - Hbc::CLI::List.run("local-transmission", "local-caffeine") + described_class.run("local-transmission", "local-caffeine") }.to output(<<-EOS.undent).to_stdout ==> Apps #{Hbc.appdir.join("Transmission.app")} (#{Hbc.appdir.join("Transmission.app").abv}) diff --git a/Library/Homebrew/test/cask/cli/options_spec.rb b/Library/Homebrew/test/cask/cli/options_spec.rb index 98eb05f7e9..82d830795b 100644 --- a/Library/Homebrew/test/cask/cli/options_spec.rb +++ b/Library/Homebrew/test/cask/cli/options_spec.rb @@ -1,6 +1,6 @@ describe Hbc::CLI, :cask do it "supports setting the appdir" do - Hbc::CLI.new.process_options("help", "--appdir=/some/path/foo") + described_class.new.process_options("help", "--appdir=/some/path/foo") expect(Hbc.appdir).to eq(Pathname.new("/some/path/foo")) end @@ -8,13 +8,13 @@ describe Hbc::CLI, :cask do it "supports setting the appdir from ENV" do ENV["HOMEBREW_CASK_OPTS"] = "--appdir=/some/path/bar" - Hbc::CLI.new.process_options("help") + described_class.new.process_options("help") expect(Hbc.appdir).to eq(Pathname.new("/some/path/bar")) end it "supports setting the prefpanedir" do - Hbc::CLI.new.process_options("help", "--prefpanedir=/some/path/foo") + described_class.new.process_options("help", "--prefpanedir=/some/path/foo") expect(Hbc.prefpanedir).to eq(Pathname.new("/some/path/foo")) end @@ -22,13 +22,13 @@ describe Hbc::CLI, :cask do it "supports setting the prefpanedir from ENV" do ENV["HOMEBREW_CASK_OPTS"] = "--prefpanedir=/some/path/bar" - Hbc::CLI.new.process_options("help") + described_class.new.process_options("help") expect(Hbc.prefpanedir).to eq(Pathname.new("/some/path/bar")) end it "supports setting the qlplugindir" do - Hbc::CLI.new.process_options("help", "--qlplugindir=/some/path/foo") + described_class.new.process_options("help", "--qlplugindir=/some/path/foo") expect(Hbc.qlplugindir).to eq(Pathname.new("/some/path/foo")) end @@ -36,13 +36,13 @@ describe Hbc::CLI, :cask do it "supports setting the qlplugindir from ENV" do ENV["HOMEBREW_CASK_OPTS"] = "--qlplugindir=/some/path/bar" - Hbc::CLI.new.process_options("help") + described_class.new.process_options("help") expect(Hbc.qlplugindir).to eq(Pathname.new("/some/path/bar")) end it "supports setting the colorpickerdir" do - Hbc::CLI.new.process_options("help", "--colorpickerdir=/some/path/foo") + described_class.new.process_options("help", "--colorpickerdir=/some/path/foo") expect(Hbc.colorpickerdir).to eq(Pathname.new("/some/path/foo")) end @@ -50,13 +50,13 @@ describe Hbc::CLI, :cask do it "supports setting the colorpickerdir from ENV" do ENV["HOMEBREW_CASK_OPTS"] = "--colorpickerdir=/some/path/bar" - Hbc::CLI.new.process_options("help") + described_class.new.process_options("help") expect(Hbc.colorpickerdir).to eq(Pathname.new("/some/path/bar")) end it "supports setting the dictionarydir" do - Hbc::CLI.new.process_options("help", "--dictionarydir=/some/path/foo") + described_class.new.process_options("help", "--dictionarydir=/some/path/foo") expect(Hbc.dictionarydir).to eq(Pathname.new("/some/path/foo")) end @@ -64,13 +64,13 @@ describe Hbc::CLI, :cask do it "supports setting the dictionarydir from ENV" do ENV["HOMEBREW_CASK_OPTS"] = "--dictionarydir=/some/path/bar" - Hbc::CLI.new.process_options("help") + described_class.new.process_options("help") expect(Hbc.dictionarydir).to eq(Pathname.new("/some/path/bar")) end it "supports setting the fontdir" do - Hbc::CLI.new.process_options("help", "--fontdir=/some/path/foo") + described_class.new.process_options("help", "--fontdir=/some/path/foo") expect(Hbc.fontdir).to eq(Pathname.new("/some/path/foo")) end @@ -78,13 +78,13 @@ describe Hbc::CLI, :cask do it "supports setting the fontdir from ENV" do ENV["HOMEBREW_CASK_OPTS"] = "--fontdir=/some/path/bar" - Hbc::CLI.new.process_options("help") + described_class.new.process_options("help") expect(Hbc.fontdir).to eq(Pathname.new("/some/path/bar")) end it "supports setting the servicedir" do - Hbc::CLI.new.process_options("help", "--servicedir=/some/path/foo") + described_class.new.process_options("help", "--servicedir=/some/path/foo") expect(Hbc.servicedir).to eq(Pathname.new("/some/path/foo")) end @@ -92,13 +92,13 @@ describe Hbc::CLI, :cask do it "supports setting the servicedir from ENV" do ENV["HOMEBREW_CASK_OPTS"] = "--servicedir=/some/path/bar" - Hbc::CLI.new.process_options("help") + described_class.new.process_options("help") expect(Hbc.servicedir).to eq(Pathname.new("/some/path/bar")) end it "allows additional options to be passed through" do - rest = Hbc::CLI.new.process_options("edit", "foo", "--create", "--appdir=/some/path/qux") + rest = described_class.new.process_options("edit", "foo", "--create", "--appdir=/some/path/qux") expect(Hbc.appdir).to eq(Pathname.new("/some/path/qux")) expect(rest).to eq(%w[edit foo --create]) @@ -106,7 +106,7 @@ describe Hbc::CLI, :cask do describe "--help" do it "sets the Cask help method to true" do - command = Hbc::CLI.new("foo", "--help") + command = described_class.new("foo", "--help") expect(command.help?).to be true end end diff --git a/Library/Homebrew/test/cask/cli/outdated_spec.rb b/Library/Homebrew/test/cask/cli/outdated_spec.rb index 946092f894..7fca8c248f 100644 --- a/Library/Homebrew/test/cask/cli/outdated_spec.rb +++ b/Library/Homebrew/test/cask/cli/outdated_spec.rb @@ -1,3 +1,5 @@ +require_relative "shared_examples/invalid_option" + describe Hbc::CLI::Outdated, :cask do let(:installed) do [ @@ -15,6 +17,8 @@ describe Hbc::CLI::Outdated, :cask do allow_any_instance_of(described_class).to receive(:verbose?).and_return(true) end + it_behaves_like "a command that handles invalid options" + describe 'without --greedy it ignores the Casks with "vesion latest" or "auto_updates true"' do it "checks all the installed Casks when no token is provided" do expect { diff --git a/Library/Homebrew/test/cask/cli/reinstall_spec.rb b/Library/Homebrew/test/cask/cli/reinstall_spec.rb index 3a9c3e2f53..073fbb23c7 100644 --- a/Library/Homebrew/test/cask/cli/reinstall_spec.rb +++ b/Library/Homebrew/test/cask/cli/reinstall_spec.rb @@ -1,4 +1,8 @@ +require_relative "shared_examples/invalid_option" + describe Hbc::CLI::Reinstall, :cask do + it_behaves_like "a command that handles invalid options" + it "displays the reinstallation progress" do caffeine = Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/local-caffeine.rb") diff --git a/Library/Homebrew/test/cask/cli/search_spec.rb b/Library/Homebrew/test/cask/cli/search_spec.rb index 3d58e6a151..a4f796f3c6 100644 --- a/Library/Homebrew/test/cask/cli/search_spec.rb +++ b/Library/Homebrew/test/cask/cli/search_spec.rb @@ -1,8 +1,12 @@ +require_relative "shared_examples/invalid_option" + describe Hbc::CLI::Search, :cask do before(:each) do allow(Tty).to receive(:width).and_return(0) end + it_behaves_like "a command that handles invalid options" + it "lists the available Casks that match the search term" do allow(GitHub).to receive(:search_code).and_return([]) diff --git a/Library/Homebrew/test/cask/cli/shared_examples/invalid_option.rb b/Library/Homebrew/test/cask/cli/shared_examples/invalid_option.rb new file mode 100644 index 0000000000..12a05be922 --- /dev/null +++ b/Library/Homebrew/test/cask/cli/shared_examples/invalid_option.rb @@ -0,0 +1,15 @@ +shared_examples "a command that handles invalid options" do + context "when an invalid option is specified" do + it "raises an exception when no Cask is specified" do + expect { + described_class.run("--not-a-valid-option") + }.to raise_error("invalid option: --not-a-valid-option") + end + + it "raises an exception when a Cask is specified" do + expect { + described_class.run("--not-a-valid-option", "basic-cask") + }.to raise_error("invalid option: --not-a-valid-option") + end + end +end diff --git a/Library/Homebrew/test/cask/cli/shared_examples/requires_cask_token.rb b/Library/Homebrew/test/cask/cli/shared_examples/requires_cask_token.rb new file mode 100644 index 0000000000..dc1e471e5a --- /dev/null +++ b/Library/Homebrew/test/cask/cli/shared_examples/requires_cask_token.rb @@ -0,0 +1,9 @@ +shared_examples "a command that requires a Cask token" do + context "when no Cask is specified" do + it "raises an exception " do + expect { + described_class.run + }.to raise_error(Hbc::CaskUnspecifiedError, "This command requires a Cask token.") + end + end +end diff --git a/Library/Homebrew/test/cask/cli/style_spec.rb b/Library/Homebrew/test/cask/cli/style_spec.rb index 2007b87d71..12cd348a09 100644 --- a/Library/Homebrew/test/cask/cli/style_spec.rb +++ b/Library/Homebrew/test/cask/cli/style_spec.rb @@ -1,11 +1,13 @@ require "open3" require "rubygems" +require_relative "shared_examples/invalid_option" + describe Hbc::CLI::Style, :cask do let(:args) { [] } let(:cli) { described_class.new(*args) } - around(&:run) + it_behaves_like "a command that handles invalid options" describe "#run" do subject { cli.run } diff --git a/Library/Homebrew/test/cask/cli/uninstall_spec.rb b/Library/Homebrew/test/cask/cli/uninstall_spec.rb index 2ec506839b..9ebd80dfbe 100644 --- a/Library/Homebrew/test/cask/cli/uninstall_spec.rb +++ b/Library/Homebrew/test/cask/cli/uninstall_spec.rb @@ -1,4 +1,10 @@ +require_relative "shared_examples/requires_cask_token" +require_relative "shared_examples/invalid_option" + describe Hbc::CLI::Uninstall, :cask do + it_behaves_like "a command that requires a Cask token" + it_behaves_like "a command that handles invalid options" + it "displays the uninstallation progress" do caffeine = Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/local-caffeine.rb") @@ -10,23 +16,23 @@ describe Hbc::CLI::Uninstall, :cask do EOS expect { - Hbc::CLI::Uninstall.run("local-caffeine") + described_class.run("local-caffeine") }.to output(output).to_stdout end it "shows an error when a bad Cask is provided" do - expect { Hbc::CLI::Uninstall.run("notacask") } + expect { described_class.run("notacask") } .to raise_error(Hbc::CaskUnavailableError, /is unavailable/) end it "shows an error when a Cask is provided that's not installed" do - expect { Hbc::CLI::Uninstall.run("local-caffeine") } + expect { described_class.run("local-caffeine") } .to raise_error(Hbc::CaskNotInstalledError, /is not installed/) end it "tries anyway on a non-present Cask when --force is given" do expect { - Hbc::CLI::Uninstall.run("local-caffeine", "--force") + described_class.run("local-caffeine", "--force") }.not_to raise_error end @@ -40,7 +46,7 @@ describe Hbc::CLI::Uninstall, :cask do expect(caffeine).to be_installed expect(transmission).to be_installed - Hbc::CLI::Uninstall.run("local-caffeine", "local-transmission") + described_class.run("local-caffeine", "local-transmission") expect(caffeine).not_to be_installed expect(Hbc.appdir.join("Transmission.app")).not_to exist @@ -57,7 +63,7 @@ describe Hbc::CLI::Uninstall, :cask do expect(Hbc.appdir.join("MyFancyApp.app")).to exist expect { - Hbc::CLI::Uninstall.run("with-uninstall-script-app") + described_class.run("with-uninstall-script-app") }.not_to raise_error expect(cask).not_to be_installed @@ -73,13 +79,13 @@ describe Hbc::CLI::Uninstall, :cask do Hbc.appdir.join("MyFancyApp.app").rmtree - expect { Hbc::CLI::Uninstall.run("with-uninstall-script-app") } + expect { described_class.run("with-uninstall-script-app") } .to raise_error(Hbc::CaskError, /uninstall script .* does not exist/) expect(cask).to be_installed expect { - Hbc::CLI::Uninstall.run("with-uninstall-script-app", "--force") + described_class.run("with-uninstall-script-app", "--force") }.not_to raise_error expect(cask).not_to be_installed @@ -112,13 +118,13 @@ describe Hbc::CLI::Uninstall, :cask do end it "uninstalls one version at a time" do - Hbc::CLI::Uninstall.run("versioned-cask") + described_class.run("versioned-cask") expect(caskroom_path.join(first_installed_version)).to exist expect(caskroom_path.join(last_installed_version)).not_to exist expect(caskroom_path).to exist - Hbc::CLI::Uninstall.run("versioned-cask") + described_class.run("versioned-cask") expect(caskroom_path.join(first_installed_version)).not_to exist expect(caskroom_path).not_to exist @@ -127,7 +133,7 @@ describe Hbc::CLI::Uninstall, :cask do it "displays a message when versions remain installed" do expect { expect { - Hbc::CLI::Uninstall.run("versioned-cask") + described_class.run("versioned-cask") }.not_to output.to_stderr }.to output(/#{token} #{first_installed_version} is still installed./).to_stdout end @@ -157,26 +163,10 @@ describe Hbc::CLI::Uninstall, :cask do end it "can still uninstall those Casks" do - Hbc::CLI::Uninstall.run("ive-been-renamed") + described_class.run("ive-been-renamed") expect(app).not_to exist expect(caskroom_path).not_to exist end end - - describe "when no Cask is specified" do - it "raises an exception" do - expect { - Hbc::CLI::Uninstall.run - }.to raise_error(Hbc::CaskUnspecifiedError) - end - end - - describe "when no Cask is specified, but an invalid option" do - it "raises an exception" do - expect { - Hbc::CLI::Uninstall.run("--notavalidoption") - }.to raise_error(/invalid option/) - end - end end diff --git a/Library/Homebrew/test/cask/cli/zap_spec.rb b/Library/Homebrew/test/cask/cli/zap_spec.rb index 502bf8e697..19e8ff261c 100644 --- a/Library/Homebrew/test/cask/cli/zap_spec.rb +++ b/Library/Homebrew/test/cask/cli/zap_spec.rb @@ -1,6 +1,12 @@ +require_relative "shared_examples/requires_cask_token" +require_relative "shared_examples/invalid_option" + describe Hbc::CLI::Zap, :cask do + it_behaves_like "a command that requires a Cask token" + it_behaves_like "a command that handles invalid options" + it "shows an error when a bad Cask is provided" do - expect { Hbc::CLI::Zap.run("notacask") } + expect { described_class.run("notacask") } .to raise_error(Hbc::CaskUnavailableError, /is unavailable/) end @@ -14,7 +20,7 @@ describe Hbc::CLI::Zap, :cask do expect(caffeine).to be_installed expect(transmission).to be_installed - Hbc::CLI::Zap.run("local-caffeine", "local-transmission") + described_class.run("local-caffeine", "local-transmission") expect(caffeine).not_to be_installed expect(Hbc.appdir.join("Caffeine.app")).not_to be_a_symlink @@ -45,20 +51,4 @@ describe Hbc::CLI::Zap, :cask do # # with_zap.wont_be :installed? # end - - describe "when no Cask is specified" do - it "raises an exception" do - expect { - Hbc::CLI::Zap.run - }.to raise_error(Hbc::CaskUnspecifiedError) - end - end - - describe "when no Cask is specified, but an invalid option" do - it "raises an exception" do - expect { - Hbc::CLI::Zap.run("--notavalidoption") - }.to raise_error(/invalid option/) - end - end end diff --git a/Library/Homebrew/test/cask/depends_on_spec.rb b/Library/Homebrew/test/cask/depends_on_spec.rb index fb92a9a24e..2818ff8b0b 100644 --- a/Library/Homebrew/test/cask/depends_on_spec.rb +++ b/Library/Homebrew/test/cask/depends_on_spec.rb @@ -10,7 +10,10 @@ describe "Satisfy Dependencies and Requirements", :cask do describe "depends_on cask" do context "when depends_on cask is cyclic" do let(:cask) { Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/with-depends-on-cask-cyclic.rb") } - it { is_expected.to raise_error(Hbc::CaskCyclicDependencyError) } + it { + is_expected.to raise_error(Hbc::CaskCyclicDependencyError, + "Cask 'with-depends-on-cask-cyclic' includes cyclic dependencies on other Casks: with-depends-on-cask-cyclic-helper") + } end context do From 9d36096d68d5b362f223b993ac7662588450d942 Mon Sep 17 00:00:00 2001 From: Kevin Abel Date: Tue, 3 Oct 2017 23:29:33 -0500 Subject: [PATCH 268/294] Add version detection support for php URL Pulls a semver from anywhere in the URL (not just stem). --- Library/Homebrew/version.rb | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Library/Homebrew/version.rb b/Library/Homebrew/version.rb index b03a4bc332..3ac7480371 100644 --- a/Library/Homebrew/version.rb +++ b/Library/Homebrew/version.rb @@ -456,6 +456,10 @@ class Version # e.g. http://www.ijg.org/files/jpegsrc.v8d.tar.gz m = /\.v(\d+[a-z]?)/.match(stem) return m.captures.first unless m.nil? + + # e.g. https://secure.php.net/get/php-7.1.10.tar.bz2/from/this/mirror + m = /[-.vV]?((?:\d+\.)+\d+(?:[-_.]?(?i:alpha|beta|pre|rc)\.?\d{,2})?)/.match(spec_s) + return m.captures.first unless m.nil? end end From 4f55565677101a1a3b63567ce937b8cf72eae252 Mon Sep 17 00:00:00 2001 From: Kevin Abel Date: Tue, 3 Oct 2017 23:39:14 -0500 Subject: [PATCH 269/294] Add test for php version in URL middle --- Library/Homebrew/test/version_spec.rb | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/Library/Homebrew/test/version_spec.rb b/Library/Homebrew/test/version_spec.rb index d670d79c80..d0393afa65 100644 --- a/Library/Homebrew/test/version_spec.rb +++ b/Library/Homebrew/test/version_spec.rb @@ -649,6 +649,11 @@ describe Version do .to be_detected_from("ftp://gcc.gnu.org/pub/gcc/snapshots/6-20151227/gcc-6-20151227.tar.bz2") end + specify "semver in middle of URL" do + expect(Version.create("7.1.10")) + .to be_detected_from("https://php.net/get/php-7.1.10.tar.gz/from/this/mirror") + end + specify "from URL" do expect(Version.create("1.2.3")) .to be_detected_from("http://github.com/foo/bar.git", tag: "v1.2.3") From 83e2049636d023f8181badf844171fe4f9e5a29f Mon Sep 17 00:00:00 2001 From: Mike McQuaid Date: Wed, 4 Oct 2017 10:14:06 +0100 Subject: [PATCH 270/294] formulary: handle unreadable bottle formula. This occurs for any formulae that use relative `require` to files that are inside of e.g. a tap to use abstract formulae. --- Library/Homebrew/formulary.rb | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/Library/Homebrew/formulary.rb b/Library/Homebrew/formulary.rb index c8ab8a9228..0eb34ee2ab 100644 --- a/Library/Homebrew/formulary.rb +++ b/Library/Homebrew/formulary.rb @@ -124,7 +124,15 @@ module Formulary def get_formula(spec, **) contents = Utils::Bottles.formula_contents @bottle_filename, name: name - formula = Formulary.from_contents name, @bottle_filename, contents, spec + formula = begin + Formulary.from_contents name, @bottle_filename, contents, spec + rescue FormulaUnreadableError => e + opoo <<-EOS.undent + Unreadable formula in #{@bottle_filename}: + #{e} + EOS + super + end formula.local_bottle_path = @bottle_filename formula end From a9f5c175c72c24ae13f3ffd24552a81c1c7f118f Mon Sep 17 00:00:00 2001 From: Mike McQuaid Date: Wed, 4 Oct 2017 16:39:49 +0100 Subject: [PATCH 271/294] CODE_OF_CONDUCT: rename from CODEOFCONDUCT. So GitHub can detect it. --- CODEOFCONDUCT.md => CODE_OF_CONDUCT.md | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename CODEOFCONDUCT.md => CODE_OF_CONDUCT.md (100%) diff --git a/CODEOFCONDUCT.md b/CODE_OF_CONDUCT.md similarity index 100% rename from CODEOFCONDUCT.md rename to CODE_OF_CONDUCT.md From 2c7ef064e4ff0833ac94a4f18f5049ad17c30b7c Mon Sep 17 00:00:00 2001 From: Markus Reiter Date: Wed, 4 Oct 2017 15:47:53 +0200 Subject: [PATCH 272/294] Refactor DSL and Artifacts. --- .../lib/hbc/artifact/abstract_artifact.rb | 2 +- .../lib/hbc/artifact/abstract_flight_block.rb | 6 ----- Library/Homebrew/cask/lib/hbc/audit.rb | 2 +- .../Homebrew/cask/lib/hbc/container/base.rb | 2 +- Library/Homebrew/cask/lib/hbc/dsl.rb | 19 ++++++++-------- Library/Homebrew/cask/lib/hbc/dsl/appcast.rb | 16 +++++++------- Library/Homebrew/cask/lib/hbc/dsl/base.rb | 6 ++--- Library/Homebrew/cask/lib/hbc/staged.rb | 2 +- Library/Homebrew/test/cask/dsl_spec.rb | 22 +++++++++---------- 9 files changed, 35 insertions(+), 42 deletions(-) diff --git a/Library/Homebrew/cask/lib/hbc/artifact/abstract_artifact.rb b/Library/Homebrew/cask/lib/hbc/artifact/abstract_artifact.rb index 1b18cc6e7d..fa8fc29968 100644 --- a/Library/Homebrew/cask/lib/hbc/artifact/abstract_artifact.rb +++ b/Library/Homebrew/cask/lib/hbc/artifact/abstract_artifact.rb @@ -20,7 +20,7 @@ module Hbc end def self.for_cask(cask) - cask.artifacts[dsl_key].to_a + cask.artifacts[self].to_a end # TODO: this sort of logic would make more sense in dsl.rb, or a diff --git a/Library/Homebrew/cask/lib/hbc/artifact/abstract_flight_block.rb b/Library/Homebrew/cask/lib/hbc/artifact/abstract_flight_block.rb index 4e8edbc11c..a3075ff409 100644 --- a/Library/Homebrew/cask/lib/hbc/artifact/abstract_flight_block.rb +++ b/Library/Homebrew/cask/lib/hbc/artifact/abstract_flight_block.rb @@ -11,12 +11,6 @@ module Hbc dsl_key.to_s.prepend("uninstall_").to_sym end - def self.for_cask(cask) - [dsl_key, uninstall_dsl_key].flat_map do |key| - [*cask.artifacts[key]].map { |block| new(cask, key => block) } - end - end - attr_reader :directives def initialize(cask, **directives) diff --git a/Library/Homebrew/cask/lib/hbc/audit.rb b/Library/Homebrew/cask/lib/hbc/audit.rb index 9ab93a67f0..2d8e4e4d74 100644 --- a/Library/Homebrew/cask/lib/hbc/audit.rb +++ b/Library/Homebrew/cask/lib/hbc/audit.rb @@ -218,7 +218,7 @@ module Hbc end def check_generic_artifacts - cask.artifacts[:artifact].each do |artifact| + cask.artifacts[Hbc::Artifact::Artifact].each do |artifact| unless artifact.target.absolute? add_error "target must be absolute path for #{artifact.class.english_name} #{artifact.source}" end diff --git a/Library/Homebrew/cask/lib/hbc/container/base.rb b/Library/Homebrew/cask/lib/hbc/container/base.rb index 52eb5aab17..4363168e73 100644 --- a/Library/Homebrew/cask/lib/hbc/container/base.rb +++ b/Library/Homebrew/cask/lib/hbc/container/base.rb @@ -20,7 +20,7 @@ module Hbc unless children.count == 1 && !nested_container.directory? && - @cask.artifacts[:nested_container].empty? && + Artifact::NestedContainer.for_cask(@cask).none? && extract_nested_container(nested_container) children.each do |src| diff --git a/Library/Homebrew/cask/lib/hbc/dsl.rb b/Library/Homebrew/cask/lib/hbc/dsl.rb index 8d5b6c9a9d..75c1ca8736 100644 --- a/Library/Homebrew/cask/lib/hbc/dsl.rb +++ b/Library/Homebrew/cask/lib/hbc/dsl.rb @@ -43,7 +43,7 @@ module Hbc Artifact::Zap, ].freeze - ACTIVATABLE_ARTIFACT_TYPES = (ORDINARY_ARTIFACT_CLASSES.map(&:dsl_key) - [:stage_only]).freeze + ACTIVATABLE_ARTIFACT_CLASSES = ORDINARY_ARTIFACT_CLASSES - [Artifact::StageOnly] ARTIFACT_BLOCK_CLASSES = [ Artifact::PreflightBlock, @@ -71,11 +71,12 @@ module Hbc :version, :appdir, *ORDINARY_ARTIFACT_CLASSES.map(&:dsl_key), - *ACTIVATABLE_ARTIFACT_TYPES, + *ACTIVATABLE_ARTIFACT_CLASSES.map(&:dsl_key), *ARTIFACT_BLOCK_CLASSES.flat_map { |klass| [klass.dsl_key, klass.uninstall_dsl_key] }, ].freeze - attr_reader :token, :cask + attr_reader :cask, :token + def initialize(cask) @cask = cask @token = cask.token @@ -175,7 +176,7 @@ module Hbc DSL::Container.new(*args).tap do |container| # TODO: remove this backward-compatibility section after removing nested_container if container&.nested - artifacts[:nested_container] << Artifact::NestedContainer.new(cask, container.nested) + artifacts[Artifact::NestedContainer] << Artifact::NestedContainer.new(cask, container.nested) end end end @@ -250,15 +251,13 @@ module Hbc end ORDINARY_ARTIFACT_CLASSES.each do |klass| - type = klass.dsl_key - - define_method(type) do |*args| + define_method(klass.dsl_key) do |*args| begin - if [*artifacts.keys, type].include?(:stage_only) && (artifacts.keys & ACTIVATABLE_ARTIFACT_TYPES).any? + if [*artifacts.keys, klass].include?(Artifact::StageOnly) && (artifacts.keys & ACTIVATABLE_ARTIFACT_CLASSES).any? raise CaskInvalidError.new(cask, "'stage_only' must be the only activatable artifact.") end - artifacts[type].add(klass.from_args(cask, *args)) + artifacts[klass].add(klass.from_args(cask, *args)) rescue CaskInvalidError raise rescue StandardError => e @@ -270,7 +269,7 @@ module Hbc ARTIFACT_BLOCK_CLASSES.each do |klass| [klass.dsl_key, klass.uninstall_dsl_key].each do |dsl_key| define_method(dsl_key) do |&block| - artifacts[dsl_key] << block + artifacts[klass] << klass.new(cask, dsl_key => block) end end end diff --git a/Library/Homebrew/cask/lib/hbc/dsl/appcast.rb b/Library/Homebrew/cask/lib/hbc/dsl/appcast.rb index f984ac088c..f3994b81f2 100644 --- a/Library/Homebrew/cask/lib/hbc/dsl/appcast.rb +++ b/Library/Homebrew/cask/lib/hbc/dsl/appcast.rb @@ -3,17 +3,17 @@ require "hbc/system_command" module Hbc class DSL class Appcast - attr_reader :parameters, :checkpoint + attr_reader :uri, :checkpoint, :parameters - def initialize(uri, parameters = {}) - @parameters = parameters - @uri = URI(uri) - @checkpoint = @parameters[:checkpoint] + def initialize(uri, **parameters) + @uri = URI(uri) + @parameters = parameters + @checkpoint = parameters[:checkpoint] end def calculate_checkpoint curl_executable, *args = curl_args( - "--compressed", "--location", "--fail", @uri, + "--compressed", "--location", "--fail", uri, user_agent: :fake ) result = SystemCommand.run(curl_executable, args: args, print_stderr: false) @@ -30,11 +30,11 @@ module Hbc end def to_yaml - [@uri, @parameters].to_yaml + [uri, parameters].to_yaml end def to_s - @uri.to_s + uri.to_s end end end diff --git a/Library/Homebrew/cask/lib/hbc/dsl/base.rb b/Library/Homebrew/cask/lib/hbc/dsl/base.rb index 63df847e95..b97c4e104e 100644 --- a/Library/Homebrew/cask/lib/hbc/dsl/base.rb +++ b/Library/Homebrew/cask/lib/hbc/dsl/base.rb @@ -10,14 +10,14 @@ module Hbc def_delegators :@cask, :token, :version, :caskroom_path, :staged_path, :appdir, :language - def system_command(executable, options = {}) - @command.run!(executable, options) + def system_command(executable, **options) + @command.run!(executable, **options) end def method_missing(method, *) if method underscored_class = self.class.name.gsub(/([[:lower:]])([[:upper:]][[:lower:]])/, '\1_\2').downcase - section = underscored_class.downcase.split("::").last + section = underscored_class.split("::").last Utils.method_missing_message(method, @cask.to_s, section) nil else diff --git a/Library/Homebrew/cask/lib/hbc/staged.rb b/Library/Homebrew/cask/lib/hbc/staged.rb index dc21279dee..6fd3f6709a 100644 --- a/Library/Homebrew/cask/lib/hbc/staged.rb +++ b/Library/Homebrew/cask/lib/hbc/staged.rb @@ -4,7 +4,7 @@ module Hbc index = 0 if index == :first index = 1 if index == :second index = -1 if index == :last - @cask.artifacts[:app].to_a.at(index).target.join("Contents", "Info.plist") + @cask.artifacts[Artifact::App].to_a.at(index).target.join("Contents", "Info.plist") end def plist_exec(cmd) diff --git a/Library/Homebrew/test/cask/dsl_spec.rb b/Library/Homebrew/test/cask/dsl_spec.rb index 7df8de6f81..e03af9aef4 100644 --- a/Library/Homebrew/test/cask/dsl_spec.rb +++ b/Library/Homebrew/test/cask/dsl_spec.rb @@ -216,12 +216,12 @@ describe Hbc::DSL, :cask do app "Bar.app" end - expect(cask.artifacts[:app].map(&:to_s)).to eq(["Foo.app (App)", "Bar.app (App)"]) + expect(cask.artifacts[Hbc::Artifact::App].map(&:to_s)).to eq(["Foo.app (App)", "Bar.app (App)"]) end it "allow app stanzas to be empty" do cask = Hbc::Cask.new("cask-with-no-apps") - expect(cask.artifacts[:app]).to be_empty + expect(cask.artifacts[Hbc::Artifact::App]).to be_empty end end @@ -249,7 +249,7 @@ describe Hbc::DSL, :cask do pkg "Bar.pkg" end - expect(cask.artifacts[:pkg].map(&:to_s)).to eq(["Foo.pkg (Pkg)", "Bar.pkg (Pkg)"]) + expect(cask.artifacts[Hbc::Artifact::Pkg].map(&:to_s)).to eq(["Foo.pkg (Pkg)", "Bar.pkg (Pkg)"]) end end @@ -501,10 +501,10 @@ describe Hbc::DSL, :cask do let(:token) { "with-installer-script" } it "allows installer script to be specified" do - expect(cask.artifacts[:installer].first.path).to eq(Pathname("/usr/bin/true")) - expect(cask.artifacts[:installer].first.args[:args]).to eq(["--flag"]) - expect(cask.artifacts[:installer].to_a[1].path).to eq(Pathname("/usr/bin/false")) - expect(cask.artifacts[:installer].to_a[1].args[:args]).to eq(["--flag"]) + expect(cask.artifacts[Hbc::Artifact::Installer].first.path).to eq(Pathname("/usr/bin/true")) + expect(cask.artifacts[Hbc::Artifact::Installer].first.args[:args]).to eq(["--flag"]) + expect(cask.artifacts[Hbc::Artifact::Installer].to_a[1].path).to eq(Pathname("/usr/bin/false")) + expect(cask.artifacts[Hbc::Artifact::Installer].to_a[1].args[:args]).to eq(["--flag"]) end end @@ -512,7 +512,7 @@ describe Hbc::DSL, :cask do let(:token) { "with-installer-manual" } it "allows installer manual to be specified" do - installer = cask.artifacts[:installer].first + installer = cask.artifacts[Hbc::Artifact::Installer].first expect(installer).to be_a(Hbc::Artifact::Installer::ManualInstaller) expect(installer.path).to eq(cask.staged_path.join("Caffeine.app")) end @@ -524,7 +524,7 @@ describe Hbc::DSL, :cask do let(:token) { "stage-only" } it "allows stage_only stanza to be specified" do - expect(cask.artifacts[:stage_only]).not_to be_empty + expect(cask.artifacts[Hbc::Artifact::StageOnly]).not_to be_empty end end @@ -550,7 +550,7 @@ describe Hbc::DSL, :cask do let(:token) { "appdir-interpolation" } it "is allowed" do - expect(cask.artifacts[:binary].first.source).to eq(Hbc.appdir/"some/path") + expect(cask.artifacts[Hbc::Artifact::Binary].first.source).to eq(Hbc.appdir/"some/path") end end @@ -563,7 +563,7 @@ describe Hbc::DSL, :cask do binary "#{appdir}/some/path" end - expect(cask.artifacts[:binary].first.source).to eq(original_appdir/"some/path") + expect(cask.artifacts[Hbc::Artifact::Binary].first.source).to eq(original_appdir/"some/path") ensure Hbc.appdir = original_appdir end From 51a0de6368974eb3476369b819c3823feebebdce Mon Sep 17 00:00:00 2001 From: Markus Reiter Date: Wed, 4 Oct 2017 17:08:35 +0200 Subject: [PATCH 273/294] Directly save artifacts in DSL. --- Library/Homebrew/cask/lib/hbc/artifact.rb | 5 -- .../lib/hbc/artifact/abstract_artifact.rb | 32 +++++++++++- Library/Homebrew/cask/lib/hbc/audit.rb | 2 +- Library/Homebrew/cask/lib/hbc/cli/info.rb | 10 ++-- Library/Homebrew/cask/lib/hbc/cli/list.rb | 2 +- .../Homebrew/cask/lib/hbc/container/base.rb | 2 +- Library/Homebrew/cask/lib/hbc/dsl.rb | 10 ++-- Library/Homebrew/cask/lib/hbc/installer.rb | 6 +-- Library/Homebrew/cask/lib/hbc/staged.rb | 2 +- .../test/cask/artifact/alt_target_spec.rb | 2 +- .../Homebrew/test/cask/artifact/app_spec.rb | 2 +- .../test/cask/artifact/binary_spec.rb | 14 +++--- .../cask/artifact/generic_artifact_spec.rb | 2 +- .../cask/artifact/nested_container_spec.rb | 2 +- .../Homebrew/test/cask/artifact/pkg_spec.rb | 4 +- .../cask/artifact/postflight_block_spec.rb | 4 +- .../cask/artifact/preflight_block_spec.rb | 4 +- .../Homebrew/test/cask/artifact/suite_spec.rb | 2 +- .../cask/artifact/two_apps_correct_spec.rb | 2 +- .../cask/artifact/uninstall_no_zap_spec.rb | 2 +- .../artifact/uninstall_zap_shared_examples.rb | 2 +- Library/Homebrew/test/cask/cli/list_spec.rb | 2 +- Library/Homebrew/test/cask/dsl_spec.rb | 49 ++++++++++++++----- 23 files changed, 106 insertions(+), 58 deletions(-) diff --git a/Library/Homebrew/cask/lib/hbc/artifact.rb b/Library/Homebrew/cask/lib/hbc/artifact.rb index cb15ec0513..505f9ec134 100644 --- a/Library/Homebrew/cask/lib/hbc/artifact.rb +++ b/Library/Homebrew/cask/lib/hbc/artifact.rb @@ -59,10 +59,5 @@ module Hbc PostflightBlock, Zap, ].freeze - - def self.for_cask(cask) - odebug "Determining which artifacts are present in Cask #{cask}" - CLASSES.flat_map { |klass| klass.for_cask(cask) } - end end end diff --git a/Library/Homebrew/cask/lib/hbc/artifact/abstract_artifact.rb b/Library/Homebrew/cask/lib/hbc/artifact/abstract_artifact.rb index fa8fc29968..331e098e01 100644 --- a/Library/Homebrew/cask/lib/hbc/artifact/abstract_artifact.rb +++ b/Library/Homebrew/cask/lib/hbc/artifact/abstract_artifact.rb @@ -1,6 +1,7 @@ module Hbc module Artifact class AbstractArtifact + include Comparable extend Predicable def self.english_name @@ -19,8 +20,35 @@ module Hbc @dirmethod ||= "#{dsl_key}dir".to_sym end - def self.for_cask(cask) - cask.artifacts[self].to_a + def <=>(other) + @@sort_order ||= [ # rubocop:disable Style/ClassVars + PreflightBlock, + Uninstall, + NestedContainer, + Installer, + App, + Suite, + Artifact, # generic 'artifact' stanza + Colorpicker, + Pkg, + Prefpane, + Qlplugin, + Dictionary, + Font, + Service, + StageOnly, + Binary, + InputMethod, + InternetPlugin, + AudioUnitPlugin, + VstPlugin, + Vst3Plugin, + ScreenSaver, + PostflightBlock, + Zap, + ] + + (@@sort_order.index(self.class) <=> @@sort_order.index(other.class)).to_i end # TODO: this sort of logic would make more sense in dsl.rb, or a diff --git a/Library/Homebrew/cask/lib/hbc/audit.rb b/Library/Homebrew/cask/lib/hbc/audit.rb index 2d8e4e4d74..5b5a7b63d6 100644 --- a/Library/Homebrew/cask/lib/hbc/audit.rb +++ b/Library/Homebrew/cask/lib/hbc/audit.rb @@ -218,7 +218,7 @@ module Hbc end def check_generic_artifacts - cask.artifacts[Hbc::Artifact::Artifact].each do |artifact| + cask.artifacts.select { |a| a.is_a?(Hbc::Artifact::Artifact) }.each do |artifact| unless artifact.target.absolute? add_error "target must be absolute path for #{artifact.class.english_name} #{artifact.source}" end diff --git a/Library/Homebrew/cask/lib/hbc/cli/info.rb b/Library/Homebrew/cask/lib/hbc/cli/info.rb index 2b4db95309..f12fe55648 100644 --- a/Library/Homebrew/cask/lib/hbc/cli/info.rb +++ b/Library/Homebrew/cask/lib/hbc/cli/info.rb @@ -77,11 +77,11 @@ module Hbc def self.artifact_info(cask) ohai "Artifacts" - DSL::ORDINARY_ARTIFACT_CLASSES.flat_map { |klass| klass.for_cask(cask) } - .select { |artifact| artifact.respond_to?(:install_phase) } - .each do |artifact| - puts artifact.to_s - end + cask.artifacts.each do |artifact| + next unless artifact.respond_to?(:install_phase) + next unless DSL::ORDINARY_ARTIFACT_CLASSES.include?(artifact.class) + puts artifact.to_s + end end end end diff --git a/Library/Homebrew/cask/lib/hbc/cli/list.rb b/Library/Homebrew/cask/lib/hbc/cli/list.rb index 32415af8a5..4b6a25d01e 100644 --- a/Library/Homebrew/cask/lib/hbc/cli/list.rb +++ b/Library/Homebrew/cask/lib/hbc/cli/list.rb @@ -30,7 +30,7 @@ module Hbc end def self.list_artifacts(cask) - Artifact.for_cask(cask).group_by(&:class).each do |klass, artifacts| + cask.artifacts.group_by(&:class).each do |klass, artifacts| next unless klass.respond_to?(:english_description) ohai klass.english_description, artifacts.map(&:summarize_installed) end diff --git a/Library/Homebrew/cask/lib/hbc/container/base.rb b/Library/Homebrew/cask/lib/hbc/container/base.rb index 4363168e73..78610a1ab5 100644 --- a/Library/Homebrew/cask/lib/hbc/container/base.rb +++ b/Library/Homebrew/cask/lib/hbc/container/base.rb @@ -20,7 +20,7 @@ module Hbc unless children.count == 1 && !nested_container.directory? && - Artifact::NestedContainer.for_cask(@cask).none? && + @cask.artifacts.none? { |a| a.is_a?(Artifact::NestedContainer) } && extract_nested_container(nested_container) children.each do |src| diff --git a/Library/Homebrew/cask/lib/hbc/dsl.rb b/Library/Homebrew/cask/lib/hbc/dsl.rb index 75c1ca8736..2db2c66a98 100644 --- a/Library/Homebrew/cask/lib/hbc/dsl.rb +++ b/Library/Homebrew/cask/lib/hbc/dsl.rb @@ -176,7 +176,7 @@ module Hbc DSL::Container.new(*args).tap do |container| # TODO: remove this backward-compatibility section after removing nested_container if container&.nested - artifacts[Artifact::NestedContainer] << Artifact::NestedContainer.new(cask, container.nested) + artifacts.add(Artifact::NestedContainer.new(cask, container.nested)) end end end @@ -219,7 +219,7 @@ module Hbc end def artifacts - @artifacts ||= Hash.new { |hash, key| hash[key] = Set.new } + @artifacts ||= SortedSet.new end def caskroom_path @@ -253,11 +253,11 @@ module Hbc ORDINARY_ARTIFACT_CLASSES.each do |klass| define_method(klass.dsl_key) do |*args| begin - if [*artifacts.keys, klass].include?(Artifact::StageOnly) && (artifacts.keys & ACTIVATABLE_ARTIFACT_CLASSES).any? + if [*artifacts.map(&:class), klass].include?(Artifact::StageOnly) && (artifacts.map(&:class) & ACTIVATABLE_ARTIFACT_CLASSES).any? raise CaskInvalidError.new(cask, "'stage_only' must be the only activatable artifact.") end - artifacts[klass].add(klass.from_args(cask, *args)) + artifacts.add(klass.from_args(cask, *args)) rescue CaskInvalidError raise rescue StandardError => e @@ -269,7 +269,7 @@ module Hbc ARTIFACT_BLOCK_CLASSES.each do |klass| [klass.dsl_key, klass.uninstall_dsl_key].each do |dsl_key| define_method(dsl_key) do |&block| - artifacts[klass] << klass.new(cask, dsl_key => block) + artifacts.add(klass.new(cask, dsl_key => block)) end end end diff --git a/Library/Homebrew/cask/lib/hbc/installer.rb b/Library/Homebrew/cask/lib/hbc/installer.rb index 01aae935df..ffbbac181d 100644 --- a/Library/Homebrew/cask/lib/hbc/installer.rb +++ b/Library/Homebrew/cask/lib/hbc/installer.rb @@ -177,7 +177,7 @@ module Hbc already_installed_artifacts = [] odebug "Installing artifacts" - artifacts = Artifact.for_cask(@cask) + artifacts = @cask.artifacts odebug "#{artifacts.length} artifact/s defined", artifacts artifacts.each do |artifact| @@ -374,7 +374,7 @@ module Hbc def uninstall_artifacts odebug "Un-installing artifacts" - artifacts = Artifact.for_cask(@cask) + artifacts = @cask.artifacts odebug "#{artifacts.length} artifact/s defined", artifacts @@ -388,7 +388,7 @@ module Hbc def zap ohai %Q(Implied "brew cask uninstall #{@cask}") uninstall_artifacts - if (zap_stanzas = Artifact::Zap.for_cask(@cask)).empty? + if (zap_stanzas = @cask.artifacts.select { |a| a.is_a?(Artifact::Zap) }).empty? opoo "No zap stanza present for Cask '#{@cask}'" else ohai "Dispatching zap stanza" diff --git a/Library/Homebrew/cask/lib/hbc/staged.rb b/Library/Homebrew/cask/lib/hbc/staged.rb index 6fd3f6709a..da097e0cf9 100644 --- a/Library/Homebrew/cask/lib/hbc/staged.rb +++ b/Library/Homebrew/cask/lib/hbc/staged.rb @@ -4,7 +4,7 @@ module Hbc index = 0 if index == :first index = 1 if index == :second index = -1 if index == :last - @cask.artifacts[Artifact::App].to_a.at(index).target.join("Contents", "Info.plist") + @cask.artifacts.select { |a| a.is_a?(Artifact::App) }.at(index).target.join("Contents", "Info.plist") end def plist_exec(cmd) diff --git a/Library/Homebrew/test/cask/artifact/alt_target_spec.rb b/Library/Homebrew/test/cask/artifact/alt_target_spec.rb index 02be796edc..fa5d7e6508 100644 --- a/Library/Homebrew/test/cask/artifact/alt_target_spec.rb +++ b/Library/Homebrew/test/cask/artifact/alt_target_spec.rb @@ -3,7 +3,7 @@ describe Hbc::Artifact::App, :cask do let(:cask) { Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/with-alt-target.rb") } let(:install_phase) { - -> { described_class.for_cask(cask).each { |artifact| artifact.install_phase(command: Hbc::NeverSudoSystemCommand, force: false) } } + -> { cask.artifacts.select { |a| a.is_a?(described_class) }.each { |artifact| artifact.install_phase(command: Hbc::NeverSudoSystemCommand, force: false) } } } let(:source_path) { cask.staged_path.join("Caffeine.app") } diff --git a/Library/Homebrew/test/cask/artifact/app_spec.rb b/Library/Homebrew/test/cask/artifact/app_spec.rb index f67ffd31b5..5ecaaef22e 100644 --- a/Library/Homebrew/test/cask/artifact/app_spec.rb +++ b/Library/Homebrew/test/cask/artifact/app_spec.rb @@ -2,7 +2,7 @@ describe Hbc::Artifact::App, :cask do let(:cask) { Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/local-caffeine.rb") } let(:command) { Hbc::SystemCommand } let(:force) { false } - let(:app) { described_class.for_cask(cask).first } + let(:app) { cask.artifacts.select { |a| a.is_a?(described_class) }.first } let(:source_path) { cask.staged_path.join("Caffeine.app") } let(:target_path) { Hbc.appdir.join("Caffeine.app") } diff --git a/Library/Homebrew/test/cask/artifact/binary_spec.rb b/Library/Homebrew/test/cask/artifact/binary_spec.rb index 5ffaca861f..08b0af1985 100644 --- a/Library/Homebrew/test/cask/artifact/binary_spec.rb +++ b/Library/Homebrew/test/cask/artifact/binary_spec.rb @@ -26,7 +26,7 @@ describe Hbc::Artifact::Binary, :cask do end it "links the binary to the proper directory" do - described_class.for_cask(cask) + cask.artifacts.select { |a| a.is_a?(described_class) } .each { |artifact| artifact.install_phase(command: Hbc::NeverSudoSystemCommand, force: false) } expect(expected_path).to be_a_symlink @@ -46,7 +46,7 @@ describe Hbc::Artifact::Binary, :cask do expect(FileUtils).to receive(:chmod) .with("+x", cask.staged_path.join("naked_non_executable")).and_call_original - described_class.for_cask(cask) + cask.artifacts.select { |a| a.is_a?(described_class) } .each { |artifact| artifact.install_phase(command: Hbc::NeverSudoSystemCommand, force: false) } expect(expected_path).to be_a_symlink @@ -58,7 +58,7 @@ describe Hbc::Artifact::Binary, :cask do FileUtils.touch expected_path expect { - described_class.for_cask(cask) + cask.artifacts.select { |a| a.is_a?(described_class) } .each { |artifact| artifact.install_phase(command: Hbc::NeverSudoSystemCommand, force: false) } }.to raise_error(Hbc::CaskError) @@ -68,7 +68,7 @@ describe Hbc::Artifact::Binary, :cask do it "clobbers an existing symlink" do expected_path.make_symlink("/tmp") - described_class.for_cask(cask) + cask.artifacts.select { |a| a.is_a?(described_class) } .each { |artifact| artifact.install_phase(command: Hbc::NeverSudoSystemCommand, force: false) } expect(File.readlink(expected_path)).not_to eq("/tmp") @@ -77,7 +77,7 @@ describe Hbc::Artifact::Binary, :cask do it "creates parent directory if it doesn't exist" do FileUtils.rmdir Hbc.binarydir - described_class.for_cask(cask) + cask.artifacts.select { |a| a.is_a?(described_class) } .each { |artifact| artifact.install_phase(command: Hbc::NeverSudoSystemCommand, force: false) } expect(expected_path.exist?).to be true @@ -91,9 +91,9 @@ describe Hbc::Artifact::Binary, :cask do } it "links the binary to the proper directory" do - Hbc::Artifact::App.for_cask(cask) + cask.artifacts.select { |a| a.is_a?(Hbc::Artifact::App) } .each { |artifact| artifact.install_phase(command: Hbc::NeverSudoSystemCommand, force: false) } - described_class.for_cask(cask) + cask.artifacts.select { |a| a.is_a?(described_class) } .each { |artifact| artifact.install_phase(command: Hbc::NeverSudoSystemCommand, force: false) } expect(expected_path).to be_a_symlink diff --git a/Library/Homebrew/test/cask/artifact/generic_artifact_spec.rb b/Library/Homebrew/test/cask/artifact/generic_artifact_spec.rb index bec8c27428..8dc30439dd 100644 --- a/Library/Homebrew/test/cask/artifact/generic_artifact_spec.rb +++ b/Library/Homebrew/test/cask/artifact/generic_artifact_spec.rb @@ -2,7 +2,7 @@ describe Hbc::Artifact::Artifact, :cask do let(:cask) { Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/with-generic-artifact.rb") } let(:install_phase) { - -> { described_class.for_cask(cask).each { |artifact| artifact.install_phase(command: Hbc::NeverSudoSystemCommand, force: false) } } + -> { cask.artifacts.select { |a| a.is_a?(described_class) }.each { |artifact| artifact.install_phase(command: Hbc::NeverSudoSystemCommand, force: false) } } } let(:source_path) { cask.staged_path.join("Caffeine.app") } diff --git a/Library/Homebrew/test/cask/artifact/nested_container_spec.rb b/Library/Homebrew/test/cask/artifact/nested_container_spec.rb index 41d143764b..65759b5b72 100644 --- a/Library/Homebrew/test/cask/artifact/nested_container_spec.rb +++ b/Library/Homebrew/test/cask/artifact/nested_container_spec.rb @@ -5,7 +5,7 @@ describe Hbc::Artifact::NestedContainer, :cask do InstallHelper.install_without_artifacts(c) end - described_class.for_cask(cask) + cask.artifacts.select { |a| a.is_a?(described_class) } .each { |artifact| artifact.install_phase(command: Hbc::NeverSudoSystemCommand, force: false) } expect(cask.staged_path.join("MyNestedApp.app")).to be_a_directory diff --git a/Library/Homebrew/test/cask/artifact/pkg_spec.rb b/Library/Homebrew/test/cask/artifact/pkg_spec.rb index c6a45c49ab..d3028be9cb 100644 --- a/Library/Homebrew/test/cask/artifact/pkg_spec.rb +++ b/Library/Homebrew/test/cask/artifact/pkg_spec.rb @@ -8,7 +8,7 @@ describe Hbc::Artifact::Pkg, :cask do describe "install_phase" do it "runs the system installer on the specified pkgs" do - pkg = described_class.for_cask(cask).first + pkg = cask.artifacts.select { |a| a.is_a?(described_class) }.first expect(fake_system_command).to receive(:run!).with( "/usr/sbin/installer", @@ -25,7 +25,7 @@ describe Hbc::Artifact::Pkg, :cask do let(:cask) { Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/with-choices.rb") } it "passes the choice changes xml to the system installer" do - pkg = described_class.for_cask(cask).first + pkg = cask.artifacts.select { |a| a.is_a?(described_class) }.first file = double(path: Pathname.new("/tmp/choices.xml")) diff --git a/Library/Homebrew/test/cask/artifact/postflight_block_spec.rb b/Library/Homebrew/test/cask/artifact/postflight_block_spec.rb index 4a44bb59be..acd63671aa 100644 --- a/Library/Homebrew/test/cask/artifact/postflight_block_spec.rb +++ b/Library/Homebrew/test/cask/artifact/postflight_block_spec.rb @@ -11,7 +11,7 @@ describe Hbc::Artifact::PostflightBlock, :cask do end end - described_class.for_cask(cask) + cask.artifacts.select { |a| a.is_a?(described_class) } .each { |artifact| artifact.install_phase(command: Hbc::NeverSudoSystemCommand, force: false) } expect(called).to be true @@ -31,7 +31,7 @@ describe Hbc::Artifact::PostflightBlock, :cask do end end - described_class.for_cask(cask) + cask.artifacts.select { |a| a.is_a?(described_class) } .each { |artifact| artifact.uninstall_phase(command: Hbc::NeverSudoSystemCommand, force: false) } expect(called).to be true diff --git a/Library/Homebrew/test/cask/artifact/preflight_block_spec.rb b/Library/Homebrew/test/cask/artifact/preflight_block_spec.rb index d7d4e72d93..285a93ffba 100644 --- a/Library/Homebrew/test/cask/artifact/preflight_block_spec.rb +++ b/Library/Homebrew/test/cask/artifact/preflight_block_spec.rb @@ -11,7 +11,7 @@ describe Hbc::Artifact::PreflightBlock, :cask do end end - described_class.for_cask(cask) + cask.artifacts.select { |a| a.is_a?(described_class) } .each { |artifact| artifact.install_phase(command: Hbc::NeverSudoSystemCommand, force: false) } expect(called).to be true @@ -31,7 +31,7 @@ describe Hbc::Artifact::PreflightBlock, :cask do end end - described_class.for_cask(cask) + cask.artifacts.select { |a| a.is_a?(described_class) } .each { |artifact| artifact.uninstall_phase(command: Hbc::NeverSudoSystemCommand, force: false) } expect(called).to be true diff --git a/Library/Homebrew/test/cask/artifact/suite_spec.rb b/Library/Homebrew/test/cask/artifact/suite_spec.rb index 2f913fecc7..1826dffbbb 100644 --- a/Library/Homebrew/test/cask/artifact/suite_spec.rb +++ b/Library/Homebrew/test/cask/artifact/suite_spec.rb @@ -2,7 +2,7 @@ describe Hbc::Artifact::Suite, :cask do let(:cask) { Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/with-suite.rb") } let(:install_phase) { - -> { described_class.for_cask(cask).each { |artifact| artifact.install_phase(command: Hbc::NeverSudoSystemCommand, force: false) } } + -> { cask.artifacts.select { |a| a.is_a?(described_class) }.each { |artifact| artifact.install_phase(command: Hbc::NeverSudoSystemCommand, force: false) } } } let(:target_path) { Hbc.appdir.join("Caffeine") } diff --git a/Library/Homebrew/test/cask/artifact/two_apps_correct_spec.rb b/Library/Homebrew/test/cask/artifact/two_apps_correct_spec.rb index f6e0d3c97b..ca8c44903e 100644 --- a/Library/Homebrew/test/cask/artifact/two_apps_correct_spec.rb +++ b/Library/Homebrew/test/cask/artifact/two_apps_correct_spec.rb @@ -3,7 +3,7 @@ describe Hbc::Artifact::App, :cask do let(:cask) { Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/with-two-apps-correct.rb") } let(:install_phase) { - -> { described_class.for_cask(cask).each { |artifact| artifact.install_phase(command: Hbc::NeverSudoSystemCommand, force: false) } } + -> { cask.artifacts.select { |a| a.is_a?(described_class) }.each { |artifact| artifact.install_phase(command: Hbc::NeverSudoSystemCommand, force: false) } } } let(:source_path_mini) { cask.staged_path.join("Caffeine Mini.app") } diff --git a/Library/Homebrew/test/cask/artifact/uninstall_no_zap_spec.rb b/Library/Homebrew/test/cask/artifact/uninstall_no_zap_spec.rb index d6a8393dac..da0bfbb787 100644 --- a/Library/Homebrew/test/cask/artifact/uninstall_no_zap_spec.rb +++ b/Library/Homebrew/test/cask/artifact/uninstall_no_zap_spec.rb @@ -2,7 +2,7 @@ describe Hbc::Artifact::Zap, :cask do let(:cask) { Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/with-installable.rb") } let(:zap_artifact) { - described_class.for_cask(cask).first + cask.artifacts.select { |a| a.is_a?(described_class) }.first } before(:each) do diff --git a/Library/Homebrew/test/cask/artifact/uninstall_zap_shared_examples.rb b/Library/Homebrew/test/cask/artifact/uninstall_zap_shared_examples.rb index 4fdab60d00..f1eb1b913e 100644 --- a/Library/Homebrew/test/cask/artifact/uninstall_zap_shared_examples.rb +++ b/Library/Homebrew/test/cask/artifact/uninstall_zap_shared_examples.rb @@ -1,6 +1,6 @@ shared_examples "#uninstall_phase or #zap_phase" do let(:artifact_dsl_key) { described_class.dsl_key } - let(:artifact) { described_class.for_cask(cask).first } + let(:artifact) { cask.artifacts.select { |a| a.is_a?(described_class) }.first } let(:fake_system_command) { Hbc::FakeSystemCommand } subject { artifact.public_send(:"#{artifact_dsl_key}_phase", command: fake_system_command) } diff --git a/Library/Homebrew/test/cask/cli/list_spec.rb b/Library/Homebrew/test/cask/cli/list_spec.rb index 75da827621..4f59aafe92 100644 --- a/Library/Homebrew/test/cask/cli/list_spec.rb +++ b/Library/Homebrew/test/cask/cli/list_spec.rb @@ -72,7 +72,7 @@ describe Hbc::CLI::List, :cask do it "lists the installed files for those Casks" do casks.each(&InstallHelper.method(:install_without_artifacts_with_caskfile)) - Hbc::Artifact::App.for_cask(transmission) + transmission.artifacts.select { |a| a.is_a?(Hbc::Artifact::App) } .each { |artifact| artifact.install_phase(command: Hbc::NeverSudoSystemCommand, force: false) } expect { diff --git a/Library/Homebrew/test/cask/dsl_spec.rb b/Library/Homebrew/test/cask/dsl_spec.rb index e03af9aef4..390e56b186 100644 --- a/Library/Homebrew/test/cask/dsl_spec.rb +++ b/Library/Homebrew/test/cask/dsl_spec.rb @@ -216,12 +216,12 @@ describe Hbc::DSL, :cask do app "Bar.app" end - expect(cask.artifacts[Hbc::Artifact::App].map(&:to_s)).to eq(["Foo.app (App)", "Bar.app (App)"]) + expect(cask.artifacts.select { |a| a.is_a?(Hbc::Artifact::App) }.map(&:to_s)).to eq(["Foo.app (App)", "Bar.app (App)"]) end it "allow app stanzas to be empty" do cask = Hbc::Cask.new("cask-with-no-apps") - expect(cask.artifacts[Hbc::Artifact::App]).to be_empty + expect(cask.artifacts.select { |a| a.is_a?(Hbc::Artifact::App) }).to be_empty end end @@ -249,7 +249,7 @@ describe Hbc::DSL, :cask do pkg "Bar.pkg" end - expect(cask.artifacts[Hbc::Artifact::Pkg].map(&:to_s)).to eq(["Foo.pkg (Pkg)", "Bar.pkg (Pkg)"]) + expect(cask.artifacts.select { |a| a.is_a?(Hbc::Artifact::Pkg) }.map(&:to_s)).to eq(["Foo.pkg (Pkg)", "Bar.pkg (Pkg)"]) end end @@ -501,10 +501,10 @@ describe Hbc::DSL, :cask do let(:token) { "with-installer-script" } it "allows installer script to be specified" do - expect(cask.artifacts[Hbc::Artifact::Installer].first.path).to eq(Pathname("/usr/bin/true")) - expect(cask.artifacts[Hbc::Artifact::Installer].first.args[:args]).to eq(["--flag"]) - expect(cask.artifacts[Hbc::Artifact::Installer].to_a[1].path).to eq(Pathname("/usr/bin/false")) - expect(cask.artifacts[Hbc::Artifact::Installer].to_a[1].args[:args]).to eq(["--flag"]) + expect(cask.artifacts.select { |a| a.is_a?(Hbc::Artifact::Installer) }.first.path).to eq(Pathname("/usr/bin/true")) + expect(cask.artifacts.select { |a| a.is_a?(Hbc::Artifact::Installer) }.first.args[:args]).to eq(["--flag"]) + expect(cask.artifacts.select { |a| a.is_a?(Hbc::Artifact::Installer) }.to_a[1].path).to eq(Pathname("/usr/bin/false")) + expect(cask.artifacts.select { |a| a.is_a?(Hbc::Artifact::Installer) }.to_a[1].args[:args]).to eq(["--flag"]) end end @@ -512,7 +512,7 @@ describe Hbc::DSL, :cask do let(:token) { "with-installer-manual" } it "allows installer manual to be specified" do - installer = cask.artifacts[Hbc::Artifact::Installer].first + installer = cask.artifacts.select { |a| a.is_a?(Hbc::Artifact::Installer) }.first expect(installer).to be_a(Hbc::Artifact::Installer::ManualInstaller) expect(installer.path).to eq(cask.staged_path.join("Caffeine.app")) end @@ -524,7 +524,7 @@ describe Hbc::DSL, :cask do let(:token) { "stage-only" } it "allows stage_only stanza to be specified" do - expect(cask.artifacts[Hbc::Artifact::StageOnly]).not_to be_empty + expect(cask.artifacts.select { |a| a.is_a?(Hbc::Artifact::StageOnly) }).not_to be_empty end end @@ -545,12 +545,12 @@ describe Hbc::DSL, :cask do end end - describe "appdir" do + describe "#appdir" do context "interpolation of the appdir in stanzas" do let(:token) { "appdir-interpolation" } it "is allowed" do - expect(cask.artifacts[Hbc::Artifact::Binary].first.source).to eq(Hbc.appdir/"some/path") + expect(cask.artifacts.select { |a| a.is_a?(Hbc::Artifact::Binary) }.first.source).to eq(Hbc.appdir/"some/path") end end @@ -563,10 +563,35 @@ describe Hbc::DSL, :cask do binary "#{appdir}/some/path" end - expect(cask.artifacts[Hbc::Artifact::Binary].first.source).to eq(original_appdir/"some/path") + expect(cask.artifacts.select { |a| a.is_a?(Hbc::Artifact::Binary) }.first.source).to eq(original_appdir/"some/path") ensure Hbc.appdir = original_appdir end end end + + describe "#artifacts" do + it "sorts artifacts according to the preferable installation order" do + cask = Hbc::Cask.new("appdir-trailing-slash") do + postflight do + next + end + + preflight do + next + end + + binary "binary" + + app "App.app" + end + + expect(cask.artifacts.map(&:class).map(&:dsl_key)).to eq [ + :preflight, + :app, + :binary, + :postflight, + ] + end + end end From 02362259a54c0b8d7399e7b19f0a56519cb1b9d1 Mon Sep 17 00:00:00 2001 From: Markus Reiter Date: Wed, 4 Oct 2017 17:46:29 +0200 Subject: [PATCH 274/294] =?UTF-8?q?Don=E2=80=99t=20reorder=20=E2=80=9Cbasi?= =?UTF-8?q?c=E2=80=9D=20artifacts.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Library/Homebrew/cask/lib/hbc/artifact.rb | 34 -------------- .../lib/hbc/artifact/abstract_artifact.rb | 46 +++++++++++-------- 2 files changed, 27 insertions(+), 53 deletions(-) diff --git a/Library/Homebrew/cask/lib/hbc/artifact.rb b/Library/Homebrew/cask/lib/hbc/artifact.rb index 505f9ec134..1cbe49cf27 100644 --- a/Library/Homebrew/cask/lib/hbc/artifact.rb +++ b/Library/Homebrew/cask/lib/hbc/artifact.rb @@ -25,39 +25,5 @@ require "hbc/artifact/zap" module Hbc module Artifact - # NOTE: Order is important here! - # - # The `uninstall` stanza should be run first, as it may - # depend on other artifacts still being installed. - # - # We want to extract nested containers before we - # handle any other artifacts. - # - CLASSES = [ - PreflightBlock, - Uninstall, - NestedContainer, - Installer, - App, - Suite, - Artifact, # generic 'artifact' stanza - Colorpicker, - Pkg, - Prefpane, - Qlplugin, - Dictionary, - Font, - Service, - StageOnly, - Binary, - InputMethod, - InternetPlugin, - AudioUnitPlugin, - VstPlugin, - Vst3Plugin, - ScreenSaver, - PostflightBlock, - Zap, - ].freeze end end diff --git a/Library/Homebrew/cask/lib/hbc/artifact/abstract_artifact.rb b/Library/Homebrew/cask/lib/hbc/artifact/abstract_artifact.rb index 331e098e01..17a778f665 100644 --- a/Library/Homebrew/cask/lib/hbc/artifact/abstract_artifact.rb +++ b/Library/Homebrew/cask/lib/hbc/artifact/abstract_artifact.rb @@ -21,34 +21,42 @@ module Hbc end def <=>(other) + return unless other.class < AbstractArtifact + return 0 if self.class == other.class + @@sort_order ||= [ # rubocop:disable Style/ClassVars PreflightBlock, + # The `uninstall` stanza should be run first, as it may + # depend on other artifacts still being installed. Uninstall, + # We want to extract nested containers before we + # handle any other artifacts. NestedContainer, Installer, - App, - Suite, - Artifact, # generic 'artifact' stanza - Colorpicker, - Pkg, - Prefpane, - Qlplugin, - Dictionary, - Font, - Service, - StageOnly, + [ + App, + Suite, + Artifact, + Colorpicker, + Prefpane, + Qlplugin, + Dictionary, + Font, + Service, + InputMethod, + InternetPlugin, + AudioUnitPlugin, + VstPlugin, + Vst3Plugin, + ScreenSaver, + ], Binary, - InputMethod, - InternetPlugin, - AudioUnitPlugin, - VstPlugin, - Vst3Plugin, - ScreenSaver, + Pkg, PostflightBlock, Zap, - ] + ].each_with_index.flat_map { |classes, i| [*classes].map { |c| [c, i] } }.to_h - (@@sort_order.index(self.class) <=> @@sort_order.index(other.class)).to_i + (@@sort_order[self.class] <=> @@sort_order[other.class]).to_i end # TODO: this sort of logic would make more sense in dsl.rb, or a From e9c587d7510ca6fe820bbc03db5bb6d0b9672c22 Mon Sep 17 00:00:00 2001 From: Markus Reiter Date: Wed, 4 Oct 2017 17:54:52 +0200 Subject: [PATCH 275/294] Refactor tests. --- .../test/cask/artifact/alt_target_spec.rb | 6 +++- .../Homebrew/test/cask/artifact/app_spec.rb | 2 +- .../test/cask/artifact/binary_spec.rb | 36 +++++++++++-------- .../cask/artifact/generic_artifact_spec.rb | 6 +++- .../cask/artifact/nested_container_spec.rb | 5 +-- .../Homebrew/test/cask/artifact/pkg_spec.rb | 4 +-- .../cask/artifact/postflight_block_spec.rb | 10 +++--- .../cask/artifact/preflight_block_spec.rb | 10 +++--- .../Homebrew/test/cask/artifact/suite_spec.rb | 6 +++- .../cask/artifact/two_apps_correct_spec.rb | 6 +++- .../cask/artifact/uninstall_no_zap_spec.rb | 2 +- .../artifact/uninstall_zap_shared_examples.rb | 2 +- Library/Homebrew/test/cask/cli/list_spec.rb | 5 +-- Library/Homebrew/test/cask/dsl_spec.rb | 22 ++++++------ 14 files changed, 76 insertions(+), 46 deletions(-) diff --git a/Library/Homebrew/test/cask/artifact/alt_target_spec.rb b/Library/Homebrew/test/cask/artifact/alt_target_spec.rb index fa5d7e6508..f7543c05d5 100644 --- a/Library/Homebrew/test/cask/artifact/alt_target_spec.rb +++ b/Library/Homebrew/test/cask/artifact/alt_target_spec.rb @@ -3,7 +3,11 @@ describe Hbc::Artifact::App, :cask do let(:cask) { Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/with-alt-target.rb") } let(:install_phase) { - -> { cask.artifacts.select { |a| a.is_a?(described_class) }.each { |artifact| artifact.install_phase(command: Hbc::NeverSudoSystemCommand, force: false) } } + lambda do + cask.artifacts.select { |a| a.is_a?(described_class) }.each do |artifact| + artifact.install_phase(command: Hbc::NeverSudoSystemCommand, force: false) + end + end } let(:source_path) { cask.staged_path.join("Caffeine.app") } diff --git a/Library/Homebrew/test/cask/artifact/app_spec.rb b/Library/Homebrew/test/cask/artifact/app_spec.rb index 5ecaaef22e..e61fefaa0b 100644 --- a/Library/Homebrew/test/cask/artifact/app_spec.rb +++ b/Library/Homebrew/test/cask/artifact/app_spec.rb @@ -2,7 +2,7 @@ describe Hbc::Artifact::App, :cask do let(:cask) { Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/local-caffeine.rb") } let(:command) { Hbc::SystemCommand } let(:force) { false } - let(:app) { cask.artifacts.select { |a| a.is_a?(described_class) }.first } + let(:app) { cask.artifacts.find { |a| a.is_a?(described_class) } } let(:source_path) { cask.staged_path.join("Caffeine.app") } let(:target_path) { Hbc.appdir.join("Caffeine.app") } diff --git a/Library/Homebrew/test/cask/artifact/binary_spec.rb b/Library/Homebrew/test/cask/artifact/binary_spec.rb index 08b0af1985..bf11ba2379 100644 --- a/Library/Homebrew/test/cask/artifact/binary_spec.rb +++ b/Library/Homebrew/test/cask/artifact/binary_spec.rb @@ -4,6 +4,7 @@ describe Hbc::Artifact::Binary, :cask do InstallHelper.install_without_artifacts(cask) end } + let(:artifacts) { cask.artifacts.select { |a| a.is_a?(described_class) } } let(:expected_path) { Hbc.binarydir.join("binary") } before(:each) do @@ -26,8 +27,9 @@ describe Hbc::Artifact::Binary, :cask do end it "links the binary to the proper directory" do - cask.artifacts.select { |a| a.is_a?(described_class) } - .each { |artifact| artifact.install_phase(command: Hbc::NeverSudoSystemCommand, force: false) } + artifacts.each do |artifact| + artifact.install_phase(command: Hbc::NeverSudoSystemCommand, force: false) + end expect(expected_path).to be_a_symlink expect(expected_path.readlink).to exist @@ -46,8 +48,9 @@ describe Hbc::Artifact::Binary, :cask do expect(FileUtils).to receive(:chmod) .with("+x", cask.staged_path.join("naked_non_executable")).and_call_original - cask.artifacts.select { |a| a.is_a?(described_class) } - .each { |artifact| artifact.install_phase(command: Hbc::NeverSudoSystemCommand, force: false) } + artifacts.each do |artifact| + artifact.install_phase(command: Hbc::NeverSudoSystemCommand, force: false) + end expect(expected_path).to be_a_symlink expect(expected_path.readlink).to be_executable @@ -58,8 +61,9 @@ describe Hbc::Artifact::Binary, :cask do FileUtils.touch expected_path expect { - cask.artifacts.select { |a| a.is_a?(described_class) } - .each { |artifact| artifact.install_phase(command: Hbc::NeverSudoSystemCommand, force: false) } + artifacts.each do |artifact| + artifact.install_phase(command: Hbc::NeverSudoSystemCommand, force: false) + end }.to raise_error(Hbc::CaskError) expect(expected_path).not_to be :symlink? @@ -68,8 +72,9 @@ describe Hbc::Artifact::Binary, :cask do it "clobbers an existing symlink" do expected_path.make_symlink("/tmp") - cask.artifacts.select { |a| a.is_a?(described_class) } - .each { |artifact| artifact.install_phase(command: Hbc::NeverSudoSystemCommand, force: false) } + artifacts.each do |artifact| + artifact.install_phase(command: Hbc::NeverSudoSystemCommand, force: false) + end expect(File.readlink(expected_path)).not_to eq("/tmp") end @@ -77,8 +82,9 @@ describe Hbc::Artifact::Binary, :cask do it "creates parent directory if it doesn't exist" do FileUtils.rmdir Hbc.binarydir - cask.artifacts.select { |a| a.is_a?(described_class) } - .each { |artifact| artifact.install_phase(command: Hbc::NeverSudoSystemCommand, force: false) } + artifacts.each do |artifact| + artifact.install_phase(command: Hbc::NeverSudoSystemCommand, force: false) + end expect(expected_path.exist?).to be true end @@ -91,10 +97,12 @@ describe Hbc::Artifact::Binary, :cask do } it "links the binary to the proper directory" do - cask.artifacts.select { |a| a.is_a?(Hbc::Artifact::App) } - .each { |artifact| artifact.install_phase(command: Hbc::NeverSudoSystemCommand, force: false) } - cask.artifacts.select { |a| a.is_a?(described_class) } - .each { |artifact| artifact.install_phase(command: Hbc::NeverSudoSystemCommand, force: false) } + cask.artifacts.select { |a| a.is_a?(Hbc::Artifact::App) }.each do |artifact| + artifact.install_phase(command: Hbc::NeverSudoSystemCommand, force: false) + end + artifacts.each do |artifact| + artifact.install_phase(command: Hbc::NeverSudoSystemCommand, force: false) + end expect(expected_path).to be_a_symlink expect(expected_path.readlink).to exist diff --git a/Library/Homebrew/test/cask/artifact/generic_artifact_spec.rb b/Library/Homebrew/test/cask/artifact/generic_artifact_spec.rb index 8dc30439dd..1bf3bbbdb7 100644 --- a/Library/Homebrew/test/cask/artifact/generic_artifact_spec.rb +++ b/Library/Homebrew/test/cask/artifact/generic_artifact_spec.rb @@ -2,7 +2,11 @@ describe Hbc::Artifact::Artifact, :cask do let(:cask) { Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/with-generic-artifact.rb") } let(:install_phase) { - -> { cask.artifacts.select { |a| a.is_a?(described_class) }.each { |artifact| artifact.install_phase(command: Hbc::NeverSudoSystemCommand, force: false) } } + lambda do + cask.artifacts.select { |a| a.is_a?(described_class) }.each do |artifact| + artifact.install_phase(command: Hbc::NeverSudoSystemCommand, force: false) + end + end } let(:source_path) { cask.staged_path.join("Caffeine.app") } diff --git a/Library/Homebrew/test/cask/artifact/nested_container_spec.rb b/Library/Homebrew/test/cask/artifact/nested_container_spec.rb index 65759b5b72..d7bd6f59ae 100644 --- a/Library/Homebrew/test/cask/artifact/nested_container_spec.rb +++ b/Library/Homebrew/test/cask/artifact/nested_container_spec.rb @@ -5,8 +5,9 @@ describe Hbc::Artifact::NestedContainer, :cask do InstallHelper.install_without_artifacts(c) end - cask.artifacts.select { |a| a.is_a?(described_class) } - .each { |artifact| artifact.install_phase(command: Hbc::NeverSudoSystemCommand, force: false) } + cask.artifacts.select { |a| a.is_a?(described_class) }.each do |artifact| + artifact.install_phase(command: Hbc::NeverSudoSystemCommand, force: false) + end expect(cask.staged_path.join("MyNestedApp.app")).to be_a_directory end diff --git a/Library/Homebrew/test/cask/artifact/pkg_spec.rb b/Library/Homebrew/test/cask/artifact/pkg_spec.rb index d3028be9cb..8ea5a1bb30 100644 --- a/Library/Homebrew/test/cask/artifact/pkg_spec.rb +++ b/Library/Homebrew/test/cask/artifact/pkg_spec.rb @@ -8,7 +8,7 @@ describe Hbc::Artifact::Pkg, :cask do describe "install_phase" do it "runs the system installer on the specified pkgs" do - pkg = cask.artifacts.select { |a| a.is_a?(described_class) }.first + pkg = cask.artifacts.find { |a| a.is_a?(described_class) } expect(fake_system_command).to receive(:run!).with( "/usr/sbin/installer", @@ -25,7 +25,7 @@ describe Hbc::Artifact::Pkg, :cask do let(:cask) { Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/with-choices.rb") } it "passes the choice changes xml to the system installer" do - pkg = cask.artifacts.select { |a| a.is_a?(described_class) }.first + pkg = cask.artifacts.find { |a| a.is_a?(described_class) } file = double(path: Pathname.new("/tmp/choices.xml")) diff --git a/Library/Homebrew/test/cask/artifact/postflight_block_spec.rb b/Library/Homebrew/test/cask/artifact/postflight_block_spec.rb index acd63671aa..18cc4ca91a 100644 --- a/Library/Homebrew/test/cask/artifact/postflight_block_spec.rb +++ b/Library/Homebrew/test/cask/artifact/postflight_block_spec.rb @@ -11,8 +11,9 @@ describe Hbc::Artifact::PostflightBlock, :cask do end end - cask.artifacts.select { |a| a.is_a?(described_class) } - .each { |artifact| artifact.install_phase(command: Hbc::NeverSudoSystemCommand, force: false) } + cask.artifacts.select { |a| a.is_a?(described_class) }.each do |artifact| + artifact.install_phase(command: Hbc::NeverSudoSystemCommand, force: false) + end expect(called).to be true expect(yielded_arg).to be_kind_of(Hbc::DSL::Postflight) @@ -31,8 +32,9 @@ describe Hbc::Artifact::PostflightBlock, :cask do end end - cask.artifacts.select { |a| a.is_a?(described_class) } - .each { |artifact| artifact.uninstall_phase(command: Hbc::NeverSudoSystemCommand, force: false) } + cask.artifacts.select { |a| a.is_a?(described_class) }.each do |artifact| + artifact.uninstall_phase(command: Hbc::NeverSudoSystemCommand, force: false) + end expect(called).to be true expect(yielded_arg).to be_kind_of(Hbc::DSL::UninstallPostflight) diff --git a/Library/Homebrew/test/cask/artifact/preflight_block_spec.rb b/Library/Homebrew/test/cask/artifact/preflight_block_spec.rb index 285a93ffba..405cdbd6f8 100644 --- a/Library/Homebrew/test/cask/artifact/preflight_block_spec.rb +++ b/Library/Homebrew/test/cask/artifact/preflight_block_spec.rb @@ -11,8 +11,9 @@ describe Hbc::Artifact::PreflightBlock, :cask do end end - cask.artifacts.select { |a| a.is_a?(described_class) } - .each { |artifact| artifact.install_phase(command: Hbc::NeverSudoSystemCommand, force: false) } + cask.artifacts.select { |a| a.is_a?(described_class) }.each do |artifact| + artifact.install_phase(command: Hbc::NeverSudoSystemCommand, force: false) + end expect(called).to be true expect(yielded_arg).to be_kind_of Hbc::DSL::Preflight @@ -31,8 +32,9 @@ describe Hbc::Artifact::PreflightBlock, :cask do end end - cask.artifacts.select { |a| a.is_a?(described_class) } - .each { |artifact| artifact.uninstall_phase(command: Hbc::NeverSudoSystemCommand, force: false) } + cask.artifacts.select { |a| a.is_a?(described_class) }.each do |artifact| + artifact.uninstall_phase(command: Hbc::NeverSudoSystemCommand, force: false) + end expect(called).to be true expect(yielded_arg).to be_kind_of Hbc::DSL::UninstallPreflight diff --git a/Library/Homebrew/test/cask/artifact/suite_spec.rb b/Library/Homebrew/test/cask/artifact/suite_spec.rb index 1826dffbbb..01d25c4cc2 100644 --- a/Library/Homebrew/test/cask/artifact/suite_spec.rb +++ b/Library/Homebrew/test/cask/artifact/suite_spec.rb @@ -2,7 +2,11 @@ describe Hbc::Artifact::Suite, :cask do let(:cask) { Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/with-suite.rb") } let(:install_phase) { - -> { cask.artifacts.select { |a| a.is_a?(described_class) }.each { |artifact| artifact.install_phase(command: Hbc::NeverSudoSystemCommand, force: false) } } + lambda do + cask.artifacts.select { |a| a.is_a?(described_class) }.each do |artifact| + artifact.install_phase(command: Hbc::NeverSudoSystemCommand, force: false) + end + end } let(:target_path) { Hbc.appdir.join("Caffeine") } diff --git a/Library/Homebrew/test/cask/artifact/two_apps_correct_spec.rb b/Library/Homebrew/test/cask/artifact/two_apps_correct_spec.rb index ca8c44903e..84072fd1a7 100644 --- a/Library/Homebrew/test/cask/artifact/two_apps_correct_spec.rb +++ b/Library/Homebrew/test/cask/artifact/two_apps_correct_spec.rb @@ -3,7 +3,11 @@ describe Hbc::Artifact::App, :cask do let(:cask) { Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/with-two-apps-correct.rb") } let(:install_phase) { - -> { cask.artifacts.select { |a| a.is_a?(described_class) }.each { |artifact| artifact.install_phase(command: Hbc::NeverSudoSystemCommand, force: false) } } + lambda do + cask.artifacts.select { |a| a.is_a?(described_class) }.each do |artifact| + artifact.install_phase(command: Hbc::NeverSudoSystemCommand, force: false) + end + end } let(:source_path_mini) { cask.staged_path.join("Caffeine Mini.app") } diff --git a/Library/Homebrew/test/cask/artifact/uninstall_no_zap_spec.rb b/Library/Homebrew/test/cask/artifact/uninstall_no_zap_spec.rb index da0bfbb787..a91e934050 100644 --- a/Library/Homebrew/test/cask/artifact/uninstall_no_zap_spec.rb +++ b/Library/Homebrew/test/cask/artifact/uninstall_no_zap_spec.rb @@ -2,7 +2,7 @@ describe Hbc::Artifact::Zap, :cask do let(:cask) { Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/with-installable.rb") } let(:zap_artifact) { - cask.artifacts.select { |a| a.is_a?(described_class) }.first + cask.artifacts.find { |a| a.is_a?(described_class) } } before(:each) do diff --git a/Library/Homebrew/test/cask/artifact/uninstall_zap_shared_examples.rb b/Library/Homebrew/test/cask/artifact/uninstall_zap_shared_examples.rb index f1eb1b913e..5e302d35a1 100644 --- a/Library/Homebrew/test/cask/artifact/uninstall_zap_shared_examples.rb +++ b/Library/Homebrew/test/cask/artifact/uninstall_zap_shared_examples.rb @@ -1,6 +1,6 @@ shared_examples "#uninstall_phase or #zap_phase" do let(:artifact_dsl_key) { described_class.dsl_key } - let(:artifact) { cask.artifacts.select { |a| a.is_a?(described_class) }.first } + let(:artifact) { cask.artifacts.find { |a| a.is_a?(described_class) } } let(:fake_system_command) { Hbc::FakeSystemCommand } subject { artifact.public_send(:"#{artifact_dsl_key}_phase", command: fake_system_command) } diff --git a/Library/Homebrew/test/cask/cli/list_spec.rb b/Library/Homebrew/test/cask/cli/list_spec.rb index 4f59aafe92..6a92289aaf 100644 --- a/Library/Homebrew/test/cask/cli/list_spec.rb +++ b/Library/Homebrew/test/cask/cli/list_spec.rb @@ -72,8 +72,9 @@ describe Hbc::CLI::List, :cask do it "lists the installed files for those Casks" do casks.each(&InstallHelper.method(:install_without_artifacts_with_caskfile)) - transmission.artifacts.select { |a| a.is_a?(Hbc::Artifact::App) } - .each { |artifact| artifact.install_phase(command: Hbc::NeverSudoSystemCommand, force: false) } + transmission.artifacts.select { |a| a.is_a?(Hbc::Artifact::App) }.each do |artifact| + artifact.install_phase(command: Hbc::NeverSudoSystemCommand, force: false) + end expect { described_class.run("local-transmission", "local-caffeine") diff --git a/Library/Homebrew/test/cask/dsl_spec.rb b/Library/Homebrew/test/cask/dsl_spec.rb index 390e56b186..e4149398e9 100644 --- a/Library/Homebrew/test/cask/dsl_spec.rb +++ b/Library/Homebrew/test/cask/dsl_spec.rb @@ -216,12 +216,12 @@ describe Hbc::DSL, :cask do app "Bar.app" end - expect(cask.artifacts.select { |a| a.is_a?(Hbc::Artifact::App) }.map(&:to_s)).to eq(["Foo.app (App)", "Bar.app (App)"]) + expect(cask.artifacts.map(&:to_s)).to eq(["Foo.app (App)", "Bar.app (App)"]) end it "allow app stanzas to be empty" do cask = Hbc::Cask.new("cask-with-no-apps") - expect(cask.artifacts.select { |a| a.is_a?(Hbc::Artifact::App) }).to be_empty + expect(cask.artifacts).to be_empty end end @@ -249,7 +249,7 @@ describe Hbc::DSL, :cask do pkg "Bar.pkg" end - expect(cask.artifacts.select { |a| a.is_a?(Hbc::Artifact::Pkg) }.map(&:to_s)).to eq(["Foo.pkg (Pkg)", "Bar.pkg (Pkg)"]) + expect(cask.artifacts.map(&:to_s)).to eq(["Foo.pkg (Pkg)", "Bar.pkg (Pkg)"]) end end @@ -501,10 +501,10 @@ describe Hbc::DSL, :cask do let(:token) { "with-installer-script" } it "allows installer script to be specified" do - expect(cask.artifacts.select { |a| a.is_a?(Hbc::Artifact::Installer) }.first.path).to eq(Pathname("/usr/bin/true")) - expect(cask.artifacts.select { |a| a.is_a?(Hbc::Artifact::Installer) }.first.args[:args]).to eq(["--flag"]) - expect(cask.artifacts.select { |a| a.is_a?(Hbc::Artifact::Installer) }.to_a[1].path).to eq(Pathname("/usr/bin/false")) - expect(cask.artifacts.select { |a| a.is_a?(Hbc::Artifact::Installer) }.to_a[1].args[:args]).to eq(["--flag"]) + expect(cask.artifacts.to_a[0].path).to eq(Pathname("/usr/bin/true")) + expect(cask.artifacts.to_a[0].args[:args]).to eq(["--flag"]) + expect(cask.artifacts.to_a[1].path).to eq(Pathname("/usr/bin/false")) + expect(cask.artifacts.to_a[1].args[:args]).to eq(["--flag"]) end end @@ -512,7 +512,7 @@ describe Hbc::DSL, :cask do let(:token) { "with-installer-manual" } it "allows installer manual to be specified" do - installer = cask.artifacts.select { |a| a.is_a?(Hbc::Artifact::Installer) }.first + installer = cask.artifacts.first expect(installer).to be_a(Hbc::Artifact::Installer::ManualInstaller) expect(installer.path).to eq(cask.staged_path.join("Caffeine.app")) end @@ -524,7 +524,7 @@ describe Hbc::DSL, :cask do let(:token) { "stage-only" } it "allows stage_only stanza to be specified" do - expect(cask.artifacts.select { |a| a.is_a?(Hbc::Artifact::StageOnly) }).not_to be_empty + expect(cask.artifacts).to contain_exactly a_kind_of Hbc::Artifact::StageOnly end end @@ -550,7 +550,7 @@ describe Hbc::DSL, :cask do let(:token) { "appdir-interpolation" } it "is allowed" do - expect(cask.artifacts.select { |a| a.is_a?(Hbc::Artifact::Binary) }.first.source).to eq(Hbc.appdir/"some/path") + expect(cask.artifacts.first.source).to eq(Hbc.appdir/"some/path") end end @@ -563,7 +563,7 @@ describe Hbc::DSL, :cask do binary "#{appdir}/some/path" end - expect(cask.artifacts.select { |a| a.is_a?(Hbc::Artifact::Binary) }.first.source).to eq(original_appdir/"some/path") + expect(cask.artifacts.first.source).to eq(original_appdir/"some/path") ensure Hbc.appdir = original_appdir end From 32c69ed789044cb898146eb0591f809ec09d0c83 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Go=C5=82e=CC=A8biowski-Owczarek?= Date: Wed, 4 Oct 2017 11:37:17 +0200 Subject: [PATCH 276/294] Update my name in Kickstarter-Supporters --- docs/Kickstarter-Supporters.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/Kickstarter-Supporters.md b/docs/Kickstarter-Supporters.md index 84ba662b47..146718aecc 100644 --- a/docs/Kickstarter-Supporters.md +++ b/docs/Kickstarter-Supporters.md @@ -379,7 +379,7 @@ These wonderful people supported our Kickstarter by giving us £10 or more: * [Andrew Brown](http://pvalu.es) * [Bethany Sumner](http://www.bethanysumner.com/) * [Orta](http://orta.io) -* [Michał Gołębiowski](https://github.com/mgol) +* [Michał Gołębiowski-Owczarek](https://github.com/mgol) * [Adam C. Foltzer](http://www.acfoltzer.net/) * [Steve Hiemstra](https://www.speg.com) * [Anton Sipos](http://www.softwarefuturism.com) From 8e82c2ba94aff84437b4e0b757374291115628df Mon Sep 17 00:00:00 2001 From: Cody Lewis Date: Wed, 4 Oct 2017 14:56:29 -0500 Subject: [PATCH 277/294] fixed link to CODE_OF_CONDUCT.md within CONTRIBUTING.md fixed link url to navigate to main brew repo instead of forked repo --- CONTRIBUTING.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index e5272c6826..4729d6ca33 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -1,5 +1,5 @@ # Contributing to Homebrew -First time contributing to Homebrew? Read our [Code of Conduct](https://github.com/Homebrew/brew/blob/master/CODEOFCONDUCT.md#code-of-conduct). +First time contributing to Homebrew? Read our [Code of Conduct](https://github.com/Homebrew/brew/blob/master/CODE_OF_CONDUCT.md#code-of-conduct). ### Report a bug From 4e957165d14f14d7dc5a306bf9233ae17b6ed772 Mon Sep 17 00:00:00 2001 From: Dominyk Tiller Date: Thu, 5 Oct 2017 02:52:21 +0100 Subject: [PATCH 278/294] audit: prefer assert/refute_predicate over File.exist? --- Library/Homebrew/dev-cmd/audit.rb | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/Library/Homebrew/dev-cmd/audit.rb b/Library/Homebrew/dev-cmd/audit.rb index 49e7969af0..ee5fb8df81 100644 --- a/Library/Homebrew/dev-cmd/audit.rb +++ b/Library/Homebrew/dev-cmd/audit.rb @@ -967,6 +967,14 @@ class FormulaAuditor problem "Use `assert_match` instead of `assert ...include?`" end + if line =~ /(assert File\.exist\?|File\.exist\?)/ + problem "Use `assert_predicate , :exist?` instead of `#{Regexp.last_match(1)}`" + end + + if line =~ /(assert !File\.exist\?|!File\.exist\?)/ + problem "Use `refute_predicate , :exist?` instead of `#{Regexp.last_match(1)}`" + end + return unless @strict problem "`#{Regexp.last_match(1)}` in formulae is deprecated" if line =~ /(env :(std|userpaths))/ From fcf0c7db6cc7704641064344091e33f1bc9d7d7f Mon Sep 17 00:00:00 2001 From: EricFromCanada Date: Thu, 5 Oct 2017 16:11:11 -0400 Subject: [PATCH 279/294] docs: update list of taps - the official homebrew/apache tap was removed - besport/ocaml was deprecated and now points at the OPAM package manager - added sidaf/pentest & osrf/simulation - improved description for homebrew/nginx & homebrew/php --- docs/Interesting-Taps-and-Forks.md | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/docs/Interesting-Taps-and-Forks.md b/docs/Interesting-Taps-and-Forks.md index 6b70fadecb..5e3fc19d24 100644 --- a/docs/Interesting-Taps-and-Forks.md +++ b/docs/Interesting-Taps-and-Forks.md @@ -5,11 +5,9 @@ Homebrew has the capability to add (and remove) multiple taps to your local inst ## Main taps -* [homebrew/apache](https://github.com/Homebrew/homebrew-apache): A tap for Apache modules, extending macOS's built-in Apache. These brews may require unconventional additional setup, as explained in the caveats. +* [homebrew/nginx](https://github.com/Homebrew/homebrew-nginx): A tap for NGINX modules, intended for its `nginx-full` formula which includes more module options. -* [homebrew/nginx](https://github.com/Homebrew/homebrew-nginx): Feature rich Nginx tap for modules. - -* [homebrew/php](https://github.com/Homebrew/homebrew-php): Repository for php-related formulae. +* [homebrew/php](https://github.com/Homebrew/homebrew-php): Repository for PHP-related formulae. * [homebrew/science](https://github.com/Homebrew/homebrew-science): A collection of scientific libraries and tools. @@ -21,8 +19,6 @@ You can be added as a maintainer for one of the Homebrew organization taps and a * [InstantClientTap/instantclient](https://github.com/InstantClientTap/homebrew-instantclient): A tap for Oracle Instant Client. The packages need to be downloaded manually. -* [besport/ocaml](https://github.com/besport/homebrew-ocaml): A tap for Ocaml libraries, though with caveats, it requires you install its customized ocaml formula. Perhaps a template for more work. - * [osx-cross/avr](https://github.com/osx-cross/homebrew-avr): GNU AVR toolchain (Libc, compilers and other tools for Atmel MCUs, useful for Arduino hackers and AVR programmers). * [petere/postgresql](https://github.com/petere/homebrew-postgresql): Allows installing multiple PostgreSQL versions in parallel. @@ -31,6 +27,10 @@ You can be added as a maintainer for one of the Homebrew organization taps and a * [dunn/emacs](https://github.com/dunn/homebrew-emacs): A tap for Emacs packages. +* [sidaf/pentest](https://github.com/sidaf/homebrew-pentest): Tools for penetration testing. + +* [osrf/simulation](https://github.com/osrf/homebrew-simulation): Tools for robotics simulation. + ## Interesting forks * [mistydemeo/tigerbrew](https://github.com/mistydemeo/tigerbrew): Experimental Tiger PowerPC version From 4f8af059dfd0e73f23571747cc703bda29de9b8f Mon Sep 17 00:00:00 2001 From: Mike McQuaid Date: Thu, 5 Oct 2017 21:47:26 +0100 Subject: [PATCH 280/294] os/mac: ignore apps found in Time Machine backups. These can introduce confusion on e.g. outdated Xcode versions when they are the only (or first) versions that are found. --- Library/Homebrew/os/mac.rb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Library/Homebrew/os/mac.rb b/Library/Homebrew/os/mac.rb index 15c301f994..853f75140f 100644 --- a/Library/Homebrew/os/mac.rb +++ b/Library/Homebrew/os/mac.rb @@ -229,7 +229,9 @@ module OS end def app_with_bundle_id(*ids) - path = mdfind(*ids).first + path = mdfind(*ids) + .reject { |p| p.include?("/Backups.backupdb/") } + .first Pathname.new(path) unless path.nil? || path.empty? end From 53e66d950e849e0a768a7a39bb3b23762ab86f49 Mon Sep 17 00:00:00 2001 From: Cody Lewis Date: Thu, 5 Oct 2017 21:00:09 -0500 Subject: [PATCH 281/294] Fixing link to CODE_OF_CONDUCT.md within README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index a9684b5bba..2ff99df3aa 100644 --- a/README.md +++ b/README.md @@ -22,7 +22,7 @@ Second, read the [Troubleshooting Checklist](https://docs.brew.sh/Troubleshootin [![Travis](https://img.shields.io/travis/Homebrew/brew.svg)](https://travis-ci.org/Homebrew/brew) [![Codecov](https://img.shields.io/codecov/c/github/Homebrew/brew.svg)](https://codecov.io/gh/Homebrew/brew) -We'd love you to contribute to Homebrew. First, please read our [Contribution Guide](https://github.com/Homebrew/brew/blob/master/CONTRIBUTING.md) and [Code of Conduct](https://github.com/Homebrew/brew/blob/master/CODEOFCONDUCT.md#code-of-conduct). +We'd love you to contribute to Homebrew. First, please read our [Contribution Guide](https://github.com/Homebrew/brew/blob/master/CONTRIBUTING.md) and [Code of Conduct](https://github.com/Homebrew/brew/blob/master/CODE_OF_CONDUCT.md#code-of-conduct). We explicitly welcome contributions from people who have never contributed to open-source before: we were all beginners once! We can help build on a partially working pull request with the aim of getting it merged. We are also actively seeking to diversify our contributors and especially welcome contributions from women from all backgrounds and people of colour. From 1c0f12307bc1699e90fcf3c61543d359100dbe43 Mon Sep 17 00:00:00 2001 From: Mike McQuaid Date: Thu, 5 Oct 2017 20:33:22 -0700 Subject: [PATCH 282/294] official_taps: remove apache. It's now deprecated. --- Library/Homebrew/official_taps.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Library/Homebrew/official_taps.rb b/Library/Homebrew/official_taps.rb index dcb65d9f80..ed966c804e 100644 --- a/Library/Homebrew/official_taps.rb +++ b/Library/Homebrew/official_taps.rb @@ -1,5 +1,4 @@ OFFICIAL_TAPS = %w[ - apache nginx php science @@ -17,6 +16,7 @@ OFFICIAL_CMD_TAPS = { }.freeze DEPRECATED_OFFICIAL_TAPS = %w[ + apache binary completions devel-only From d5cc68fba3a244d96eae1b6dbe0ef91634b2f921 Mon Sep 17 00:00:00 2001 From: commitay Date: Sat, 7 Oct 2017 12:53:07 +1000 Subject: [PATCH 283/294] InternalAuditModifiedCask: audit renamed Casks --- .../Homebrew/cask/lib/hbc/cli/internal_audit_modified_casks.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Library/Homebrew/cask/lib/hbc/cli/internal_audit_modified_casks.rb b/Library/Homebrew/cask/lib/hbc/cli/internal_audit_modified_casks.rb index 3673a5391a..b83224fb1e 100644 --- a/Library/Homebrew/cask/lib/hbc/cli/internal_audit_modified_casks.rb +++ b/Library/Homebrew/cask/lib/hbc/cli/internal_audit_modified_casks.rb @@ -59,7 +59,7 @@ module Hbc end def modified_cask_files - @modified_cask_files ||= git_filter_cask_files("AM") + @modified_cask_files ||= git_filter_cask_files("AMR") end def added_cask_files From a7cf6c1ff038a14b09d433e969c4e4a186d7b6f1 Mon Sep 17 00:00:00 2001 From: commitay Date: Sat, 7 Oct 2017 22:06:39 +1000 Subject: [PATCH 284/294] Cask AbstractArtifact: fix install order --- Library/Homebrew/cask/lib/hbc/artifact/abstract_artifact.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Library/Homebrew/cask/lib/hbc/artifact/abstract_artifact.rb b/Library/Homebrew/cask/lib/hbc/artifact/abstract_artifact.rb index 17a778f665..972a51a45a 100644 --- a/Library/Homebrew/cask/lib/hbc/artifact/abstract_artifact.rb +++ b/Library/Homebrew/cask/lib/hbc/artifact/abstract_artifact.rb @@ -50,8 +50,8 @@ module Hbc Vst3Plugin, ScreenSaver, ], - Binary, Pkg, + Binary, PostflightBlock, Zap, ].each_with_index.flat_map { |classes, i| [*classes].map { |c| [c, i] } }.to_h From 4fde8f56ce0515a359f817376cd18b5e62f1512b Mon Sep 17 00:00:00 2001 From: commitay Date: Sat, 7 Oct 2017 23:10:59 +1000 Subject: [PATCH 285/294] add pkg / binary comment --- Library/Homebrew/cask/lib/hbc/artifact/abstract_artifact.rb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Library/Homebrew/cask/lib/hbc/artifact/abstract_artifact.rb b/Library/Homebrew/cask/lib/hbc/artifact/abstract_artifact.rb index 972a51a45a..f9f736662f 100644 --- a/Library/Homebrew/cask/lib/hbc/artifact/abstract_artifact.rb +++ b/Library/Homebrew/cask/lib/hbc/artifact/abstract_artifact.rb @@ -50,6 +50,8 @@ module Hbc Vst3Plugin, ScreenSaver, ], + # `pkg` should be run before `binary`, so + # targets are created prior to linking. Pkg, Binary, PostflightBlock, From 97333df4cb4bd006401193639400a8bc6df56e3a Mon Sep 17 00:00:00 2001 From: Markus Reiter Date: Sat, 7 Oct 2017 15:58:49 +0200 Subject: [PATCH 286/294] Add helper method for Cask fixture paths and refactor CaskLoader. --- Library/Homebrew/cask/lib/hbc/audit.rb | 2 +- Library/Homebrew/cask/lib/hbc/auditor.rb | 2 +- Library/Homebrew/cask/lib/hbc/cask_loader.rb | 15 +++--- Library/Homebrew/cask/lib/hbc/cli/list.rb | 2 +- .../Homebrew/cask/lib/hbc/cli/uninstall.rb | 2 +- Library/Homebrew/cask/lib/hbc/installer.rb | 2 +- .../Homebrew/test/cask/accessibility_spec.rb | 2 +- .../test/cask/artifact/alt_target_spec.rb | 2 +- .../Homebrew/test/cask/artifact/app_spec.rb | 2 +- .../test/cask/artifact/binary_spec.rb | 8 ++-- .../cask/artifact/generic_artifact_spec.rb | 4 +- .../cask/artifact/nested_container_spec.rb | 2 +- .../Homebrew/test/cask/artifact/pkg_spec.rb | 4 +- .../Homebrew/test/cask/artifact/suite_spec.rb | 2 +- .../cask/artifact/two_apps_correct_spec.rb | 4 +- .../cask/artifact/two_apps_incorrect_spec.rb | 2 +- .../cask/artifact/uninstall_no_zap_spec.rb | 2 +- .../artifact/uninstall_zap_shared_examples.rb | 18 +++---- Library/Homebrew/test/cask/cli/fetch_spec.rb | 4 +- .../Homebrew/test/cask/cli/install_spec.rb | 12 ++--- Library/Homebrew/test/cask/cli/list_spec.rb | 4 +- .../Homebrew/test/cask/cli/outdated_spec.rb | 12 ++--- .../Homebrew/test/cask/cli/reinstall_spec.rb | 10 ++-- .../Homebrew/test/cask/cli/uninstall_spec.rb | 10 ++-- Library/Homebrew/test/cask/cli/zap_spec.rb | 4 +- .../Homebrew/test/cask/conflicts_with_spec.rb | 4 +- .../Homebrew/test/cask/container/dmg_spec.rb | 2 +- Library/Homebrew/test/cask/depends_on_spec.rb | 22 ++++----- .../Homebrew/test/cask/dsl/caveats_spec.rb | 2 +- .../Homebrew/test/cask/dsl/postflight_spec.rb | 2 +- .../Homebrew/test/cask/dsl/preflight_spec.rb | 2 +- .../cask/dsl/uninstall_postflight_spec.rb | 2 +- .../test/cask/dsl/uninstall_preflight_spec.rb | 2 +- Library/Homebrew/test/cask/dsl_spec.rb | 2 +- Library/Homebrew/test/cask/installer_spec.rb | 48 +++++++++---------- Library/Homebrew/test/cask/staged_spec.rb | 2 +- .../Homebrew/test/support/helper/fixtures.rb | 4 ++ 37 files changed, 115 insertions(+), 112 deletions(-) diff --git a/Library/Homebrew/cask/lib/hbc/audit.rb b/Library/Homebrew/cask/lib/hbc/audit.rb index 9ab93a67f0..c15fa6307c 100644 --- a/Library/Homebrew/cask/lib/hbc/audit.rb +++ b/Library/Homebrew/cask/lib/hbc/audit.rb @@ -71,7 +71,7 @@ module Hbc return if previous_cask_contents.empty? begin - previous_cask = CaskLoader.load_from_string(previous_cask_contents) + previous_cask = CaskLoader.load(previous_cask_contents) return unless previous_cask.version == cask.version return if previous_cask.sha256 == cask.sha256 diff --git a/Library/Homebrew/cask/lib/hbc/auditor.rb b/Library/Homebrew/cask/lib/hbc/auditor.rb index 48f36a54d5..231c005f9b 100644 --- a/Library/Homebrew/cask/lib/hbc/auditor.rb +++ b/Library/Homebrew/cask/lib/hbc/auditor.rb @@ -43,7 +43,7 @@ module Hbc def audit_languages(languages) ohai "Auditing language: #{languages.map { |lang| "'#{lang}'" }.join(", ")}" MacOS.instance_variable_set(:@languages, languages) - audit_cask_instance(CaskLoader.load_from_file(cask.sourcefile_path)) + audit_cask_instance(CaskLoader.load(cask.sourcefile_path)) ensure CLI::Cleanup.run(cask.token) if audit_download? end diff --git a/Library/Homebrew/cask/lib/hbc/cask_loader.rb b/Library/Homebrew/cask/lib/hbc/cask_loader.rb index 8fce9636ad..5660992da8 100644 --- a/Library/Homebrew/cask/lib/hbc/cask_loader.rb +++ b/Library/Homebrew/cask/lib/hbc/cask_loader.rb @@ -147,14 +147,6 @@ module Hbc end end - def self.load_from_file(path) - FromPathLoader.new(path).load - end - - def self.load_from_string(content) - FromContentLoader.new(content).load - end - def self.path(ref) self.for(ref).path end @@ -164,6 +156,13 @@ module Hbc end def self.for(ref) + if ref.respond_to?(:to_str) + content = ref.to_str + if content.match?(/\A\s*cask\s+(?:"[^"]*"|'[^']*')\s+do(?:\s+.*\s+|;?\s+)end\s*\Z/) + return FromContentLoader.new(content) + end + end + [ FromInstanceLoader, FromURILoader, diff --git a/Library/Homebrew/cask/lib/hbc/cli/list.rb b/Library/Homebrew/cask/lib/hbc/cli/list.rb index 32415af8a5..72b78d110b 100644 --- a/Library/Homebrew/cask/lib/hbc/cli/list.rb +++ b/Library/Homebrew/cask/lib/hbc/cli/list.rb @@ -23,7 +23,7 @@ module Hbc elsif versions? puts self.class.format_versioned(cask) else - cask = CaskLoader.load_from_file(cask.installed_caskfile) + cask = CaskLoader.load(cask.installed_caskfile) self.class.list_artifacts(cask) end end diff --git a/Library/Homebrew/cask/lib/hbc/cli/uninstall.rb b/Library/Homebrew/cask/lib/hbc/cli/uninstall.rb index 7e55db5f18..f2059605ca 100644 --- a/Library/Homebrew/cask/lib/hbc/cli/uninstall.rb +++ b/Library/Homebrew/cask/lib/hbc/cli/uninstall.rb @@ -16,7 +16,7 @@ module Hbc if cask.installed? && !cask.installed_caskfile.nil? # use the same cask file that was used for installation, if possible - cask = CaskLoader.load_from_file(cask.installed_caskfile) if cask.installed_caskfile.exist? + cask = CaskLoader.load(cask.installed_caskfile) if cask.installed_caskfile.exist? end Installer.new(cask, binaries: binaries?, verbose: verbose?, force: force?).uninstall diff --git a/Library/Homebrew/cask/lib/hbc/installer.rb b/Library/Homebrew/cask/lib/hbc/installer.rb index 01aae935df..ee4494a62a 100644 --- a/Library/Homebrew/cask/lib/hbc/installer.rb +++ b/Library/Homebrew/cask/lib/hbc/installer.rb @@ -126,7 +126,7 @@ module Hbc # use the same cask file that was used for installation, if possible installed_caskfile = @cask.installed_caskfile - installed_cask = installed_caskfile.exist? ? CaskLoader.load_from_file(installed_caskfile) : @cask + installed_cask = installed_caskfile.exist? ? CaskLoader.load(installed_caskfile) : @cask # Always force uninstallation, ignore method parameter Installer.new(installed_cask, binaries: binaries?, verbose: verbose?, force: true).uninstall diff --git a/Library/Homebrew/test/cask/accessibility_spec.rb b/Library/Homebrew/test/cask/accessibility_spec.rb index 9e56f6bd33..b77bcb0020 100644 --- a/Library/Homebrew/test/cask/accessibility_spec.rb +++ b/Library/Homebrew/test/cask/accessibility_spec.rb @@ -1,7 +1,7 @@ # TODO: this test should be named after the corresponding class, once # that class is abstracted from installer.rb. describe "Accessibility Access", :cask do - let(:cask) { Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/with-accessibility-access.rb") } + let(:cask) { Hbc::CaskLoader.load(cask_path("with-accessibility-access")) } let(:fake_system_command) { class_double(Hbc::SystemCommand) } let(:installer) { Hbc::Installer.new(cask, command: fake_system_command) } diff --git a/Library/Homebrew/test/cask/artifact/alt_target_spec.rb b/Library/Homebrew/test/cask/artifact/alt_target_spec.rb index 02be796edc..346b90e78c 100644 --- a/Library/Homebrew/test/cask/artifact/alt_target_spec.rb +++ b/Library/Homebrew/test/cask/artifact/alt_target_spec.rb @@ -1,6 +1,6 @@ describe Hbc::Artifact::App, :cask do describe "activate to alternate target" do - let(:cask) { Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/with-alt-target.rb") } + let(:cask) { Hbc::CaskLoader.load(cask_path("with-alt-target")) } let(:install_phase) { -> { described_class.for_cask(cask).each { |artifact| artifact.install_phase(command: Hbc::NeverSudoSystemCommand, force: false) } } diff --git a/Library/Homebrew/test/cask/artifact/app_spec.rb b/Library/Homebrew/test/cask/artifact/app_spec.rb index f67ffd31b5..b38a603170 100644 --- a/Library/Homebrew/test/cask/artifact/app_spec.rb +++ b/Library/Homebrew/test/cask/artifact/app_spec.rb @@ -1,5 +1,5 @@ describe Hbc::Artifact::App, :cask do - let(:cask) { Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/local-caffeine.rb") } + let(:cask) { Hbc::CaskLoader.load(cask_path("local-caffeine")) } let(:command) { Hbc::SystemCommand } let(:force) { false } let(:app) { described_class.for_cask(cask).first } diff --git a/Library/Homebrew/test/cask/artifact/binary_spec.rb b/Library/Homebrew/test/cask/artifact/binary_spec.rb index 5ffaca861f..bbd1258640 100644 --- a/Library/Homebrew/test/cask/artifact/binary_spec.rb +++ b/Library/Homebrew/test/cask/artifact/binary_spec.rb @@ -1,6 +1,6 @@ describe Hbc::Artifact::Binary, :cask do let(:cask) { - Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/with-binary.rb").tap do |cask| + Hbc::CaskLoader.load(cask_path("with-binary")).tap do |cask| InstallHelper.install_without_artifacts(cask) end } @@ -16,7 +16,7 @@ describe Hbc::Artifact::Binary, :cask do context "when --no-binaries is specified" do let(:cask) { - Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/with-binary.rb") + Hbc::CaskLoader.load(cask_path("with-binary")) } it "doesn't link the binary when --no-binaries is specified" do @@ -35,7 +35,7 @@ describe Hbc::Artifact::Binary, :cask do context "when the binary is not executable" do let(:cask) { - Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/with-non-executable-binary.rb").tap do |cask| + Hbc::CaskLoader.load(cask_path("with-non-executable-binary")).tap do |cask| InstallHelper.install_without_artifacts(cask) end } @@ -85,7 +85,7 @@ describe Hbc::Artifact::Binary, :cask do context "binary is inside an app package" do let(:cask) { - Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/with-embedded-binary.rb").tap do |cask| + Hbc::CaskLoader.load(cask_path("with-embedded-binary")).tap do |cask| InstallHelper.install_without_artifacts(cask) end } diff --git a/Library/Homebrew/test/cask/artifact/generic_artifact_spec.rb b/Library/Homebrew/test/cask/artifact/generic_artifact_spec.rb index bec8c27428..bcd3155d35 100644 --- a/Library/Homebrew/test/cask/artifact/generic_artifact_spec.rb +++ b/Library/Homebrew/test/cask/artifact/generic_artifact_spec.rb @@ -1,5 +1,5 @@ describe Hbc::Artifact::Artifact, :cask do - let(:cask) { Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/with-generic-artifact.rb") } + let(:cask) { Hbc::CaskLoader.load(cask_path("with-generic-artifact")) } let(:install_phase) { -> { described_class.for_cask(cask).each { |artifact| artifact.install_phase(command: Hbc::NeverSudoSystemCommand, force: false) } } @@ -15,7 +15,7 @@ describe Hbc::Artifact::Artifact, :cask do context "without target" do it "fails to load" do expect { - Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/with-generic-artifact-no-target.rb") + Hbc::CaskLoader.load(cask_path("with-generic-artifact-no-target")) }.to raise_error(Hbc::CaskInvalidError, /target required for Generic Artifact/) end end diff --git a/Library/Homebrew/test/cask/artifact/nested_container_spec.rb b/Library/Homebrew/test/cask/artifact/nested_container_spec.rb index 41d143764b..ef23c3fd7c 100644 --- a/Library/Homebrew/test/cask/artifact/nested_container_spec.rb +++ b/Library/Homebrew/test/cask/artifact/nested_container_spec.rb @@ -1,7 +1,7 @@ describe Hbc::Artifact::NestedContainer, :cask do describe "install" do it "extracts the specified paths as containers" do - cask = Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/nested-app.rb").tap do |c| + cask = Hbc::CaskLoader.load(cask_path("nested-app")).tap do |c| InstallHelper.install_without_artifacts(c) end diff --git a/Library/Homebrew/test/cask/artifact/pkg_spec.rb b/Library/Homebrew/test/cask/artifact/pkg_spec.rb index c6a45c49ab..71eb7bf4f9 100644 --- a/Library/Homebrew/test/cask/artifact/pkg_spec.rb +++ b/Library/Homebrew/test/cask/artifact/pkg_spec.rb @@ -1,5 +1,5 @@ describe Hbc::Artifact::Pkg, :cask do - let(:cask) { Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/with-installable.rb") } + let(:cask) { Hbc::CaskLoader.load(cask_path("with-installable")) } let(:fake_system_command) { class_double(Hbc::SystemCommand) } before(:each) do @@ -22,7 +22,7 @@ describe Hbc::Artifact::Pkg, :cask do end describe "choices" do - let(:cask) { Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/with-choices.rb") } + let(:cask) { Hbc::CaskLoader.load(cask_path("with-choices")) } it "passes the choice changes xml to the system installer" do pkg = described_class.for_cask(cask).first diff --git a/Library/Homebrew/test/cask/artifact/suite_spec.rb b/Library/Homebrew/test/cask/artifact/suite_spec.rb index 2f913fecc7..5c322e0e22 100644 --- a/Library/Homebrew/test/cask/artifact/suite_spec.rb +++ b/Library/Homebrew/test/cask/artifact/suite_spec.rb @@ -1,5 +1,5 @@ describe Hbc::Artifact::Suite, :cask do - let(:cask) { Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/with-suite.rb") } + let(:cask) { Hbc::CaskLoader.load(cask_path("with-suite")) } let(:install_phase) { -> { described_class.for_cask(cask).each { |artifact| artifact.install_phase(command: Hbc::NeverSudoSystemCommand, force: false) } } diff --git a/Library/Homebrew/test/cask/artifact/two_apps_correct_spec.rb b/Library/Homebrew/test/cask/artifact/two_apps_correct_spec.rb index f6e0d3c97b..5362966200 100644 --- a/Library/Homebrew/test/cask/artifact/two_apps_correct_spec.rb +++ b/Library/Homebrew/test/cask/artifact/two_apps_correct_spec.rb @@ -1,6 +1,6 @@ describe Hbc::Artifact::App, :cask do describe "multiple apps" do - let(:cask) { Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/with-two-apps-correct.rb") } + let(:cask) { Hbc::CaskLoader.load(cask_path("with-two-apps-correct")) } let(:install_phase) { -> { described_class.for_cask(cask).each { |artifact| artifact.install_phase(command: Hbc::NeverSudoSystemCommand, force: false) } } @@ -27,7 +27,7 @@ describe Hbc::Artifact::App, :cask do end describe "when apps are in a subdirectory" do - let(:cask) { Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/with-two-apps-subdir.rb") } + let(:cask) { Hbc::CaskLoader.load(cask_path("with-two-apps-subdir")) } it "installs both apps using the proper target directory" do install_phase.call diff --git a/Library/Homebrew/test/cask/artifact/two_apps_incorrect_spec.rb b/Library/Homebrew/test/cask/artifact/two_apps_incorrect_spec.rb index 6427ec32c3..cda5b4488c 100644 --- a/Library/Homebrew/test/cask/artifact/two_apps_incorrect_spec.rb +++ b/Library/Homebrew/test/cask/artifact/two_apps_incorrect_spec.rb @@ -2,7 +2,7 @@ describe Hbc::Artifact::App, :cask do # FIXME: Doesn't actually raise because the `app` stanza is not evaluated on load. # it "must raise" do # lambda { - # Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/with-two-apps-incorrect.rb") + # Hbc::CaskLoader.load(cask_path("with-two-apps-incorrect")) # }.must_raise # # TODO: later give the user a nice exception for this case and check for it here # end diff --git a/Library/Homebrew/test/cask/artifact/uninstall_no_zap_spec.rb b/Library/Homebrew/test/cask/artifact/uninstall_no_zap_spec.rb index d6a8393dac..f1940fc4df 100644 --- a/Library/Homebrew/test/cask/artifact/uninstall_no_zap_spec.rb +++ b/Library/Homebrew/test/cask/artifact/uninstall_no_zap_spec.rb @@ -1,5 +1,5 @@ describe Hbc::Artifact::Zap, :cask do - let(:cask) { Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/with-installable.rb") } + let(:cask) { Hbc::CaskLoader.load(cask_path("with-installable")) } let(:zap_artifact) { described_class.for_cask(cask).first diff --git a/Library/Homebrew/test/cask/artifact/uninstall_zap_shared_examples.rb b/Library/Homebrew/test/cask/artifact/uninstall_zap_shared_examples.rb index 4fdab60d00..59f3d946f9 100644 --- a/Library/Homebrew/test/cask/artifact/uninstall_zap_shared_examples.rb +++ b/Library/Homebrew/test/cask/artifact/uninstall_zap_shared_examples.rb @@ -6,7 +6,7 @@ shared_examples "#uninstall_phase or #zap_phase" do subject { artifact.public_send(:"#{artifact_dsl_key}_phase", command: fake_system_command) } context "using :launchctl" do - let(:cask) { Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/with-#{artifact_dsl_key}-launchctl.rb") } + let(:cask) { Hbc::CaskLoader.load(cask_path("with-#{artifact_dsl_key}-launchctl")) } let(:launchctl_list_cmd) { %w[/bin/launchctl list my.fancy.package.service] } let(:launchctl_remove_cmd) { %w[/bin/launchctl remove my.fancy.package.service] } let(:unknown_response) { "launchctl list returned unknown response\n" } @@ -61,7 +61,7 @@ shared_examples "#uninstall_phase or #zap_phase" do context "using :pkgutil" do let(:fake_system_command) { class_double(Hbc::SystemCommand) } - let(:cask) { Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/with-#{artifact_dsl_key}-pkgutil.rb") } + let(:cask) { Hbc::CaskLoader.load(cask_path("with-#{artifact_dsl_key}-pkgutil")) } let(:main_pkg_id) { "my.fancy.package.main" } let(:agent_pkg_id) { "my.fancy.package.agent" } @@ -85,7 +85,7 @@ shared_examples "#uninstall_phase or #zap_phase" do end context "using :kext" do - let(:cask) { Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/with-#{artifact_dsl_key}-kext.rb") } + let(:cask) { Hbc::CaskLoader.load(cask_path("with-#{artifact_dsl_key}-kext")) } let(:kext_id) { "my.fancy.package.kernelextension" } it "is supported" do @@ -110,7 +110,7 @@ shared_examples "#uninstall_phase or #zap_phase" do end context "using :quit" do - let(:cask) { Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/with-#{artifact_dsl_key}-quit.rb") } + let(:cask) { Hbc::CaskLoader.load(cask_path("with-#{artifact_dsl_key}-quit")) } let(:bundle_id) { "my.fancy.package.app" } let(:quit_application_script) do %Q(tell application id "#{bundle_id}" to quit) @@ -130,7 +130,7 @@ shared_examples "#uninstall_phase or #zap_phase" do end context "using :signal" do - let(:cask) { Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/with-#{artifact_dsl_key}-signal.rb") } + let(:cask) { Hbc::CaskLoader.load(cask_path("with-#{artifact_dsl_key}-signal")) } let(:bundle_id) { "my.fancy.package.app" } let(:signals) { %w[TERM KILL] } let(:unix_pids) { [12_345, 67_890] } @@ -172,7 +172,7 @@ shared_examples "#uninstall_phase or #zap_phase" do end let(:fake_system_command) { Hbc::NeverSudoSystemCommand } - let(:cask) { Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/with-#{artifact_dsl_key}-#{directive}.rb") } + let(:cask) { Hbc::CaskLoader.load(cask_path("with-#{artifact_dsl_key}-#{directive}")) } before(:each) do allow_any_instance_of(Hbc::Artifact::AbstractUninstall).to receive(:trash_paths) @@ -198,7 +198,7 @@ shared_examples "#uninstall_phase or #zap_phase" do context "using :rmdir" do let(:fake_system_command) { Hbc::NeverSudoSystemCommand } - let(:cask) { Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/with-#{artifact_dsl_key}-rmdir.rb") } + let(:cask) { Hbc::CaskLoader.load(cask_path("with-#{artifact_dsl_key}-rmdir")) } let(:empty_directory) { Pathname.new("#{TEST_TMPDIR}/empty_directory_path") } let(:ds_store) { empty_directory.join(".DS_Store") } @@ -226,7 +226,7 @@ shared_examples "#uninstall_phase or #zap_phase" do context "using #{script_type.inspect}" do let(:fake_system_command) { Hbc::NeverSudoSystemCommand } let(:token) { "with-#{artifact_dsl_key}-#{script_type}".tr("_", "-") } - let(:cask) { Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/#{token}.rb") } + let(:cask) { Hbc::CaskLoader.load(cask_path(token.to_s)) } let(:script_pathname) { cask.staged_path.join("MyFancyPkg", "FancyUninstaller.tool") } it "is supported" do @@ -252,7 +252,7 @@ shared_examples "#uninstall_phase or #zap_phase" do end context "using :login_item" do - let(:cask) { Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/with-#{artifact_dsl_key}-login-item.rb") } + let(:cask) { Hbc::CaskLoader.load(cask_path("with-#{artifact_dsl_key}-login-item")) } it "is supported" do Hbc::FakeSystemCommand.expects_command( diff --git a/Library/Homebrew/test/cask/cli/fetch_spec.rb b/Library/Homebrew/test/cask/cli/fetch_spec.rb index 087a30f50b..67cf6e61d9 100644 --- a/Library/Homebrew/test/cask/cli/fetch_spec.rb +++ b/Library/Homebrew/test/cask/cli/fetch_spec.rb @@ -3,11 +3,11 @@ require_relative "shared_examples/invalid_option" describe Hbc::CLI::Fetch, :cask do let(:local_transmission) { - Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/local-transmission.rb") + Hbc::CaskLoader.load(cask_path("local-transmission")) } let(:local_caffeine) { - Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/local-caffeine.rb") + Hbc::CaskLoader.load(cask_path("local-caffeine")) } it_behaves_like "a command that requires a Cask token" diff --git a/Library/Homebrew/test/cask/cli/install_spec.rb b/Library/Homebrew/test/cask/cli/install_spec.rb index 17a7b9f99c..c918a35296 100644 --- a/Library/Homebrew/test/cask/cli/install_spec.rb +++ b/Library/Homebrew/test/cask/cli/install_spec.rb @@ -22,16 +22,16 @@ describe Hbc::CLI::Install, :cask do it "allows staging and activation of multiple Casks at once" do described_class.run("local-transmission", "local-caffeine") - expect(Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/local-transmission.rb")).to be_installed + expect(Hbc::CaskLoader.load(cask_path("local-transmission"))).to be_installed expect(Hbc.appdir.join("Transmission.app")).to be_a_directory - expect(Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/local-caffeine.rb")).to be_installed + expect(Hbc::CaskLoader.load(cask_path("local-caffeine"))).to be_installed expect(Hbc.appdir.join("Caffeine.app")).to be_a_directory end it "skips double install (without nuking existing installation)" do described_class.run("local-transmission") described_class.run("local-transmission") - expect(Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/local-transmission.rb")).to be_installed + expect(Hbc::CaskLoader.load(cask_path("local-transmission"))).to be_installed end it "prints a warning message on double install" do @@ -54,9 +54,9 @@ describe Hbc::CLI::Install, :cask do it "skips dependencies with --skip-cask-deps" do described_class.run("with-depends-on-cask-multiple", "--skip-cask-deps") - expect(Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/with-depends-on-cask-multiple.rb")).to be_installed - expect(Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/local-caffeine.rb")).not_to be_installed - expect(Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/local-transmission.rb")).not_to be_installed + expect(Hbc::CaskLoader.load(cask_path("with-depends-on-cask-multiple"))).to be_installed + expect(Hbc::CaskLoader.load(cask_path("local-caffeine"))).not_to be_installed + expect(Hbc::CaskLoader.load(cask_path("local-transmission"))).not_to be_installed end it "properly handles Casks that are not present" do diff --git a/Library/Homebrew/test/cask/cli/list_spec.rb b/Library/Homebrew/test/cask/cli/list_spec.rb index 75da827621..58d8bc6329 100644 --- a/Library/Homebrew/test/cask/cli/list_spec.rb +++ b/Library/Homebrew/test/cask/cli/list_spec.rb @@ -65,8 +65,8 @@ describe Hbc::CLI::List, :cask do end describe "given a set of installed Casks" do - let(:caffeine) { Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/local-caffeine.rb") } - let(:transmission) { Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/local-transmission.rb") } + let(:caffeine) { Hbc::CaskLoader.load(cask_path("local-caffeine")) } + let(:transmission) { Hbc::CaskLoader.load(cask_path("local-transmission")) } let(:casks) { [caffeine, transmission] } it "lists the installed files for those Casks" do diff --git a/Library/Homebrew/test/cask/cli/outdated_spec.rb b/Library/Homebrew/test/cask/cli/outdated_spec.rb index 7fca8c248f..5bbf18d21a 100644 --- a/Library/Homebrew/test/cask/cli/outdated_spec.rb +++ b/Library/Homebrew/test/cask/cli/outdated_spec.rb @@ -3,11 +3,11 @@ require_relative "shared_examples/invalid_option" describe Hbc::CLI::Outdated, :cask do let(:installed) do [ - Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/basic-cask.rb"), - Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/outdated/local-caffeine.rb"), - Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/outdated/local-transmission.rb"), - Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/version-latest-string.rb"), - Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/outdated/auto-updates.rb"), + Hbc::CaskLoader.load(cask_path("basic-cask")), + Hbc::CaskLoader.load(cask_path("outdated/local-caffeine")), + Hbc::CaskLoader.load(cask_path("outdated/local-transmission")), + Hbc::CaskLoader.load(cask_path("version-latest-string")), + Hbc::CaskLoader.load(cask_path("outdated/auto-updates")), ] end @@ -74,7 +74,7 @@ describe Hbc::CLI::Outdated, :cask do end it 'does not include the Casks with "auto_updates true" when the version did not change' do - cask = Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/auto-updates.rb") + cask = Hbc::CaskLoader.load(cask_path("auto-updates")) InstallHelper.install_with_caskfile(cask) expect { diff --git a/Library/Homebrew/test/cask/cli/reinstall_spec.rb b/Library/Homebrew/test/cask/cli/reinstall_spec.rb index 073fbb23c7..95294b6958 100644 --- a/Library/Homebrew/test/cask/cli/reinstall_spec.rb +++ b/Library/Homebrew/test/cask/cli/reinstall_spec.rb @@ -4,7 +4,7 @@ describe Hbc::CLI::Reinstall, :cask do it_behaves_like "a command that handles invalid options" it "displays the reinstallation progress" do - caffeine = Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/local-caffeine.rb") + caffeine = Hbc::CaskLoader.load(cask_path("local-caffeine")) Hbc::Installer.new(caffeine).install @@ -27,16 +27,16 @@ describe Hbc::CLI::Reinstall, :cask do it "allows reinstalling a Cask" do Hbc::CLI::Install.run("local-transmission") - expect(Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/local-transmission.rb")).to be_installed + expect(Hbc::CaskLoader.load(cask_path("local-transmission"))).to be_installed Hbc::CLI::Reinstall.run("local-transmission") - expect(Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/local-transmission.rb")).to be_installed + expect(Hbc::CaskLoader.load(cask_path("local-transmission"))).to be_installed end it "allows reinstalling a non installed Cask" do - expect(Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/local-transmission.rb")).not_to be_installed + expect(Hbc::CaskLoader.load(cask_path("local-transmission"))).not_to be_installed Hbc::CLI::Reinstall.run("local-transmission") - expect(Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/local-transmission.rb")).to be_installed + expect(Hbc::CaskLoader.load(cask_path("local-transmission"))).to be_installed end end diff --git a/Library/Homebrew/test/cask/cli/uninstall_spec.rb b/Library/Homebrew/test/cask/cli/uninstall_spec.rb index 9ebd80dfbe..80b7edbd38 100644 --- a/Library/Homebrew/test/cask/cli/uninstall_spec.rb +++ b/Library/Homebrew/test/cask/cli/uninstall_spec.rb @@ -6,7 +6,7 @@ describe Hbc::CLI::Uninstall, :cask do it_behaves_like "a command that handles invalid options" it "displays the uninstallation progress" do - caffeine = Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/local-caffeine.rb") + caffeine = Hbc::CaskLoader.load(cask_path("local-caffeine")) Hbc::Installer.new(caffeine).install @@ -37,8 +37,8 @@ describe Hbc::CLI::Uninstall, :cask do end it "can uninstall and unlink multiple Casks at once" do - caffeine = Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/local-caffeine.rb") - transmission = Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/local-transmission.rb") + caffeine = Hbc::CaskLoader.load(cask_path("local-caffeine")) + transmission = Hbc::CaskLoader.load(cask_path("local-transmission")) Hbc::Installer.new(caffeine).install Hbc::Installer.new(transmission).install @@ -55,7 +55,7 @@ describe Hbc::CLI::Uninstall, :cask do end it "calls `uninstall` before removing artifacts" do - cask = Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/with-uninstall-script-app.rb") + cask = Hbc::CaskLoader.load(cask_path("with-uninstall-script-app")) Hbc::Installer.new(cask).install @@ -71,7 +71,7 @@ describe Hbc::CLI::Uninstall, :cask do end it "can uninstall Casks when the uninstall script is missing, but only when using `--force`" do - cask = Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/with-uninstall-script-app.rb") + cask = Hbc::CaskLoader.load(cask_path("with-uninstall-script-app")) Hbc::Installer.new(cask).install diff --git a/Library/Homebrew/test/cask/cli/zap_spec.rb b/Library/Homebrew/test/cask/cli/zap_spec.rb index 19e8ff261c..05c882854a 100644 --- a/Library/Homebrew/test/cask/cli/zap_spec.rb +++ b/Library/Homebrew/test/cask/cli/zap_spec.rb @@ -11,8 +11,8 @@ describe Hbc::CLI::Zap, :cask do end it "can zap and unlink multiple Casks at once" do - caffeine = Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/local-caffeine.rb") - transmission = Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/local-transmission.rb") + caffeine = Hbc::CaskLoader.load(cask_path("local-caffeine")) + transmission = Hbc::CaskLoader.load(cask_path("local-transmission")) Hbc::Installer.new(caffeine).install Hbc::Installer.new(transmission).install diff --git a/Library/Homebrew/test/cask/conflicts_with_spec.rb b/Library/Homebrew/test/cask/conflicts_with_spec.rb index 00dc252fe4..81c22ded68 100644 --- a/Library/Homebrew/test/cask/conflicts_with_spec.rb +++ b/Library/Homebrew/test/cask/conflicts_with_spec.rb @@ -1,11 +1,11 @@ describe "conflicts_with", :cask do describe "conflicts_with cask" do let(:local_caffeine) { - Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/local-caffeine.rb") + Hbc::CaskLoader.load(cask_path("local-caffeine")) } let(:with_conflicts_with) { - Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/with-conflicts-with.rb") + Hbc::CaskLoader.load(cask_path("with-conflicts-with")) } it "installs the dependency of a Cask and the Cask itself" do diff --git a/Library/Homebrew/test/cask/container/dmg_spec.rb b/Library/Homebrew/test/cask/container/dmg_spec.rb index 4f3f570710..df99a6264a 100644 --- a/Library/Homebrew/test/cask/container/dmg_spec.rb +++ b/Library/Homebrew/test/cask/container/dmg_spec.rb @@ -1,7 +1,7 @@ describe Hbc::Container::Dmg, :cask do describe "#mount!" do it "does not store nil mounts for dmgs with extra data" do - transmission = Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/local-transmission.rb") + transmission = Hbc::CaskLoader.load(cask_path("local-transmission")) dmg = Hbc::Container::Dmg.new( transmission, diff --git a/Library/Homebrew/test/cask/depends_on_spec.rb b/Library/Homebrew/test/cask/depends_on_spec.rb index 2818ff8b0b..453a761f7e 100644 --- a/Library/Homebrew/test/cask/depends_on_spec.rb +++ b/Library/Homebrew/test/cask/depends_on_spec.rb @@ -9,7 +9,7 @@ describe "Satisfy Dependencies and Requirements", :cask do describe "depends_on cask" do context "when depends_on cask is cyclic" do - let(:cask) { Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/with-depends-on-cask-cyclic.rb") } + let(:cask) { Hbc::CaskLoader.load(cask_path("with-depends-on-cask-cyclic")) } it { is_expected.to raise_error(Hbc::CaskCyclicDependencyError, "Cask 'with-depends-on-cask-cyclic' includes cyclic dependencies on other Casks: with-depends-on-cask-cyclic-helper") @@ -17,7 +17,7 @@ describe "Satisfy Dependencies and Requirements", :cask do end context do - let(:cask) { Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/with-depends-on-cask.rb") } + let(:cask) { Hbc::CaskLoader.load(cask_path("with-depends-on-cask")) } let(:dependency) { Hbc::CaskLoader.load(cask.depends_on.cask.first) } it "installs the dependency of a Cask and the Cask itself" do @@ -30,34 +30,34 @@ describe "Satisfy Dependencies and Requirements", :cask do describe "depends_on macos" do context "given an array" do - let(:cask) { Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/with-depends-on-macos-array.rb") } + let(:cask) { Hbc::CaskLoader.load(cask_path("with-depends-on-macos-array")) } it { is_expected.not_to raise_error } end context "given a comparison" do - let(:cask) { Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/with-depends-on-macos-comparison.rb") } + let(:cask) { Hbc::CaskLoader.load(cask_path("with-depends-on-macos-comparison")) } it { is_expected.not_to raise_error } end context "given a string" do - let(:cask) { Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/with-depends-on-macos-string.rb") } + let(:cask) { Hbc::CaskLoader.load(cask_path("with-depends-on-macos-string")) } it { is_expected.not_to raise_error } end context "given a symbol" do - let(:cask) { Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/with-depends-on-macos-symbol.rb") } + let(:cask) { Hbc::CaskLoader.load(cask_path("with-depends-on-macos-symbol")) } it { is_expected.not_to raise_error } end context "when not satisfied" do - let(:cask) { Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/with-depends-on-macos-failure.rb") } + let(:cask) { Hbc::CaskLoader.load(cask_path("with-depends-on-macos-failure")) } it { is_expected.to raise_error(Hbc::CaskError) } end end describe "depends_on arch" do context "when satisfied" do - let(:cask) { Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/with-depends-on-arch.rb") } + let(:cask) { Hbc::CaskLoader.load(cask_path("with-depends-on-arch")) } it { is_expected.not_to raise_error } end end @@ -68,21 +68,21 @@ describe "Satisfy Dependencies and Requirements", :cask do end context "when satisfied" do - let(:cask) { Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/with-depends-on-x11.rb") } + let(:cask) { Hbc::CaskLoader.load(cask_path("with-depends-on-x11")) } let(:x11_installed) { true } it { is_expected.not_to raise_error } end context "when not satisfied" do - let(:cask) { Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/with-depends-on-x11.rb") } + let(:cask) { Hbc::CaskLoader.load(cask_path("with-depends-on-x11")) } let(:x11_installed) { false } it { is_expected.to raise_error(Hbc::CaskX11DependencyError) } end context "when depends_on x11: false" do - let(:cask) { Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/with-depends-on-x11-false.rb") } + let(:cask) { Hbc::CaskLoader.load(cask_path("with-depends-on-x11-false")) } let(:x11_installed) { false } it { is_expected.not_to raise_error } diff --git a/Library/Homebrew/test/cask/dsl/caveats_spec.rb b/Library/Homebrew/test/cask/dsl/caveats_spec.rb index aa662e4d02..1b82d98211 100644 --- a/Library/Homebrew/test/cask/dsl/caveats_spec.rb +++ b/Library/Homebrew/test/cask/dsl/caveats_spec.rb @@ -1,7 +1,7 @@ require "test/support/helper/spec/shared_examples/hbc_dsl_base" describe Hbc::DSL::Caveats, :cask do - let(:cask) { Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/basic-cask.rb") } + let(:cask) { Hbc::CaskLoader.load(cask_path("basic-cask")) } let(:dsl) { Hbc::DSL::Caveats.new(cask) } it_behaves_like Hbc::DSL::Base diff --git a/Library/Homebrew/test/cask/dsl/postflight_spec.rb b/Library/Homebrew/test/cask/dsl/postflight_spec.rb index d2b080ca30..4ac3ae7cf7 100644 --- a/Library/Homebrew/test/cask/dsl/postflight_spec.rb +++ b/Library/Homebrew/test/cask/dsl/postflight_spec.rb @@ -2,7 +2,7 @@ require "test/support/helper/spec/shared_examples/hbc_dsl_base" require "test/support/helper/spec/shared_examples/hbc_staged" describe Hbc::DSL::Postflight, :cask do - let(:cask) { Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/basic-cask.rb") } + let(:cask) { Hbc::CaskLoader.load(cask_path("basic-cask")) } let(:dsl) { Hbc::DSL::Postflight.new(cask, Hbc::FakeSystemCommand) } it_behaves_like Hbc::DSL::Base diff --git a/Library/Homebrew/test/cask/dsl/preflight_spec.rb b/Library/Homebrew/test/cask/dsl/preflight_spec.rb index b93be95ff8..f78944c504 100644 --- a/Library/Homebrew/test/cask/dsl/preflight_spec.rb +++ b/Library/Homebrew/test/cask/dsl/preflight_spec.rb @@ -2,7 +2,7 @@ require "test/support/helper/spec/shared_examples/hbc_dsl_base" require "test/support/helper/spec/shared_examples/hbc_staged" describe Hbc::DSL::Preflight, :cask do - let(:cask) { Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/basic-cask.rb") } + let(:cask) { Hbc::CaskLoader.load(cask_path("basic-cask")) } let(:dsl) { Hbc::DSL::Preflight.new(cask, Hbc::FakeSystemCommand) } it_behaves_like Hbc::DSL::Base diff --git a/Library/Homebrew/test/cask/dsl/uninstall_postflight_spec.rb b/Library/Homebrew/test/cask/dsl/uninstall_postflight_spec.rb index f89a181ce2..b2af700dbd 100644 --- a/Library/Homebrew/test/cask/dsl/uninstall_postflight_spec.rb +++ b/Library/Homebrew/test/cask/dsl/uninstall_postflight_spec.rb @@ -1,7 +1,7 @@ require "test/support/helper/spec/shared_examples/hbc_dsl_base" describe Hbc::DSL::UninstallPostflight, :cask do - let(:cask) { Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/basic-cask.rb") } + let(:cask) { Hbc::CaskLoader.load(cask_path("basic-cask")) } let(:dsl) { Hbc::DSL::UninstallPostflight.new(cask, Hbc::FakeSystemCommand) } it_behaves_like Hbc::DSL::Base diff --git a/Library/Homebrew/test/cask/dsl/uninstall_preflight_spec.rb b/Library/Homebrew/test/cask/dsl/uninstall_preflight_spec.rb index 15a0ea1565..8e7fa47eb4 100644 --- a/Library/Homebrew/test/cask/dsl/uninstall_preflight_spec.rb +++ b/Library/Homebrew/test/cask/dsl/uninstall_preflight_spec.rb @@ -2,7 +2,7 @@ require "test/support/helper/spec/shared_examples/hbc_dsl_base" require "test/support/helper/spec/shared_examples/hbc_staged" describe Hbc::DSL::UninstallPreflight, :cask do - let(:cask) { Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/basic-cask.rb") } + let(:cask) { Hbc::CaskLoader.load(cask_path("basic-cask")) } let(:dsl) { Hbc::DSL::UninstallPreflight.new(cask, Hbc::FakeSystemCommand) } it_behaves_like Hbc::DSL::Base diff --git a/Library/Homebrew/test/cask/dsl_spec.rb b/Library/Homebrew/test/cask/dsl_spec.rb index 7df8de6f81..27d9f1afdf 100644 --- a/Library/Homebrew/test/cask/dsl_spec.rb +++ b/Library/Homebrew/test/cask/dsl_spec.rb @@ -1,5 +1,5 @@ describe Hbc::DSL, :cask do - let(:cask) { Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/#{token}.rb") } + let(:cask) { Hbc::CaskLoader.load(cask_path(token.to_s)) } let(:token) { "basic-cask" } context "stanzas" do diff --git a/Library/Homebrew/test/cask/installer_spec.rb b/Library/Homebrew/test/cask/installer_spec.rb index 6f7c6d3d7e..2dc27f04c8 100644 --- a/Library/Homebrew/test/cask/installer_spec.rb +++ b/Library/Homebrew/test/cask/installer_spec.rb @@ -5,7 +5,7 @@ describe Hbc::Installer, :cask do } it "downloads and installs a nice fresh Cask" do - caffeine = Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/local-caffeine.rb") + caffeine = Hbc::CaskLoader.load(cask_path("local-caffeine")) Hbc::Installer.new(caffeine).install @@ -14,7 +14,7 @@ describe Hbc::Installer, :cask do end it "works with dmg-based Casks" do - asset = Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/container-dmg.rb") + asset = Hbc::CaskLoader.load(cask_path("container-dmg")) Hbc::Installer.new(asset).install @@ -23,7 +23,7 @@ describe Hbc::Installer, :cask do end it "works with tar-gz-based Casks" do - asset = Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/container-tar-gz.rb") + asset = Hbc::CaskLoader.load(cask_path("container-tar-gz")) Hbc::Installer.new(asset).install @@ -32,7 +32,7 @@ describe Hbc::Installer, :cask do end it "works with xar-based Casks" do - asset = Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/container-xar.rb") + asset = Hbc::CaskLoader.load(cask_path("container-xar")) Hbc::Installer.new(asset).install @@ -41,7 +41,7 @@ describe Hbc::Installer, :cask do end it "works with pure bzip2-based Casks" do - asset = Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/container-bzip2.rb") + asset = Hbc::CaskLoader.load(cask_path("container-bzip2")) Hbc::Installer.new(asset).install @@ -50,7 +50,7 @@ describe Hbc::Installer, :cask do end it "works with pure gzip-based Casks" do - asset = Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/container-gzip.rb") + asset = Hbc::CaskLoader.load(cask_path("container-gzip")) Hbc::Installer.new(asset).install @@ -59,21 +59,21 @@ describe Hbc::Installer, :cask do end it "blows up on a bad checksum" do - bad_checksum = Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/bad-checksum.rb") + bad_checksum = Hbc::CaskLoader.load(cask_path("bad-checksum")) expect { Hbc::Installer.new(bad_checksum).install }.to raise_error(Hbc::CaskSha256MismatchError) end it "blows up on a missing checksum" do - missing_checksum = Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/missing-checksum.rb") + missing_checksum = Hbc::CaskLoader.load(cask_path("missing-checksum")) expect { Hbc::Installer.new(missing_checksum).install }.to raise_error(Hbc::CaskSha256MissingError) end it "installs fine if sha256 :no_check is used" do - no_checksum = Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/no-checksum.rb") + no_checksum = Hbc::CaskLoader.load(cask_path("no-checksum")) Hbc::Installer.new(no_checksum).install @@ -81,14 +81,14 @@ describe Hbc::Installer, :cask do end it "fails to install if sha256 :no_check is used with --require-sha" do - no_checksum = Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/no-checksum.rb") + no_checksum = Hbc::CaskLoader.load(cask_path("no-checksum")) expect { Hbc::Installer.new(no_checksum, require_sha: true).install }.to raise_error(Hbc::CaskNoShasumError) end it "installs fine if sha256 :no_check is used with --require-sha and --force" do - no_checksum = Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/no-checksum.rb") + no_checksum = Hbc::CaskLoader.load(cask_path("no-checksum")) Hbc::Installer.new(no_checksum, require_sha: true, force: true).install @@ -96,7 +96,7 @@ describe Hbc::Installer, :cask do end it "prints caveats if they're present" do - with_caveats = Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/with-caveats.rb") + with_caveats = Hbc::CaskLoader.load(cask_path("with-caveats")) expect { Hbc::Installer.new(with_caveats).install @@ -106,7 +106,7 @@ describe Hbc::Installer, :cask do end it "prints installer :manual instructions when present" do - with_installer_manual = Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/with-installer-manual.rb") + with_installer_manual = Hbc::CaskLoader.load(cask_path("with-installer-manual")) expect { Hbc::Installer.new(with_installer_manual).install @@ -116,7 +116,7 @@ describe Hbc::Installer, :cask do end it "does not extract __MACOSX directories from zips" do - with_macosx_dir = Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/with-macosx-dir.rb") + with_macosx_dir = Hbc::CaskLoader.load(cask_path("with-macosx-dir")) Hbc::Installer.new(with_macosx_dir).install @@ -124,7 +124,7 @@ describe Hbc::Installer, :cask do 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") + with_auto_updates = Hbc::CaskLoader.load(cask_path("auto-updates")) expect(with_auto_updates).not_to be_installed @@ -137,7 +137,7 @@ describe Hbc::Installer, :cask do # unlike the CLI, the internal interface throws exception on double-install it "installer method raises an exception when already-installed Casks are attempted" do - transmission = Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/local-transmission.rb") + transmission = Hbc::CaskLoader.load(cask_path("local-transmission")) expect(transmission).not_to be_installed @@ -151,7 +151,7 @@ describe Hbc::Installer, :cask do end it "allows already-installed Casks to be installed if force is provided" do - transmission = Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/local-transmission.rb") + transmission = Hbc::CaskLoader.load(cask_path("local-transmission")) expect(transmission).not_to be_installed @@ -163,7 +163,7 @@ describe Hbc::Installer, :cask do end it "works naked-pkg-based Casks" do - naked_pkg = Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/container-pkg.rb") + naked_pkg = Hbc::CaskLoader.load(cask_path("container-pkg")) Hbc::Installer.new(naked_pkg).install @@ -171,7 +171,7 @@ describe Hbc::Installer, :cask do end it "works properly with an overridden container :type" do - naked_executable = Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/naked-executable.rb") + naked_executable = Hbc::CaskLoader.load(cask_path("naked-executable")) Hbc::Installer.new(naked_executable).install @@ -179,7 +179,7 @@ describe Hbc::Installer, :cask do end it "works fine with a nested container" do - nested_app = Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/nested-app.rb") + nested_app = Hbc::CaskLoader.load(cask_path("nested-app")) Hbc::Installer.new(nested_app).install @@ -187,7 +187,7 @@ describe Hbc::Installer, :cask do end it "generates and finds a timestamped metadata directory for an installed Cask" do - caffeine = Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/local-caffeine.rb") + caffeine = Hbc::CaskLoader.load(cask_path("local-caffeine")) Hbc::Installer.new(caffeine).install @@ -196,7 +196,7 @@ describe Hbc::Installer, :cask do end it "generates and finds a metadata subdirectory for an installed Cask" do - caffeine = Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/local-caffeine.rb") + caffeine = Hbc::CaskLoader.load(cask_path("local-caffeine")) Hbc::Installer.new(caffeine).install @@ -208,7 +208,7 @@ describe Hbc::Installer, :cask do describe "uninstall" do it "fully uninstalls a Cask" do - caffeine = Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/local-caffeine.rb") + caffeine = Hbc::CaskLoader.load(cask_path("local-caffeine")) installer = Hbc::Installer.new(caffeine) installer.install @@ -220,7 +220,7 @@ describe Hbc::Installer, :cask do end it "uninstalls all versions if force is set" do - caffeine = Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/local-caffeine.rb") + caffeine = Hbc::CaskLoader.load(cask_path("local-caffeine")) mutated_version = caffeine.version + ".1" Hbc::Installer.new(caffeine).install diff --git a/Library/Homebrew/test/cask/staged_spec.rb b/Library/Homebrew/test/cask/staged_spec.rb index 73a909f35b..0229018c77 100644 --- a/Library/Homebrew/test/cask/staged_spec.rb +++ b/Library/Homebrew/test/cask/staged_spec.rb @@ -3,7 +3,7 @@ # to be invoking bundle_identifier off of the installer instance. describe "Operations on staged Casks", :cask do describe "bundle ID" do - let(:cask) { Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/local-transmission.rb") } + let(:cask) { Hbc::CaskLoader.load(cask_path("local-transmission")) } let(:installer) { Hbc::Installer.new(cask) } it "fetches the bundle ID from a staged cask" do installer.install diff --git a/Library/Homebrew/test/support/helper/fixtures.rb b/Library/Homebrew/test/support/helper/fixtures.rb index 716fe20081..460fb4aeff 100644 --- a/Library/Homebrew/test/support/helper/fixtures.rb +++ b/Library/Homebrew/test/support/helper/fixtures.rb @@ -8,6 +8,10 @@ module Test def bundle_path(name) Pathname.new("#{TEST_FIXTURE_DIR}/mach/#{name}.bundle") end + + def cask_path(name) + Pathname.new("#{TEST_FIXTURE_DIR}/cask/Casks/#{name}.rb") + end end end end From 979519572602a95bcb2b15fb279e92ddad9f4c6c Mon Sep 17 00:00:00 2001 From: Markus Reiter Date: Sat, 7 Oct 2017 22:31:23 +0200 Subject: [PATCH 287/294] Fix RuboCop tests. --- .../Homebrew/rubocops/extend/formula_cop.rb | 2 +- Library/Homebrew/test/Gemfile | 4 +- Library/Homebrew/test/Gemfile.lock | 22 +++++----- .../test/rubocops/bottle_block_cop_spec.rb | 4 +- .../test/rubocops/caveats_cop_spec.rb | 2 +- .../test/rubocops/checksum_cop_spec.rb | 12 +++--- .../Homebrew/test/rubocops/class_cop_spec.rb | 6 +-- .../rubocops/components_order_cop_spec.rb | 12 +++--- .../components_redundancy_cop_spec.rb | 6 +-- .../test/rubocops/conflicts_cop_spec.rb | 4 +- .../test/rubocops/formula_desc_cop_spec.rb | 16 +++---- .../test/rubocops/homepage_cop_spec.rb | 6 +-- .../Homebrew/test/rubocops/lines_cop_spec.rb | 42 +++++++++---------- .../test/rubocops/options_cop_spec.rb | 10 ++--- .../test/rubocops/patches_cop_spec.rb | 10 ++--- .../Homebrew/test/rubocops/text_cop_spec.rb | 22 +++++----- .../Homebrew/test/rubocops/urls_cop_spec.rb | 10 ++--- 17 files changed, 96 insertions(+), 94 deletions(-) diff --git a/Library/Homebrew/rubocops/extend/formula_cop.rb b/Library/Homebrew/rubocops/extend/formula_cop.rb index 47dd2d8033..fccce0deda 100644 --- a/Library/Homebrew/rubocops/extend/formula_cop.rb +++ b/Library/Homebrew/rubocops/extend/formula_cop.rb @@ -298,7 +298,7 @@ module RuboCop # Returns the array of arguments of the method_node def parameters(method_node) - method_node.method_args if method_node.send_type? || method_node.block_type? + method_node.arguments if method_node.send_type? || method_node.block_type? end # Returns true if the given parameters are present in method call diff --git a/Library/Homebrew/test/Gemfile b/Library/Homebrew/test/Gemfile index dbe76b51c4..b6d1405ff6 100644 --- a/Library/Homebrew/test/Gemfile +++ b/Library/Homebrew/test/Gemfile @@ -1,10 +1,12 @@ source "https://rubygems.org" +require_relative "../constants" + gem "parallel_tests" gem "rspec" gem "rspec-its", require: false gem "rspec-wait", require: false -gem "rubocop" +gem "rubocop", HOMEBREW_RUBOCOP_VERSION group :coverage do gem "codecov", require: false diff --git a/Library/Homebrew/test/Gemfile.lock b/Library/Homebrew/test/Gemfile.lock index ccfd91542d..ba12d091d4 100644 --- a/Library/Homebrew/test/Gemfile.lock +++ b/Library/Homebrew/test/Gemfile.lock @@ -9,15 +9,15 @@ GEM diff-lcs (1.3) docile (1.1.5) json (2.1.0) - parallel (1.11.2) - parallel_tests (2.14.1) + parallel (1.12.0) + parallel_tests (2.17.0) parallel parser (2.4.0.0) ast (~> 2.2) powerpack (0.1.1) rainbow (2.2.2) rake - rake (12.0.0) + rake (12.1.0) rspec (3.6.0) rspec-core (~> 3.6.0) rspec-expectations (~> 3.6.0) @@ -36,20 +36,20 @@ GEM rspec-support (3.6.0) rspec-wait (0.0.9) rspec (>= 3, < 4) - rubocop (0.49.1) + rubocop (0.50.0) parallel (~> 1.10) parser (>= 2.3.3.1, < 3.0) powerpack (~> 0.1) - rainbow (>= 1.99.1, < 3.0) + rainbow (>= 2.2.2, < 3.0) ruby-progressbar (~> 1.7) unicode-display_width (~> 1.0, >= 1.0.1) - ruby-progressbar (1.8.1) - simplecov (0.14.1) + ruby-progressbar (1.9.0) + simplecov (0.15.1) docile (~> 1.1.0) json (>= 1.8, < 3) simplecov-html (~> 0.10.0) - simplecov-html (0.10.0) - unicode-display_width (1.2.1) + simplecov-html (0.10.2) + unicode-display_width (1.3.0) url (0.3.2) PLATFORMS @@ -61,8 +61,8 @@ DEPENDENCIES rspec rspec-its rspec-wait - rubocop + rubocop (= 0.50.0) simplecov BUNDLED WITH - 1.14.6 + 1.15.4 diff --git a/Library/Homebrew/test/rubocops/bottle_block_cop_spec.rb b/Library/Homebrew/test/rubocops/bottle_block_cop_spec.rb index 563f7ad4be..b1afdc3f94 100644 --- a/Library/Homebrew/test/rubocops/bottle_block_cop_spec.rb +++ b/Library/Homebrew/test/rubocops/bottle_block_cop_spec.rb @@ -24,7 +24,7 @@ describe RuboCop::Cop::FormulaAuditStrict::BottleBlock do column: 4, source: source }] - inspect_source(cop, source) + inspect_source(source) expected_offenses.zip(cop.offenses).each do |expected, actual| expect_offense(expected, actual) @@ -60,7 +60,7 @@ describe RuboCop::Cop::FormulaAuditStrict::BottleBlock do end EOS - new_source = autocorrect_source(cop, source) + new_source = autocorrect_source(source) expect(new_source).to eq(corrected_source) end end diff --git a/Library/Homebrew/test/rubocops/caveats_cop_spec.rb b/Library/Homebrew/test/rubocops/caveats_cop_spec.rb index d44808a5d7..4dbe65cfb8 100644 --- a/Library/Homebrew/test/rubocops/caveats_cop_spec.rb +++ b/Library/Homebrew/test/rubocops/caveats_cop_spec.rb @@ -25,7 +25,7 @@ describe RuboCop::Cop::FormulaAudit::Caveats do column: 5, source: source }] - inspect_source(cop, source) + inspect_source(source) expected_offenses.zip(cop.offenses).each do |expected, actual| expect_offense(expected, actual) diff --git a/Library/Homebrew/test/rubocops/checksum_cop_spec.rb b/Library/Homebrew/test/rubocops/checksum_cop_spec.rb index 644152c32c..2f508bbf52 100644 --- a/Library/Homebrew/test/rubocops/checksum_cop_spec.rb +++ b/Library/Homebrew/test/rubocops/checksum_cop_spec.rb @@ -34,7 +34,7 @@ describe RuboCop::Cop::FormulaAudit::Checksum do column: 14, source: source }] - inspect_source(cop, source) + inspect_source(source) expected_offenses.zip(cop.offenses).each do |expected, actual| expect_offense(expected, actual) @@ -68,7 +68,7 @@ describe RuboCop::Cop::FormulaAudit::Checksum do column: 14, source: source }] - inspect_source(cop, source) + inspect_source(source) expected_offenses.zip(cop.offenses).each do |expected, actual| expect_offense(expected, actual) @@ -102,7 +102,7 @@ describe RuboCop::Cop::FormulaAudit::Checksum do column: 31, source: source }] - inspect_source(cop, source) + inspect_source(source) expected_offenses.zip(cop.offenses).each do |expected, actual| expect_offense(expected, actual) @@ -142,7 +142,7 @@ describe RuboCop::Cop::FormulaAudit::ChecksumCase do column: 20, source: source }] - inspect_source(cop, source) + inspect_source(source) expected_offenses.zip(cop.offenses).each do |expected, actual| expect_offense(expected, actual) @@ -175,7 +175,7 @@ describe RuboCop::Cop::FormulaAudit::ChecksumCase do column: 12, source: source }] - inspect_source(cop, source) + inspect_source(source) expected_offenses.zip(cop.offenses).each do |expected, actual| expect_offense(expected, actual) @@ -215,7 +215,7 @@ describe RuboCop::Cop::FormulaAudit::ChecksumCase do end EOS - new_source = autocorrect_source(cop, source) + new_source = autocorrect_source(source) expect(new_source).to eq(corrected_source) end end diff --git a/Library/Homebrew/test/rubocops/class_cop_spec.rb b/Library/Homebrew/test/rubocops/class_cop_spec.rb index 676dd4f6e9..59252587c0 100644 --- a/Library/Homebrew/test/rubocops/class_cop_spec.rb +++ b/Library/Homebrew/test/rubocops/class_cop_spec.rb @@ -29,7 +29,7 @@ describe RuboCop::Cop::FormulaAudit::ClassName do column: 12, source: source }] - inspect_source(cop, source) + inspect_source(source) expected_offenses.zip(cop.offenses.reverse).each do |expected, actual| expect_offense(expected, actual) @@ -49,7 +49,7 @@ describe RuboCop::Cop::FormulaAudit::ClassName do end EOS - new_source = autocorrect_source(cop, source) + new_source = autocorrect_source(source) expect(new_source).to eq(corrected_source) end end @@ -71,7 +71,7 @@ describe RuboCop::Cop::FormulaAuditStrict::Test do column: 0, source: source }] - inspect_source(cop, source) + inspect_source(source) expected_offenses.zip(cop.offenses).each do |expected, actual| expect_offense(expected, actual) diff --git a/Library/Homebrew/test/rubocops/components_order_cop_spec.rb b/Library/Homebrew/test/rubocops/components_order_cop_spec.rb index 25467c6353..f093f49279 100644 --- a/Library/Homebrew/test/rubocops/components_order_cop_spec.rb +++ b/Library/Homebrew/test/rubocops/components_order_cop_spec.rb @@ -21,7 +21,7 @@ describe RuboCop::Cop::FormulaAuditStrict::ComponentsOrder do column: 2, source: source }] - inspect_source(cop, source) + inspect_source(source) expected_offenses.zip(cop.offenses).each do |expected, actual| expect_offense(expected, actual) @@ -47,7 +47,7 @@ describe RuboCop::Cop::FormulaAuditStrict::ComponentsOrder do column: 2, source: source }] - inspect_source(cop, source) + inspect_source(source) expected_offenses.zip(cop.offenses).each do |expected, actual| expect_offense(expected, actual) @@ -74,7 +74,7 @@ describe RuboCop::Cop::FormulaAuditStrict::ComponentsOrder do column: 2, source: source }] - inspect_source(cop, source) + inspect_source(source) expected_offenses.zip(cop.offenses).each do |expected, actual| expect_offense(expected, actual) @@ -99,7 +99,7 @@ describe RuboCop::Cop::FormulaAuditStrict::ComponentsOrder do column: 2, source: source }] - inspect_source(cop, source) + inspect_source(source) expected_offenses.zip(cop.offenses).each do |expected, actual| expect_offense(expected, actual) @@ -129,7 +129,7 @@ describe RuboCop::Cop::FormulaAuditStrict::ComponentsOrder do end EOS - corrected_source = autocorrect_source(cop, source) + corrected_source = autocorrect_source(source) expect(corrected_source).to eq(correct_source) end @@ -156,7 +156,7 @@ describe RuboCop::Cop::FormulaAuditStrict::ComponentsOrder do end end EOS - corrected_source = autocorrect_source(cop, source) + corrected_source = autocorrect_source(source) expect(corrected_source).to eq(correct_source) end end diff --git a/Library/Homebrew/test/rubocops/components_redundancy_cop_spec.rb b/Library/Homebrew/test/rubocops/components_redundancy_cop_spec.rb index fd635a1264..9fbe159041 100644 --- a/Library/Homebrew/test/rubocops/components_redundancy_cop_spec.rb +++ b/Library/Homebrew/test/rubocops/components_redundancy_cop_spec.rb @@ -23,7 +23,7 @@ describe RuboCop::Cop::FormulaAuditStrict::ComponentsRedundancy do column: 2, source: source }] - inspect_source(cop, source) + inspect_source(source) expected_offenses.zip(cop.offenses).each do |expected, actual| expect_offense(expected, actual) @@ -46,7 +46,7 @@ describe RuboCop::Cop::FormulaAuditStrict::ComponentsRedundancy do column: 2, source: source }] - inspect_source(cop, source) + inspect_source(source) expected_offenses.zip(cop.offenses).each do |expected, actual| expect_offense(expected, actual) @@ -70,7 +70,7 @@ describe RuboCop::Cop::FormulaAuditStrict::ComponentsRedundancy do column: 2, source: source }] - inspect_source(cop, source) + inspect_source(source) expected_offenses.zip(cop.offenses).each do |expected, actual| expect_offense(expected, actual) diff --git a/Library/Homebrew/test/rubocops/conflicts_cop_spec.rb b/Library/Homebrew/test/rubocops/conflicts_cop_spec.rb index 3af0f96697..8874ecc963 100644 --- a/Library/Homebrew/test/rubocops/conflicts_cop_spec.rb +++ b/Library/Homebrew/test/rubocops/conflicts_cop_spec.rb @@ -22,7 +22,7 @@ describe RuboCop::Cop::FormulaAudit::Conflicts do column: 2, source: source }] - inspect_source(cop, source, "/homebrew-core/Formula/foo@2.0.rb") + inspect_source(source, "/homebrew-core/Formula/foo@2.0.rb") expected_offenses.zip(cop.offenses).each do |expected, actual| expect_offense(expected, actual) @@ -36,7 +36,7 @@ describe RuboCop::Cop::FormulaAudit::Conflicts do desc 'Bar' end EOS - inspect_source(cop, source, "/homebrew-core/Formula/foo@2.0.rb") + inspect_source(source, "/homebrew-core/Formula/foo@2.0.rb") expect(cop.offenses).to eq([]) 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 48342e8bca..ac8893e180 100644 --- a/Library/Homebrew/test/rubocops/formula_desc_cop_spec.rb +++ b/Library/Homebrew/test/rubocops/formula_desc_cop_spec.rb @@ -20,7 +20,7 @@ describe RuboCop::Cop::FormulaAuditStrict::DescLength do column: 0, source: source }] - inspect_source(cop, source) + inspect_source(source) expected_offenses.zip(cop.offenses).each do |expected, actual| expect_offense(expected, actual) @@ -45,7 +45,7 @@ describe RuboCop::Cop::FormulaAuditStrict::DescLength do column: 2, source: source }] - inspect_source(cop, source, "/homebrew-core/Formula/foo.rb") + inspect_source(source, "/homebrew-core/Formula/foo.rb") expected_offenses.zip(cop.offenses).each do |expected, actual| expect_offense(expected, actual) end @@ -70,7 +70,7 @@ describe RuboCop::Cop::FormulaAuditStrict::DescLength do column: 2, source: source }] - inspect_source(cop, source, "/homebrew-core/Formula/foo.rb") + inspect_source(source, "/homebrew-core/Formula/foo.rb") expected_offenses.zip(cop.offenses).each do |expected, actual| expect_offense(expected, actual) end @@ -96,7 +96,7 @@ describe RuboCop::Cop::FormulaAuditStrict::Desc do column: 8, source: source }] - inspect_source(cop, source) + inspect_source(source) expected_offenses.zip(cop.offenses).each do |expected, actual| expect_offense(expected, actual) end @@ -116,7 +116,7 @@ describe RuboCop::Cop::FormulaAuditStrict::Desc do column: 8, source: source }] - inspect_source(cop, source) + inspect_source(source) expected_offenses.zip(cop.offenses).each do |expected, actual| expect_offense(expected, actual) end @@ -136,7 +136,7 @@ describe RuboCop::Cop::FormulaAuditStrict::Desc do column: 8, source: source }] - inspect_source(cop, source) + inspect_source(source) expected_offenses.zip(cop.offenses).each do |expected, actual| expect_offense(expected, actual) end @@ -156,7 +156,7 @@ describe RuboCop::Cop::FormulaAuditStrict::Desc do column: 8, source: source }] - inspect_source(cop, source, "/homebrew-core/Formula/foo.rb") + inspect_source(source, "/homebrew-core/Formula/foo.rb") expected_offenses.zip(cop.offenses).each do |expected, actual| expect_offense(expected, actual) end @@ -176,7 +176,7 @@ describe RuboCop::Cop::FormulaAuditStrict::Desc do end EOS - corrected_source = autocorrect_source(cop, source, "/homebrew-core/Formula/foo.rb") + corrected_source = autocorrect_source(source, "/homebrew-core/Formula/foo.rb") expect(corrected_source).to eq(correct_source) end end diff --git a/Library/Homebrew/test/rubocops/homepage_cop_spec.rb b/Library/Homebrew/test/rubocops/homepage_cop_spec.rb index c03efd8257..6c7f248baa 100644 --- a/Library/Homebrew/test/rubocops/homepage_cop_spec.rb +++ b/Library/Homebrew/test/rubocops/homepage_cop_spec.rb @@ -20,7 +20,7 @@ describe RuboCop::Cop::FormulaAudit::Homepage do column: 0, source: source }] - inspect_source(cop, source) + inspect_source(source) expected_offenses.zip(cop.offenses).each do |expected, actual| expect_offense(expected, actual) @@ -41,7 +41,7 @@ describe RuboCop::Cop::FormulaAudit::Homepage do column: 2, source: source }] - inspect_source(cop, source) + inspect_source(source) expected_offenses.zip(cop.offenses).each do |expected, actual| expect_offense(expected, actual) @@ -72,7 +72,7 @@ describe RuboCop::Cop::FormulaAudit::Homepage do end EOS - inspect_source(cop, source) + inspect_source(source) if homepage =~ %r{http:\/\/www\.freedesktop\.org} if homepage =~ /Software/ expected_offenses = [{ message: "#{homepage} should be styled " \ diff --git a/Library/Homebrew/test/rubocops/lines_cop_spec.rb b/Library/Homebrew/test/rubocops/lines_cop_spec.rb index d939626883..753439c8e2 100644 --- a/Library/Homebrew/test/rubocops/lines_cop_spec.rb +++ b/Library/Homebrew/test/rubocops/lines_cop_spec.rb @@ -42,7 +42,7 @@ describe RuboCop::Cop::FormulaAudit::Lines do column: 2, source: source }] - inspect_source(cop, source) + inspect_source(source) expected_offenses.zip(cop.offenses.reverse).each do |expected, actual| expect_offense(expected, actual) @@ -70,7 +70,7 @@ describe RuboCop::Cop::FormulaAudit::ClassInheritance do column: 10, source: source }] - inspect_source(cop, source) + inspect_source(source) expected_offenses.zip(cop.offenses).each do |expected, actual| expect_offense(expected, actual) @@ -98,7 +98,7 @@ describe RuboCop::Cop::FormulaAudit::Comments do column: 2, source: source }] - inspect_source(cop, source) + inspect_source(source) expected_offenses.zip(cop.offenses).each do |expected, actual| expect_offense(expected, actual) @@ -120,7 +120,7 @@ describe RuboCop::Cop::FormulaAudit::Comments do column: 2, source: source }] - inspect_source(cop, source) + inspect_source(source) expected_offenses.zip(cop.offenses).each do |expected, actual| expect_offense(expected, actual) @@ -142,7 +142,7 @@ describe RuboCop::Cop::FormulaAudit::Comments do column: 2, source: source }] - inspect_source(cop, source) + inspect_source(source) expected_offenses.zip(cop.offenses).each do |expected, actual| expect_offense(expected, actual) @@ -170,7 +170,7 @@ describe RuboCop::Cop::FormulaAudit::Miscellaneous do column: 2, source: source }] - inspect_source(cop, source) + inspect_source(source) expected_offenses.zip(cop.offenses).each do |expected, actual| expect_offense(expected, actual) @@ -194,7 +194,7 @@ describe RuboCop::Cop::FormulaAudit::Miscellaneous do column: 2, source: source }] - inspect_source(cop, source) + inspect_source(source) expected_offenses.zip(cop.offenses).each do |expected, actual| expect_offense(expected, actual) @@ -219,7 +219,7 @@ describe RuboCop::Cop::FormulaAudit::Miscellaneous do column: 4, source: source }] - inspect_source(cop, source) + inspect_source(source) expected_offenses.zip(cop.offenses).each do |expected, actual| expect_offense(expected, actual) @@ -246,7 +246,7 @@ describe RuboCop::Cop::FormulaAudit::Miscellaneous do column: 7, source: source }] - inspect_source(cop, source, "/homebrew-core/") + inspect_source(source, "/homebrew-core/") expected_offenses.zip(cop.offenses).each do |expected, actual| expect_offense(expected, actual) @@ -274,7 +274,7 @@ describe RuboCop::Cop::FormulaAudit::Miscellaneous do column: 2, source: source }] - inspect_source(cop, source) + inspect_source(source) expected_offenses.zip(cop.offenses).each do |expected, actual| expect_offense(expected, actual) @@ -299,7 +299,7 @@ describe RuboCop::Cop::FormulaAudit::Miscellaneous do column: 2, source: source }] - inspect_source(cop, source) + inspect_source(source) expected_offenses.zip(cop.offenses).each do |expected, actual| expect_offense(expected, actual) @@ -324,7 +324,7 @@ describe RuboCop::Cop::FormulaAudit::Miscellaneous do column: 2, source: source }] - inspect_source(cop, source) + inspect_source(source) expected_offenses.zip(cop.offenses).each do |expected, actual| expect_offense(expected, actual) @@ -349,7 +349,7 @@ describe RuboCop::Cop::FormulaAudit::Miscellaneous do column: 2, source: source }] - inspect_source(cop, source) + inspect_source(source) expected_offenses.zip(cop.offenses).each do |expected, actual| expect_offense(expected, actual) @@ -373,7 +373,7 @@ describe RuboCop::Cop::FormulaAudit::Miscellaneous do column: 5, source: source }] - inspect_source(cop, source) + inspect_source(source) expected_offenses.zip(cop.offenses).each do |expected, actual| expect_offense(expected, actual) @@ -391,7 +391,7 @@ describe RuboCop::Cop::FormulaAudit::Miscellaneous do end EOS - inspect_source(cop, source, "/homebrew-core/Formula/wine.rb") + inspect_source(source, "/homebrew-core/Formula/wine.rb") expect(cop.offenses).to eq([]) end @@ -412,7 +412,7 @@ describe RuboCop::Cop::FormulaAudit::Miscellaneous do column: 5, source: source }] - inspect_source(cop, source) + inspect_source(source) expected_offenses.zip(cop.offenses).each do |expected, actual| expect_offense(expected, actual) @@ -436,7 +436,7 @@ describe RuboCop::Cop::FormulaAudit::Miscellaneous do column: 5, source: source }] - inspect_source(cop, source) + inspect_source(source) expected_offenses.zip(cop.offenses).each do |expected, actual| expect_offense(expected, actual) @@ -458,7 +458,7 @@ describe RuboCop::Cop::FormulaAudit::Miscellaneous do column: 10, source: source }] - inspect_source(cop, source) + inspect_source(source) expected_offenses.zip(cop.offenses).each do |expected, actual| expect_offense(expected, actual) @@ -474,7 +474,7 @@ describe RuboCop::Cop::FormulaAudit::Miscellaneous do end EOS - inspect_source(cop, source, "/homebrew-core/Formula/cctools.rb") + inspect_source(source, "/homebrew-core/Formula/cctools.rb") expect(cop.offenses).to eq([]) end @@ -493,7 +493,7 @@ describe RuboCop::Cop::FormulaAudit::Miscellaneous do column: 2, source: source }] - inspect_source(cop, source) + inspect_source(source) expected_offenses.zip(cop.offenses).each do |expected, actual| expect_offense(expected, actual) @@ -509,7 +509,7 @@ describe RuboCop::Cop::FormulaAudit::Miscellaneous do end EOS - inspect_source(cop, source, "/homebrew-core/Formula/kibana@4.4.rb") + inspect_source(source, "/homebrew-core/Formula/kibana@4.4.rb") expect(cop.offenses).to eq([]) end end diff --git a/Library/Homebrew/test/rubocops/options_cop_spec.rb b/Library/Homebrew/test/rubocops/options_cop_spec.rb index b89b3d9b59..c27389a68b 100644 --- a/Library/Homebrew/test/rubocops/options_cop_spec.rb +++ b/Library/Homebrew/test/rubocops/options_cop_spec.rb @@ -21,7 +21,7 @@ describe RuboCop::Cop::FormulaAudit::Options do column: 10, source: source }] - inspect_source(cop, source) + inspect_source(source) expected_offenses.zip(cop.offenses).each do |expected, actual| expect_offense(expected, actual) @@ -48,7 +48,7 @@ describe RuboCop::Cop::FormulaAuditStrict::Options do column: 2, source: source }] - inspect_source(cop, source) + inspect_source(source) expected_offenses.zip(cop.offenses).each do |expected, actual| expect_offense(expected, actual) @@ -72,7 +72,7 @@ describe RuboCop::Cop::FormulaAuditStrict::Options do column: 2, source: source }] - inspect_source(cop, source) + inspect_source(source) expected_offenses.zip(cop.offenses).each do |expected, actual| expect_offense(expected, actual) @@ -95,7 +95,7 @@ describe RuboCop::Cop::FormulaAuditStrict::Options do column: 2, source: source }] - inspect_source(cop, source) + inspect_source(source) expected_offenses.zip(cop.offenses).each do |expected, actual| expect_offense(expected, actual) @@ -122,7 +122,7 @@ describe RuboCop::Cop::NewFormulaAudit::Options do column: 2, source: source }] - inspect_source(cop, source) + inspect_source(source) expected_offenses.zip(cop.offenses).each do |expected, actual| expect_offense(expected, actual) diff --git a/Library/Homebrew/test/rubocops/patches_cop_spec.rb b/Library/Homebrew/test/rubocops/patches_cop_spec.rb index 28915a1ec9..4f9ca2df84 100644 --- a/Library/Homebrew/test/rubocops/patches_cop_spec.rb +++ b/Library/Homebrew/test/rubocops/patches_cop_spec.rb @@ -13,7 +13,7 @@ describe RuboCop::Cop::FormulaAudit::Patches do url 'http://example.com/foo-1.0.tgz' end EOS - inspect_source(cop, source) + inspect_source(source) expect(cop.offenses).to eq([]) end @@ -34,7 +34,7 @@ describe RuboCop::Cop::FormulaAudit::Patches do column: 2, source: source }] - inspect_source(cop, source) + inspect_source(source) expected_offenses.zip(cop.offenses).each do |expected, actual| expect_offense(expected, actual) @@ -61,7 +61,7 @@ describe RuboCop::Cop::FormulaAudit::Patches do end EOS - inspect_source(cop, source) + inspect_source(source) expected_offense = if patch_url =~ %r{/raw\.github\.com/} [{ message: <<-EOS.undent.chomp, GitHub/Gist patches should specify a revision: @@ -154,7 +154,7 @@ describe RuboCop::Cop::FormulaAudit::Patches do column: 26, source: source }] - inspect_source(cop, source) + inspect_source(source) expected_offenses.zip(cop.offenses).each do |expected, actual| expect_offense(expected, actual) @@ -183,7 +183,7 @@ describe RuboCop::Cop::FormulaAudit::Patches do end EOS - inspect_source(cop, source) + inspect_source(source) expected_offense = if patch_url =~ %r{/raw\.github\.com/} [{ message: <<-EOS.undent.chomp, GitHub/Gist patches should specify a revision: diff --git a/Library/Homebrew/test/rubocops/text_cop_spec.rb b/Library/Homebrew/test/rubocops/text_cop_spec.rb index ec13c40415..4908017703 100644 --- a/Library/Homebrew/test/rubocops/text_cop_spec.rb +++ b/Library/Homebrew/test/rubocops/text_cop_spec.rb @@ -24,7 +24,7 @@ describe RuboCop::Cop::FormulaAudit::Text do column: 2, source: source }] - inspect_source(cop, source) + inspect_source(source) expected_offenses.zip(cop.offenses).each do |expected, actual| expect_offense(expected, actual) @@ -48,7 +48,7 @@ describe RuboCop::Cop::FormulaAudit::Text do column: 2, source: source }] - inspect_source(cop, source) + inspect_source(source) expected_offenses.zip(cop.offenses).each do |expected, actual| expect_offense(expected, actual) @@ -73,7 +73,7 @@ describe RuboCop::Cop::FormulaAudit::Text do column: 4, source: source }] - inspect_source(cop, source) + inspect_source(source) expected_offenses.zip(cop.offenses).each do |expected, actual| expect_offense(expected, actual) @@ -98,7 +98,7 @@ describe RuboCop::Cop::FormulaAudit::Text do column: 4, source: source }] - inspect_source(cop, source) + inspect_source(source) expected_offenses.zip(cop.offenses).each do |expected, actual| expect_offense(expected, actual) @@ -123,7 +123,7 @@ describe RuboCop::Cop::FormulaAudit::Text do column: 4, source: source }] - inspect_source(cop, source) + inspect_source(source) expected_offenses.zip(cop.offenses).each do |expected, actual| expect_offense(expected, actual) @@ -148,7 +148,7 @@ describe RuboCop::Cop::FormulaAudit::Text do column: 4, source: source }] - inspect_source(cop, source) + inspect_source(source) expected_offenses.zip(cop.offenses).each do |expected, actual| expect_offense(expected, actual) @@ -173,7 +173,7 @@ describe RuboCop::Cop::FormulaAudit::Text do column: 4, source: source }] - inspect_source(cop, source) + inspect_source(source) expected_offenses.zip(cop.offenses).each do |expected, actual| expect_offense(expected, actual) @@ -210,7 +210,7 @@ describe RuboCop::Cop::FormulaAudit::Text do column: 2, source: source }] - inspect_source(cop, source) + inspect_source(source) expected_offenses.zip(cop.offenses).each do |expected, actual| expect_offense(expected, actual) @@ -237,7 +237,7 @@ describe RuboCop::Cop::FormulaAudit::Text do column: 0, source: source }] - inspect_source(cop, source) + inspect_source(source) expected_offenses.zip(cop.offenses).each do |expected, actual| expect_offense(expected, actual) @@ -267,7 +267,7 @@ describe RuboCop::Cop::FormulaAudit::Text do column: 2, source: source }] - inspect_source(cop, source) + inspect_source(source) expected_offenses.zip(cop.offenses).each do |expected, actual| expect_offense(expected, actual) @@ -292,7 +292,7 @@ describe RuboCop::Cop::FormulaAudit::Text do column: 4, source: source }] - inspect_source(cop, source) + inspect_source(source) expected_offenses.zip(cop.offenses).each do |expected, actual| expect_offense(expected, actual) diff --git a/Library/Homebrew/test/rubocops/urls_cop_spec.rb b/Library/Homebrew/test/rubocops/urls_cop_spec.rb index e51fb6be0e..ad939a1a2a 100644 --- a/Library/Homebrew/test/rubocops/urls_cop_spec.rb +++ b/Library/Homebrew/test/rubocops/urls_cop_spec.rb @@ -126,7 +126,7 @@ describe RuboCop::Cop::FormulaAudit::Urls do column: formula["col"], source: source }] - inspect_source(cop, source) + inspect_source(source) expected_offenses.zip(cop.offenses.reverse).each do |expected, actual| expect_offense(expected, actual) @@ -160,7 +160,7 @@ describe RuboCop::Cop::FormulaAudit::Urls do column: formula["col"], source: source }] - inspect_source(cop, source) + inspect_source(source) expected_offenses.zip(cop.offenses.reverse).each do |expected, actual| expect_offense(expected, actual) @@ -183,7 +183,7 @@ describe RuboCop::Cop::FormulaAudit::Urls do column: 2, source: source }] - inspect_source(cop, source) + inspect_source(source) expected_offenses.zip(cop.offenses.reverse).each do |expected, actual| expect_offense(expected, actual) @@ -222,13 +222,13 @@ describe RuboCop::Cop::FormulaAuditStrict::PyPiUrls do column: formula["col"], source: source }] - inspect_source(cop, source) + inspect_source(source) # Check for expected offenses expected_offenses.zip(cop.offenses.reverse).each do |expected, actual| expect_offense(expected, actual) end # Check for expected auto corrected source - new_source = autocorrect_source(cop, source) + new_source = autocorrect_source(source) expect(new_source).to eq(corrected_source) end end From bae08d5188808d30f48bdfc929a67709c95b0b13 Mon Sep 17 00:00:00 2001 From: Markus Reiter Date: Sun, 8 Oct 2017 00:45:18 +0200 Subject: [PATCH 288/294] =?UTF-8?q?Don=E2=80=99t=20track=20files=20in=20`t?= =?UTF-8?q?est`=20and=20`vendor`.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Library/Homebrew/.simplecov | 37 +++++++++++++++++++++---------------- 1 file changed, 21 insertions(+), 16 deletions(-) diff --git a/Library/Homebrew/.simplecov b/Library/Homebrew/.simplecov index 23e60faeb0..2d0ba3d501 100755 --- a/Library/Homebrew/.simplecov +++ b/Library/Homebrew/.simplecov @@ -11,11 +11,6 @@ SimpleCov.start do # tests to be dropped. This causes random fluctuations in test coverage. merge_timeout 86400 - add_filter "/Homebrew/compat/" - add_filter "/Homebrew/dev-cmd/tests.rb" - add_filter "/Homebrew/test/" - add_filter "/Homebrew/vendor/" - if ENV["HOMEBREW_INTEGRATION_TEST"] command_name "#{ENV["HOMEBREW_INTEGRATION_TEST"]} (#{$PROCESS_ID})" @@ -35,20 +30,30 @@ SimpleCov.start do command_name "#{command_name} (#{$PROCESS_ID})" # Not using this during integration tests makes the tests 4x times faster # without changing the coverage. - track_files "#{SimpleCov.root}/**/*.rb" + + subdirs = Dir.chdir(SimpleCov.root) { Dir.glob("*") } + .reject { |d| d.end_with?(".rb") || ["test", "vendor"].include?(d) } + .map { |d| "#{d}/**/*.rb" }.join(",") + + track_files "#{SimpleCov.root}/{#{subdirs},*.rb}" end + add_filter %r{^/compat/} + add_filter %r{^/dev-cmd/tests.rb$} + add_filter %r{^/test/} + add_filter %r{^/vendor/} + # Add groups and the proper project name to the output. project_name "Homebrew" - add_group "Cask", "/Homebrew/cask/" - add_group "Commands", %w[/Homebrew/cmd/ /Homebrew/dev-cmd/] - add_group "Extensions", "/Homebrew/extend/" - add_group "OS", %w[/Homebrew/extend/os/ /Homebrew/os/] - add_group "Requirements", "/Homebrew/requirements/" - add_group "Scripts", %w[ - /Homebrew/brew.rb - /Homebrew/build.rb - /Homebrew/postinstall.rb - /Homebrew/test.rb + add_group "Cask", %r{^/cask/} + add_group "Commands", [%r{/cmd/}, %r{^/dev-cmd/}] + add_group "Extensions", %r{^/extend/} + add_group "OS", [%r{^/extend/os/}, %r{^/os/}] + add_group "Requirements", %r{^/requirements/} + add_group "Scripts", [ + %r{^/brew.rb$}, + %r{^/build.rb$}, + %r{^/postinstall.rb$}, + %r{^/test.rb$}, ] end From 2a25825a12897b7bfa167a720f24b6df03bdca94 Mon Sep 17 00:00:00 2001 From: Dominyk Tiller Date: Sun, 8 Oct 2017 06:54:49 +0100 Subject: [PATCH 289/294] audit: tweak assert/refute_predicate audit Addresses some of the issues I raised in https://github.com/Homebrew/homebrew-core/pull/19127#issue-263566817. Would still like to work out a way to check `File.exist?`-style language inside the `test do` block exclusively but for now it's better to be too conservative on the audit than to be overly-zealous and flag too much. --- Library/Homebrew/dev-cmd/audit.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Library/Homebrew/dev-cmd/audit.rb b/Library/Homebrew/dev-cmd/audit.rb index ee5fb8df81..16ae7cba10 100644 --- a/Library/Homebrew/dev-cmd/audit.rb +++ b/Library/Homebrew/dev-cmd/audit.rb @@ -967,12 +967,12 @@ class FormulaAuditor problem "Use `assert_match` instead of `assert ...include?`" end - if line =~ /(assert File\.exist\?|File\.exist\?)/ + if line =~ /(assert File\.exist\?|assert \(.*\)\.exist\?)/ problem "Use `assert_predicate , :exist?` instead of `#{Regexp.last_match(1)}`" end - if line =~ /(assert !File\.exist\?|!File\.exist\?)/ - problem "Use `refute_predicate , :exist?` instead of `#{Regexp.last_match(1)}`" + if line =~ /assert !File\.exist\?/ + problem "Use `refute_predicate , :exist?` instead of `assert !File.exist?`" end return unless @strict From 69e2be832cbbaec7f67a77f1daae982e1ea324a4 Mon Sep 17 00:00:00 2001 From: Markus Reiter Date: Sun, 8 Oct 2017 14:14:15 +0200 Subject: [PATCH 290/294] Fix comment location. --- Library/Homebrew/.simplecov | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Library/Homebrew/.simplecov b/Library/Homebrew/.simplecov index 2d0ba3d501..e0d6d7601a 100755 --- a/Library/Homebrew/.simplecov +++ b/Library/Homebrew/.simplecov @@ -28,13 +28,13 @@ SimpleCov.start do end else command_name "#{command_name} (#{$PROCESS_ID})" - # Not using this during integration tests makes the tests 4x times faster - # without changing the coverage. subdirs = Dir.chdir(SimpleCov.root) { Dir.glob("*") } .reject { |d| d.end_with?(".rb") || ["test", "vendor"].include?(d) } .map { |d| "#{d}/**/*.rb" }.join(",") + # Not using this during integration tests makes the tests 4x times faster + # without changing the coverage. track_files "#{SimpleCov.root}/{#{subdirs},*.rb}" end From cbd9715e5b4b0f3d138cb02eb0dd41f06a0b2c85 Mon Sep 17 00:00:00 2001 From: Markus Reiter Date: Sun, 8 Oct 2017 15:20:58 +0200 Subject: [PATCH 291/294] Fix regexes in `CaskLoader`. --- Library/Homebrew/cask/lib/hbc/cask_loader.rb | 23 +++++++++++++------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/Library/Homebrew/cask/lib/hbc/cask_loader.rb b/Library/Homebrew/cask/lib/hbc/cask_loader.rb index 5660992da8..08d4576439 100644 --- a/Library/Homebrew/cask/lib/hbc/cask_loader.rb +++ b/Library/Homebrew/cask/lib/hbc/cask_loader.rb @@ -3,6 +3,18 @@ module Hbc class FromContentLoader attr_reader :content + def self.can_load?(ref) + return false unless ref.respond_to?(:to_str) + content = ref.to_str + + token = /(?:"[^"]*"|'[^']*')/ + curly = /\(\s*#{token}\s*\)\s*\{.*\}/ + do_end = /\s+#{token}\s+do(?:\s*;\s*|\s+).*end/ + regex = /\A\s*cask(?:#{curly.source}|#{do_end.source})\s*\Z/m + + content.match?(regex) + end + def initialize(content) @content = content end @@ -56,7 +68,8 @@ module Hbc class FromURILoader < FromPathLoader def self.can_load?(ref) - ref.to_s.match?(::URI::DEFAULT_PARSER.make_regexp) + uri_regex = ::URI::DEFAULT_PARSER.make_regexp + ref.to_s.match?(Regexp.new('\A' + uri_regex.source + '\Z', uri_regex.options)) end attr_reader :url @@ -156,15 +169,9 @@ module Hbc end def self.for(ref) - if ref.respond_to?(:to_str) - content = ref.to_str - if content.match?(/\A\s*cask\s+(?:"[^"]*"|'[^']*')\s+do(?:\s+.*\s+|;?\s+)end\s*\Z/) - return FromContentLoader.new(content) - end - end - [ FromInstanceLoader, + FromContentLoader, FromURILoader, FromTapLoader, FromTapPathLoader, From efbc1b0cb489ccc35110b4013145ded2abd3e03f Mon Sep 17 00:00:00 2001 From: Markus Reiter Date: Sun, 8 Oct 2017 15:48:54 +0200 Subject: [PATCH 292/294] Add specs for `CaskLoader`. --- .../cask_loader/from_content_loader_spec.rb | 57 +++++++++++++++++++ .../cask/cask_loader/from_uri_loader_spec.rb | 21 +++++++ 2 files changed, 78 insertions(+) create mode 100644 Library/Homebrew/test/cask/cask_loader/from_content_loader_spec.rb create mode 100644 Library/Homebrew/test/cask/cask_loader/from_uri_loader_spec.rb diff --git a/Library/Homebrew/test/cask/cask_loader/from_content_loader_spec.rb b/Library/Homebrew/test/cask/cask_loader/from_content_loader_spec.rb new file mode 100644 index 0000000000..e735d5eca8 --- /dev/null +++ b/Library/Homebrew/test/cask/cask_loader/from_content_loader_spec.rb @@ -0,0 +1,57 @@ +describe Hbc::CaskLoader::FromContentLoader do + alias_matcher :be_able_to_load, :be_can_load + + describe "::can_load?" do + it "returns true for Casks specified with `cask \"token\" do … end`" do + expect(described_class).to be_able_to_load <<~EOS + cask "token" do + end + EOS + end + + it "returns true for Casks specified with `cask \"token\" do; end`" do + expect(described_class).to be_able_to_load <<~EOS + cask "token" do; end + EOS + end + + it "returns true for Casks specified with `cask 'token' do … end`" do + expect(described_class).to be_able_to_load <<~EOS + cask 'token' do + end + EOS + end + + it "returns true for Casks specified with `cask 'token' do; end`" do + expect(described_class).to be_able_to_load <<~EOS + cask 'token' do; end + EOS + end + + it "returns true for Casks specified with `cask(\"token\") { … }`" do + expect(described_class).to be_able_to_load <<~EOS + cask("token") { + } + EOS + end + + it "returns true for Casks specified with `cask(\"token\") {}`" do + expect(described_class).to be_able_to_load <<~EOS + cask("token") {} + EOS + end + + it "returns true for Casks specified with `cask('token') { … }`" do + expect(described_class).to be_able_to_load <<~EOS + cask('token') { + } + EOS + end + + it "returns true for Casks specified with `cask('token') {}`" do + expect(described_class).to be_able_to_load <<~EOS + cask('token') {} + EOS + end + end +end diff --git a/Library/Homebrew/test/cask/cask_loader/from_uri_loader_spec.rb b/Library/Homebrew/test/cask/cask_loader/from_uri_loader_spec.rb new file mode 100644 index 0000000000..df2de1f828 --- /dev/null +++ b/Library/Homebrew/test/cask/cask_loader/from_uri_loader_spec.rb @@ -0,0 +1,21 @@ +describe Hbc::CaskLoader::FromURILoader do + alias_matcher :be_able_to_load, :be_can_load + + describe "::can_load?" do + it "returns true when given an URI" do + expect(described_class).to be_able_to_load(URI("http://example.com/")) + end + + it "returns true when given a String which can be parsed to a URI" do + expect(described_class).to be_able_to_load("http://example.com/") + end + + it "returns false when given a String with Cask contents containing a URL" do + expect(described_class).not_to be_able_to_load <<~EOS + cask 'token' do + url 'http://example.com/' + end + EOS + end + end +end From 175ca909ee1a5b57aa0cae2c879920511f311b14 Mon Sep 17 00:00:00 2001 From: Markus Reiter Date: Sat, 7 Oct 2017 00:31:28 +0200 Subject: [PATCH 293/294] Clean up code style and remove `.rubocop_todo.yml`. --- Library/Homebrew/.rubocop.yml | 29 ++- Library/Homebrew/.rubocop_todo.yml | 138 ------------ Library/Homebrew/brew.rb | 2 +- Library/Homebrew/build.rb | 2 +- Library/Homebrew/cmd/fetch.rb | 6 +- Library/Homebrew/cmd/install.rb | 1 + Library/Homebrew/cmd/reinstall.rb | 4 +- Library/Homebrew/cmd/style.rb | 1 + Library/Homebrew/cmd/tap.rb | 3 +- Library/Homebrew/cmd/update-report.rb | 6 +- Library/Homebrew/cmd/upgrade.rb | 1 + Library/Homebrew/cmd/uses.rb | 6 +- Library/Homebrew/debrew.rb | 6 +- Library/Homebrew/debrew/irb.rb | 3 +- Library/Homebrew/dependency.rb | 2 +- Library/Homebrew/dependency_collector.rb | 11 +- Library/Homebrew/descriptions.rb | 4 +- .../Homebrew/dev-cmd/aspell-dictionaries.rb | 5 +- Library/Homebrew/dev-cmd/audit.rb | 18 +- Library/Homebrew/dev-cmd/bottle.rb | 9 +- Library/Homebrew/dev-cmd/man.rb | 9 +- Library/Homebrew/dev-cmd/pull.rb | 4 +- Library/Homebrew/dev-cmd/test.rb | 2 +- Library/Homebrew/diagnostic.rb | 22 +- Library/Homebrew/download_strategy.rb | 18 +- Library/Homebrew/extend/ENV/super.rb | 9 +- Library/Homebrew/extend/cachable.rb | 9 + Library/Homebrew/extend/pathname.rb | 2 +- Library/Homebrew/formula.rb | 55 +++-- Library/Homebrew/formula_installer.rb | 45 ++-- Library/Homebrew/formula_versions.rb | 2 +- Library/Homebrew/formulary.rb | 9 +- Library/Homebrew/migrator.rb | 6 +- Library/Homebrew/os/mac/xcode.rb | 2 +- Library/Homebrew/patch.rb | 12 +- Library/Homebrew/postinstall.rb | 2 +- Library/Homebrew/readall.rb | 2 +- Library/Homebrew/tab.rb | 12 +- Library/Homebrew/tap.rb | 11 +- Library/Homebrew/test.rb | 2 +- .../Homebrew/test/formula_installer_spec.rb | 2 +- Library/Homebrew/utils.rb | 6 +- Library/Homebrew/utils/fork.rb | 7 +- Library/Homebrew/version.rb | 210 +++++++++--------- 44 files changed, 296 insertions(+), 421 deletions(-) delete mode 100644 Library/Homebrew/.rubocop_todo.yml create mode 100644 Library/Homebrew/extend/cachable.rb diff --git a/Library/Homebrew/.rubocop.yml b/Library/Homebrew/.rubocop.yml index 3b440c33c8..1434686432 100644 --- a/Library/Homebrew/.rubocop.yml +++ b/Library/Homebrew/.rubocop.yml @@ -1,6 +1,5 @@ inherit_from: - ../.rubocop.yml - - .rubocop_todo.yml AllCops: Include: @@ -26,9 +25,26 @@ Lint/NestedMethodDefinition: Lint/ParenthesesAsGroupedExpression: Enabled: true +Metrics/BlockNesting: + Max: 5 + +Metrics/ModuleLength: + Max: 360 + Metrics/ParameterLists: CountKeywordArgs: false +# we won't change backward compatible method names +Naming/MethodName: + Exclude: + - 'compat/**/*' + +# we won't change backward compatible predicate names +Naming/PredicateName: + Exclude: + - 'compat/**/*' + NameWhitelist: is_32_bit?, is_64_bit? + Style/BlockDelimiters: Exclude: - '**/*_spec.rb' @@ -41,14 +57,3 @@ Style/GuardClause: # hash-rockets preferred for formulae, a: 1 preferred elsewhere Style/HashSyntax: EnforcedStyle: ruby19_no_mixed_keys - -# we won't change backward compatible method names -Naming/MethodName: - Exclude: - - 'compat/**/*' - -# we won't change backward compatible predicate names -Naming/PredicateName: - Exclude: - - 'compat/**/*' - NameWhitelist: is_32_bit?, is_64_bit? diff --git a/Library/Homebrew/.rubocop_todo.yml b/Library/Homebrew/.rubocop_todo.yml deleted file mode 100644 index 96c2f3676c..0000000000 --- a/Library/Homebrew/.rubocop_todo.yml +++ /dev/null @@ -1,138 +0,0 @@ -# This configuration was generated by -# `rubocop --auto-gen-config --exclude-limit 100` -# on 2017-01-27 21:44:55 +0000 using RuboCop version 0.47.1. -# The point is for the user to remove these configuration records -# one by one as the offenses are removed from the code base. -# Note that changes in the inspected code, or installation of new -# versions of RuboCop, may require this file to be generated again. - -# Offense count: 17 -Lint/HandleExceptions: - Exclude: - - 'cmd/install.rb' - - 'cmd/reinstall.rb' - - 'cmd/tap.rb' - - 'cmd/update-report.rb' - - 'cmd/upgrade.rb' - - 'cmd/uses.rb' - - 'descriptions.rb' - - 'diagnostic.rb' - - 'extend/ENV/super.rb' - - 'extend/pathname.rb' - - 'formula.rb' - - 'formula_versions.rb' - - 'test/ENV_test.rb' - -# Offense count: 3 -Lint/IneffectiveAccessModifier: - Exclude: - - 'formula.rb' - - 'version.rb' - -# Offense count: 1 -Lint/Loop: - Exclude: - - 'patch.rb' - -# Offense count: 28 -Lint/RescueException: - Exclude: - - 'brew.rb' - - 'build.rb' - - 'cmd/fetch.rb' - - 'cmd/reinstall.rb' - - 'cmd/update-report.rb' - - 'debrew.rb' - - 'dev-cmd/pull.rb' - - 'dev-cmd/test.rb' - - 'formula.rb' - - 'formula_installer.rb' - - 'migrator.rb' - - 'postinstall.rb' - - 'readall.rb' - - 'test.rb' - - 'test/ENV_test.rb' - - 'utils/fork.rb' - -# Offense count: 1 -Lint/ShadowedException: - Exclude: - - 'utils/fork.rb' - -# Offense count: 13 -# Configuration parameters: CountBlocks. -Metrics/BlockNesting: - Max: 5 - -# Offense count: 19 -# Configuration parameters: CountComments. -Metrics/ModuleLength: - Max: 400 - -# Offense count: 1 -# Configuration parameters: CountKeywordArgs. -Metrics/ParameterLists: - Max: 6 - -# Offense count: 2 -Security/MarshalLoad: - Exclude: - - 'dependency.rb' - - 'utils/fork.rb' - -# Offense count: 1 -Naming/AccessorMethodName: - Exclude: - - 'extend/ENV/super.rb' - -# Offense count: 6 -Style/ClassVars: - Exclude: - - 'dev-cmd/audit.rb' - - 'formula_installer.rb' - - 'test/support/helper/fs_leak_logger.rb' - -# Offense count: 13 -# Cop supports --auto-correct. -# Configuration parameters: EnforcedStyle, SupportedStyles. -# SupportedStyles: compact, expanded -Style/EmptyMethod: - Exclude: - - 'debrew/irb.rb' - - 'download_strategy.rb' - - 'extend/ENV/super.rb' - - 'formula.rb' - - 'patch.rb' - -# Offense count: 13 -# Configuration parameters: AllowedVariables. -Style/GlobalVars: - Exclude: - - 'diagnostic.rb' - - 'utils.rb' - -# Offense count: 1 -# Configuration parameters: EnforcedStyle, SupportedStyles. -# SupportedStyles: module_function, extend_self -Style/ModuleFunction: - Exclude: - - 'os/mac/xcode.rb' - -# Offense count: 8 -Style/MultilineBlockChain: - Exclude: - - 'cmd/search.rb' - - 'dev-cmd/aspell-dictionaries.rb' - - 'dev-cmd/audit.rb' - - 'dev-cmd/man.rb' - - 'diagnostic.rb' - - 'test/patching_test.rb' - -# Offense count: 4 -# Cop supports --auto-correct. -Style/MutableConstant: - Exclude: - - 'dependency_collector.rb' - - 'formulary.rb' - - 'tab.rb' - - 'tap.rb' diff --git a/Library/Homebrew/brew.rb b/Library/Homebrew/brew.rb index 41955e60e0..86b40a79da 100644 --- a/Library/Homebrew/brew.rb +++ b/Library/Homebrew/brew.rb @@ -146,7 +146,7 @@ rescue MethodDeprecatedError => e $stderr.puts " #{Formatter.url(e.issues_url)}" end exit 1 -rescue Exception => e +rescue Exception => e # rubocop:disable Lint/RescueException onoe e if internal_cmd && defined?(OS::ISSUES_URL) && !ENV["HOMEBREW_NO_AUTO_UPDATE"] diff --git a/Library/Homebrew/build.rb b/Library/Homebrew/build.rb index cd2fa4c022..836b360daa 100644 --- a/Library/Homebrew/build.rb +++ b/Library/Homebrew/build.rb @@ -190,7 +190,7 @@ begin options = Options.create(ARGV.flags_only) build = Build.new(formula, options) build.install -rescue Exception => e +rescue Exception => e # rubocop:disable Lint/RescueException Marshal.dump(e, error_pipe) error_pipe.close exit! 1 diff --git a/Library/Homebrew/cmd/fetch.rb b/Library/Homebrew/cmd/fetch.rb index 006c637466..4117539927 100644 --- a/Library/Homebrew/cmd/fetch.rb +++ b/Library/Homebrew/cmd/fetch.rb @@ -49,8 +49,10 @@ module Homebrew if fetch_bottle?(f) begin fetch_formula(f.bottle) - rescue Exception => e - raise if ARGV.homebrew_developer? || e.is_a?(Interrupt) + rescue Interrupt + raise + rescue => e + raise if ARGV.homebrew_developer? fetched_bottle = false onoe e.message opoo "Bottle fetch failed: fetching the source." diff --git a/Library/Homebrew/cmd/install.rb b/Library/Homebrew/cmd/install.rb index 732e96b004..ca8f294772 100644 --- a/Library/Homebrew/cmd/install.rb +++ b/Library/Homebrew/cmd/install.rb @@ -339,6 +339,7 @@ module Homebrew rescue FormulaInstallationAlreadyAttemptedError # We already attempted to install f as part of the dependency tree of # another formula. In that case, don't generate an error, just move on. + return rescue CannotInstallFormulaError => e ofail e.message end diff --git a/Library/Homebrew/cmd/reinstall.rb b/Library/Homebrew/cmd/reinstall.rb index 94096d2dd4..6727c0b6bb 100644 --- a/Library/Homebrew/cmd/reinstall.rb +++ b/Library/Homebrew/cmd/reinstall.rb @@ -47,8 +47,8 @@ module Homebrew fi.install fi.finish rescue FormulaInstallationAlreadyAttemptedError - # next - rescue Exception + return + rescue Exception # rubocop:disable Lint/RescueException ignore_interrupts { restore_backup(keg, keg_was_linked) } raise else diff --git a/Library/Homebrew/cmd/style.rb b/Library/Homebrew/cmd/style.rb index e816db5dc6..58f430a27d 100644 --- a/Library/Homebrew/cmd/style.rb +++ b/Library/Homebrew/cmd/style.rb @@ -117,6 +117,7 @@ module Homebrew case output_type when :print + args << "--debug" if ARGV.debug? args << "--display-cop-names" if ARGV.include? "--display-cop-names" args << "--format" << "simple" if files system(cache_env, "rubocop", "_#{HOMEBREW_RUBOCOP_VERSION}_", *args) diff --git a/Library/Homebrew/cmd/tap.rb b/Library/Homebrew/cmd/tap.rb index 2a07c1b2f3..fa520e2c56 100644 --- a/Library/Homebrew/cmd/tap.rb +++ b/Library/Homebrew/cmd/tap.rb @@ -54,8 +54,7 @@ module Homebrew quiet: ARGV.quieter? rescue TapRemoteMismatchError => e odie e - rescue TapAlreadyTappedError, TapAlreadyUnshallowError - # Do nothing. + rescue TapAlreadyTappedError, TapAlreadyUnshallowError # rubocop:disable Lint/HandleExceptions end end end diff --git a/Library/Homebrew/cmd/update-report.rb b/Library/Homebrew/cmd/update-report.rb index 781ee88081..0974df0b41 100644 --- a/Library/Homebrew/cmd/update-report.rb +++ b/Library/Homebrew/cmd/update-report.rb @@ -372,7 +372,7 @@ class Reporter new_version = formula.pkg_version old_version = FormulaVersions.new(formula).formula_at_revision(@initial_revision, &:pkg_version) next if new_version == old_version - rescue Exception => e + rescue Exception => e # rubocop:disable Lint/RescueException onoe "#{e.message}\n#{e.backtrace.join "\n"}" if ARGV.homebrew_developer? end @report[:M] << tap.formula_file_to_name(src) @@ -460,7 +460,7 @@ class Reporter unless Formulary.factory(new_full_name).keg_only? system HOMEBREW_BREW_FILE, "link", new_full_name, "--overwrite" end - rescue Exception => e + rescue Exception => e # rubocop:disable Lint/RescueException onoe "#{e.message}\n#{e.backtrace.join "\n"}" if ARGV.homebrew_developer? end next @@ -521,7 +521,7 @@ class Reporter begin f = Formulary.factory(new_full_name) - rescue Exception => e + rescue Exception => e # rubocop:disable Lint/RescueException onoe "#{e.message}\n#{e.backtrace.join "\n"}" if ARGV.homebrew_developer? next end diff --git a/Library/Homebrew/cmd/upgrade.rb b/Library/Homebrew/cmd/upgrade.rb index 1cdb497cf6..f1ce3c7da4 100644 --- a/Library/Homebrew/cmd/upgrade.rb +++ b/Library/Homebrew/cmd/upgrade.rb @@ -150,6 +150,7 @@ module Homebrew rescue FormulaInstallationAlreadyAttemptedError # We already attempted to upgrade f as part of the dependency tree of # another formula. In that case, don't generate an error, just move on. + return rescue CannotInstallFormulaError => e ofail e rescue BuildError => e diff --git a/Library/Homebrew/cmd/uses.rb b/Library/Homebrew/cmd/uses.rb index 24684c3b6c..0b09e1bf19 100644 --- a/Library/Homebrew/cmd/uses.rb +++ b/Library/Homebrew/cmd/uses.rb @@ -74,12 +74,13 @@ module Homebrew end end - dep_formulae = deps.map do |dep| + dep_formulae = deps.flat_map do |dep| begin dep.to_formula rescue + [] end - end.compact + end reqs_by_formula = ([f] + dep_formulae).flat_map do |formula| formula.requirements.map { |req| [formula, req] } @@ -118,6 +119,7 @@ module Homebrew rescue FormulaUnavailableError # Silently ignore this case as we don't care about things used in # taps that aren't currently tapped. + next end end end diff --git a/Library/Homebrew/debrew.rb b/Library/Homebrew/debrew.rb index 5bc3d2daad..6206eb8a27 100644 --- a/Library/Homebrew/debrew.rb +++ b/Library/Homebrew/debrew.rb @@ -9,7 +9,7 @@ module Debrew module Raise def raise(*) super - rescue Exception => e + rescue Exception => e # rubocop:disable Lint/RescueException e.extend(Ignorable) super(e) unless Debrew.debug(e) == :ignore end @@ -92,7 +92,7 @@ module Debrew yield rescue SystemExit original_raise - rescue Exception => e + rescue Exception => e # rubocop:disable Lint/RescueException debug(e) ensure @active = false @@ -119,7 +119,7 @@ module Debrew if e.is_a?(Ignorable) menu.choice(:irb) do puts "When you exit this IRB session, execution will continue." - set_trace_func proc { |event, _, _, id, binding, klass| + set_trace_func proc { |event, _, _, id, binding, klass| # rubocop:disable Metrics/ParameterLists if klass == Raise && id == :raise && event == "return" set_trace_func(nil) synchronize { IRB.start_within(binding) } diff --git a/Library/Homebrew/debrew/irb.rb b/Library/Homebrew/debrew/irb.rb index 069dbe6760..eeb3758a98 100644 --- a/Library/Homebrew/debrew/irb.rb +++ b/Library/Homebrew/debrew/irb.rb @@ -4,8 +4,7 @@ module IRB @setup_done = false extend Module.new { - def parse_opts - end + def parse_opts; end def start_within(binding) unless @setup_done diff --git a/Library/Homebrew/dependency.rb b/Library/Homebrew/dependency.rb index 0fbc2625b1..7f0e7fbffe 100644 --- a/Library/Homebrew/dependency.rb +++ b/Library/Homebrew/dependency.rb @@ -64,7 +64,7 @@ class Dependency end def self._load(marshaled) - new(*Marshal.load(marshaled)) + new(*Marshal.load(marshaled)) # rubocop:disable Security/MarshalLoad end class << self diff --git a/Library/Homebrew/dependency_collector.rb b/Library/Homebrew/dependency_collector.rb index fff80a28cf..f855669e0a 100644 --- a/Library/Homebrew/dependency_collector.rb +++ b/Library/Homebrew/dependency_collector.rb @@ -4,6 +4,7 @@ require "ld64_dependency" require "requirement" require "requirements" require "set" +require "extend/cachable" ## A dependency is a formula that another formula needs to install. ## A requirement is something other than a formula that another formula @@ -16,17 +17,13 @@ require "set" # This class is used by `depends_on` in the formula DSL to turn dependency # specifications into the proper kinds of dependencies and requirements. class DependencyCollector + extend Cachable + # Define the languages that we can handle as external dependencies. LANGUAGE_MODULES = Set[ :lua, :lua51, :perl, :python, :python3, :ruby ].freeze - CACHE = {} - - def self.clear_cache - CACHE.clear - end - attr_reader :deps, :requirements def initialize @@ -45,7 +42,7 @@ class DependencyCollector end def fetch(spec) - CACHE.fetch(cache_key(spec)) { |key| CACHE[key] = build(spec) } + self.class.cache.fetch(cache_key(spec)) { |key| self.class.cache[key] = build(spec) } end def cache_key(spec) diff --git a/Library/Homebrew/descriptions.rb b/Library/Homebrew/descriptions.rb index ac1d68216a..bc19826731 100644 --- a/Library/Homebrew/descriptions.rb +++ b/Library/Homebrew/descriptions.rb @@ -78,10 +78,10 @@ class Descriptions formula_names.each do |name| begin - desc = Formulary.factory(name).desc + @cache[name] = Formulary.factory(name).desc rescue FormulaUnavailableError, *FormulaVersions::IGNORED_EXCEPTIONS + @cache.delete(name) end - @cache[name] = desc end save_cache if options[:save] end diff --git a/Library/Homebrew/dev-cmd/aspell-dictionaries.rb b/Library/Homebrew/dev-cmd/aspell-dictionaries.rb index 955e41b01f..ab0e66d2bf 100644 --- a/Library/Homebrew/dev-cmd/aspell-dictionaries.rb +++ b/Library/Homebrew/dev-cmd/aspell-dictionaries.rb @@ -27,13 +27,12 @@ module Homebrew end end - languages.inject([]) do |resources, (lang, path)| + languages.each do |lang, path| r = Resource.new(lang) r.owner = Formulary.factory("aspell") r.url "#{dict_url}/#{path}" r.mirror "#{dict_mirror}/#{path}" - resources << r - end.each(&:fetch).each do |r| + r.fetch puts <<-EOS option "with-lang-#{r.name}", "Install #{r.name} dictionary" resource "#{r.name}" do diff --git a/Library/Homebrew/dev-cmd/audit.rb b/Library/Homebrew/dev-cmd/audit.rb index 16ae7cba10..6afd1f8028 100644 --- a/Library/Homebrew/dev-cmd/audit.rb +++ b/Library/Homebrew/dev-cmd/audit.rb @@ -53,7 +53,7 @@ module Homebrew module_function def audit - Homebrew.inject_dump_stats!(FormulaAuditor, /^audit_/) if ARGV.switch? "D" + inject_dump_stats!(FormulaAuditor, /^audit_/) if ARGV.switch? "D" Homebrew.auditing = true formula_count = 0 @@ -387,8 +387,10 @@ class FormulaAuditor end end - # core aliases + tap alias names + tap alias full name - @@aliases ||= Formula.aliases + Formula.tap_aliases + def self.aliases + # core aliases + tap alias names + tap alias full name + @aliases ||= Formula.aliases + Formula.tap_aliases + end def audit_formula_name return unless @strict @@ -442,7 +444,7 @@ class FormulaAuditor problem "Dependency '#{dep.name}' was renamed; use new name '#{dep_f.name}'." end - if @@aliases.include?(dep.name) && + if self.class.aliases.include?(dep.name) && (dep_f.core_formula? || !dep_f.versioned_formula?) problem "Dependency '#{dep.name}' is an alias; use the canonical name '#{dep.to_formula.full_name}'." end @@ -453,16 +455,16 @@ class FormulaAuditor problem "Dependency '#{dep.name}' may be unnecessary as it is provided by macOS; try to build this formula without it." end - dep.options.reject do |opt| - next true if dep_f.option_defined?(opt) - dep_f.requirements.detect do |r| + dep.options.each do |opt| + next if dep_f.option_defined?(opt) + next if dep_f.requirements.detect do |r| if r.recommended? opt.name == "with-#{r.name}" elsif r.optional? opt.name == "without-#{r.name}" end end - end.each do |opt| + problem "Dependency #{dep} does not define option #{opt.name.inspect}" end diff --git a/Library/Homebrew/dev-cmd/bottle.rb b/Library/Homebrew/dev-cmd/bottle.rb index 8dfd0d12c6..fb862c7733 100644 --- a/Library/Homebrew/dev-cmd/bottle.rb +++ b/Library/Homebrew/dev-cmd/bottle.rb @@ -75,7 +75,7 @@ module Homebrew @put_filenames ||= [] - return if @put_filenames.include? filename + return if @put_filenames.include?(filename) puts Formatter.error(filename.to_s) @put_filenames << filename @@ -84,8 +84,7 @@ module Homebrew result = false keg.each_unique_file_matching(string) do |file| - # skip document file. - next if Metafiles::EXTENSIONS.include? file.extname + next if Metafiles::EXTENSIONS.include?(file.extname) # Skip document files. linked_libraries = Keg.file_linked_libraries(file, string) result ||= !linked_libraries.empty? @@ -156,9 +155,7 @@ module Homebrew return ofail "Formula not installed or up-to-date: #{f.full_name}" end - tap = f.tap - - unless tap + unless tap = f.tap unless ARGV.include?("--force-core-tap") return ofail "Formula not from core or any taps: #{f.full_name}" end diff --git a/Library/Homebrew/dev-cmd/man.rb b/Library/Homebrew/dev-cmd/man.rb index 472bb7c2b1..b2bb3c8c34 100644 --- a/Library/Homebrew/dev-cmd/man.rb +++ b/Library/Homebrew/dev-cmd/man.rb @@ -48,12 +48,9 @@ module Homebrew def path_glob_commands(glob) Pathname.glob(glob) .sort_by { |source_file| sort_key_for_path(source_file) } - .map do |source_file| - source_file.read.lines - .grep(/^#:/) - .map { |line| line.slice(2..-1) } - .join - end.reject { |s| s.strip.empty? || s.include?("@hide_from_man_page") } + .map(&:read).map(&:lines) + .map { |lines| lines.grep(/^#:/).map { |line| line.slice(2..-1) }.join } + .reject { |s| s.strip.empty? || s.include?("@hide_from_man_page") } end def build_man_page diff --git a/Library/Homebrew/dev-cmd/pull.rb b/Library/Homebrew/dev-cmd/pull.rb index cd0d6fbd06..8cb2703035 100644 --- a/Library/Homebrew/dev-cmd/pull.rb +++ b/Library/Homebrew/dev-cmd/pull.rb @@ -154,8 +154,8 @@ module Homebrew begin f = Formula[name] - # Make sure we catch syntax errors. - rescue Exception + rescue Exception # rubocop:disable Lint/RescueException + # Make sure we catch syntax errors. next end diff --git a/Library/Homebrew/dev-cmd/test.rb b/Library/Homebrew/dev-cmd/test.rb index ab2b0edb0a..6622a8c257 100644 --- a/Library/Homebrew/dev-cmd/test.rb +++ b/Library/Homebrew/dev-cmd/test.rb @@ -84,7 +84,7 @@ module Homebrew rescue ::Test::Unit::AssertionFailedError => e ofail "#{f.full_name}: failed" puts e.message - rescue Exception => e + rescue Exception => e # rubocop:disable Lint/RescueException ofail "#{f.full_name}: failed" puts e, e.backtrace ensure diff --git a/Library/Homebrew/diagnostic.rb b/Library/Homebrew/diagnostic.rb index 88aa4dbc90..3edf31012f 100644 --- a/Library/Homebrew/diagnostic.rb +++ b/Library/Homebrew/diagnostic.rb @@ -151,8 +151,10 @@ module Homebrew return unless File.directory?(dir) files = Dir.chdir(dir) do - Dir[pattern].select { |f| File.file?(f) && !File.symlink?(f) } - Dir.glob(white_list) - end.map { |file| File.join(dir, file) } + (Dir.glob(pattern) - Dir.glob(white_list)) + .select { |f| File.file?(f) && !File.symlink?(f) } + .map { |f| File.join(dir, f) } + end return if files.empty? inject_file_list(files, message) @@ -427,15 +429,15 @@ module Homebrew end def check_user_path_1 - $seen_prefix_bin = false - $seen_prefix_sbin = false + @seen_prefix_bin = false + @seen_prefix_sbin = false message = "" paths(ENV["HOMEBREW_PATH"]).each do |p| case p when "/usr/bin" - unless $seen_prefix_bin + unless @seen_prefix_bin # only show the doctor message if there are any conflicts # rationale: a default install should not trigger any brew doctor messages conflicts = Dir["#{HOMEBREW_PREFIX}/bin/*"] @@ -458,9 +460,9 @@ module Homebrew end end when "#{HOMEBREW_PREFIX}/bin" - $seen_prefix_bin = true + @seen_prefix_bin = true when "#{HOMEBREW_PREFIX}/sbin" - $seen_prefix_sbin = true + @seen_prefix_sbin = true end end @@ -468,7 +470,7 @@ module Homebrew end def check_user_path_2 - return if $seen_prefix_bin + return if @seen_prefix_bin <<-EOS.undent Homebrew's bin was not found in your PATH. @@ -478,7 +480,7 @@ module Homebrew end def check_user_path_3 - return if $seen_prefix_sbin + return if @seen_prefix_sbin # Don't complain about sbin not being in the path if it doesn't exist sbin = HOMEBREW_PREFIX/"sbin" @@ -952,6 +954,7 @@ module Homebrew Putting non-prefixed coreutils in your path can cause gmp builds to fail. EOS rescue FormulaUnavailableError + return end def check_for_non_prefixed_findutils @@ -966,6 +969,7 @@ module Homebrew Putting non-prefixed findutils in your path can cause python builds to fail. EOS rescue FormulaUnavailableError + return end def check_for_pydistutils_cfg_in_home diff --git a/Library/Homebrew/download_strategy.rb b/Library/Homebrew/download_strategy.rb index 7012fccc81..e69a56ddfa 100644 --- a/Library/Homebrew/download_strategy.rb +++ b/Library/Homebrew/download_strategy.rb @@ -18,8 +18,7 @@ class AbstractDownloadStrategy end # Download and cache the resource as {#cached_location}. - def fetch - end + def fetch; end # Suppress output def shutup! @@ -37,13 +36,11 @@ class AbstractDownloadStrategy # Unpack {#cached_location} into the current working directory, and possibly # chdir into the newly-unpacked directory. # Unlike {Resource#stage}, this does not take a block. - def stage - end + def stage; end # @!attribute [r] cached_location # The path to the cached file or directory associated with the resource. - def cached_location - end + def cached_location; end # @!attribute [r] # return most recent modified time for all files in the current working directory after stage. @@ -204,14 +201,11 @@ class VCSDownloadStrategy < AbstractDownloadStrategy true end - def clone_repo - end + def clone_repo; end - def update - end + def update; end - def current_revision - end + def current_revision; end def extract_ref(specs) key = REF_TYPES.find { |type| specs.key?(type) } diff --git a/Library/Homebrew/extend/ENV/super.rb b/Library/Homebrew/extend/ENV/super.rb index b518c22a1c..b4f0dfcac0 100644 --- a/Library/Homebrew/extend/ENV/super.rb +++ b/Library/Homebrew/extend/ENV/super.rb @@ -24,8 +24,7 @@ module Superenv end # @private - def self.bin - end + def self.bin; end def reset super @@ -324,11 +323,9 @@ module Superenv end end - def set_x11_env_if_installed - end + def set_x11_env_if_installed; end - def set_cpu_flags(*) - end + def set_cpu_flags(_, _ = "", _ = {}); end end require "extend/os/extend/ENV/super" diff --git a/Library/Homebrew/extend/cachable.rb b/Library/Homebrew/extend/cachable.rb new file mode 100644 index 0000000000..69d86ccb7b --- /dev/null +++ b/Library/Homebrew/extend/cachable.rb @@ -0,0 +1,9 @@ +module Cachable + def cache + @cache ||= {} + end + + def clear_cache + cache.clear + end +end diff --git a/Library/Homebrew/extend/pathname.rb b/Library/Homebrew/extend/pathname.rb index e1acd1f775..e3d6880ba6 100644 --- a/Library/Homebrew/extend/pathname.rb +++ b/Library/Homebrew/extend/pathname.rb @@ -186,7 +186,7 @@ class Pathname begin tf.chown(uid, gid) tf.chmod(old_stat.mode) - rescue Errno::EPERM + rescue Errno::EPERM # rubocop:disable Lint/HandleExceptions end File.rename(tf.path, self) diff --git a/Library/Homebrew/formula.rb b/Library/Homebrew/formula.rb index d999b9c5fe..61042aae76 100644 --- a/Library/Homebrew/formula.rb +++ b/Library/Homebrew/formula.rb @@ -1041,14 +1041,14 @@ class Formula # keg's formula is deleted. begin keg = Keg.for(path) - rescue NotAKegError, Errno::ENOENT + rescue NotAKegError, Errno::ENOENT # rubocop:disable Lint/HandleExceptions # file doesn't belong to any keg. else tab_tap = Tab.for_keg(keg).tap return false if tab_tap.nil? # this keg doesn't below to any core/tap formula, most likely coming from a DIY install. begin Formulary.factory(keg.name) - rescue FormulaUnavailableError + rescue FormulaUnavailableError # rubocop:disable Lint/HandleExceptions # formula for this keg is deleted, so defer to whitelist rescue TapFormulaAmbiguityError, TapFormulaWithOldnameAmbiguityError return false # this keg belongs to another formula @@ -1379,12 +1379,13 @@ class Formula # An array of all installed {Formula} # @private def self.installed - @installed ||= racks.map do |rack| + @installed ||= racks.flat_map do |rack| begin Formulary.from_rack(rack) rescue FormulaUnavailableError, TapFormulaAmbiguityError, TapFormulaWithOldnameAmbiguityError + [] end - end.compact.uniq(&:name) + end.uniq(&:name) end def self.installed_with_alias_path(alias_path) @@ -1642,7 +1643,7 @@ class Formula with_logging("test") do test end - rescue Exception + rescue Exception # rubocop:disable Lint/RescueException staging.retain! if ARGV.debug? raise end @@ -1667,8 +1668,7 @@ class Formula end # @private - def test - end + def test; end # @private def test_fixtures(file) @@ -1683,8 +1683,7 @@ class Formula # system "./configure", "--prefix=#{prefix}" # system "make", "install" # end - def install - end + def install; end protected @@ -1932,29 +1931,29 @@ class Formula end end - def self.method_added(method) - case method - when :brew - raise "You cannot override Formula#brew in class #{name}" - when :test - define_method(:test_defined?) { true } - when :options - instance = allocate - - specs.each do |spec| - instance.options.each do |opt, desc| - spec.option(opt[/^--(.+)$/, 1], desc) - end - end - - remove_method(:options) - end - end - # The methods below define the formula DSL. class << self include BuildEnvironment::DSL + def method_added(method) + case method + when :brew + raise "You cannot override Formula#brew in class #{name}" + when :test + define_method(:test_defined?) { true } + when :options + instance = allocate + + specs.each do |spec| + instance.options.each do |opt, desc| + spec.option(opt[/^--(.+)$/, 1], desc) + end + end + + remove_method(:options) + end + end + # The reason for why this software is not linked (by default) to # {::HOMEBREW_PREFIX}. # @private diff --git a/Library/Homebrew/formula_installer.rb b/Library/Homebrew/formula_installer.rb index 56238ad734..7cd87e7513 100644 --- a/Library/Homebrew/formula_installer.rb +++ b/Library/Homebrew/formula_installer.rb @@ -58,13 +58,14 @@ class FormulaInstaller @options = Options.new @invalid_option_names = [] @requirement_messages = [] - - @@attempted ||= Set.new - @poured_bottle = false @pour_failed = false end + def self.attempted + @attempted ||= Set.new + end + # When no build tools are available and build flags are passed through ARGV, # it's necessary to interrupt the user before any sort of installation # can proceed. Only invoked when the user has no developer tools. @@ -145,7 +146,7 @@ class FormulaInstaller end def check_install_sanity - raise FormulaInstallationAlreadyAttemptedError, formula if @@attempted.include?(formula) + raise FormulaInstallationAlreadyAttemptedError, formula if self.class.attempted.include?(formula) return if ignore_deps? @@ -287,12 +288,12 @@ class FormulaInstaller end end - @@attempted << formula + self.class.attempted << formula if pour_bottle?(warn: true) begin pour - rescue Exception => e + rescue Exception => e # rubocop:disable Lint/RescueException # any exceptions must leave us with nothing installed ignore_interrupts do formula.prefix.rmtree if formula.prefix.directory? @@ -567,7 +568,7 @@ class FormulaInstaller oh1 "Installing #{formula.full_name} dependency: #{Formatter.identifier(dep.name)}" fi.install fi.finish - rescue Exception + rescue Exception # rubocop:disable Lint/RescueException ignore_interrupts do tmp_keg.rename(installed_keg) if tmp_keg && !installed_keg.directory? linked_keg.link if keg_was_linked @@ -723,7 +724,7 @@ class FormulaInstaller if !formula.prefix.directory? || Keg.new(formula.prefix).empty_installation? raise "Empty installation" end - rescue Exception => e + rescue Exception => e # rubocop:disable Lint/RescueException e.options = display_options(formula) if e.is_a?(BuildError) ignore_interrupts do # any exceptions must leave us with nothing installed @@ -784,7 +785,7 @@ class FormulaInstaller puts " brew link #{formula.name}" @show_summary_heading = true Homebrew.failed = true - rescue Exception => e + rescue Exception => e # rubocop:disable Lint/RescueException onoe "An unexpected error occurred during the `brew link` step" puts "The formula built, but is not symlinked into #{HOMEBREW_PREFIX}" puts e @@ -815,7 +816,7 @@ class FormulaInstaller formula.plist_path.chmod 0644 log = formula.var/"log" log.mkpath if formula.plist.include? log.to_s - rescue Exception => e + rescue Exception => e # rubocop:disable Lint/RescueException onoe "Failed to install plist file" ohai e, e.backtrace if debug? Homebrew.failed = true @@ -823,7 +824,7 @@ class FormulaInstaller def fix_dynamic_linkage(keg) keg.fix_dynamic_linkage - rescue Exception => e + rescue Exception => e # rubocop:disable Lint/RescueException onoe "Failed to fix install linkage" puts "The formula built, but you may encounter issues using it or linking other" puts "formula against it." @@ -835,7 +836,7 @@ class FormulaInstaller def clean ohai "Cleaning" if verbose? Cleaner.new(formula).clean - rescue Exception => e + rescue Exception => e # rubocop:disable Lint/RescueException opoo "The cleaning step did not complete successfully" puts "Still, the installation was successful, so we will link it into your prefix" ohai e, e.backtrace if debug? @@ -845,7 +846,7 @@ class FormulaInstaller def post_install Homebrew.run_post_install(formula) - rescue Exception => e + rescue Exception => e # rubocop:disable Lint/RescueException opoo "The post-install step did not complete successfully" puts "You can try again using `brew postinstall #{formula.full_name}`" ohai e, e.backtrace if debug? @@ -905,27 +906,31 @@ class FormulaInstaller super end + def self.locked + @locked ||= [] + end + private attr_predicate :hold_locks? def lock - return unless (@@locked ||= []).empty? + return unless self.class.locked.empty? unless ignore_deps? formula.recursive_dependencies.each do |dep| - @@locked << dep.to_formula + self.class.locked << dep.to_formula end end - @@locked.unshift(formula) - @@locked.uniq! - @@locked.each(&:lock) + self.class.locked.unshift(formula) + self.class.locked.uniq! + self.class.locked.each(&:lock) @hold_locks = true end def unlock return unless hold_locks? - @@locked.each(&:unlock) - @@locked.clear + self.class.locked.each(&:unlock) + self.class.locked.clear @hold_locks = false end diff --git a/Library/Homebrew/formula_versions.rb b/Library/Homebrew/formula_versions.rb index bb68035679..c10c69e674 100644 --- a/Library/Homebrew/formula_versions.rb +++ b/Library/Homebrew/formula_versions.rb @@ -44,7 +44,7 @@ class FormulaVersions # continue walking the history ohai "#{e} in #{name} at revision #{rev}", e.backtrace if ARGV.debug? rescue FormulaUnavailableError - # Suppress this error + return ensure Homebrew.raise_deprecation_exceptions = false end diff --git a/Library/Homebrew/formulary.rb b/Library/Homebrew/formulary.rb index 0eb34ee2ab..fddeac6312 100644 --- a/Library/Homebrew/formulary.rb +++ b/Library/Homebrew/formulary.rb @@ -1,18 +1,19 @@ require "digest/md5" require "tap" +require "extend/cachable" # The Formulary is responsible for creating instances of Formula. # It is not meant to be used directly from formulae. module Formulary - FORMULAE = {} + extend Cachable def self.formula_class_defined?(path) - FORMULAE.key?(path) + cache.key?(path) end def self.formula_class_get(path) - FORMULAE.fetch(path) + cache.fetch(path) end def self.load_formula(name, path, contents, namespace) @@ -44,7 +45,7 @@ module Formulary contents = path.open("r") { |f| ensure_utf8_encoding(f).read } namespace = "FormulaNamespace#{Digest::MD5.hexdigest(path.to_s)}" klass = load_formula(name, path, contents, namespace) - FORMULAE[path] = klass + cache[path] = klass end if IO.method_defined?(:set_encoding) diff --git a/Library/Homebrew/migrator.rb b/Library/Homebrew/migrator.rb index 7ecdafe2fb..0eb7492dfd 100644 --- a/Library/Homebrew/migrator.rb +++ b/Library/Homebrew/migrator.rb @@ -100,7 +100,7 @@ class Migrator begin migrator = Migrator.new(formula) migrator.migrate - rescue Exception => e + rescue => e onoe e end end @@ -196,7 +196,7 @@ class Migrator update_tabs rescue Interrupt ignore_interrupts { backup_oldname } - rescue Exception => e + rescue Exception => e # rubocop:disable Lint/RescueException onoe "Error occurred while migrating." puts e puts e.backtrace if ARGV.debug? @@ -304,7 +304,7 @@ class Migrator puts puts "You can try again using:" puts " brew link #{formula.name}" - rescue Exception => e + rescue Exception => e # rubocop:disable Lint/RescueException onoe "An unexpected error occurred during linking" puts e puts e.backtrace if ARGV.debug? diff --git a/Library/Homebrew/os/mac/xcode.rb b/Library/Homebrew/os/mac/xcode.rb index 59e7026bdc..5071aafcf0 100644 --- a/Library/Homebrew/os/mac/xcode.rb +++ b/Library/Homebrew/os/mac/xcode.rb @@ -183,7 +183,7 @@ module OS end module CLT - extend self + module_function STANDALONE_PKG_ID = "com.apple.pkg.DeveloperToolsCLILeo".freeze FROM_XCODE_PKG_ID = "com.apple.pkg.DeveloperToolsCLI".freeze diff --git a/Library/Homebrew/patch.rb b/Library/Homebrew/patch.rb index 7045adf5e6..8a1b00930d 100644 --- a/Library/Homebrew/patch.rb +++ b/Library/Homebrew/patch.rb @@ -60,8 +60,7 @@ class EmbeddedPatch false end - def contents - end + def contents; end def apply data = contents.gsub("HOMEBREW_PREFIX", HOMEBREW_PREFIX) @@ -87,10 +86,13 @@ class DATAPatch < EmbeddedPatch def contents data = "" path.open("rb") do |f| - begin + loop do line = f.gets - end until line.nil? || line =~ /^__END__$/ - data << line while line = f.gets + break if line.nil? || line =~ /^__END__$/ + end + while line = f.gets + data << line + end end data end diff --git a/Library/Homebrew/postinstall.rb b/Library/Homebrew/postinstall.rb index 0b6d8f6b01..53a5b7e751 100644 --- a/Library/Homebrew/postinstall.rb +++ b/Library/Homebrew/postinstall.rb @@ -14,7 +14,7 @@ begin formula = ARGV.resolved_formulae.first formula.extend(Debrew::Formula) if ARGV.debug? formula.run_post_install -rescue Exception => e +rescue Exception => e # rubocop:disable Lint/RescueException Marshal.dump(e, error_pipe) error_pipe.close exit! 1 diff --git a/Library/Homebrew/readall.rb b/Library/Homebrew/readall.rb index 3595c16be4..5f4fd947c6 100644 --- a/Library/Homebrew/readall.rb +++ b/Library/Homebrew/readall.rb @@ -52,7 +52,7 @@ module Readall Formulary.factory(file) rescue Interrupt raise - rescue Exception => e + rescue Exception => e # rubocop:disable Lint/RescueException onoe "Invalid formula: #{file}" puts e failed = true diff --git a/Library/Homebrew/tab.rb b/Library/Homebrew/tab.rb index af19cabe67..aa0208d51a 100644 --- a/Library/Homebrew/tab.rb +++ b/Library/Homebrew/tab.rb @@ -3,18 +3,16 @@ require "ostruct" require "options" require "json" require "development_tools" +require "extend/cachable" # Inherit from OpenStruct to gain a generic initialization method that takes a # hash and creates an attribute for each key and value. `Tab.new` probably # should not be called directly, instead use one of the class methods like # `Tab.create`. class Tab < OpenStruct - FILENAME = "INSTALL_RECEIPT.json".freeze - CACHE = {} + extend Cachable - def self.clear_cache - CACHE.clear - end + FILENAME = "INSTALL_RECEIPT.json".freeze # Instantiates a Tab for a new installation of a formula. def self.create(formula, compiler, stdlib) @@ -57,7 +55,7 @@ class Tab < OpenStruct # Returns the Tab for an install receipt at `path`. # Results are cached. def self.from_file(path) - CACHE.fetch(path) { |p| CACHE[p] = from_file_content(File.read(p), p) } + cache.fetch(path) { |p| cache[p] = from_file_content(File.read(p), p) } end # Like Tab.from_file, but bypass the cache. @@ -343,7 +341,7 @@ class Tab < OpenStruct # will no longer be valid. Formula.clear_installed_formulae_cache unless tabfile.exist? - CACHE[tabfile] = self + self.class.cache[tabfile] = self tabfile.atomic_write(to_json) end diff --git a/Library/Homebrew/tap.rb b/Library/Homebrew/tap.rb index f4e7631b49..78dc4cf4e7 100644 --- a/Library/Homebrew/tap.rb +++ b/Library/Homebrew/tap.rb @@ -1,4 +1,5 @@ require "extend/string" +require "extend/cachable" require "readall" # a {Tap} is used to extend the formulae provided by Homebrew core. @@ -8,14 +9,10 @@ require "readall" # {#user} represents Github username and {#repo} represents repository # name without leading `homebrew-`. class Tap + extend Cachable + TAP_DIRECTORY = HOMEBREW_LIBRARY/"Taps" - CACHE = {} - - def self.clear_cache - CACHE.clear - end - def self.fetch(*args) case args.length when 1 @@ -38,7 +35,7 @@ class Tap end cache_key = "#{user}/#{repo}".downcase - CACHE.fetch(cache_key) { |key| CACHE[key] = Tap.new(user, repo) } + cache.fetch(cache_key) { |key| cache[key] = Tap.new(user, repo) } end def self.from_path(path) diff --git a/Library/Homebrew/test.rb b/Library/Homebrew/test.rb index d9ec8250ee..3d5e62a884 100644 --- a/Library/Homebrew/test.rb +++ b/Library/Homebrew/test.rb @@ -27,7 +27,7 @@ begin Timeout.timeout TEST_TIMEOUT_SECONDS do raise "test returned false" if formula.run_test == false end -rescue Exception => e +rescue Exception => e # rubocop:disable Lint/RescueException Marshal.dump(e, error_pipe) error_pipe.close exit! 1 diff --git a/Library/Homebrew/test/formula_installer_spec.rb b/Library/Homebrew/test/formula_installer_spec.rb index 7365b27589..7b729312b7 100644 --- a/Library/Homebrew/test/formula_installer_spec.rb +++ b/Library/Homebrew/test/formula_installer_spec.rb @@ -107,7 +107,7 @@ describe FormulaInstaller do end EOS - Formulary::FORMULAE.delete(dep_path) + Formulary.cache.delete(dep_path) dependency = Formulary.factory(dep_name) dependent = formula do diff --git a/Library/Homebrew/utils.rb b/Library/Homebrew/utils.rb index d293b2a6fa..237ffa74e8 100644 --- a/Library/Homebrew/utils.rb +++ b/Library/Homebrew/utils.rb @@ -229,10 +229,9 @@ module Homebrew EOS end - # Hash of Module => Set(method_names) - @injected_dump_stat_modules = {} - + # rubocop:disable Style/GlobalVars def inject_dump_stats!(the_module, pattern) + @injected_dump_stat_modules ||= {} @injected_dump_stat_modules[the_module] ||= [] injected_methods = @injected_dump_stat_modules[the_module] the_module.module_eval do @@ -260,6 +259,7 @@ module Homebrew end end end + # rubocop:enable Style/GlobalVars end def with_system_path diff --git a/Library/Homebrew/utils/fork.rb b/Library/Homebrew/utils/fork.rb index 2f2a403e2a..57ddbfae29 100644 --- a/Library/Homebrew/utils/fork.rb +++ b/Library/Homebrew/utils/fork.rb @@ -14,7 +14,7 @@ module Utils read.close write.fcntl(Fcntl::F_SETFD, Fcntl::FD_CLOEXEC) yield - rescue Exception => e + rescue Exception => e # rubocop:disable Lint/RescueException Marshal.dump(e, write) write.close exit! @@ -26,8 +26,11 @@ module Utils ignore_interrupts(:quietly) do # the child will receive the interrupt and marshal it back begin socket = server.accept_nonblock + # rubocop:disable Lint/ShadowedException + # FIXME: https://github.com/bbatsov/rubocop/issues/4843 rescue Errno::EAGAIN, Errno::EWOULDBLOCK, Errno::ECONNABORTED, Errno::EPROTO, Errno::EINTR retry unless Process.waitpid(pid, Process::WNOHANG) + # rubocop:enable Lint/ShadowedException else socket.send_io(write) socket.close @@ -36,7 +39,7 @@ module Utils data = read.read read.close Process.wait(pid) unless socket.nil? - raise Marshal.load(data) unless data.nil? || data.empty? + raise Marshal.load(data) unless data.nil? || data.empty? # rubocop:disable Security/MarshalLoad raise Interrupt if $CHILD_STATUS.exitstatus == 130 raise "Forked child process failed: #{$CHILD_STATUS}" unless $CHILD_STATUS.success? end diff --git a/Library/Homebrew/version.rb b/Library/Homebrew/version.rb index 3ac7480371..d43e0c6657 100644 --- a/Library/Homebrew/version.rb +++ b/Library/Homebrew/version.rb @@ -213,110 +213,6 @@ class Version end end - def initialize(val) - unless val.respond_to?(:to_str) - raise TypeError, "Version value must be a string; got a #{val.class} (#{val})" - end - @version = val.to_str - end - - def detected_from_url? - false - end - - def head? - false - end - - def null? - false - end - - def <=>(other) - # Needed to retain API compatibility with older string comparisons - # for compiler versions, etc. - other = Version.new(other) if other.is_a? String - # Used by the *_build_version comparisons, which formerly returned Fixnum - other = Version.new(other.to_s) if other.is_a? Integer - return 1 if other.nil? - - return unless other.is_a?(Version) - return 0 if version == other.version - return 1 if head? && !other.head? - return -1 if !head? && other.head? - return 0 if head? && other.head? - - ltokens = tokens - rtokens = other.tokens - max = max(ltokens.length, rtokens.length) - l = r = 0 - - while l < max - a = ltokens[l] || NULL_TOKEN - b = rtokens[r] || NULL_TOKEN - - if a == b - l += 1 - r += 1 - next - elsif a.numeric? && b.numeric? - return a <=> b - elsif a.numeric? - return 1 if a > NULL_TOKEN - l += 1 - elsif b.numeric? - return -1 if b > NULL_TOKEN - r += 1 - else - return a <=> b - end - end - - 0 - end - alias eql? == - - def hash - version.hash - end - - def to_f - version.to_f - end - - def to_s - version.dup - end - alias to_str to_s - - protected - - attr_reader :version - - def tokens - @tokens ||= tokenize - end - - private - - def max(a, b) - (a > b) ? a : b - end - - def tokenize - version.scan(SCAN_PATTERN).map! do |token| - case token - when /\A#{AlphaToken::PATTERN}\z/o then AlphaToken - when /\A#{BetaToken::PATTERN}\z/o then BetaToken - when /\A#{RCToken::PATTERN}\z/o then RCToken - when /\A#{PreToken::PATTERN}\z/o then PreToken - when /\A#{PatchToken::PATTERN}\z/o then PatchToken - when /\A#{NumericToken::PATTERN}\z/o then NumericToken - when /\A#{StringToken::PATTERN}\z/o then StringToken - end.new(token) - end - end - def self.parse(spec) version = _parse(spec) version.nil? ? NULL : new(version) @@ -461,6 +357,112 @@ class Version m = /[-.vV]?((?:\d+\.)+\d+(?:[-_.]?(?i:alpha|beta|pre|rc)\.?\d{,2})?)/.match(spec_s) return m.captures.first unless m.nil? end + + private_class_method :_parse + + def initialize(val) + unless val.respond_to?(:to_str) + raise TypeError, "Version value must be a string; got a #{val.class} (#{val})" + end + @version = val.to_str + end + + def detected_from_url? + false + end + + def head? + false + end + + def null? + false + end + + def <=>(other) + # Needed to retain API compatibility with older string comparisons + # for compiler versions, etc. + other = Version.new(other) if other.is_a? String + # Used by the *_build_version comparisons, which formerly returned Fixnum + other = Version.new(other.to_s) if other.is_a? Integer + return 1 if other.nil? + + return unless other.is_a?(Version) + return 0 if version == other.version + return 1 if head? && !other.head? + return -1 if !head? && other.head? + return 0 if head? && other.head? + + ltokens = tokens + rtokens = other.tokens + max = max(ltokens.length, rtokens.length) + l = r = 0 + + while l < max + a = ltokens[l] || NULL_TOKEN + b = rtokens[r] || NULL_TOKEN + + if a == b + l += 1 + r += 1 + next + elsif a.numeric? && b.numeric? + return a <=> b + elsif a.numeric? + return 1 if a > NULL_TOKEN + l += 1 + elsif b.numeric? + return -1 if b > NULL_TOKEN + r += 1 + else + return a <=> b + end + end + + 0 + end + alias eql? == + + def hash + version.hash + end + + def to_f + version.to_f + end + + def to_s + version.dup + end + alias to_str to_s + + protected + + attr_reader :version + + def tokens + @tokens ||= tokenize + end + + private + + def max(a, b) + (a > b) ? a : b + end + + def tokenize + version.scan(SCAN_PATTERN).map! do |token| + case token + when /\A#{AlphaToken::PATTERN}\z/o then AlphaToken + when /\A#{BetaToken::PATTERN}\z/o then BetaToken + when /\A#{RCToken::PATTERN}\z/o then RCToken + when /\A#{PreToken::PATTERN}\z/o then PreToken + when /\A#{PatchToken::PATTERN}\z/o then PatchToken + when /\A#{NumericToken::PATTERN}\z/o then NumericToken + when /\A#{StringToken::PATTERN}\z/o then StringToken + end.new(token) + end + end end class HeadVersion < Version From 53dd0e3f28655f9e0ba93139cd832408542b6f12 Mon Sep 17 00:00:00 2001 From: Shaun Jackman Date: Fri, 6 Oct 2017 11:39:43 -0700 Subject: [PATCH 294/294] audit: Silence not notable on non-Homebrew taps Silence "GitHub repository not notable" on non-Homebrew taps. --- Library/Homebrew/dev-cmd/audit.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Library/Homebrew/dev-cmd/audit.rb b/Library/Homebrew/dev-cmd/audit.rb index 16ae7cba10..ff71616912 100644 --- a/Library/Homebrew/dev-cmd/audit.rb +++ b/Library/Homebrew/dev-cmd/audit.rb @@ -590,7 +590,8 @@ class FormulaAuditor return if metadata.nil? problem "GitHub fork (not canonical repository)" if metadata["fork"] - if (metadata["forks_count"] < 20) && (metadata["subscribers_count"] < 20) && + if formula&.tap&.core_tap? && + (metadata["forks_count"] < 20) && (metadata["subscribers_count"] < 20) && (metadata["stargazers_count"] < 50) problem "GitHub repository not notable enough (<20 forks, <20 watchers and <50 stars)" end