language
stringclasses
1 value
owner
stringlengths
2
15
repo
stringlengths
2
21
sha
stringlengths
45
45
message
stringlengths
7
36.3k
path
stringlengths
1
199
patch
stringlengths
15
102k
is_multipart
bool
2 classes
Other
Homebrew
brew
3db65e7ee53039c63e6b570d9881896ee51c5569.json
move tests to own specs file
Library/Homebrew/test/rubocops/lines/generate_completions_spec.rb
@@ -0,0 +1,78 @@ +# typed: false +# frozen_string_literal: true + +require "rubocops/lines" + +describe RuboCop::Cop::FormulaAudit do + describe RuboCop::Cop::FormulaAudit::GenerateCompletionsDSL do + subject(:cop) { described_class.new } + + it "reports an offense when writing to a shell completions file directly" do + expect_offense(<<~RUBY, "/homebrew-core/Formula/foo.rb") + class Foo < Formula + name "foo" + + def install + (bash_completion/"foo").write Utils.safe_popen_read(bin/"foo", "completions", "bash") + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Use `generate_completions_from_executable(bin/"foo", "completions", shells: [:bash])` instead of `(bash_completion/"foo").write Utils.safe_popen_read(bin/"foo", "completions", "bash")`. + end + end + RUBY + + expect_correction(<<~RUBY) + class Foo < Formula + name "foo" + + def install + generate_completions_from_executable(bin/"foo", "completions", shells: [:bash]) + end + end + RUBY + end + + it "reports an offense when writing to a completions file indirectly" do + expect_offense(<<~RUBY) + class Foo < Formula + name "foo" + + def install + output = Utils.safe_popen_read(bin/"foo", "completions", "bash") + (bash_completion/"foo").write output + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Use `generate_completions_from_executable` DSL instead of `(bash_completion/"foo").write output`. + end + end + RUBY + end + end + + describe RuboCop::Cop::FormulaAudit::SingleGenerateCompletionsDSLCall do + subject(:cop) { described_class.new } + + it "reports an offense when using multiple #generate_completions_from_executable calls for different shells" do + expect_offense(<<~RUBY) + class Foo < Formula + name "foo" + + def install + generate_completions_from_executable(bin/"foo", "completions", shells: [:bash]) + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Use a single `generate_completions_from_executable` call combining all specified shells. + generate_completions_from_executable(bin/"foo", "completions", shells: [:zsh]) + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Use a single `generate_completions_from_executable` call combining all specified shells. + generate_completions_from_executable(bin/"foo", "completions", shells: [:fish]) + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Use `generate_completions_from_executable(bin/"foo", "completions")` instead of `generate_completions_from_executable(bin/"foo", "completions", shells: [:fish])`. + end + end + RUBY + + expect_correction(<<~RUBY) + class Foo < Formula + name "foo" + + def install + generate_completions_from_executable(bin/"foo", "completions") + end + end + RUBY + end + end +end
true
Other
Homebrew
brew
3db65e7ee53039c63e6b570d9881896ee51c5569.json
move tests to own specs file
Library/Homebrew/test/rubocops/lines_spec.rb
@@ -3,130 +3,56 @@ require "rubocops/lines" -describe RuboCop::Cop::FormulaAudit do - describe RuboCop::Cop::FormulaAudit::Lines do - subject(:cop) { described_class.new } +describe RuboCop::Cop::FormulaAudit::Lines do + subject(:cop) { described_class.new } - context "when auditing deprecated special dependencies" do - it "reports an offense when using depends_on :automake" do - expect_offense(<<~RUBY) - class Foo < Formula - url 'https://brew.sh/foo-1.0.tgz' - depends_on :automake - ^^^^^^^^^^^^^^^^^^^^ :automake is deprecated. Usage should be \"automake\". - end - RUBY - end - - it "reports an offense when using depends_on :autoconf" do - expect_offense(<<~RUBY) - class Foo < Formula - url 'https://brew.sh/foo-1.0.tgz' - depends_on :autoconf - ^^^^^^^^^^^^^^^^^^^^ :autoconf is deprecated. Usage should be \"autoconf\". - end - RUBY - end - - it "reports an offense when using depends_on :libtool" do - expect_offense(<<~RUBY) - class Foo < Formula - url 'https://brew.sh/foo-1.0.tgz' - depends_on :libtool - ^^^^^^^^^^^^^^^^^^^ :libtool is deprecated. Usage should be \"libtool\". - end - RUBY - end - - it "reports an offense when using depends_on :apr" do - expect_offense(<<~RUBY) - class Foo < Formula - url 'https://brew.sh/foo-1.0.tgz' - depends_on :apr - ^^^^^^^^^^^^^^^ :apr is deprecated. Usage should be \"apr-util\". - end - RUBY - end - - it "reports an offense when using depends_on :tex" do - expect_offense(<<~RUBY) - class Foo < Formula - url 'https://brew.sh/foo-1.0.tgz' - depends_on :tex - ^^^^^^^^^^^^^^^ :tex is deprecated. - end - RUBY - end - end - end - - describe RuboCop::Cop::FormulaAudit::GenerateCompletionsDSL do - subject(:cop) { described_class.new } - - it "reports an offense when writing to a shell completions file directly" do - expect_offense(<<~RUBY, "/homebrew-core/Formula/foo.rb") + context "when auditing deprecated special dependencies" do + it "reports an offense when using depends_on :automake" do + expect_offense(<<~RUBY) class Foo < Formula - name "foo" - - def install - (bash_completion/"foo").write Utils.safe_popen_read(bin/"foo", "completions", "bash") - ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Use `generate_completions_from_executable(bin/"foo", "completions", shells: [:bash])` instead of `(bash_completion/"foo").write Utils.safe_popen_read(bin/"foo", "completions", "bash")`. - end + url 'https://brew.sh/foo-1.0.tgz' + depends_on :automake + ^^^^^^^^^^^^^^^^^^^^ :automake is deprecated. Usage should be \"automake\". end RUBY + end - expect_correction(<<~RUBY) + it "reports an offense when using depends_on :autoconf" do + expect_offense(<<~RUBY) class Foo < Formula - name "foo" - - def install - generate_completions_from_executable(bin/"foo", "completions", shells: [:bash]) - end + url 'https://brew.sh/foo-1.0.tgz' + depends_on :autoconf + ^^^^^^^^^^^^^^^^^^^^ :autoconf is deprecated. Usage should be \"autoconf\". end RUBY end - it "reports an offense when writing to a completions file indirectly" do + it "reports an offense when using depends_on :libtool" do expect_offense(<<~RUBY) class Foo < Formula - name "foo" - - def install - output = Utils.safe_popen_read(bin/"foo", "completions", "bash") - (bash_completion/"foo").write output - ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Use `generate_completions_from_executable` DSL instead of `(bash_completion/"foo").write output`. - end + url 'https://brew.sh/foo-1.0.tgz' + depends_on :libtool + ^^^^^^^^^^^^^^^^^^^ :libtool is deprecated. Usage should be \"libtool\". end RUBY end - end - describe RuboCop::Cop::FormulaAudit::SingleGenerateCompletionsDSLCall do - subject(:cop) { described_class.new } - - it "reports an offense when using multiple #generate_completions_from_executable calls for different shells" do + it "reports an offense when using depends_on :apr" do expect_offense(<<~RUBY) class Foo < Formula - name "foo" - - def install - generate_completions_from_executable(bin/"foo", "completions", shells: [:bash]) - ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Use a single `generate_completions_from_executable` call combining all specified shells. - generate_completions_from_executable(bin/"foo", "completions", shells: [:zsh]) - ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Use a single `generate_completions_from_executable` call combining all specified shells. - generate_completions_from_executable(bin/"foo", "completions", shells: [:fish]) - ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Use `generate_completions_from_executable(bin/"foo", "completions")` instead of `generate_completions_from_executable(bin/"foo", "completions", shells: [:fish])`. - end + url 'https://brew.sh/foo-1.0.tgz' + depends_on :apr + ^^^^^^^^^^^^^^^ :apr is deprecated. Usage should be \"apr-util\". end RUBY + end - expect_correction(<<~RUBY) + it "reports an offense when using depends_on :tex" do + expect_offense(<<~RUBY) class Foo < Formula - name "foo" - - def install - generate_completions_from_executable(bin/"foo", "completions") - end + url 'https://brew.sh/foo-1.0.tgz' + depends_on :tex + ^^^^^^^^^^^^^^^ :tex is deprecated. end RUBY end
true
Other
Homebrew
brew
5b3f5dcbf2c0a10239b530db354da1cd9f6480bb.json
fix whitespace removal, fix string concatenation
Library/Homebrew/rubocops/lines.rb
@@ -519,10 +519,10 @@ def audit_formula(_node, _class_node, _parent_class_node, body_node) T.must(offenses[0...-1]).each do |node| offending_node(node) - problem "Use a single `generate_completions_from_executable` call - combining all specified shells" do |corrector| - # adjust range by +1 to also include & remove trailing \n - corrector.replace(@offensive_node.source_range.adjust(end_pos: 1), "") + problem "Use a single `generate_completions_from_executable` " \ + "call combining all specified shells." do |corrector| + # adjust range by -4 and +1 to also include & remove leading spaces and trailing \n + corrector.replace(@offensive_node.source_range.adjust(begin_pos: -4, end_pos: 1), "") end end
false
Other
Homebrew
brew
ab09d15703e897a77f4af9177a92c275973bd0a3.json
remove newlines left behind after correction
Library/Homebrew/rubocops/lines.rb
@@ -519,7 +519,8 @@ def audit_formula(_node, _class_node, _parent_class_node, body_node) offending_node(node) problem "Use a single `generate_completions_from_executable` call combining all specified shells" do |corrector| - corrector.replace(@offensive_node.source_range, "") + # adjust range by +1 to also include & remove trailing \n + corrector.replace(@offensive_node.source_range.adjust(end_pos: 1), "") end end
false
Other
Homebrew
brew
de7ef64f6150806957161fd4b28e6486fd866a88.json
use #inspect instead of wrapping symbols
Library/Homebrew/rubocops/lines.rb
@@ -435,9 +435,9 @@ def audit_formula(_node, _class_node, _parent_class_node, body_node) shell_parameter_format = if shell_parameter_stripped.empty? nil elsif shell_parameter_stripped == "--" - ":flag" + :flag elsif shell_parameter_stripped == "--shell=" - ":arg" + :arg else "\"#{shell_parameter_stripped}\"" end @@ -449,7 +449,7 @@ def audit_formula(_node, _class_node, _parent_class_node, body_node) replacement_args << "executable: #{executable}" end replacement_args << "cmd: \"#{cmd}\"" unless cmd == "completion" - replacement_args << "shell_parameter_format: #{shell_parameter_format}" unless shell_parameter_format.nil? + replacement_args << "shell_parameter_format: #{shell_parameter_format.inspect}" unless shell_parameter_format.nil? offending_node(node) replacement = "generate_completions_from_executable(#{replacement_args.join(", ")})"
false
Other
Homebrew
brew
06518ec6132d4191daed18ee4352d5746af6573b.json
add RuboCop to combine multiple calls
Library/Homebrew/rubocops/lines.rb
@@ -492,6 +492,56 @@ def audit_formula(_node, _class_node, _parent_class_node, body_node) EOS end + # This cop makes sure that the `generate_completions_from_executable` DSL is used with only + # a single, combined call for all shells. + # + # @api private + class SingleGenerateCompletionsDSLCall < FormulaCop + extend AutoCorrector + + def audit_formula(_node, _class_node, _parent_class_node, body_node) + install = find_method_def(body_node, :install) + + methods = find_every_method_call_by_name(install, :generate_completions_from_executable) + return if methods.length <= 1 + + offenses = [] + shells = [] + methods.each do |method| + next unless method.source.include?("shells:") + + shells << method.source.match(/shells: \[(:bash|:zsh|:fish)\]/).captures.first + offenses << method + end + + return if offenses.blank? + + offenses[0...-1].each do |node| + offending_node(node) + problem "Use a single `generate_completions_from_executable` call + combining all specified shells" do |corrector| + corrector.replace(@offensive_node.source_range, "") + end + end + + offending_node(offenses.last) + replacement = if (shells - %w[:bash :zsh :fish]).empty? + @offensive_node.source.sub(/shells: \[(:bash|:zsh|:fish)\]/, "") + .gsub(",,", ",") + .sub(", )", ")") + .sub("(, ", "(") + .sub("()", "") + else + @offensive_node.source.sub(/shells: \[(:bash|:zsh|:fish)\]/, + "shells: [#{shells.join(", ")}]") + end + + problem "Use `#{replacement}` instead of `#{@offensive_node.source}`." do |corrector| + corrector.replace(@offensive_node.source_range, replacement) + end + end + end + # This cop checks for other miscellaneous style violations. # # @api private
false
Other
Homebrew
brew
911aa6ab186c5c871b89f22a75ef67178021a79f.json
resource: determine version before freezing
Library/Homebrew/resource.rb
@@ -239,13 +239,13 @@ def url(val = nil, **specs) @download_strategy = DownloadStrategyDetector.detect(url, using) @specs.merge!(specs) @downloader = nil + @version = detect_version(@version) end def version(val = nil) - @version ||= begin - version = detect_version(val) - version.null? ? nil : version - end + return @version if val.nil? + + @version = detect_version(val) end def mirror(val) @@ -266,15 +266,15 @@ def stage_resource(prefix, debug_symbols: false, &block) private def detect_version(val) - return Version::NULL if val.nil? && url.nil? - - case val - when nil then Version.detect(url, **specs) + version = case val + when nil then url.nil? ? Version::NULL : Version.detect(url, **specs) when String then Version.create(val) when Version then val else raise TypeError, "version '#{val.inspect}' should be a string" end + + version.null? ? nil : version end # A resource containing a Go package.
false
Other
Homebrew
brew
675e80e9aedb104c9a1814d8c1450d8debb3147b.json
formula_auditor: use symbols for spec iteration
Library/Homebrew/formula_auditor.rb
@@ -482,13 +482,10 @@ def audit_homepage return unless DevelopmentTools.curl_handles_most_https_certificates? - use_homebrew_curl = false - %w[Stable HEAD].each do |name| - spec_name = name.downcase.to_sym - next unless (spec = formula.send(spec_name)) + use_homebrew_curl = [:stable, :head].any? do |spec_name| + next false unless (spec = formula.send(spec_name)) - use_homebrew_curl = spec.using == :homebrew_curl - break if use_homebrew_curl + spec.using == :homebrew_curl end if (http_content_problem = curl_check_http_content(homepage,
false
Other
Homebrew
brew
15280ba1073afc13f239b9606de8f9623e8bc0a3.json
test: avoid improper, late usage of formula DSL
Library/Homebrew/test/build_environment_spec.rb
@@ -30,11 +30,16 @@ end describe BuildEnvironment::DSL do - subject(:build_environment_dsl) { double.extend(described_class) } + let(:build_environment_dsl) do + klass = described_class + Class.new do + extend(klass) + end + end context "with a single argument" do - before do - build_environment_dsl.instance_eval do + subject do + Class.new(build_environment_dsl) do env :std end end
true
Other
Homebrew
brew
15280ba1073afc13f239b9606de8f9623e8bc0a3.json
test: avoid improper, late usage of formula DSL
Library/Homebrew/test/cleaner_spec.rb
@@ -7,15 +7,15 @@ describe Cleaner do include FileUtils - subject(:cleaner) { described_class.new(f) } + describe "#clean" do + subject(:cleaner) { described_class.new(f) } - let(:f) { formula("cleaner_test") { url "foo-1.0" } } + let(:f) { formula("cleaner_test") { url "foo-1.0" } } - before do - f.prefix.mkpath - end + before do + f.prefix.mkpath + end - describe "#clean" do it "cleans files" do f.bin.mkpath f.lib.mkpath @@ -159,98 +159,110 @@ end describe "::skip_clean" do + def stub_formula_skip_clean(skip_paths) + formula("cleaner_test") do + url "foo-1.0" + + skip_clean skip_paths + end + end + it "adds paths that should be skipped" do - f.class.skip_clean "bin" + f = stub_formula_skip_clean("bin") f.bin.mkpath - cleaner.clean + described_class.new(f).clean expect(f.bin).to be_a_directory end it "also skips empty sub-directories under the added paths" do - f.class.skip_clean "bin" + f = stub_formula_skip_clean("bin") subdir = f.bin/"subdir" subdir.mkpath - cleaner.clean + described_class.new(f).clean expect(f.bin).to be_a_directory expect(subdir).to be_a_directory end it "allows skipping broken symlinks" do - f.class.skip_clean "symlink" + f = stub_formula_skip_clean("symlink") + f.prefix.mkpath symlink = f.prefix/"symlink" ln_s "target", symlink - cleaner.clean + described_class.new(f).clean expect(symlink).to be_a_symlink end it "allows skipping symlinks pointing to an empty directory" do - f.class.skip_clean "c" + f = stub_formula_skip_clean("c") dir = f.prefix/"b" symlink = f.prefix/"c" dir.mkpath ln_s dir.basename, symlink - cleaner.clean + described_class.new(f).clean expect(dir).not_to exist expect(symlink).to be_a_symlink expect(symlink).not_to exist end it "allows skipping symlinks whose target was pruned before" do - f.class.skip_clean "a" + f = stub_formula_skip_clean("a") dir = f.prefix/"b" symlink = f.prefix/"a" dir.mkpath ln_s dir.basename, symlink - cleaner.clean + described_class.new(f).clean expect(dir).not_to exist expect(symlink).to be_a_symlink expect(symlink).not_to exist end it "allows skipping '.la' files" do + f = stub_formula_skip_clean(:la) + file = f.lib/"foo.la" - f.class.skip_clean :la f.lib.mkpath touch file - cleaner.clean + described_class.new(f).clean expect(file).to exist end it "allows skipping sub-directories" do + f = stub_formula_skip_clean("lib/subdir") + dir = f.lib/"subdir" - f.class.skip_clean "lib/subdir" dir.mkpath - cleaner.clean + described_class.new(f).clean expect(dir).to be_a_directory end it "allows skipping paths relative to prefix" do + f = stub_formula_skip_clean("bin/a") + dir1 = f.bin/"a" dir2 = f.lib/"bin/a" - f.class.skip_clean "bin/a" dir1.mkpath dir2.mkpath - cleaner.clean + described_class.new(f).clean expect(dir1).to exist expect(dir2).not_to exist
true
Other
Homebrew
brew
15280ba1073afc13f239b9606de8f9623e8bc0a3.json
test: avoid improper, late usage of formula DSL
Library/Homebrew/test/formula_spec.rb
@@ -832,15 +832,15 @@ specify "service complicated" do f = formula do url "https://brew.sh/test-1.0.tbz" - end - f.class.service do - run [opt_bin/"beanstalkd"] - run_type :immediate - error_log_path var/"log/beanstalkd.error.log" - log_path var/"log/beanstalkd.log" - working_dir var - keep_alive true + service do + run [opt_bin/"beanstalkd"] + run_type :immediate + error_log_path var/"log/beanstalkd.error.log" + log_path var/"log/beanstalkd.log" + working_dir var + keep_alive true + end end expect(f.service).not_to be_nil end
true
Other
Homebrew
brew
15280ba1073afc13f239b9606de8f9623e8bc0a3.json
test: avoid improper, late usage of formula DSL
Library/Homebrew/test/livecheck/livecheck_spec.rb
@@ -98,11 +98,15 @@ describe "::livecheck_url_to_string" do let(:f_livecheck_url) do + homepage_url_s = homepage_url + stable_url_s = stable_url + head_url_s = head_url + formula("test_livecheck_url") do desc "Test Livecheck URL formula" - homepage "https://brew.sh" - url "https://brew.sh/test-0.0.1.tgz" - head "https://github.com/Homebrew/brew.git" + homepage homepage_url_s + url stable_url_s + head head_url_s end end @@ -120,25 +124,15 @@ end it "returns a URL string when given a livecheck_url string" do - f_livecheck_url.livecheck.url(livecheck_url) expect(livecheck.livecheck_url_to_string(livecheck_url, f_livecheck_url)).to eq(livecheck_url) end it "returns a URL symbol when given a valid livecheck_url symbol" do - f_livecheck_url.livecheck.url(:head) - expect(livecheck.livecheck_url_to_string(head_url, f_livecheck_url)).to eq(head_url) - - f_livecheck_url.livecheck.url(:homepage) - expect(livecheck.livecheck_url_to_string(homepage_url, f_livecheck_url)).to eq(homepage_url) - - c_livecheck_url.livecheck.url(:homepage) - expect(livecheck.livecheck_url_to_string(homepage_url, c_livecheck_url)).to eq(homepage_url) - - f_livecheck_url.livecheck.url(:stable) - expect(livecheck.livecheck_url_to_string(stable_url, f_livecheck_url)).to eq(stable_url) - - c_livecheck_url.livecheck.url(:url) - expect(livecheck.livecheck_url_to_string(cask_url, c_livecheck_url)).to eq(cask_url) + expect(livecheck.livecheck_url_to_string(:head, f_livecheck_url)).to eq(head_url) + expect(livecheck.livecheck_url_to_string(:homepage, f_livecheck_url)).to eq(homepage_url) + expect(livecheck.livecheck_url_to_string(:homepage, c_livecheck_url)).to eq(homepage_url) + expect(livecheck.livecheck_url_to_string(:stable, f_livecheck_url)).to eq(stable_url) + expect(livecheck.livecheck_url_to_string(:url, c_livecheck_url)).to eq(cask_url) end it "returns nil when not given a string or valid symbol" do
true
Other
Homebrew
brew
15280ba1073afc13f239b9606de8f9623e8bc0a3.json
test: avoid improper, late usage of formula DSL
Library/Homebrew/test/service_spec.rb
@@ -5,26 +5,28 @@ require "service" describe Homebrew::Service do - let(:klass) do - Class.new(Formula) do + let(:name) { "formula_name" } + + def stub_formula(&block) + formula(name) do url "https://brew.sh/test-1.0.tbz" + + instance_eval(&block) if block end end - let(:name) { "formula_name" } - let(:path) { Formulary.core_path(name) } - let(:spec) { :stable } - let(:f) { klass.new(name, path, spec) } describe "#std_service_path_env" do it "returns valid std_service_path_env" do - f.class.service do - run opt_bin/"beanstalkd" - run_type :immediate - environment_variables PATH: std_service_path_env - error_log_path var/"log/beanstalkd.error.log" - log_path var/"log/beanstalkd.log" - working_dir var - keep_alive true + f = stub_formula do + service do + run opt_bin/"beanstalkd" + run_type :immediate + environment_variables PATH: std_service_path_env + error_log_path var/"log/beanstalkd.error.log" + log_path var/"log/beanstalkd.log" + working_dir var + keep_alive true + end end path = f.service.std_service_path_env @@ -34,9 +36,11 @@ describe "#process_type" do it "throws for unexpected type" do - f.class.service do - run opt_bin/"beanstalkd" - process_type :cow + f = stub_formula do + service do + run opt_bin/"beanstalkd" + process_type :cow + end end expect { @@ -47,9 +51,11 @@ describe "#keep_alive" do it "throws for unexpected keys" do - f.class.service do - run opt_bin/"beanstalkd" - keep_alive test: "key" + f = stub_formula do + service do + run opt_bin/"beanstalkd" + keep_alive test: "key" + end end expect { @@ -60,9 +66,11 @@ describe "#run_type" do it "throws for unexpected type" do - f.class.service do - run opt_bin/"beanstalkd" - run_type :cow + f = stub_formula do + service do + run opt_bin/"beanstalkd" + run_type :cow + end end expect { @@ -73,9 +81,11 @@ describe "#sockets" do it "throws for missing type" do - f.class.service do - run opt_bin/"beanstalkd" - sockets "127.0.0.1:80" + f = stub_formula do + service do + run opt_bin/"beanstalkd" + sockets "127.0.0.1:80" + end end expect { @@ -84,9 +94,11 @@ end it "throws for missing host" do - f.class.service do - run opt_bin/"beanstalkd" - sockets "tcp://:80" + f = stub_formula do + service do + run opt_bin/"beanstalkd" + sockets "tcp://:80" + end end expect { @@ -95,9 +107,11 @@ end it "throws for missing port" do - f.class.service do - run opt_bin/"beanstalkd" - sockets "tcp://127.0.0.1" + f = stub_formula do + service do + run opt_bin/"beanstalkd" + sockets "tcp://127.0.0.1" + end end expect { @@ -108,29 +122,33 @@ describe "#manual_command" do it "returns valid manual_command" do - f.class.service do - run "#{HOMEBREW_PREFIX}/bin/beanstalkd" - run_type :immediate - environment_variables PATH: std_service_path_env, ETC_DIR: etc/"beanstalkd" - error_log_path var/"log/beanstalkd.error.log" - log_path var/"log/beanstalkd.log" - working_dir var - keep_alive true + f = stub_formula do + service do + run "#{HOMEBREW_PREFIX}/bin/beanstalkd" + run_type :immediate + environment_variables PATH: std_service_path_env, ETC_DIR: etc/"beanstalkd" + error_log_path var/"log/beanstalkd.error.log" + log_path var/"log/beanstalkd.log" + working_dir var + keep_alive true + end end path = f.service.manual_command expect(path).to eq("ETC_DIR=\"#{HOMEBREW_PREFIX}/etc/beanstalkd\" #{HOMEBREW_PREFIX}/bin/beanstalkd") end it "returns valid manual_command without variables" do - f.class.service do - run opt_bin/"beanstalkd" - run_type :immediate - environment_variables PATH: std_service_path_env - error_log_path var/"log/beanstalkd.error.log" - log_path var/"log/beanstalkd.log" - working_dir var - keep_alive true + f = stub_formula do + service do + run opt_bin/"beanstalkd" + run_type :immediate + environment_variables PATH: std_service_path_env + error_log_path var/"log/beanstalkd.error.log" + log_path var/"log/beanstalkd.log" + working_dir var + keep_alive true + end end path = f.service.manual_command @@ -140,21 +158,23 @@ describe "#to_plist" do it "returns valid plist" do - f.class.service do - run [opt_bin/"beanstalkd", "test"] - run_type :immediate - environment_variables PATH: std_service_path_env, FOO: "BAR", ETC_DIR: etc/"beanstalkd" - error_log_path var/"log/beanstalkd.error.log" - log_path var/"log/beanstalkd.log" - input_path var/"in/beanstalkd" - root_dir var - working_dir var - keep_alive true - launch_only_once true - process_type :interactive - restart_delay 30 - interval 5 - macos_legacy_timers true + f = stub_formula do + service do + run [opt_bin/"beanstalkd", "test"] + run_type :immediate + environment_variables PATH: std_service_path_env, FOO: "BAR", ETC_DIR: etc/"beanstalkd" + error_log_path var/"log/beanstalkd.error.log" + log_path var/"log/beanstalkd.log" + input_path var/"in/beanstalkd" + root_dir var + working_dir var + keep_alive true + launch_only_once true + process_type :interactive + restart_delay 30 + interval 5 + macos_legacy_timers true + end end plist = f.service.to_plist @@ -216,9 +236,11 @@ end it "returns valid plist with socket" do - f.class.service do - run [opt_bin/"beanstalkd", "test"] - sockets "tcp://127.0.0.1:80" + f = stub_formula do + service do + run [opt_bin/"beanstalkd", "test"] + sockets "tcp://127.0.0.1:80" + end end plist = f.service.to_plist @@ -265,9 +287,11 @@ end it "returns valid partial plist" do - f.class.service do - run opt_bin/"beanstalkd" - run_type :immediate + f = stub_formula do + service do + run opt_bin/"beanstalkd" + run_type :immediate + end end plist = f.service.to_plist @@ -299,10 +323,12 @@ end it "returns valid interval plist" do - f.class.service do - run opt_bin/"beanstalkd" - run_type :interval - interval 5 + f = stub_formula do + service do + run opt_bin/"beanstalkd" + run_type :interval + interval 5 + end end plist = f.service.to_plist @@ -336,10 +362,12 @@ end it "returns valid cron plist" do - f.class.service do - run opt_bin/"beanstalkd" - run_type :cron - cron "@daily" + f = stub_formula do + service do + run opt_bin/"beanstalkd" + run_type :cron + cron "@daily" + end end plist = f.service.to_plist @@ -378,9 +406,11 @@ end it "returns valid keepalive-exit plist" do - f.class.service do - run opt_bin/"beanstalkd" - keep_alive successful_exit: false + f = stub_formula do + service do + run opt_bin/"beanstalkd" + keep_alive successful_exit: false + end end plist = f.service.to_plist @@ -417,9 +447,11 @@ end it "returns valid keepalive-crashed plist" do - f.class.service do - run opt_bin/"beanstalkd" - keep_alive crashed: true + f = stub_formula do + service do + run opt_bin/"beanstalkd" + keep_alive crashed: true + end end plist = f.service.to_plist @@ -456,9 +488,11 @@ end it "returns valid keepalive-path plist" do - f.class.service do - run opt_bin/"beanstalkd" - keep_alive path: opt_pkgshare/"test-path" + f = stub_formula do + service do + run opt_bin/"beanstalkd" + keep_alive path: opt_pkgshare/"test-path" + end end plist = f.service.to_plist @@ -497,19 +531,21 @@ describe "#to_systemd_unit" do it "returns valid unit" do - f.class.service do - run [opt_bin/"beanstalkd", "test"] - run_type :immediate - environment_variables PATH: std_service_path_env, FOO: "BAR" - error_log_path var/"log/beanstalkd.error.log" - log_path var/"log/beanstalkd.log" - input_path var/"in/beanstalkd" - root_dir var - working_dir var - keep_alive true - process_type :interactive - restart_delay 30 - macos_legacy_timers true + f = stub_formula do + service do + run [opt_bin/"beanstalkd", "test"] + run_type :immediate + environment_variables PATH: std_service_path_env, FOO: "BAR" + error_log_path var/"log/beanstalkd.error.log" + log_path var/"log/beanstalkd.log" + input_path var/"in/beanstalkd" + root_dir var + working_dir var + keep_alive true + process_type :interactive + restart_delay 30 + macos_legacy_timers true + end end unit = f.service.to_systemd_unit @@ -538,10 +574,12 @@ end it "returns valid partial oneshot unit" do - f.class.service do - run opt_bin/"beanstalkd" - run_type :immediate - launch_only_once true + f = stub_formula do + service do + run opt_bin/"beanstalkd" + run_type :immediate + launch_only_once true + end end unit = f.service.to_systemd_unit @@ -562,10 +600,12 @@ describe "#to_systemd_timer" do it "returns valid timer" do - f.class.service do - run [opt_bin/"beanstalkd", "test"] - run_type :interval - interval 5 + f = stub_formula do + service do + run [opt_bin/"beanstalkd", "test"] + run_type :interval + interval 5 + end end unit = f.service.to_systemd_timer @@ -584,9 +624,11 @@ end it "returns valid partial timer" do - f.class.service do - run opt_bin/"beanstalkd" - run_type :immediate + f = stub_formula do + service do + run opt_bin/"beanstalkd" + run_type :immediate + end end unit = f.service.to_systemd_timer @@ -604,10 +646,12 @@ end it "throws on incomplete cron" do - f.class.service do - run opt_bin/"beanstalkd" - run_type :cron - cron "1 2 3 4" + f = stub_formula do + service do + run opt_bin/"beanstalkd" + run_type :cron + cron "1 2 3 4" + end end expect { @@ -627,10 +671,12 @@ } styles.each do |cron, calendar| - f.class.service do - run opt_bin/"beanstalkd" - run_type :cron - cron cron.to_s + f = stub_formula do + service do + run opt_bin/"beanstalkd" + run_type :cron + cron cron.to_s + end end unit = f.service.to_systemd_timer @@ -653,18 +699,22 @@ describe "#timed?" do it "returns false for immediate" do - f.class.service do - run [opt_bin/"beanstalkd", "test"] - run_type :immediate + f = stub_formula do + service do + run [opt_bin/"beanstalkd", "test"] + run_type :immediate + end end expect(f.service.timed?).to be(false) end it "returns true for interval" do - f.class.service do - run [opt_bin/"beanstalkd", "test"] - run_type :interval + f = stub_formula do + service do + run [opt_bin/"beanstalkd", "test"] + run_type :interval + end end expect(f.service.timed?).to be(true) @@ -673,35 +723,43 @@ describe "#keep_alive?" do it "returns true when keep_alive set to hash" do - f.class.service do - run [opt_bin/"beanstalkd", "test"] - keep_alive crashed: true + f = stub_formula do + service do + run [opt_bin/"beanstalkd", "test"] + keep_alive crashed: true + end end expect(f.service.keep_alive?).to be(true) end it "returns true when keep_alive set to true" do - f.class.service do - run [opt_bin/"beanstalkd", "test"] - keep_alive true + f = stub_formula do + service do + run [opt_bin/"beanstalkd", "test"] + keep_alive true + end end expect(f.service.keep_alive?).to be(true) end it "returns false when keep_alive not set" do - f.class.service do - run [opt_bin/"beanstalkd", "test"] + f = stub_formula do + service do + run [opt_bin/"beanstalkd", "test"] + end end expect(f.service.keep_alive?).to be(false) end it "returns false when keep_alive set to false" do - f.class.service do - run [opt_bin/"beanstalkd", "test"] - keep_alive false + f = stub_formula do + service do + run [opt_bin/"beanstalkd", "test"] + keep_alive false + end end expect(f.service.keep_alive?).to be(false) @@ -710,9 +768,11 @@ describe "#command" do it "returns @run data" do - f.class.service do - run [opt_bin/"beanstalkd", "test"] - run_type :immediate + f = stub_formula do + service do + run [opt_bin/"beanstalkd", "test"] + run_type :immediate + end end command = f.service.command
true
Other
Homebrew
brew
15280ba1073afc13f239b9606de8f9623e8bc0a3.json
test: avoid improper, late usage of formula DSL
Library/Homebrew/test/support/fixtures/failball.rb
@@ -4,13 +4,22 @@ class Failball < Formula def initialize(name = "failball", path = Pathname.new(__FILE__).expand_path, spec = :stable, alias_path: nil, force_bottle: false) - self.class.instance_eval do - stable.url "file://#{TEST_FIXTURE_DIR}/tarballs/testball-0.1.tbz" - stable.sha256 TESTBALL_SHA256 - end super end + DSL_PROC = proc do + url "file://#{TEST_FIXTURE_DIR}/tarballs/testball-0.1.tbz" + sha256 TESTBALL_SHA256 + end.freeze + private_constant :DSL_PROC + + DSL_PROC.call + + def self.inherited(other) + super + other.instance_eval(&DSL_PROC) + end + def install prefix.install "bin" prefix.install "libexec"
true
Other
Homebrew
brew
15280ba1073afc13f239b9606de8f9623e8bc0a3.json
test: avoid improper, late usage of formula DSL
Library/Homebrew/test/support/fixtures/testball.rb
@@ -4,13 +4,22 @@ class Testball < Formula def initialize(name = "testball", path = Pathname.new(__FILE__).expand_path, spec = :stable, alias_path: nil, force_bottle: false) - self.class.instance_eval do - stable.url "file://#{TEST_FIXTURE_DIR}/tarballs/testball-0.1.tbz" - stable.sha256 TESTBALL_SHA256 - end super end + DSL_PROC = proc do + url "file://#{TEST_FIXTURE_DIR}/tarballs/testball-0.1.tbz" + sha256 TESTBALL_SHA256 + end.freeze + private_constant :DSL_PROC + + DSL_PROC.call + + def self.inherited(other) + super + other.instance_eval(&DSL_PROC) + end + def install prefix.install "bin" prefix.install "libexec"
true
Other
Homebrew
brew
15280ba1073afc13f239b9606de8f9623e8bc0a3.json
test: avoid improper, late usage of formula DSL
Library/Homebrew/test/support/fixtures/testball_bottle.rb
@@ -4,16 +4,27 @@ class TestballBottle < Formula def initialize(name = "testball_bottle", path = Pathname.new(__FILE__).expand_path, spec = :stable, alias_path: nil, force_bottle: false) - self.class.instance_eval do - stable.url "file://#{TEST_FIXTURE_DIR}/tarballs/testball-0.1.tbz" - stable.sha256 TESTBALL_SHA256 - stable.bottle do - root_url "file://#{TEST_FIXTURE_DIR}/bottles" - sha256 cellar: :any_skip_relocation, Utils::Bottles.tag.to_sym => "8f9aecd233463da6a4ea55f5f88fc5841718c013f3e2a7941350d6130f1dc149" - end - cxxstdlib_check :skip + super + end + + DSL_PROC = proc do + url "file://#{TEST_FIXTURE_DIR}/tarballs/testball-0.1.tbz" + sha256 TESTBALL_SHA256 + + bottle do + root_url "file://#{TEST_FIXTURE_DIR}/bottles" + sha256 cellar: :any_skip_relocation, Utils::Bottles.tag.to_sym => "8f9aecd233463da6a4ea55f5f88fc5841718c013f3e2a7941350d6130f1dc149" end + + cxxstdlib_check :skip + end.freeze + private_constant :DSL_PROC + + DSL_PROC.call + + def self.inherited(other) super + other.instance_eval(&DSL_PROC) end def install
true
Other
Homebrew
brew
15280ba1073afc13f239b9606de8f9623e8bc0a3.json
test: avoid improper, late usage of formula DSL
Library/Homebrew/test/support/fixtures/testball_bottle_cellar.rb
@@ -4,17 +4,27 @@ class TestballBottleCellar < Formula def initialize(name = "testball_bottle", path = Pathname.new(__FILE__).expand_path, spec = :stable, alias_path: nil, force_bottle: false) - self.class.instance_eval do - stable.url "file://#{TEST_FIXTURE_DIR}/tarballs/testball-0.1.tbz" - stable.sha256 TESTBALL_SHA256 - hexdigest = "8f9aecd233463da6a4ea55f5f88fc5841718c013f3e2a7941350d6130f1dc149" - stable.bottle do - root_url "file://#{TEST_FIXTURE_DIR}/bottles" - sha256 cellar: :any_skip_relocation, Utils::Bottles.tag.to_sym => hexdigest - end - cxxstdlib_check :skip + super + end + + DSL_PROC = proc do + url "file://#{TEST_FIXTURE_DIR}/tarballs/testball-0.1.tbz" + sha256 TESTBALL_SHA256 + + bottle do + root_url "file://#{TEST_FIXTURE_DIR}/bottles" + sha256 cellar: :any_skip_relocation, Utils::Bottles.tag.to_sym => "8f9aecd233463da6a4ea55f5f88fc5841718c013f3e2a7941350d6130f1dc149" end + + cxxstdlib_check :skip + end.freeze + private_constant :DSL_PROC + + DSL_PROC.call + + def self.inherited(other) super + other.instance_eval(&DSL_PROC) end def install
true
Other
Homebrew
brew
76199ddd72900cecc0d9b23c10b5606e1cbbc547.json
utils: prefer BBEdit over TextWrangler
Library/Homebrew/utils.rb
@@ -364,8 +364,8 @@ def which_editor editor = Homebrew::EnvConfig.editor return editor if editor - # Find Atom, Sublime Text, VS Code, Textmate, BBEdit / TextWrangler, or vim - editor = %w[atom subl code mate edit vim].find do |candidate| + # Find Atom, Sublime Text, VS Code, Textmate, BBEdit, or vim + editor = %w[atom subl code mate bbedit vim].find do |candidate| candidate if which(candidate, ORIGINAL_PATHS) end editor ||= "vim"
false
Other
Homebrew
brew
88a8def34cf617f20ef84c6191a9dbfc7b8790d6.json
formula: add signature for bottle DSL
Library/Homebrew/formula.rb
@@ -2695,6 +2695,7 @@ def stage(interactive: false, debug_symbols: false) # The methods below define the formula DSL. class << self extend Predicable + extend T::Sig include BuildEnvironment::DSL include OnSystem::MacOSAndLinux @@ -2903,8 +2904,9 @@ def sha256(val) # # Formulae which should not be bottled should be tagged with: # <pre>bottle :disable, "reasons"</pre> - def bottle(*args, &block) - stable.bottle(*args, &block) + sig { params(block: T.proc.bind(BottleSpecification).void).void } + def bottle(&block) + stable.bottle(&block) end # @private
false
Other
Homebrew
brew
1c5ba1f6859418f5b0e0b6a0047db00f15f105ab.json
formula: require instances to use a subclass
Library/Homebrew/formula.rb
@@ -181,6 +181,9 @@ class Formula # @private def initialize(name, path, spec, alias_path: nil, force_bottle: false) + # Only allow instances of subclasses. The base class does not hold any spec information (URLs etc). + raise "Do not call `Formula.new' directly without a subclass." unless self.class < Formula + @name = name @path = path @alias_path = alias_path
false
Other
Homebrew
brew
93647e5c987f89f27502b79af4aedda8c917c6e3.json
requirement: require instances to use a subclass
Library/Homebrew/requirement.rb
@@ -20,6 +20,10 @@ class Requirement attr_reader :tags, :name, :cask, :download def initialize(tags = []) + # Only allow instances of subclasses. This base class enforces no constraints on its own. + # Individual subclasses use the `satisfy` DSL to define those constraints. + raise "Do not call `Requirement.new' directly without a subclass." unless self.class < Requirement + @cask = self.class.cask @download = self.class.download tags.each do |tag|
true
Other
Homebrew
brew
93647e5c987f89f27502b79af4aedda8c917c6e3.json
requirement: require instances to use a subclass
Library/Homebrew/test/requirement_spec.rb
@@ -12,7 +12,7 @@ let(:klass) { Class.new(described_class) } describe "#tags" do - subject { described_class.new(tags) } + subject { klass.new(tags) } context "with a single tag" do let(:tags) { ["bar"] } @@ -149,7 +149,7 @@ describe "#build?" do context "when the :build tag is specified" do - subject { described_class.new([:build]) } + subject { klass.new([:build]) } it { is_expected.to be_a_build_requirement } end @@ -186,46 +186,46 @@ end describe "#eql? and #==" do - subject(:requirement) { described_class.new } + subject(:requirement) { klass.new } it "returns true if the names and tags are equal" do - other = described_class.new + other = klass.new expect(requirement).to eql(other) expect(requirement).to eq(other) end it "returns false if names differ" do - other = described_class.new + other = klass.new allow(other).to receive(:name).and_return("foo") expect(requirement).not_to eql(other) expect(requirement).not_to eq(other) end it "returns false if tags differ" do - other = described_class.new([:optional]) + other = klass.new([:optional]) expect(requirement).not_to eql(other) expect(requirement).not_to eq(other) end end describe "#hash" do - subject(:requirement) { described_class.new } + subject(:requirement) { klass.new } it "is equal if names and tags are equal" do - other = described_class.new + other = klass.new expect(requirement.hash).to eq(other.hash) end it "differs if names differ" do - other = described_class.new + other = klass.new allow(other).to receive(:name).and_return("foo") expect(requirement.hash).not_to eq(other.hash) end it "differs if tags differ" do - other = described_class.new([:optional]) + other = klass.new([:optional]) expect(requirement.hash).not_to eq(other.hash) end end
true
Other
Homebrew
brew
93647e5c987f89f27502b79af4aedda8c917c6e3.json
requirement: require instances to use a subclass
Library/Homebrew/test/requirements_spec.rb
@@ -12,7 +12,8 @@ end it "merges duplicate requirements" do - requirements << Requirement.new << Requirement.new + klass = Class.new(Requirement) + requirements << klass.new << klass.new expect(requirements.count).to eq(1) end end
true
Other
Homebrew
brew
f12442cce676bf88fca8dc56c2bd430171c346c6.json
requirement: improve name detection of anonymous subclasses
Library/Homebrew/requirement.rb
@@ -141,9 +141,9 @@ def mktemp(&block) private def infer_name - klass = self.class.name || self.class.to_s - klass = klass.sub(/(Dependency|Requirement)$/, "") - .sub(/^(\w+::)*/, "") + klass = self.class.name + klass = klass&.sub(/(Dependency|Requirement)$/, "") + &.sub(/^(\w+::)*/, "") return klass.downcase if klass.present? return @cask if @cask.present?
false
Other
Homebrew
brew
fd432aa1db286360dab2361714e1e39406531ae0.json
cmd/deps: improve switch names. The previous `-n` and `--1` made both the code and the help harder to read and follow. Co-authored-by: Eric Knibbe <enk3@outlook.com> Co-Authored-By: Carlo Cabrera <30379873+carlocab@users.noreply.github.com>
Library/Homebrew/cmd/deps.rb
@@ -22,10 +22,10 @@ def deps_args may be appended to the command. When given multiple formula arguments, show the intersection of dependencies for each formula. EOS - switch "-n", + switch "-n", "--topological", description: "Sort dependencies in topological order." - switch "--1", - description: "Only show dependencies one level down, instead of recursing." + switch "-1", "--direct", "--declared", "--1", + description: "Show only the direct dependencies declared in the formula." switch "--union", description: "Show the union of dependencies for multiple <formula>, instead of the intersection." switch "--full-name", @@ -81,7 +81,7 @@ def deps Formulary.enable_factory_cache! - recursive = !args.send(:"1?") + recursive = !args.direct? installed = args.installed? || dependents(args.named.to_formulae_and_casks).all?(&:any_version_installed?) @use_runtime_dependencies = installed && recursive && @@ -149,7 +149,7 @@ def deps condense_requirements(all_deps, args: args) all_deps.map! { |d| dep_display_name(d, args: args) } all_deps.uniq! - all_deps.sort! unless args.n? + all_deps.sort! unless args.topological? puts all_deps end
true
Other
Homebrew
brew
fd432aa1db286360dab2361714e1e39406531ae0.json
cmd/deps: improve switch names. The previous `-n` and `--1` made both the code and the help harder to read and follow. Co-authored-by: Eric Knibbe <enk3@outlook.com> Co-Authored-By: Carlo Cabrera <30379873+carlocab@users.noreply.github.com>
completions/bash/brew
@@ -728,11 +728,11 @@ _brew_deps() { case "${cur}" in -*) __brewcomp " - --1 --all --annotate --cask --debug + --direct --dot --for-each --formula @@ -746,10 +746,10 @@ _brew_deps() { --installed --quiet --skip-recommended + --topological --tree --union --verbose - -n " return ;;
true
Other
Homebrew
brew
fd432aa1db286360dab2361714e1e39406531ae0.json
cmd/deps: improve switch names. The previous `-n` and `--1` made both the code and the help harder to read and follow. Co-authored-by: Eric Knibbe <enk3@outlook.com> Co-Authored-By: Carlo Cabrera <30379873+carlocab@users.noreply.github.com>
completions/fish/brew.fish
@@ -565,11 +565,11 @@ __fish_brew_complete_arg 'create' -l verbose -d 'Make some output more verbose' __fish_brew_complete_cmd 'deps' 'Show dependencies for formula' -__fish_brew_complete_arg 'deps' -l 1 -d 'Only show dependencies one level down, instead of recursing' __fish_brew_complete_arg 'deps' -l all -d 'List dependencies for all available formulae' __fish_brew_complete_arg 'deps' -l annotate -d 'Mark any build, test, optional, or recommended dependencies as such in the output' __fish_brew_complete_arg 'deps' -l cask -d 'Treat all named arguments as casks' __fish_brew_complete_arg 'deps' -l debug -d 'Display any debugging information' +__fish_brew_complete_arg 'deps' -l direct -d 'Show only the direct dependencies declared in the formula' __fish_brew_complete_arg 'deps' -l dot -d 'Show text-based graph description in DOT format' __fish_brew_complete_arg 'deps' -l for-each -d 'Switch into the mode used by the `--all` option, but only list dependencies for each provided formula, one formula per line. This is used for debugging the `--installed`/`--all` display mode' __fish_brew_complete_arg 'deps' -l formula -d 'Treat all named arguments as formulae' @@ -583,10 +583,10 @@ __fish_brew_complete_arg 'deps' -l include-test -d 'Include `:test` dependencies __fish_brew_complete_arg 'deps' -l installed -d 'List dependencies for formulae that are currently installed. If formula is specified, list only its dependencies that are currently installed' __fish_brew_complete_arg 'deps' -l quiet -d 'Make some output more quiet' __fish_brew_complete_arg 'deps' -l skip-recommended -d 'Skip `:recommended` dependencies for formula' +__fish_brew_complete_arg 'deps' -l topological -d 'Sort dependencies in topological order' __fish_brew_complete_arg 'deps' -l tree -d 'Show dependencies as a tree. When given multiple formula arguments, show individual trees for each formula' __fish_brew_complete_arg 'deps' -l union -d 'Show the union of dependencies for multiple formula, instead of the intersection' __fish_brew_complete_arg 'deps' -l verbose -d 'Make some output more verbose' -__fish_brew_complete_arg 'deps' -l n -d 'Sort dependencies in topological order' __fish_brew_complete_arg 'deps; and not __fish_seen_argument -l cask -l casks' -a '(__fish_brew_suggest_formulae_all)' __fish_brew_complete_arg 'deps; and not __fish_seen_argument -l formula -l formulae' -a '(__fish_brew_suggest_casks_all)'
true
Other
Homebrew
brew
fd432aa1db286360dab2361714e1e39406531ae0.json
cmd/deps: improve switch names. The previous `-n` and `--1` made both the code and the help harder to read and follow. Co-authored-by: Eric Knibbe <enk3@outlook.com> Co-Authored-By: Carlo Cabrera <30379873+carlocab@users.noreply.github.com>
completions/zsh/_brew
@@ -695,10 +695,10 @@ _brew_create() { # brew deps _brew_deps() { _arguments \ - '--1[Only show dependencies one level down, instead of recursing]' \ '(--installed)--all[List dependencies for all available formulae]' \ '--annotate[Mark any build, test, optional, or recommended dependencies as such in the output]' \ '--debug[Display any debugging information]' \ + '--direct[Show only the direct dependencies declared in the formula]' \ '--dot[Show text-based graph description in DOT format]' \ '--for-each[Switch into the mode used by the `--all` option, but only list dependencies for each provided formula, one formula per line. This is used for debugging the `--installed`/`--all` display mode]' \ '--full-name[List dependencies by their full name]' \ @@ -711,10 +711,10 @@ _brew_deps() { '(--all)--installed[List dependencies for formulae that are currently installed. If formula is specified, list only its dependencies that are currently installed]' \ '--quiet[Make some output more quiet]' \ '--skip-recommended[Skip `:recommended` dependencies for formula]' \ + '--topological[Sort dependencies in topological order]' \ '(--graph)--tree[Show dependencies as a tree. When given multiple formula arguments, show individual trees for each formula]' \ '--union[Show the union of dependencies for multiple formula, instead of the intersection]' \ '--verbose[Make some output more verbose]' \ - '-n[Sort dependencies in topological order]' \ - formula \ '(--cask)--formula[Treat all named arguments as formulae]' \ '*::formula:__brew_formulae' \
true
Other
Homebrew
brew
fd432aa1db286360dab2361714e1e39406531ae0.json
cmd/deps: improve switch names. The previous `-n` and `--1` made both the code and the help harder to read and follow. Co-authored-by: Eric Knibbe <enk3@outlook.com> Co-Authored-By: Carlo Cabrera <30379873+carlocab@users.noreply.github.com>
docs/Manpage.md
@@ -140,10 +140,10 @@ Show dependencies for *`formula`*. Additional options specific to *`formula`* may be appended to the command. When given multiple formula arguments, show the intersection of dependencies for each formula. -* `-n`: +* `-n`, `--topological`: Sort dependencies in topological order. -* `--1`: - Only show dependencies one level down, instead of recursing. +* `-1`, `--direct`: + Show only the direct dependencies declared in the formula. * `--union`: Show the union of dependencies for multiple *`formula`*, instead of the intersection. * `--full-name`:
true
Other
Homebrew
brew
fd432aa1db286360dab2361714e1e39406531ae0.json
cmd/deps: improve switch names. The previous `-n` and `--1` made both the code and the help harder to read and follow. Co-authored-by: Eric Knibbe <enk3@outlook.com> Co-Authored-By: Carlo Cabrera <30379873+carlocab@users.noreply.github.com>
manpages/brew.1
@@ -154,12 +154,12 @@ Show Homebrew and system configuration info useful for debugging\. If you file a Show dependencies for \fIformula\fR\. Additional options specific to \fIformula\fR may be appended to the command\. When given multiple formula arguments, show the intersection of dependencies for each formula\. . .TP -\fB\-n\fR +\fB\-n\fR, \fB\-\-topological\fR Sort dependencies in topological order\. . .TP -\fB\-\-1\fR -Only show dependencies one level down, instead of recursing\. +\fB\-1\fR, \fB\-\-direct\fR +Show only the direct dependencies declared in the formula\. . .TP \fB\-\-union\fR
true
Other
Homebrew
brew
10304ef5696268b81b043335fc0b171f5ecc4f77.json
util/ruby.sh: fix HOMEBREW_USE_RUBY_FROM_PATH to use user's PATH
Library/Homebrew/utils/ruby.sh
@@ -13,30 +13,54 @@ test_ruby() { "${HOMEBREW_REQUIRED_RUBY_VERSION}" 2>/dev/null } +can_use_ruby_from_path() { + if [[ -n "${HOMEBREW_DEVELOPER}" && -n "${HOMEBREW_USE_RUBY_FROM_PATH}" ]] + then + return 0 + fi + + return 1 +} + +find_first_valid_ruby() { + local ruby_exec + while IFS= read -r ruby_exec + do + if test_ruby "${ruby_exec}" + then + echo "${ruby_exec}" + break + fi + done +} + # HOMEBREW_MACOS is set by brew.sh # HOMEBREW_PATH is set by global.rb # shellcheck disable=SC2154 find_ruby() { - if [[ -n "${HOMEBREW_MACOS}" && -z "${HOMEBREW_USE_RUBY_FROM_PATH}" ]] + if [[ -n "${HOMEBREW_MACOS}" ]] && ! can_use_ruby_from_path then echo "/System/Library/Frameworks/Ruby.framework/Versions/Current/usr/bin/ruby" else - local ruby_exec - while read -r ruby_exec - do - if test_ruby "${ruby_exec}" - then - echo "${ruby_exec}" - break - fi - done < <( + local valid_ruby + + # Prioritise rubies from the filtered path (/usr/bin etc) unless explicitly overridden. + if ! can_use_ruby_from_path + then # function which() is set by brew.sh # it is aliased to `type -P` # shellcheck disable=SC2230 - which -a ruby + valid_ruby=$(find_first_valid_ruby < <(which -a ruby)) + fi + + if [[ -z "${valid_ruby}" ]] + then + # Same as above # shellcheck disable=SC2230 - PATH="${HOMEBREW_PATH}" which -a ruby - ) + valid_ruby=$(find_first_valid_ruby < <(PATH="${HOMEBREW_PATH}" which -a ruby)) + fi + + echo "${valid_ruby}" fi } @@ -47,10 +71,10 @@ need_vendored_ruby() { if [[ -n "${HOMEBREW_FORCE_VENDOR_RUBY}" ]] then return 0 - elif [[ -n "${HOMEBREW_MACOS_SYSTEM_RUBY_NEW_ENOUGH}" && -z "${HOMEBREW_USE_RUBY_FROM_PATH}" ]] + elif [[ -n "${HOMEBREW_MACOS_SYSTEM_RUBY_NEW_ENOUGH}" ]] && ! can_use_ruby_from_path then return 1 - elif [[ -z "${HOMEBREW_MACOS}" || -n "${HOMEBREW_USE_RUBY_FROM_PATH}" ]] && test_ruby "${HOMEBREW_RUBY_PATH}" + elif ([[ -z "${HOMEBREW_MACOS}" ]] || can_use_ruby_from_path) && test_ruby "${HOMEBREW_RUBY_PATH}" then return 1 else
false
Other
Homebrew
brew
d6368806e88b1e3a94c355bb9c1fbe2d65236708.json
os/linux/dependency_collector: install gcc if glibc is too old. gcc is required for libgcc_s.so.1 if glibc or gcc are too old.
Library/Homebrew/extend/os/linux/dependency_collector.rb
@@ -12,7 +12,8 @@ class DependencyCollector sig { params(related_formula_names: T::Set[String]).returns(T.nilable(Dependency)) } def gcc_dep_if_needed(related_formula_names) - return unless DevelopmentTools.system_gcc_too_old? + # gcc is required for libgcc_s.so.1 if glibc or gcc are too old + return unless DevelopmentTools.build_system_too_old? return if building_global_dep_tree? return if related_formula_names.include?(GCC) return if global_dep_tree[GCC]&.intersect?(related_formula_names)
false
Other
Homebrew
brew
c6428d9def384358a48eee9fa87e0273e7662b69.json
Add tests for `cleanup_python_site_packages`.
Library/Homebrew/test/cleanup_spec.rb
@@ -364,4 +364,41 @@ end end end + + describe "::cleanup_python_site_packages" do + context "when cleaning up Python modules" do + let(:foo_module) { (HOMEBREW_PREFIX/"lib/python3.99/site-packages/foo") } + let(:foo_pycache) { (foo_module/"__pycache__") } + let(:foo_pyc) { (foo_pycache/"foo.cypthon-399.pyc") } + + before do + foo_pycache.mkpath + FileUtils.touch foo_pyc + end + + it "cleans up stray `*.pyc` files" do + cleanup.cleanup_python_site_packages + expect(foo_pyc).not_to exist + end + + it "retains `*.pyc` files of installed modules" do + FileUtils.touch foo_module/"__init__.py" + + cleanup.cleanup_python_site_packages + expect(foo_pyc).to exist + end + end + + it "cleans up stale `*.pyc` files in the top-level `__pycache__`" do + pycache = HOMEBREW_PREFIX/"lib/python3.99/site-packages/__pycache__" + foo_pyc = pycache/"foo.cypthon-3.99.pyc" + pycache.mkpath + FileUtils.touch foo_pyc + + allow_any_instance_of(Pathname).to receive(:ctime).and_return(Time.now - (2 * 60 * 60 * 24)) + allow_any_instance_of(Pathname).to receive(:mtime).and_return(Time.now - (2 * 60 * 60 * 24)) + described_class.new(days: 1).cleanup_python_site_packages + expect(foo_pyc).not_to exist + end + end end
false
Other
Homebrew
brew
155f4d73946c522f3224288546c70085fb0ff44b.json
Fix collection of `unused_pyc_files`.
Library/Homebrew/cleanup.rb
@@ -531,6 +531,7 @@ def cleanup_python_site_packages unused_pyc_files += pyc_files.reject { |k,| seen_non_pyc_file[k] } .values + .flatten return if unused_pyc_files.blank? unused_pyc_files.each do |pyc|
false
Other
Homebrew
brew
a5f7fc814e8e6452625fde42f958ee3804cb17e7.json
cmd/deps: return failing exit code on circular dependencies. This makes more sense but will also be useful in `brew test-bot`.
Library/Homebrew/cmd/deps.rb
@@ -286,8 +286,14 @@ def recursive_deps_tree(f, dep_stack:, prefix:, recursive:, args:) end display_s = "#{tree_lines} #{dep_display_name(dep, args: args)}" + + # Detect circular dependencies and consider them a failure if present. is_circular = dep_stack.include?(dep.name) - display_s = "#{display_s} (CIRCULAR DEPENDENCY)" if is_circular + if is_circular + display_s = "#{display_s} (CIRCULAR DEPENDENCY)" + Homebrew.failed = true + end + puts "#{prefix}#{display_s}" next if !recursive || is_circular
false
Other
Homebrew
brew
5c2dd5779458b056ce3fb4ed4fc207ef1bb695b5.json
Fix unreachable code.
Library/Homebrew/cask/audit.rb
@@ -585,7 +585,7 @@ def check_signing next if result.success? # Only fail if signature is wrong, not when no signature is present at all. - next result.stderr.include?("not signed at all") + next if result.stderr.include?("not signed at all") add_warning "Signature verification failed: #{result.merged_output}" end
false
Other
Homebrew
brew
5c7e7eebe4d779dca0d5aaaec440105fb3e85c83.json
Condense artifact entries Co-authored-by: Mike McQuaid <mike@mikemcquaid.com>
Library/Homebrew/cask/cask.rb
@@ -283,14 +283,13 @@ def to_hash_with_variations def artifacts_list artifacts.map do |artifact| - if artifact.is_a? Artifact::AbstractFlightBlock - { type: artifact.summarize } + key, value = if artifact.is_a? Artifact::AbstractFlightBlock + artifact.summarize else - { - type: artifact.class.dsl_key, - args: to_h_gsubs(artifact.to_args), - } + [artifact.class.dsl_key, to_h_gsubs(artifact.to_args)] end + + { key => value } end end
true
Other
Homebrew
brew
5c7e7eebe4d779dca0d5aaaec440105fb3e85c83.json
Condense artifact entries Co-authored-by: Mike McQuaid <mike@mikemcquaid.com>
Library/Homebrew/test/cask/cmd/list_spec.rb
@@ -107,14 +107,12 @@ "sha256": "67cdb8a02803ef37fdbf7e0be205863172e41a561ca446cd84f0d7ab35a99d94", "artifacts": [ { - "type": "app", - "args": [ + "app": [ "Caffeine.app" ] }, { - "type": "zap", - "args": [ + "zap": [ { "trash": "$HOME/support/fixtures/cask/caffeine/org.example.caffeine.plist" } @@ -147,8 +145,7 @@ "sha256": "e44ffa103fbf83f55c8d0b1bea309a43b2880798dae8620b1ee8da5e1095ec68", "artifacts": [ { - "type": "app", - "args": [ + "app": [ "Transmission.app" ] } @@ -182,8 +179,7 @@ "sha256": "67cdb8a02803ef37fdbf7e0be205863172e41a561ca446cd84f0d7ab35a99d94", "artifacts": [ { - "type": "app", - "args": [ + "app": [ "Caffeine.app" ] } @@ -214,8 +210,7 @@ "sha256": "8c62a2b791cf5f0da6066a0a4b6e85f62949cd60975da062df44adf887f4370b", "artifacts": [ { - "type": "app", - "args": [ + "app": [ "ThirdParty.app" ] }
true
Other
Homebrew
brew
f09be9a5f75b44bfd16033af8b9ec456c24081c4.json
formula: try optimise `versioned_formulae_names`
Library/Homebrew/formula.rb
@@ -447,7 +447,17 @@ def versioned_formula? # Returns any `@`-versioned formulae names for any formula (including versioned formulae). sig { returns(T::Array[String]) } def versioned_formulae_names - Pathname.glob(path.to_s.gsub(/(@[\d.]+)?\.rb$/, "@*.rb")).map do |versioned_path| + versioned_paths = if tap + # Faster path, due to `tap.versioned_formula_files` caching. + name_prefix = "#{name.gsub(/(@[\d.]+)?$/, "")}@" + tap.versioned_formula_files.select do |file| + file.basename.to_s.start_with?(name_prefix) + end + else + Pathname.glob(path.to_s.gsub(/(@[\d.]+)?\.rb$/, "@*.rb")) + end + + versioned_paths.map do |versioned_path| next if versioned_path == path versioned_path.basename(".rb").to_s
false
Other
Homebrew
brew
84f544f08ff280ea1750a647933e4bb6420c5b22.json
Require git log only when not strict
Library/Homebrew/formula_auditor.rb
@@ -411,7 +411,7 @@ def audit_conflicts def audit_gcc_dependency return unless @git return unless @core_tap - return unless formula.tap.git? # git log is required + return if !@strict && !formula.tap.git? # git log is required for non-strict audit return unless Homebrew::SimulateSystem.simulating_or_running_on_linux? return unless linux_only_gcc_dep?(formula)
false
Other
Homebrew
brew
d271614872279cce7cec6344d3262f5a19315787.json
install glibc/gcc automatically if too old. Right now this is done through the gcc@5 formula. See https://github.com/Homebrew/homebrew-core/blob/9692318ca653f58857fec12136381c9cec290aa9/Formula/gcc%405.rb#L33 This is fragile because when we will migrate to gcc@11 we have to think about migrating the installation from one gcc formula to another.. Also, not having the right glibc version results in a non-functional brew installation on an older Linux: the glibc installation needs to be done by brew, and not by a workaround in a specific formula Co-Authored-By: Mike McQuaid <mike@mikemcquaid.com> Co-Authored-By: Bo Anderson <mail@boanderson.me> Co-Authored-By: Shaun Jackman <sjackman@gmail.com>
Library/Homebrew/dependency_collector.rb
@@ -28,6 +28,8 @@ class DependencyCollector def initialize @deps = Dependencies.new @requirements = Requirements.new + + init_global_dep_tree_if_needed! end def initialize_copy(other) @@ -68,6 +70,12 @@ def build(spec) parse_spec(spec, Array(tags)) end + sig { params(related_formula_names: T::Array[String]).returns(T.nilable(Dependency)) } + def gcc_dep_if_needed(related_formula_names); end + + sig { params(related_formula_names: T::Array[String]).returns(T.nilable(Dependency)) } + def glibc_dep_if_needed(related_formula_names); end + def git_dep_if_needed(tags) return if Utils::Git.available? @@ -110,6 +118,9 @@ def self.tar_needs_xz_dependency? private + sig { void } + def init_global_dep_tree_if_needed!; end + def parse_spec(spec, tags) case spec when String
true
Other
Homebrew
brew
d271614872279cce7cec6344d3262f5a19315787.json
install glibc/gcc automatically if too old. Right now this is done through the gcc@5 formula. See https://github.com/Homebrew/homebrew-core/blob/9692318ca653f58857fec12136381c9cec290aa9/Formula/gcc%405.rb#L33 This is fragile because when we will migrate to gcc@11 we have to think about migrating the installation from one gcc formula to another.. Also, not having the right glibc version results in a non-functional brew installation on an older Linux: the glibc installation needs to be done by brew, and not by a workaround in a specific formula Co-Authored-By: Mike McQuaid <mike@mikemcquaid.com> Co-Authored-By: Bo Anderson <mail@boanderson.me> Co-Authored-By: Shaun Jackman <sjackman@gmail.com>
Library/Homebrew/development_tools.rb
@@ -98,6 +98,16 @@ def clear_version_cache @gcc_version = {} end + sig { returns(T::Boolean) } + def build_system_too_old? + false + end + + sig { returns(T::Boolean) } + def system_gcc_too_old? + false + end + sig { returns(T::Boolean) } def ca_file_handles_most_https_certificates? # The system CA file is too old for some modern HTTPS certificates on
true
Other
Homebrew
brew
d271614872279cce7cec6344d3262f5a19315787.json
install glibc/gcc automatically if too old. Right now this is done through the gcc@5 formula. See https://github.com/Homebrew/homebrew-core/blob/9692318ca653f58857fec12136381c9cec290aa9/Formula/gcc%405.rb#L33 This is fragile because when we will migrate to gcc@11 we have to think about migrating the installation from one gcc formula to another.. Also, not having the right glibc version results in a non-functional brew installation on an older Linux: the glibc installation needs to be done by brew, and not by a workaround in a specific formula Co-Authored-By: Mike McQuaid <mike@mikemcquaid.com> Co-Authored-By: Bo Anderson <mail@boanderson.me> Co-Authored-By: Shaun Jackman <sjackman@gmail.com>
Library/Homebrew/extend/os/dependency_collector.rb
@@ -1,4 +1,8 @@ # typed: strict # frozen_string_literal: true -require "extend/os/mac/dependency_collector" if OS.mac? +if OS.mac? + require "extend/os/mac/dependency_collector" +elsif OS.linux? + require "extend/os/linux/dependency_collector" +end
true
Other
Homebrew
brew
d271614872279cce7cec6344d3262f5a19315787.json
install glibc/gcc automatically if too old. Right now this is done through the gcc@5 formula. See https://github.com/Homebrew/homebrew-core/blob/9692318ca653f58857fec12136381c9cec290aa9/Formula/gcc%405.rb#L33 This is fragile because when we will migrate to gcc@11 we have to think about migrating the installation from one gcc formula to another.. Also, not having the right glibc version results in a non-functional brew installation on an older Linux: the glibc installation needs to be done by brew, and not by a workaround in a specific formula Co-Authored-By: Mike McQuaid <mike@mikemcquaid.com> Co-Authored-By: Bo Anderson <mail@boanderson.me> Co-Authored-By: Shaun Jackman <sjackman@gmail.com>
Library/Homebrew/extend/os/linux/dependency_collector.rb
@@ -0,0 +1,76 @@ +# typed: true +# frozen_string_literal: true + +require "os/linux/glibc" + +class DependencyCollector + extend T::Sig + + undef gcc_dep_if_needed + undef glibc_dep_if_needed + undef init_global_dep_tree_if_needed! + + sig { params(related_formula_names: T::Set[String]).returns(T.nilable(Dependency)) } + def gcc_dep_if_needed(related_formula_names) + return unless DevelopmentTools.system_gcc_too_old? + return if related_formula_names.include?(GCC) + return if global_dep_tree[GCC]&.intersect?(related_formula_names) + return if global_dep_tree[GLIBC]&.intersect?(related_formula_names) # gcc depends on glibc + + Dependency.new(GCC) + end + + sig { params(related_formula_names: T::Set[String]).returns(T.nilable(Dependency)) } + def glibc_dep_if_needed(related_formula_names) + return unless OS::Linux::Glibc.below_ci_version? + return if global_dep_tree[GLIBC]&.intersect?(related_formula_names) + + Dependency.new(GLIBC) + end + + private + + GLIBC = "glibc" + GCC = CompilerSelector.preferred_gcc.freeze + + # Use class variables to avoid this expensive logic needing to be done more + # than once. + # rubocop:disable Style/ClassVars + @@global_dep_tree = {} + + sig { void } + def init_global_dep_tree_if_needed! + return unless DevelopmentTools.build_system_too_old? + return if @@global_dep_tree.present? + + # Defined in precedence order (gcc depends on glibc). + global_deps = [GLIBC, GCC].freeze + + @@global_dep_tree = global_deps.to_h { |name| [name, Set.new([name])] } + + global_deps.each do |global_dep_name| + # This is an arbitrary number picked based on testing the current tree + # depth and just to ensure that this doesn't loop indefinitely if we + # introduce a circular dependency by mistake. + maximum_tree_depth = 10 + current_tree_depth = 0 + + deps = Formula[global_dep_name].deps + while deps.present? + current_tree_depth += 1 + if current_tree_depth > maximum_tree_depth + raise "maximum tree depth (#{maximum_tree_depth}) exceeded calculating #{global_dep_name} dependency tree!" + end + + @@global_dep_tree[global_dep_name].merge(deps.map(&:name)) + deps = deps.flat_map { |dep| dep.to_formula.deps } + end + end + end + + sig { returns(T::Hash[String, T::Set[String]]) } + def global_dep_tree + @@global_dep_tree + end + # rubocop:enable Style/ClassVars +end
true
Other
Homebrew
brew
d271614872279cce7cec6344d3262f5a19315787.json
install glibc/gcc automatically if too old. Right now this is done through the gcc@5 formula. See https://github.com/Homebrew/homebrew-core/blob/9692318ca653f58857fec12136381c9cec290aa9/Formula/gcc%405.rb#L33 This is fragile because when we will migrate to gcc@11 we have to think about migrating the installation from one gcc formula to another.. Also, not having the right glibc version results in a non-functional brew installation on an older Linux: the glibc installation needs to be done by brew, and not by a workaround in a specific formula Co-Authored-By: Mike McQuaid <mike@mikemcquaid.com> Co-Authored-By: Bo Anderson <mail@boanderson.me> Co-Authored-By: Shaun Jackman <sjackman@gmail.com>
Library/Homebrew/extend/os/linux/development_tools.rb
@@ -21,6 +21,18 @@ def default_compiler :gcc end + sig { returns(T::Boolean) } + def build_system_too_old? + return @build_system_too_old if defined? @build_system_too_old + + @build_system_too_old = (system_gcc_too_old? || OS::Linux::Glibc.below_ci_version?) + end + + sig { returns(T::Boolean) } + def system_gcc_too_old? + gcc_version("gcc") < OS::LINUX_GCC_CI_VERSION + end + sig { returns(T::Hash[String, T.nilable(String)]) } def build_system_info generic_build_system_info.merge({
true
Other
Homebrew
brew
d271614872279cce7cec6344d3262f5a19315787.json
install glibc/gcc automatically if too old. Right now this is done through the gcc@5 formula. See https://github.com/Homebrew/homebrew-core/blob/9692318ca653f58857fec12136381c9cec290aa9/Formula/gcc%405.rb#L33 This is fragile because when we will migrate to gcc@11 we have to think about migrating the installation from one gcc formula to another.. Also, not having the right glibc version results in a non-functional brew installation on an older Linux: the glibc installation needs to be done by brew, and not by a workaround in a specific formula Co-Authored-By: Mike McQuaid <mike@mikemcquaid.com> Co-Authored-By: Bo Anderson <mail@boanderson.me> Co-Authored-By: Shaun Jackman <sjackman@gmail.com>
Library/Homebrew/extend/os/linux/formula.rb
@@ -5,6 +5,7 @@ class Formula undef shared_library undef loader_path undef deuniversalize_machos + undef add_global_deps_to_spec sig { params(name: String, version: T.nilable(T.any(String, Integer))).returns(String) } def shared_library(name, version = nil) @@ -23,4 +24,20 @@ def loader_path sig { params(targets: T.nilable(T.any(Pathname, String))).void } def deuniversalize_machos(*targets); end + + sig { params(spec: SoftwareSpec).void } + def add_global_deps_to_spec(spec) + @global_deps ||= begin + dependency_collector = spec.dependency_collector + related_formula_names = Set.new([ + name, + *versioned_formulae_names, + ]) + [ + dependency_collector.gcc_dep_if_needed(related_formula_names), + dependency_collector.glibc_dep_if_needed(related_formula_names), + ].compact.freeze + end + @global_deps.each { |dep| spec.dependency_collector.add(dep) } + end end
true
Other
Homebrew
brew
d271614872279cce7cec6344d3262f5a19315787.json
install glibc/gcc automatically if too old. Right now this is done through the gcc@5 formula. See https://github.com/Homebrew/homebrew-core/blob/9692318ca653f58857fec12136381c9cec290aa9/Formula/gcc%405.rb#L33 This is fragile because when we will migrate to gcc@11 we have to think about migrating the installation from one gcc formula to another.. Also, not having the right glibc version results in a non-functional brew installation on an older Linux: the glibc installation needs to be done by brew, and not by a workaround in a specific formula Co-Authored-By: Mike McQuaid <mike@mikemcquaid.com> Co-Authored-By: Bo Anderson <mail@boanderson.me> Co-Authored-By: Shaun Jackman <sjackman@gmail.com>
Library/Homebrew/extend/os/linux/linkage_checker.rb
@@ -80,9 +80,5 @@ def check_dylibs(rebuild_cache:) @unwanted_system_dylibs = @system_dylibs.reject do |s| SYSTEM_LIBRARY_ALLOWLIST.include? File.basename(s) end - # FIXME: Remove this when these dependencies are injected correctly (e.g. through `DependencyCollector`) - # See discussion at - # https://github.com/Homebrew/brew/pull/13577 - @undeclared_deps -= [CompilerSelector.preferred_gcc, "glibc", "gcc"] end end
true
Other
Homebrew
brew
d271614872279cce7cec6344d3262f5a19315787.json
install glibc/gcc automatically if too old. Right now this is done through the gcc@5 formula. See https://github.com/Homebrew/homebrew-core/blob/9692318ca653f58857fec12136381c9cec290aa9/Formula/gcc%405.rb#L33 This is fragile because when we will migrate to gcc@11 we have to think about migrating the installation from one gcc formula to another.. Also, not having the right glibc version results in a non-functional brew installation on an older Linux: the glibc installation needs to be done by brew, and not by a workaround in a specific formula Co-Authored-By: Mike McQuaid <mike@mikemcquaid.com> Co-Authored-By: Bo Anderson <mail@boanderson.me> Co-Authored-By: Shaun Jackman <sjackman@gmail.com>
Library/Homebrew/formula.rb
@@ -262,9 +262,13 @@ def spec_eval(name) return unless spec.url spec.owner = self + add_global_deps_to_spec(spec) instance_variable_set("@#{name}", spec) end + sig { params(spec: SoftwareSpec).void } + def add_global_deps_to_spec(spec); end + def determine_active_spec(requested) spec = send(requested) || stable || head spec || raise(FormulaSpecificationError, "formulae require at least a URL") @@ -443,7 +447,7 @@ def versioned_formula? # Returns any `@`-versioned formulae names for any formula (including versioned formulae). sig { returns(T::Array[String]) } def versioned_formulae_names - @versioned_formulae_names ||= Pathname.glob(path.to_s.gsub(/(@[\d.]+)?\.rb$/, "@*.rb")).map do |versioned_path| + Pathname.glob(path.to_s.gsub(/(@[\d.]+)?\.rb$/, "@*.rb")).map do |versioned_path| next if versioned_path == path versioned_path.basename(".rb").to_s @@ -453,7 +457,7 @@ def versioned_formulae_names # Returns any `@`-versioned Formula objects for any Formula (including versioned formulae). sig { returns(T::Array[Formula]) } def versioned_formulae - @versioned_formulae ||= versioned_formulae_names.map do |name| + versioned_formulae_names.map do |name| Formula[name] rescue FormulaUnavailableError nil
true
Other
Homebrew
brew
d271614872279cce7cec6344d3262f5a19315787.json
install glibc/gcc automatically if too old. Right now this is done through the gcc@5 formula. See https://github.com/Homebrew/homebrew-core/blob/9692318ca653f58857fec12136381c9cec290aa9/Formula/gcc%405.rb#L33 This is fragile because when we will migrate to gcc@11 we have to think about migrating the installation from one gcc formula to another.. Also, not having the right glibc version results in a non-functional brew installation on an older Linux: the glibc installation needs to be done by brew, and not by a workaround in a specific formula Co-Authored-By: Mike McQuaid <mike@mikemcquaid.com> Co-Authored-By: Bo Anderson <mail@boanderson.me> Co-Authored-By: Shaun Jackman <sjackman@gmail.com>
Library/Homebrew/formula_installer.rb
@@ -581,11 +581,9 @@ def expand_requirements end def expand_dependencies_for_formula(formula, inherited_options) - any_bottle_used = false - # Cache for this expansion only. FormulaInstaller has a lot of inputs which can alter expansion. cache_key = "FormulaInstaller-#{formula.full_name}-#{Time.now.to_f}" - expanded_deps = Dependency.expand(formula, cache_key: cache_key) do |dependent, dep| + Dependency.expand(formula, cache_key: cache_key) do |dependent, dep| inherited_options[dep.name] |= inherited_options_for(dep) build = effective_build_options_for( dependent, @@ -601,36 +599,14 @@ def expand_dependencies_for_formula(formula, inherited_options) Dependency.prune elsif dep.satisfied?(inherited_options[dep.name]) Dependency.skip - else - any_bottle_used ||= install_bottle_for?(dep.to_formula, build) end end - - [expanded_deps, any_bottle_used] end def expand_dependencies inherited_options = Hash.new { |hash, key| hash[key] = Options.new } - any_bottle_used = pour_bottle? - expanded_deps, any_dep_bottle_used = expand_dependencies_for_formula(formula, inherited_options) - any_bottle_used ||= any_dep_bottle_used - - # We require some dependencies (glibc, GCC 5, etc.) if binaries were built. - # Native binaries shouldn't exist in cross-platform `all` bottles. - if any_bottle_used && !formula.bottled?(:all) && !Keg.bottle_dependencies.empty? - all_bottle_deps = Keg.bottle_dependencies.flat_map do |bottle_dep| - bottle_dep.recursive_dependencies.map(&:name) + [bottle_dep.name] - end - - if all_bottle_deps.exclude?(formula.name) - bottle_deps = Keg.bottle_dependencies.flat_map do |bottle_dep| - expanded_bottle_deps, = expand_dependencies_for_formula(bottle_dep, inherited_options) - expanded_bottle_deps - end - expanded_deps = Dependency.merge_repeats(bottle_deps + expanded_deps) - end - end + expanded_deps = expand_dependencies_for_formula(formula, inherited_options) expanded_deps.map { |dep| [dep, inherited_options[dep.name]] } end
true
Other
Homebrew
brew
d271614872279cce7cec6344d3262f5a19315787.json
install glibc/gcc automatically if too old. Right now this is done through the gcc@5 formula. See https://github.com/Homebrew/homebrew-core/blob/9692318ca653f58857fec12136381c9cec290aa9/Formula/gcc%405.rb#L33 This is fragile because when we will migrate to gcc@11 we have to think about migrating the installation from one gcc formula to another.. Also, not having the right glibc version results in a non-functional brew installation on an older Linux: the glibc installation needs to be done by brew, and not by a workaround in a specific formula Co-Authored-By: Mike McQuaid <mike@mikemcquaid.com> Co-Authored-By: Bo Anderson <mail@boanderson.me> Co-Authored-By: Shaun Jackman <sjackman@gmail.com>
Library/Homebrew/keg_relocate.rb
@@ -366,17 +366,6 @@ def self.text_matches_in_file(file, string, ignores, linked_libraries, formula_a def self.file_linked_libraries(_file, _string) [] end - - def self.bottle_dependencies - return [] unless Homebrew::SimulateSystem.simulating_or_running_on_linux? - - @bottle_dependencies ||= begin - formulae = [] - gcc = Formulary.factory(CompilerSelector.preferred_gcc) - formulae << gcc if DevelopmentTools.gcc_version("gcc") < gcc.version.to_i - formulae - end - end end require "extend/os/keg_relocate"
true
Other
Homebrew
brew
d271614872279cce7cec6344d3262f5a19315787.json
install glibc/gcc automatically if too old. Right now this is done through the gcc@5 formula. See https://github.com/Homebrew/homebrew-core/blob/9692318ca653f58857fec12136381c9cec290aa9/Formula/gcc%405.rb#L33 This is fragile because when we will migrate to gcc@11 we have to think about migrating the installation from one gcc formula to another.. Also, not having the right glibc version results in a non-functional brew installation on an older Linux: the glibc installation needs to be done by brew, and not by a workaround in a specific formula Co-Authored-By: Mike McQuaid <mike@mikemcquaid.com> Co-Authored-By: Bo Anderson <mail@boanderson.me> Co-Authored-By: Shaun Jackman <sjackman@gmail.com>
Library/Homebrew/os/linux/glibc.rb
@@ -44,6 +44,11 @@ def minimum_version def below_minimum_version? system_version < minimum_version end + + sig { returns(T::Boolean) } + def below_ci_version? + system_version < LINUX_GLIBC_CI_VERSION + end end end end
true
Other
Homebrew
brew
d271614872279cce7cec6344d3262f5a19315787.json
install glibc/gcc automatically if too old. Right now this is done through the gcc@5 formula. See https://github.com/Homebrew/homebrew-core/blob/9692318ca653f58857fec12136381c9cec290aa9/Formula/gcc%405.rb#L33 This is fragile because when we will migrate to gcc@11 we have to think about migrating the installation from one gcc formula to another.. Also, not having the right glibc version results in a non-functional brew installation on an older Linux: the glibc installation needs to be done by brew, and not by a workaround in a specific formula Co-Authored-By: Mike McQuaid <mike@mikemcquaid.com> Co-Authored-By: Bo Anderson <mail@boanderson.me> Co-Authored-By: Shaun Jackman <sjackman@gmail.com>
Library/Homebrew/software_spec.rb
@@ -50,6 +50,11 @@ def initialize(flags: []) @uses_from_macos_elements = [] end + def initialize_copy(other) + super + @dependency_collector = @dependency_collector.dup + end + def owner=(owner) @name = owner.name @full_name = owner.full_name
true
Other
Homebrew
brew
d271614872279cce7cec6344d3262f5a19315787.json
install glibc/gcc automatically if too old. Right now this is done through the gcc@5 formula. See https://github.com/Homebrew/homebrew-core/blob/9692318ca653f58857fec12136381c9cec290aa9/Formula/gcc%405.rb#L33 This is fragile because when we will migrate to gcc@11 we have to think about migrating the installation from one gcc formula to another.. Also, not having the right glibc version results in a non-functional brew installation on an older Linux: the glibc installation needs to be done by brew, and not by a workaround in a specific formula Co-Authored-By: Mike McQuaid <mike@mikemcquaid.com> Co-Authored-By: Bo Anderson <mail@boanderson.me> Co-Authored-By: Shaun Jackman <sjackman@gmail.com>
Library/Homebrew/test/installed_dependents_spec.rb
@@ -6,7 +6,20 @@ describe InstalledDependents do include FileUtils - def setup_test_keg(name, version) + def stub_formula(name, version = "1.0", &block) + f = formula(name) do + url "#{name}-#{version}" + + instance_eval(&block) if block + end + stub_formula_loader f + stub_formula_loader f, "homebrew/core/#{f}" + f + end + + def setup_test_keg(name, version, &block) + stub_formula(name, version, &block) + path = HOMEBREW_CELLAR/name/version (path/"bin").mkpath @@ -18,136 +31,146 @@ def setup_test_keg(name, version) end let!(:keg) { setup_test_keg("foo", "1.0") } - - describe "::find_some_installed_dependents" do - def stub_formula_name(name) - f = formula(name) { url "foo-1.0" } - stub_formula_loader f - stub_formula_loader f, "homebrew/core/#{f}" - f + let!(:keg_only_keg) do + setup_test_keg("foo-keg-only", "1.0") do + keg_only "a good reason" end + end - def setup_test_keg(name, version) - f = stub_formula_name(name) + describe "::find_some_installed_dependents" do + def setup_test_keg(name, version, &block) keg = super - Tab.create(f, DevelopmentTools.default_compiler, :libcxx).write + Tab.create(keg.to_formula, DevelopmentTools.default_compiler, :libcxx).write keg end before do keg.link + keg_only_keg.optlink end - def alter_tab(keg = dependent) + def alter_tab(keg) tab = Tab.for_keg(keg) yield tab tab.write end # 1.1.6 is the earliest version of Homebrew that generates correct runtime # dependency lists in {Tab}s. - def dependencies(deps, homebrew_version: "1.1.6") - alter_tab do |tab| + def tab_dependencies(keg, deps, homebrew_version: "1.1.6") + alter_tab(keg) do |tab| tab.homebrew_version = homebrew_version - tab.tabfile = dependent/Tab::FILENAME + tab.tabfile = keg/Tab::FILENAME tab.runtime_dependencies = deps end end - def unreliable_dependencies(deps) + def unreliable_tab_dependencies(keg, deps) # 1.1.5 is (hopefully!) the last version of Homebrew that generates # incorrect runtime dependency lists in {Tab}s. - dependencies(deps, homebrew_version: "1.1.5") + tab_dependencies(keg, deps, homebrew_version: "1.1.5") end - let(:dependent) { setup_test_keg("bar", "1.0") } - specify "a dependency with no Tap in Tab" do tap_dep = setup_test_keg("baz", "1.0") + dependent = setup_test_keg("bar", "1.0") do + depends_on "foo" + depends_on "baz" + end # allow tap_dep to be linked too FileUtils.rm_r tap_dep/"bin" tap_dep.link alter_tab(keg) { |t| t.source["tap"] = nil } - dependencies nil - Formula["bar"].class.depends_on "foo" - Formula["bar"].class.depends_on "baz" + tab_dependencies dependent, nil result = described_class.find_some_installed_dependents([keg, tap_dep]) expect(result).to eq([[keg, tap_dep], ["bar"]]) end specify "no dependencies anywhere" do - dependencies nil + dependent = setup_test_keg("bar", "1.0") + tab_dependencies dependent, nil expect(described_class.find_some_installed_dependents([keg])).to be_nil end specify "missing Formula dependency" do - dependencies nil - Formula["bar"].class.depends_on "foo" + dependent = setup_test_keg("bar", "1.0") do + depends_on "foo" + end + tab_dependencies dependent, nil expect(described_class.find_some_installed_dependents([keg])).to eq([[keg], ["bar"]]) end specify "uninstalling dependent and dependency" do - dependencies nil - Formula["bar"].class.depends_on "foo" + dependent = setup_test_keg("bar", "1.0") do + depends_on "foo" + end + tab_dependencies dependent, nil expect(described_class.find_some_installed_dependents([keg, dependent])).to be_nil end specify "renamed dependency" do - dependencies nil + dependent = setup_test_keg("bar", "1.0") do + depends_on "foo" + end + tab_dependencies dependent, nil stub_formula_loader Formula["foo"], "homebrew/core/foo-old" renamed_path = HOMEBREW_CELLAR/"foo-old" (HOMEBREW_CELLAR/"foo").rename(renamed_path) - renamed_keg = Keg.new(renamed_path/"1.0") - - Formula["bar"].class.depends_on "foo" + renamed_keg = Keg.new(renamed_path/keg.version.to_s) result = described_class.find_some_installed_dependents([renamed_keg]) expect(result).to eq([[renamed_keg], ["bar"]]) end specify "empty dependencies in Tab" do - dependencies [] + dependent = setup_test_keg("bar", "1.0") + tab_dependencies dependent, [] expect(described_class.find_some_installed_dependents([keg])).to be_nil end specify "same name but different version in Tab" do - dependencies [{ "full_name" => "foo", "version" => "1.1" }] + dependent = setup_test_keg("bar", "1.0") + tab_dependencies dependent, [{ "full_name" => keg.name, "version" => "1.1" }] expect(described_class.find_some_installed_dependents([keg])).to eq([[keg], ["bar"]]) end specify "different name and same version in Tab" do - stub_formula_name("baz") - dependencies [{ "full_name" => "baz", "version" => keg.version.to_s }] + stub_formula("baz") + dependent = setup_test_keg("bar", "1.0") + tab_dependencies dependent, [{ "full_name" => "baz", "version" => keg.version.to_s }] expect(described_class.find_some_installed_dependents([keg])).to be_nil end specify "same name and version in Tab" do - dependencies [{ "full_name" => "foo", "version" => "1.0" }] + dependent = setup_test_keg("bar", "1.0") + tab_dependencies dependent, [{ "full_name" => keg.name, "version" => keg.version.to_s }] expect(described_class.find_some_installed_dependents([keg])).to eq([[keg], ["bar"]]) end specify "fallback for old versions" do - unreliable_dependencies [{ "full_name" => "baz", "version" => "1.0" }] - Formula["bar"].class.depends_on "foo" + dependent = setup_test_keg("bar", "1.0") do + depends_on "foo" + end + unreliable_tab_dependencies dependent, [{ "full_name" => "baz", "version" => "1.0" }] expect(described_class.find_some_installed_dependents([keg])).to eq([[keg], ["bar"]]) end specify "non-opt-linked" do keg.remove_opt_record - dependencies [{ "full_name" => "foo", "version" => "1.0" }] + dependent = setup_test_keg("bar", "1.0") + tab_dependencies dependent, [{ "full_name" => keg.name, "version" => keg.version.to_s }] expect(described_class.find_some_installed_dependents([keg])).to be_nil end specify "keg-only" do - keg.unlink - Formula["foo"].class.keg_only "a good reason" - dependencies [{ "full_name" => "foo", "version" => "1.1" }] # different version - expect(described_class.find_some_installed_dependents([keg])).to eq([[keg], ["bar"]]) + dependent = setup_test_keg("bar", "1.0") + tab_dependencies dependent, [{ "full_name" => keg_only_keg.name, "version" => "1.1" }] # different version + expect(described_class.find_some_installed_dependents([keg_only_keg])).to eq([[keg_only_keg], ["bar"]]) end def stub_cask_name(name, version, dependency)
true
Other
Homebrew
brew
be4e926b15ec58ff6273e6bf9377cfc8d11e57f9.json
Fix `"dependencies"` being `nil`.
Library/Homebrew/formula_auditor.rb
@@ -888,11 +888,10 @@ def linux_only_gcc_dep?(formula) # depends_on "gcc" # end # ``` - variations_deps = [] - variations.each_value do |data| - variations_deps += data["dependencies"] - end - variations_deps.uniq! + variations_deps = variations.values + .flat_map { |data| data["dependencies"] } + .compact + .uniq variations_deps.exclude?("gcc") end
false
Other
Homebrew
brew
4bbcab235b69e44affc31a47179a80a818b50c3e.json
change local variable
Library/Homebrew/install.rb
@@ -322,7 +322,7 @@ def install_formulae( if dry_run formulae_name_to_install = formulae_to_install.map(&:name) if formulae_name_to_install.present? - plural = "package".pluralize(casks_to_install.count) + plural = "package".pluralize(formulae_name_to_install.count) ohai "Would install #{formulae_name_to_install.count} #{plural}:" puts formulae_name_to_install.join(" ") end
false
Other
Homebrew
brew
59692b5bf4410436eec5bddc3c3769a67836496a.json
service: provide formula accessor. Use `f` because it's generally recognised as a formula and this shouldn't be widely needed/used.
Library/Homebrew/service.rb
@@ -28,6 +28,11 @@ def initialize(formula, &block) @service_block = block end + sig { returns(Formula) } + def f + @formula + end + sig { params(command: T.nilable(T.any(T::Array[String], String, Pathname))).returns(T.nilable(Array)) } def run(command = nil) case T.unsafe(command)
false
Other
Homebrew
brew
2de6958a36a4ef3172e2269a5ce11f15e94e57e9.json
build_environment: add proper types to dump() and fix inreplace error
Library/Homebrew/build_environment.rb
@@ -55,22 +55,23 @@ def env(*settings) ].freeze private_constant :KEYS - sig { params(env: T.untyped).returns(T::Array[String]) } + sig { params(env: T::Hash[String, T.nilable(T.any(String, Pathname))]).returns(T::Array[String]) } def self.keys(env) KEYS & env.keys end - sig { params(env: T.untyped, f: IO).void } + sig { params(env: T::Hash[String, T.nilable(T.any(String, Pathname))], f: IO).void } def self.dump(env, f = $stdout) keys = self.keys(env) keys -= %w[CC CXX OBJC OBJCXX] if env["CC"] == env["HOMEBREW_CC"] keys.each do |key| value = env.fetch(key) + s = +"#{key}: #{value}" case key when "CC", "CXX", "LD" - s << " => #{Pathname.new(value).realpath}" if File.symlink?(value) + s << " => #{Pathname.new(value).realpath}" if value.present? && File.symlink?(value) end s.freeze f.puts s
true
Other
Homebrew
brew
2de6958a36a4ef3172e2269a5ce11f15e94e57e9.json
build_environment: add proper types to dump() and fix inreplace error
Library/Homebrew/cmd/--env.rb
@@ -51,7 +51,7 @@ def __env if shell.nil? BuildEnvironment.dump ENV else - BuildEnvironment.keys(ENV).each do |key| + BuildEnvironment.keys(ENV.to_h).each do |key| puts Utils::Shell.export_value(key, ENV.fetch(key), shell) end end
true
Other
Homebrew
brew
2de6958a36a4ef3172e2269a5ce11f15e94e57e9.json
build_environment: add proper types to dump() and fix inreplace error
Library/Homebrew/exceptions.rb
@@ -466,9 +466,19 @@ def initialize(formula) # Raised when an error occurs during a formula build. class BuildError < RuntimeError + extend T::Sig + attr_reader :cmd, :args, :env attr_accessor :formula, :options + sig { + params( + formula: T.nilable(Formula), + cmd: T.any(String, Pathname), + args: T::Array[T.any(String, Pathname, Integer)], + env: T::Hash[String, T.untyped], + ).void + } def initialize(formula, cmd, args, env) @formula = formula @cmd = cmd @@ -478,17 +488,20 @@ def initialize(formula, cmd, args, env) super "Failed executing: #{cmd} #{pretty_args}".strip end + sig { returns(T::Array[T.untyped]) } def issues @issues ||= fetch_issues end + sig { returns(T::Array[T.untyped]) } def fetch_issues GitHub.issues_for_formula(formula.name, tap: formula.tap, state: "open") rescue GitHub::API::RateLimitExceededError => e opoo e.message [] end + sig { params(verbose: T::Boolean).void } def dump(verbose: false) puts
true
Other
Homebrew
brew
2de6958a36a4ef3172e2269a5ce11f15e94e57e9.json
build_environment: add proper types to dump() and fix inreplace error
Library/Homebrew/formula.rb
@@ -2219,7 +2219,7 @@ def install; end def inreplace(paths, before = nil, after = nil, audit_result = true) # rubocop:disable Style/OptionalBooleanParameter super(paths, before, after, audit_result) rescue Utils::Inreplace::Error - raise BuildError.new(self, "inreplace", paths, nil) + raise BuildError.new(self, "inreplace", paths, {}) end protected
true
Other
Homebrew
brew
8064a39c18d4425a5f1c1999bbea5359414e45fc.json
Prefer newer versions of Python Some formulae declare multiple Python dependencies, and they can appear in any order in the `deps` array. Let's make sure to prefer the newest one when adding their `libexec/"bin"` directory to `PATH`.
Library/Homebrew/extend/ENV/super.rb
@@ -125,7 +125,10 @@ def determine_cxx sig { returns(T::Array[Pathname]) } def homebrew_extra_paths + # Reverse sort by version so that we prefer the newest when there are multiple. deps.select { |d| d.name.match? Version.formula_optionally_versioned_regex(:python) } + .sort_by(&:version) + .reverse .map { |d| d.opt_libexec/"bin" } end alias generic_homebrew_extra_paths homebrew_extra_paths
false
Other
Homebrew
brew
ad7e5ccc4451136854296958ffd2d87b31280a62.json
Add additional test
Library/Homebrew/test/rubocops/cask/variables_spec.rb
@@ -76,6 +76,37 @@ include_examples "autocorrects source" end + context "when there is an arch variable that doesn't use strings" do + let(:source) do + <<-CASK.undent + cask 'foo' do + arch = Hardware::CPU.intel? ? :darwin : :darwin_arm64 + end + CASK + end + let(:correct_source) do + <<-CASK.undent + cask 'foo' do + arch arm: :darwin_arm64, intel: :darwin + end + CASK + end + let(:expected_offenses) do + [{ + message: "Use `arch arm: :darwin_arm64, intel: :darwin` instead of " \ + "`arch = Hardware::CPU.intel? ? :darwin : :darwin_arm64`", + severity: :convention, + line: 2, + column: 2, + source: "arch = Hardware::CPU.intel? ? :darwin : :darwin_arm64", + }] + end + + include_examples "reports offenses" + + include_examples "autocorrects source" + end + context "when there is an arch with an empty string" do let(:source) do <<-CASK.undent
false
Other
Homebrew
brew
74a8e5bb235cfdc476b84863e2eb1847fc3eec3e.json
dev-cmd/rubocop: use bundle check. It's not reliable enough to just check for the binary.
Library/Homebrew/dev-cmd/rubocop.sh
@@ -13,13 +13,16 @@ homebrew-rubocop() { GEM_VERSION="$("${HOMEBREW_RUBY_PATH}" "${RUBY_DISABLE_OPTIONS}" -rrbconfig -e 'puts RbConfig::CONFIG["ruby_version"]')" GEM_HOME="${HOMEBREW_LIBRARY}/Homebrew/vendor/bundle/ruby/${GEM_VERSION}" + BUNDLE_GEMFILE="${HOMEBREW_LIBRARY}/Homebrew/Gemfile" - if ! [[ -f "${GEM_HOME}/bin/rubocop" ]] + export GEM_HOME + export BUNDLE_GEMFILE + + if ! bundle check &>/dev/null then "${HOMEBREW_BREW_FILE}" install-bundler-gems fi - export GEM_HOME export PATH="${GEM_HOME}/bin:${PATH}" RUBOCOP="${HOMEBREW_LIBRARY}/Homebrew/utils/rubocop.rb"
false
Other
Homebrew
brew
e90371f8abd188c046692ed4998737cba656e697.json
cask: add audit for incorrect signing
Library/Homebrew/cask/audit.rb
@@ -20,28 +20,31 @@ class Audit attr_reader :cask, :download - attr_predicate :appcast?, :new_cask?, :strict?, :online?, :token_conflicts? + attr_predicate :appcast?, :new_cask?, :strict?, :signing?, :online?, :token_conflicts? def initialize(cask, appcast: nil, download: nil, quarantine: nil, - token_conflicts: nil, online: nil, strict: nil, + token_conflicts: nil, online: nil, strict: nil, signing: nil, new_cask: nil) - # `new_cask` implies `online` and `strict` + # `new_cask` implies `online`, `token_conflicts`, `strict` and signing online = new_cask if online.nil? strict = new_cask if strict.nil? + signing = new_cask if signing.nil? + token_conflicts = new_cask if token_conflicts.nil? # `online` implies `appcast` and `download` appcast = online if appcast.nil? download = online if download.nil? - # `new_cask` implies `token_conflicts` - token_conflicts = new_cask if token_conflicts.nil? + # `signing` implies `download` + download = signing if download.nil? @cask = cask @appcast = appcast @download = Download.new(cask, quarantine: quarantine) if download @online = online @strict = strict + @signing = signing @new_cask = new_cask @token_conflicts = token_conflicts end @@ -81,6 +84,7 @@ def run! check_github_repository_archived check_github_prerelease_version check_bitbucket_repository + check_signing self rescue => e odebug e, e.backtrace @@ -550,6 +554,33 @@ def check_download add_error "download not possible: #{e}" end + def check_signing + return if !signing? || download.blank? || cask.url.blank? + + odebug "Auditing signing" + odebug cask.artifacts + artifacts = cask.artifacts.select { |k| k.is_a?(Artifact::Pkg) || k.is_a?(Artifact::App) } + + return if artifacts.empty? + + downloaded_path = download.fetch + primary_container = UnpackStrategy.detect(downloaded_path, type: @cask.container&.type, merge_xattrs: true) + + return if primary_container.nil? + + Dir.mktmpdir do |tmpdir| + tmpdir = Pathname(tmpdir) + primary_container.extract_nestedly(to: tmpdir, basename: downloaded_path.basename, verbose: false) + cask.artifacts.each do |artifact| + result = system_command("codesign", args: [ + "--verify", + tmpdir/artifact.source.basename, + ], print_stderr: false) + add_warning result.merged_output unless result.success? + end + end + end + def check_livecheck_version return unless appcast?
true
Other
Homebrew
brew
e90371f8abd188c046692ed4998737cba656e697.json
cask: add audit for incorrect signing
Library/Homebrew/cask/auditor.rb
@@ -15,6 +15,7 @@ def self.audit( audit_online: nil, audit_new_cask: nil, audit_strict: nil, + audit_signing: nil, audit_token_conflicts: nil, quarantine: nil, any_named_args: nil, @@ -29,6 +30,7 @@ def self.audit( audit_online: audit_online, audit_new_cask: audit_new_cask, audit_strict: audit_strict, + audit_signing: audit_signing, audit_token_conflicts: audit_token_conflicts, quarantine: quarantine, any_named_args: any_named_args, @@ -46,6 +48,7 @@ def initialize( audit_appcast: nil, audit_online: nil, audit_strict: nil, + audit_signing: nil, audit_token_conflicts: nil, audit_new_cask: nil, quarantine: nil, @@ -60,6 +63,7 @@ def initialize( @audit_online = audit_online @audit_new_cask = audit_new_cask @audit_strict = audit_strict + @audit_signing = audit_signing @quarantine = quarantine @audit_token_conflicts = audit_token_conflicts @any_named_args = any_named_args @@ -133,6 +137,7 @@ def audit_cask_instance(cask) appcast: @audit_appcast, online: @audit_online, strict: @audit_strict, + signing: @audit_signing, new_cask: @audit_new_cask, token_conflicts: @audit_token_conflicts, download: @audit_download,
true
Other
Homebrew
brew
e90371f8abd188c046692ed4998737cba656e697.json
cask: add audit for incorrect signing
Library/Homebrew/cask/cmd/audit.rb
@@ -19,6 +19,8 @@ def self.parser description: "Audit the appcast" switch "--[no-]token-conflicts", description: "Audit for token conflicts" + switch "--[no-]signing", + description: "Audit for signed apps, which is required on ARM" switch "--[no-]strict", description: "Run additional, stricter style checks" switch "--[no-]online", @@ -50,6 +52,7 @@ def run appcast: args.appcast?, online: args.online?, strict: args.strict?, + signing: args.signing?, new_cask: args.new_cask?, token_conflicts: args.token_conflicts?, quarantine: args.quarantine?, @@ -71,6 +74,7 @@ def self.audit_casks( appcast: nil, online: nil, strict: nil, + signing: nil, new_cask: nil, token_conflicts: nil, quarantine: nil, @@ -84,6 +88,7 @@ def self.audit_casks( audit_appcast: appcast, audit_online: online, audit_strict: strict, + audit_signing: signing, audit_new_cask: new_cask, audit_token_conflicts: token_conflicts, quarantine: quarantine,
true
Other
Homebrew
brew
e90371f8abd188c046692ed4998737cba656e697.json
cask: add audit for incorrect signing
Library/Homebrew/test/cask/audit_spec.rb
@@ -411,6 +411,53 @@ def tmp_cask(name, text) end end + describe "signing checks" do + let(:download_double) { instance_double(Cask::Download) } + let(:unpack_double) { instance_double(UnpackStrategy::Zip) } + + before do + allow(audit).to receive(:download).and_return(download_double) + allow(audit).to receive(:signing?).and_return(true) + allow(audit).to receive(:check_https_availability) + end + + context "when cask is not using a signed artifact" do + let(:cask) do + tmp_cask "signing-cask-test", <<~RUBY + cask 'signing-cask-test' do + version '1.0' + url "https://brew.sh/index.html" + binary 'Audit.app' + end + RUBY + end + + it "does not fail" do + expect(download_double).not_to receive(:fetch) + expect(UnpackStrategy).not_to receive(:detect) + expect(run).not_to warn_with(/Audit\.app/) + end + end + + context "when cask is using a signed artifact" do + let(:cask) do + tmp_cask "signing-cask-test", <<~RUBY + cask 'signing-cask-test' do + version '1.0' + url "https://brew.sh/" + pkg 'Audit.app' + end + RUBY + end + + it "does not fail since no extract" do + allow(download_double).to receive(:fetch).and_return(Pathname.new("/tmp/test.zip")) + allow(UnpackStrategy).to receive(:detect).and_return(nil) + expect(run).not_to warn_with(/Audit\.app/) + end + end + end + describe "livecheck should be skipped" do let(:online) { true } let(:message) { /Version '[^']*' differs from '[^']*' retrieved by livecheck\./ } @@ -888,18 +935,19 @@ def tmp_cask(name, text) end describe "audit of downloads" do - let(:cask_token) { "with-binary" } + let(:cask_token) { "basic-cask" } let(:cask) { Cask::CaskLoader.load(cask_token) } let(:download_double) { instance_double(Cask::Download) } let(:message) { "Download Failed" } before do allow(audit).to receive(:download).and_return(download_double) allow(audit).to receive(:check_https_availability) + allow(UnpackStrategy).to receive(:detect).and_return(nil) end it "when download and verification succeed it does not fail" do - expect(download_double).to receive(:fetch) + expect(download_double).to receive(:fetch).and_return(Pathname.new("/tmp/test.zip")) expect(run).to pass end
true
Other
Homebrew
brew
acf39f8777a825d48b4ca46249c75be13614e2d1.json
add TODO comment
Library/Homebrew/cask/cask.rb
@@ -90,6 +90,7 @@ def versions end def os_versions + # TODO: use #to_hash_with_variations instead once all casks use on_system blocks @os_versions ||= begin version_os_hash = {} actual_version = MacOS.full_version.to_s
false
Other
Homebrew
brew
03a489bf78709f9361109d65817ae8821eeef864.json
brew.rb: tell users to fix head issues with inreplace
Library/Homebrew/formula.rb
@@ -69,9 +69,6 @@ class Formula extend Cachable extend Predicable - # @!method inreplace(paths, before = nil, after = nil) - # @see Utils::Inreplace.inreplace - # The name of this {Formula}. # e.g. `this-formula` attr_reader :name @@ -2169,6 +2166,12 @@ def test_fixtures(file) # end</pre> def install; end + def inreplace(paths, before = nil, after = nil, audit_result = true) # rubocop:disable Style/OptionalBooleanParameter + super(paths, before, after, audit_result) + rescue Utils::Inreplace::Error + raise BuildError.new(self, "inreplace", paths, nil) + end + protected def setup_home(home)
true
Other
Homebrew
brew
03a489bf78709f9361109d65817ae8821eeef864.json
brew.rb: tell users to fix head issues with inreplace
Library/Homebrew/test/formula_spec.rb
@@ -483,6 +483,16 @@ end end + describe "::inreplace" do + specify "raises build error on failure" do + f = formula do + url "https://brew.sh/test-1.0.tbz" + end + + expect { f.inreplace([]) }.to raise_error(BuildError) + end + end + describe "::installed_with_alias_path" do specify "with alias path with nil" do expect(described_class.installed_with_alias_path(nil)).to be_empty
true
Other
Homebrew
brew
03a489bf78709f9361109d65817ae8821eeef864.json
brew.rb: tell users to fix head issues with inreplace
Library/Homebrew/utils/inreplace.rb
@@ -10,7 +10,7 @@ module Utils module Inreplace extend T::Sig - # Error during replacement. + # Error during text replacement. class Error < RuntimeError def initialize(errors) formatted_errors = errors.reduce(+"inreplace failed\n") do |s, (path, errs)| @@ -70,7 +70,7 @@ def inreplace(paths, before = nil, after = nil, audit_result = true) # rubocop:d Pathname(path).atomic_write(s.inreplace_string) end - raise Error, errors unless errors.empty? + raise Utils::Inreplace::Error, errors unless errors.empty? end # @api private @@ -86,7 +86,7 @@ def inreplace_pairs(path, replacement_pairs, read_only_run: false, silent: false contents.gsub!(old, new) end - raise Error, path => contents.errors unless contents.errors.empty? + raise Utils::Inreplace::Error, [path => contents.errors] unless contents.errors.empty? Pathname(path).atomic_write(contents.inreplace_string) unless read_only_run contents.inreplace_string
true
Other
Homebrew
brew
0acadc857c7c5999ee89e9b18f5d6cace34a60e4.json
repair CaskLoader.load args
Library/Homebrew/cask/cask.rb
@@ -96,7 +96,7 @@ def os_versions MacOSVersions::SYMBOLS.each do |os_name, os_version| MacOS.full_version = os_version - cask = CaskLoader.load(token) + cask = CaskLoader.load(full_name) version_os_hash[os_name] = cask.version if cask.version != version end
true
Other
Homebrew
brew
0acadc857c7c5999ee89e9b18f5d6cace34a60e4.json
repair CaskLoader.load args
Library/Homebrew/cask/cask_loader.rb
@@ -236,9 +236,7 @@ def self.for(ref) when 2..Float::INFINITY loaders = possible_tap_casks.map(&FromTapPathLoader.method(:new)) - raise TapCaskAmbiguityError.new(ref, loaders) if loaders.map(&:tap).map(&:name).uniq.size == 1 - - return FromTapPathLoader.new(possible_tap_casks.first) + raise TapCaskAmbiguityError.new(ref, loaders) end possible_installed_cask = Cask.new(ref)
true
Other
Homebrew
brew
ddc23eb268328f45fb88031c7b011981c1266f1e.json
update-report: reset `version_scheme` only for runtime dependents `recursive_dependencies` includes build and test dependencies as well, which means that we're doing this for too many formulae.
Library/Homebrew/cmd/update-report.rb
@@ -298,7 +298,14 @@ def migrate_gcc_dependents_if_needed Formula.installed.each do |formula| next unless formula.tap&.core_tap? - next unless formula.recursive_dependencies.map(&:name).include? "gcc" + + recursive_runtime_dependencies = Dependency.expand( + formula, + cache_key: "update-report", + ) do |_, dependency| + Dependency.prune if dependency.build? || dependency.test? + end + next unless recursive_runtime_dependencies.map(&:name).include? "gcc" keg = formula.installed_kegs.last tab = Tab.for_keg(keg)
false
Other
Homebrew
brew
2d95b9acda5b56380a3ca603fd2e0a0afbfa91f0.json
linux/keg_relocate: remove patchelf exemption I don't think this is needed anymore. We probably needed this when we used `patchelf` to do `RPATH` rewriting, but this is no longer the case.
Library/Homebrew/extend/os/linux/keg_relocate.rb
@@ -8,9 +8,6 @@ def relocate_dynamic_linkage(relocation) # Patching the dynamic linker of glibc breaks it. return if name.match? Version.formula_optionally_versioned_regex(:glibc) - # Patching patchelf fails with "Text file busy" or SIGBUS. - return if name == "patchelf" - old_prefix, new_prefix = relocation.replacement_pair_for(:prefix) elf_files.each do |file|
false
Other
Homebrew
brew
61544369e45234e3452eb2c21e67c43736aa08a1.json
pr-pull: fix PRs conflicting with themselves https://github.com/Homebrew/homebrew-core/pull/106755#issuecomment-1206460655
Library/Homebrew/dev-cmd/pr-pull.rb
@@ -373,6 +373,8 @@ def pr_check_conflicts(user, repo, pr) "org:#{user}", repo: repo, state: "open", label: "\"no long build conflict\"" ).each_with_object({}) do |long_build_pr, hash| number = long_build_pr["number"] + next if number == pr + GitHub.get_pull_request_changed_files("#{user}/#{repo}", number).each do |file| key = file["filename"] hash[key] ||= []
false
Other
Homebrew
brew
a43633e0948dbbb1fceeebcad965c7ccbdc498cb.json
add uniq to check multiple tap
Library/Homebrew/cask/cask_loader.rb
@@ -236,7 +236,7 @@ def self.for(ref) when 2..Float::INFINITY loaders = possible_tap_casks.map(&FromTapPathLoader.method(:new)) - raise TapCaskAmbiguityError.new(ref, loaders) if loaders.map(&:tap).map(&:name).size == 1 + raise TapCaskAmbiguityError.new(ref, loaders) if loaders.map(&:tap).map(&:name).uniq.size == 1 return FromTapPathLoader.new(possible_tap_casks.first) end
false
Other
Homebrew
brew
2ce58f9fcba5a9c214d9f56c6101b1c5bab3a304.json
fix removing of previous source
Library/Homebrew/mktemp.rb
@@ -47,11 +47,11 @@ def to_s def run prefix_name = @prefix.tr "@", "AT" - if @retain_in_cache + if retain_in_cache? source_dir = "#{HOMEBREW_CACHE}/Sources/#{prefix_name}" - chmod_rm_rf(source_dir) # clear out previous (otherwise not sure what happens) - FileUtils.mkdir_p(source_dir) @tmpdir = Pathname.new(source_dir) + chmod_rm_rf(@tmpdir) # clear out previous (otherwise not sure what happens) + FileUtils.mkdir_p(source_dir) else @tmpdir = Pathname.new(Dir.mktmpdir("#{prefix_name}-", HOMEBREW_TEMP)) end
false
Other
Homebrew
brew
71ab2f6e7afee7307471cdd61d828c48b68e4c25.json
Run periodic cleanup after installing all packages
Library/Homebrew/cleanup.rb
@@ -156,15 +156,19 @@ def initialize(*args, dry_run: false, scrub: false, days: nil, cache: HOMEBREW_C def self.install_formula_clean!(f, dry_run: false) return if Homebrew::EnvConfig.no_install_cleanup? + return unless f.latest_version_installed? + return if skip_clean_formula?(f) - cleanup = Cleanup.new(dry_run: dry_run) - if cleanup.periodic_clean_due? - cleanup.periodic_clean! - elsif f.latest_version_installed? && !Cleanup.skip_clean_formula?(f) + if dry_run + ohai "Would run `brew cleanup #{f}`" + else ohai "Running `brew cleanup #{f}`..." - puts_no_install_cleanup_disable_message_if_not_already! - cleanup.cleanup_formula(f) end + + puts_no_install_cleanup_disable_message_if_not_already! + return if dry_run + + Cleanup.new.cleanup_formula(f) end def self.puts_no_install_cleanup_disable_message_if_not_already! @@ -184,7 +188,7 @@ def self.skip_clean_formula?(f) skip_clean_formulae.include?(f.name) || (skip_clean_formulae & f.aliases).present? end - def periodic_clean_due? + def self.periodic_clean_due? return false if Homebrew::EnvConfig.no_install_cleanup? unless PERIODIC_CLEAN_FILE.exist? @@ -196,19 +200,20 @@ def periodic_clean_due? PERIODIC_CLEAN_FILE.mtime < CLEANUP_DEFAULT_DAYS.days.ago end - def periodic_clean! - return false unless periodic_clean_due? + def self.periodic_clean!(dry_run: false) + return if Homebrew::EnvConfig.no_install_cleanup? + return unless periodic_clean_due? - if dry_run? - ohai "Would run `brew cleanup` which has not been run in the last #{CLEANUP_DEFAULT_DAYS} days" + if dry_run + oh1 "Would run `brew cleanup` which has not been run in the last #{CLEANUP_DEFAULT_DAYS} days" else - ohai "`brew cleanup` has not been run in the last #{CLEANUP_DEFAULT_DAYS} days, running now..." + oh1 "`brew cleanup` has not been run in the last #{CLEANUP_DEFAULT_DAYS} days, running now..." end - Cleanup.puts_no_install_cleanup_disable_message_if_not_already! - return if dry_run? + puts_no_install_cleanup_disable_message_if_not_already! + return if dry_run - clean!(quiet: true, periodic: true) + Cleanup.new.clean!(quiet: true, periodic: true) end def clean!(quiet: false, periodic: false)
true
Other
Homebrew
brew
71ab2f6e7afee7307471cdd61d828c48b68e4c25.json
Run periodic cleanup after installing all packages
Library/Homebrew/cmd/install.rb
@@ -253,6 +253,8 @@ def install verbose: args.verbose?, ) + Cleanup.periodic_clean! + Homebrew.messages.display_messages(display_times: args.display_times?) rescue FormulaUnreadableError, FormulaClassUnavailableError, TapFormulaUnreadableError, TapFormulaClassUnavailableError => e
true
Other
Homebrew
brew
71ab2f6e7afee7307471cdd61d828c48b68e4c25.json
Run periodic cleanup after installing all packages
Library/Homebrew/cmd/reinstall.rb
@@ -151,6 +151,8 @@ def reinstall ) end + Cleanup.periodic_clean! + Homebrew.messages.display_messages(display_times: args.display_times?) end end
true
Other
Homebrew
brew
71ab2f6e7afee7307471cdd61d828c48b68e4c25.json
Run periodic cleanup after installing all packages
Library/Homebrew/cmd/upgrade.rb
@@ -110,6 +110,8 @@ def upgrade upgrade_outdated_formulae(formulae, args: args) unless only_upgrade_casks upgrade_outdated_casks(casks, args: args) unless only_upgrade_formulae + Cleanup.periodic_clean!(dry_run: args.dry_run?) + Homebrew.messages.display_messages(display_times: args.display_times?) end
true
Other
Homebrew
brew
78bf62ee5d05ca6d1fdaa30f48e2a6728968dce9.json
Apply suggestions from code review Co-authored-by: Adrian Ho <the.gromgit@gmail.com>
docs/Formula-Cookbook.md
@@ -554,7 +554,7 @@ on_linux do end ``` -Components can also be declared for specific macOS versions or version ranges. For example, to declare a dependency only on High Sierra, nest the `depends_on` call inside an `on_high_sierra` block. Add an `:or_older` or `:or_newer` parameter to the `on_high_sierra` method to add the dependency to all macOS versions that meet the condition. For example, to add `gettext` as a build dependency on Mojave and all macOS versions that are newer than Mojave, use: +Components can also be declared for specific macOS versions or version ranges. For example, to declare a dependency only on High Sierra, nest the `depends_on` call inside an `on_high_sierra` block. Add an `:or_older` or `:or_newer` parameter to the `on_high_sierra` method to add the dependency to all macOS versions that meet the condition. For example, to add `gettext` as a build dependency on Mojave and all later macOS versions, use: ```ruby on_mojave :or_newer do @@ -574,15 +574,15 @@ To check multiple conditions, nest the corresponding blocks. For example, the fo ```ruby on_macos do - on_intel do + on_arm do depends_on "gettext" => :build end end ``` #### Inside `def install` and `test do` -Inside `def install` and `test` do, don't use these `on_*` methods. Instead, use `if` statements and the following conditionals: +Inside `def install` and `test do`, don't use these `on_*` methods. Instead, use `if` statements and the following conditionals: * `OS.mac?` and `OS.linux?` return `true` or `false` based on the OS * `Hardware::CPU.intel?` and `Hardware::CPU.arm?` return `true` or `false` based on the arch
false
Other
Homebrew
brew
8c762d96879d598eaeb9e78abefadb2b6619f631.json
dev-cmd/contributions: Improve Sorbet typing Co-authored-by: Rylan Polster <rslpolster@gmail.com>
Library/Homebrew/dev-cmd/contributions.rb
@@ -38,7 +38,7 @@ def contributions_args end end - sig { returns(NilClass) } + sig { void } def contributions args = contributions_args.parse
false
Other
Homebrew
brew
5ecdf10e27f872d445be9947147071f13b280881.json
dev-cmd/contributions: Start output with the name/email Co-authored-by: Rylan Polster <rslpolster@gmail.com>
Library/Homebrew/dev-cmd/contributions.rb
@@ -65,7 +65,7 @@ def contributions coauthorships += git_log_coauthor_cmd(T.must(repo_path), args) end - sentence = "Person #{args.named.first} directly authored #{commits} commits " \ + sentence = "#{args.named.first} directly authored #{commits} commits " \ "and co-authored #{coauthorships} commits " \ "across #{all_repos ? "all Homebrew repos" : repos.to_sentence}" sentence += if args.from && args.to
false
Other
Homebrew
brew
0c7825accd9ad960cc045e503bb4edab3a955b2a.json
dev-cmd/contributions: Make the first arg either a name or email - This is easier than mapping GitHub usernames to email addresses, when folks don't have email addresses always public on their GitHub profiles. Also, the users of this command (PLC members, other interested parties) don't have to remember folks' email addresses. - It also gives better data for people who've changed their name over the years, and who commit with multiple email addresses (personal and work). ``` ❯ brew contributions "Issy Long" all Person Issy Long directly authored 687 commits and co-authored 33 commits across all Homebrew repos in all time. ❯ brew contributions "Rylan Polster" all Person Rylan Polster directly authored 1747 commits and co-authored 133 commits across all Homebrew repos in all time. ❯ brew contributions me@issyl0.co.uk all Person me@issyl0.co.uk directly authored 711 commits and co-authored 25 commits across all Homebrew repos in all time. ❯ brew contributions "Mike McQuaid" all Person Mike McQuaid directly authored 26879 commits and co-authored 204 commits across all Homebrew repos in all time. ```
Library/Homebrew/dev-cmd/contributions.rb
@@ -17,10 +17,12 @@ module Homebrew sig { returns(CLI::Parser) } def contributions_args Homebrew::CLI::Parser.new do - usage_banner "`contributions` <email> <repo1,repo2|all>" + usage_banner "`contributions` <email|name> <repo1,repo2|all>" description <<~EOS Contributions to Homebrew repos for a user. + The first argument is a name (e.g. "BrewTestBot") or an email address (e.g. "brewtestbot@brew.sh"). + The second argument is a comma-separated list of repos to search. Specify <all> to search all repositories. Supported repositories: #{SUPPORTED_REPOS.join(", ")}. @@ -32,7 +34,7 @@ def contributions_args flag "--to=", description: "Date (ISO-8601 format) to stop searching contributions." - named_args [:email, :repositories], min: 2, max: 2 + named_args [:email, :name, :repositories], min: 2, max: 2 end end
false
Other
Homebrew
brew
ae73f28d0fb6ccba90462fd9e0b5660a2c835d6b.json
dev-cmd/contributions: Use a named arg for required `repositories` - This is apparently "more in-keeping with how we do required arguments (never requiring flags)" across Homebrew. - New usage: `brew contributions me@issyl0.co.uk all`, `brew contributions me@issyl0.co.uk brew,core`
Library/Homebrew/dev-cmd/contributions.rb
@@ -17,9 +17,13 @@ module Homebrew sig { returns(CLI::Parser) } def contributions_args Homebrew::CLI::Parser.new do - usage_banner "`contributions` [<email>]" + usage_banner "`contributions` <email> <repo1,repo2|all>" description <<~EOS Contributions to Homebrew repos for a user. + + The second argument is a comma-separated list of repos to search. + Specify <all> to search all repositories. + Supported repositories: #{SUPPORTED_REPOS.join(", ")}. EOS flag "--from=", @@ -28,25 +32,20 @@ def contributions_args flag "--to=", description: "Date (ISO-8601 format) to stop searching contributions." - comma_array "--repositories=", - description: "The Homebrew repositories to search for contributions in. " \ - "Comma separated. Pass `all` to search all repositories. " \ - "Supported repositories: #{SUPPORTED_REPOS.join(", ")}." - - named_args :email, number: 1 + named_args [:email, :repositories], min: 2, max: 2 end end sig { returns(NilClass) } def contributions args = contributions_args.parse - return ofail "Please specify `--repositories` to search, or `--repositories=all`." unless args[:repositories].empty? commits = 0 coauthorships = 0 - all_repos = args.repositories.first == "all" - repos = all_repos ? SUPPORTED_REPOS : args.repositories + all_repos = args.named.last == "all" + repos = all_repos ? SUPPORTED_REPOS : args.named.last.split(",") + repos.each do |repo| if SUPPORTED_REPOS.exclude?(repo) return ofail "Unsupported repository: #{repo}. Try one of #{SUPPORTED_REPOS.join(", ")}."
false
Other
Homebrew
brew
c02e03a1798c383863ee87b7a14a66a122db6679.json
dev-cmd/contributions: Use methods to get arguments - I got these with hash syntax because I couldn't figure out Sorbet, but there's `args.rbi` to add the CLI args methods to. Nice! - In doing this I realised that `--repositories` is required again, we no longer infer `--repositories=all` from no `--repositories` passed as we did in a previous version of this.
Library/Homebrew/cli/args.rbi
@@ -300,6 +300,15 @@ module Homebrew sig { returns(T.nilable(String)) } def screen_saverdir; end + sig { returns(T::Array[String])} + def repositories; end + + sig { returns(T.nilable(String)) } + def from; end + + sig { returns(T.nilable(String)) } + def to; end + sig { returns(T.nilable(T::Array[String])) } def groups; end
true
Other
Homebrew
brew
c02e03a1798c383863ee87b7a14a66a122db6679.json
dev-cmd/contributions: Use methods to get arguments - I got these with hash syntax because I couldn't figure out Sorbet, but there's `args.rbi` to add the CLI args methods to. Nice! - In doing this I realised that `--repositories` is required again, we no longer infer `--repositories=all` from no `--repositories` passed as we did in a previous version of this.
Library/Homebrew/dev-cmd/contributions.rb
@@ -40,12 +40,13 @@ def contributions_args sig { returns(NilClass) } def contributions args = contributions_args.parse + return ofail "Please specify `--repositories` to search, or `--repositories=all`." unless args[:repositories].empty? commits = 0 coauthorships = 0 - all_repos = args[:repositories].first == "all" - repos = all_repos ? SUPPORTED_REPOS : args[:repositories] + all_repos = args.repositories.first == "all" + repos = all_repos ? SUPPORTED_REPOS : args.repositories repos.each do |repo| if SUPPORTED_REPOS.exclude?(repo) return ofail "Unsupported repository: #{repo}. Try one of #{SUPPORTED_REPOS.join(", ")}." @@ -66,12 +67,12 @@ def contributions sentence = "Person #{args.named.first} directly authored #{commits} commits " \ "and co-authored #{coauthorships} commits " \ "across #{all_repos ? "all Homebrew repos" : repos.to_sentence}" - sentence += if args[:from] && args[:to] - " between #{args[:from]} and #{args[:to]}" - elsif args[:from] - " after #{args[:from]}" - elsif args[:to] - " before #{args[:to]}" + sentence += if args.from && args.to + " between #{args.from} and #{args.to}" + elsif args.from + " after #{args.from}" + elsif args.to + " before #{args.to}" else " in all time" end @@ -90,8 +91,8 @@ def find_repo_path_for_repo(repo) sig { params(repo_path: Pathname, args: Homebrew::CLI::Args).returns(Integer) } def git_log_author_cmd(repo_path, args) cmd = ["git", "-C", repo_path, "log", "--oneline", "--author=#{args.named.first}"] - cmd << "--before=#{args[:to]}" if args[:to] - cmd << "--after=#{args[:from]}" if args[:from] + cmd << "--before=#{args.to}" if args.to + cmd << "--after=#{args.from}" if args.from Utils.safe_popen_read(*cmd).lines.count end @@ -100,8 +101,8 @@ def git_log_author_cmd(repo_path, args) def git_log_coauthor_cmd(repo_path, args) cmd = ["git", "-C", repo_path, "log", "--oneline"] cmd << "--format='%(trailers:key=Co-authored-by:)'" - cmd << "--before=#{args[:to]}" if args[:to] - cmd << "--after=#{args[:from]}" if args[:from] + cmd << "--before=#{args.to}" if args.to + cmd << "--after=#{args.from}" if args.from Utils.safe_popen_read(*cmd).lines.count { |l| l.include?(args.named.first) } end
true
Other
Homebrew
brew
63a1a078b9b101fd5654ffcdf099632f3f258851.json
dev-cmd/contributions: Improve `SUPPORTED_REPOS` array syntax Co-authored-by: Mike McQuaid <mike@mikemcquaid.com>
Library/Homebrew/dev-cmd/contributions.rb
@@ -8,11 +8,11 @@ module Homebrew module_function - SUPPORTED_REPOS = ( - %w[brew core cask] + - OFFICIAL_CMD_TAPS.keys.map { |t| t.delete_prefix("homebrew/") } + - OFFICIAL_CASK_TAPS - ).freeze + SUPPORTED_REPOS = [ + %w[brew core cask], + OFFICIAL_CMD_TAPS.keys.map { |t| t.delete_prefix("homebrew/") }, + OFFICIAL_CASK_TAPS, + ].flatten.freeze sig { returns(CLI::Parser) } def contributions_args
false
Other
Homebrew
brew
6f79b5dee292257692148017529f6b25badc47cb.json
Minor change: fix the argument for formulae
Library/Homebrew/livecheck/livecheck.rb
@@ -361,7 +361,7 @@ def run_checks( end puts if debug print_latest_version(info, verbose: verbose, ambiguous_cask: ambiguous_casks.include?(formula_or_cask), -check_resource: false) +resource: false) if check_resources && formula_or_cask.resources.present? resources_info = [] @@ -396,7 +396,7 @@ def run_checks( r_info, verbose: verbose, ambiguous_cask: false, - resource: true, + resource: true, ) end end
false
Other
Homebrew
brew
d5f949e60b6d78aa50f0409a2dfb50a63eaa554e.json
Check dependency order in on_system methods
Library/Homebrew/rubocops/components_order.rb
@@ -14,12 +14,6 @@ module FormulaAudit class ComponentsOrder < FormulaCop extend AutoCorrector - def on_system_methods - @on_system_methods ||= [:intel, :arm, :macos, :linux, :system, *MacOSVersions::SYMBOLS.keys].map do |m| - :"on_#{m}" - end - end - def audit_formula(_node, _class_node, _parent_class_node, body_node) @present_components, @offensive_nodes = check_order(FORMULA_COMPONENT_PRECEDENCE_LIST, body_node)
true
Other
Homebrew
brew
d5f949e60b6d78aa50f0409a2dfb50a63eaa554e.json
Check dependency order in on_system methods
Library/Homebrew/rubocops/dependency_order.rb
@@ -16,7 +16,7 @@ class DependencyOrder < FormulaCop def audit_formula(_node, _class_node, _parent_class_node, body_node) check_dependency_nodes_order(body_node) check_uses_from_macos_nodes_order(body_node) - [:head, :stable].each do |block_name| + ([:head, :stable] + on_system_methods).each do |block_name| block = find_block(body_node, block_name) next unless block
true
Other
Homebrew
brew
d5f949e60b6d78aa50f0409a2dfb50a63eaa554e.json
Check dependency order in on_system methods
Library/Homebrew/rubocops/extend/formula.rb
@@ -198,6 +198,12 @@ def file_path_allowed? @file_path !~ Regexp.union(paths_to_exclude) end + + def on_system_methods + @on_system_methods ||= [:intel, :arm, :macos, :linux, :system, *MacOSVersions::SYMBOLS.keys].map do |m| + :"on_#{m}" + end + end end end end
true
Other
Homebrew
brew
fec5b4080a87cb99e1aff19d36afcbbec4f725cf.json
linux/diagnostic: add check for versioned GCC linkage This complements my other two GCC-on-Linux PRs (#13631, #13633), however they are both reliant on bottles eventually being (re-)poured. Let's try to speed that up by returning an error message from `brew doctor` whenever a user has formulae installed that would benefit from a `brew reinstall`.
Library/Homebrew/extend/os/linux/diagnostic.rb
@@ -139,6 +139,34 @@ def check_linuxbrew_bottle_domain e.g. by using homebrew instead). EOS end + + def check_gcc_dependent_linkage + gcc_dependents = Formula.installed.select do |formula| + next false unless formula.tap&.core_tap? + + formula.recursive_dependencies.map(&:name).include? "gcc" + rescue TapFormulaUnavailableError + false + end + return if gcc_dependents.empty? + + badly_linked = gcc_dependents.select do |dependent| + keg = Keg.new(dependent.prefix) + keg.binary_executable_or_library_files.any? do |binary| + paths = binary.rpath.split(":") + versioned_linkage = paths.any? { |path| path.match?(%r{lib/gcc/\d+$}) } + unversioned_linkage = paths.any? { |path| path.match?(%r{lib/gcc/current$}) } + + versioned_linkage && !unversioned_linkage + end + end + return if badly_linked.empty? + + inject_file_list badly_linked, <<~EOS + Formulae which link to GCC through a versioned path were found. These formulae + are prone to breaking when GCC is updated. You should `brew reinstall` these formulae: + EOS + end end end end
false
Other
Homebrew
brew
e1f8fa2c9be199365e25cd1ab490095001c18aa8.json
Improve settings name This leads to a slightly more readable entry in `.git/config`.
Library/Homebrew/cmd/update-report.rb
@@ -294,7 +294,7 @@ def link_completions_manpages_and_docs(repository = HOMEBREW_REPOSITORY) def migrate_gcc_dependents_if_needed return if OS.mac? - return if Settings.read("gcc.dep.rpaths.migrated") == "true" + return if Settings.read("gcc-rpaths.fixed") == "true" Formula.installed.each do |formula| next unless formula.tap&.core_tap? @@ -309,7 +309,7 @@ def migrate_gcc_dependents_if_needed nil end - Settings.write "gcc.dep.rpaths.migrated", true + Settings.write "gcc-rpaths.fixed", true end end
false
Other
Homebrew
brew
023261038192a4f55c95a4d2486873ec1c9a728a.json
official_taps: Refer to`Homebrew/homebrew-cask-versions` properly - This is needed for https://github.com/Homebrew/brew/pull/13603 because `Homebrew/homebrew-versions` is deprecated (legitimately), but `OFFICIAL_CASK_TAPS` spits out `versions` as a repo, which could then be interpreted as `Homebrew/versions` rather than `Homebrew/cask-versions` which it actually is.
Library/Homebrew/official_taps.rb
@@ -3,7 +3,7 @@ OFFICIAL_CASK_TAPS = %w[ cask - versions + cask-versions ].freeze OFFICIAL_CMD_TAPS = {
false
Other
Homebrew
brew
7326019c93bb271899e379e524c7001e84d9c7eb.json
Add clarification comment
Library/Homebrew/extend/on_system.rb
@@ -32,6 +32,8 @@ def os_condition_met?(os_name, or_condition = nil) base_os = MacOS::Version.from_symbol(os_name) current_os = if Homebrew::SimulateSystem.current_os == :macos + # Assume the oldest macOS version when simulating a generic macOS version + # Version::NULL is always treated as less than any other version. Version::NULL else MacOS::Version.from_symbol(Homebrew::SimulateSystem.current_os)
false
Other
Homebrew
brew
d04051a9b94553fb4290929f12aeb5c72062d2aa.json
Add integration tests for autoremove cmd
Library/Homebrew/test/cmd/autoremove_spec.rb
@@ -5,4 +5,34 @@ describe "brew autoremove" do it_behaves_like "parseable arguments" + + describe "integration test" do + let(:requested_formula) { Formula["testball1"] } + let(:unused_formula) { Formula["testball2"] } + + before do + install_test_formula "testball1" + install_test_formula "testball2" + + # Make testball2 an unused dependency + tab = Tab.for_name("testball2") + tab.installed_on_request = false + tab.installed_as_dependency = true + tab.write + end + + it "only removes unused dependencies", :integration_test do + expect(requested_formula.any_version_installed?).to be true + expect(unused_formula.any_version_installed?).to be true + + # When there are unused dependencies + expect { brew "autoremove" } + .to be_a_success + .and output(/Autoremoving/).to_stdout + .and not_to_output.to_stderr + + expect(requested_formula.any_version_installed?).to be true + expect(unused_formula.any_version_installed?).to be false + end + end end
false
Other
Homebrew
brew
88a69b3de20e0faa12f8dee2c2298617d76b55ec.json
Restore previous style
Library/Homebrew/build.rb
@@ -78,17 +78,27 @@ def install ENV.keg_only_deps = keg_only_deps ENV.deps = formula_deps ENV.run_time_deps = run_time_deps - ENV.setup_build_environment(formula: formula, cc: args.cc, build_bottle: args.build_bottle?, - bottle_arch: args.bottle_arch, debug_symbols: args.debug_symbols?) + ENV.setup_build_environment( + formula: formula, + cc: args.cc, + build_bottle: args.build_bottle?, + bottle_arch: args.bottle_arch, + debug_symbols: args.debug_symbols?, + ) reqs.each do |req| req.modify_build_environment( env: args.env, cc: args.cc, build_bottle: args.build_bottle?, bottle_arch: args.bottle_arch, ) end deps.each(&:modify_build_environment) else - ENV.setup_build_environment(formula: formula, cc: args.cc, build_bottle: args.build_bottle?, - bottle_arch: args.bottle_arch, debug_symbols: args.debug_symbols?) + ENV.setup_build_environment( + formula: formula, + cc: args.cc, + build_bottle: args.build_bottle?, + bottle_arch: args.bottle_arch, + debug_symbols: args.debug_symbols?, + ) reqs.each do |req| req.modify_build_environment( env: args.env, cc: args.cc, build_bottle: args.build_bottle?, bottle_arch: args.bottle_arch,
false