From f8934c0255796a8cfd3537c79bf1258c637f6c3e Mon Sep 17 00:00:00 2001 From: Markus Reiter Date: Sat, 25 Jul 2020 21:33:48 +0200 Subject: [PATCH 01/22] Pass `args` in `Install` and `Messages` instead of using global `args`. --- Library/Homebrew/cmd/gist-logs.rb | 6 ++++-- Library/Homebrew/cmd/install.rb | 11 ++++++----- Library/Homebrew/cmd/migrate.rb | 4 ++-- Library/Homebrew/cmd/reinstall.rb | 9 ++++++--- Library/Homebrew/cmd/update-report.rb | 8 ++++---- Library/Homebrew/cmd/upgrade.rb | 6 ++++-- Library/Homebrew/formula_installer.rb | 5 ++--- Library/Homebrew/install.rb | 6 ++---- Library/Homebrew/messages.rb | 4 ++-- Library/Homebrew/migrator.rb | 6 +++--- Library/Homebrew/test/messages_spec.rb | 26 +++++++------------------- Library/Homebrew/upgrade.rb | 2 +- 12 files changed, 43 insertions(+), 50 deletions(-) diff --git a/Library/Homebrew/cmd/gist-logs.rb b/Library/Homebrew/cmd/gist-logs.rb index 346ee8ab6e..a7f95f353a 100644 --- a/Library/Homebrew/cmd/gist-logs.rb +++ b/Library/Homebrew/cmd/gist-logs.rb @@ -8,6 +8,8 @@ require "socket" require "cli/parser" module Homebrew + extend Install + module_function def gist_logs_args @@ -142,8 +144,8 @@ module Homebrew def gist_logs gist_logs_args.parse - Install.perform_preinstall_checks(all_fatal: true) - Install.perform_build_from_source_checks(all_fatal: true) + perform_preinstall_checks(all_fatal: true) + perform_build_from_source_checks(all_fatal: true) gistify_logs(args.resolved_formulae.first) end end diff --git a/Library/Homebrew/cmd/install.rb b/Library/Homebrew/cmd/install.rb index 7725ef1a11..71671228d4 100644 --- a/Library/Homebrew/cmd/install.rb +++ b/Library/Homebrew/cmd/install.rb @@ -10,10 +10,11 @@ require "cli/parser" require "upgrade" module Homebrew - module_function - + extend Install extend Search + module_function + def install_args Homebrew::CLI::Parser.new do usage_banner <<~EOS @@ -255,17 +256,17 @@ module Homebrew return if formulae.empty? - Install.perform_preinstall_checks + perform_preinstall_checks formulae.each do |f| - Migrator.migrate_if_needed(f) + Migrator.migrate_if_needed(f, force: args.force?) install_formula(f) Cleanup.install_formula_clean!(f) end check_installed_dependents(args: args) - Homebrew.messages.display_messages + Homebrew.messages.display_messages(display_times: args.display_times?) rescue FormulaUnreadableError, FormulaClassUnavailableError, TapFormulaUnreadableError, TapFormulaClassUnavailableError => e # Need to rescue before `FormulaUnavailableError` (superclass of this) diff --git a/Library/Homebrew/cmd/migrate.rb b/Library/Homebrew/cmd/migrate.rb index 55dde86513..a9d3619543 100644 --- a/Library/Homebrew/cmd/migrate.rb +++ b/Library/Homebrew/cmd/migrate.rb @@ -24,7 +24,7 @@ module Homebrew end def migrate - migrate_args.parse + args = migrate_args.parse args.resolved_formulae.each do |f| if f.oldname @@ -34,7 +34,7 @@ module Homebrew raise "#{rack} is a symlink" if rack.symlink? end - migrator = Migrator.new(f) + migrator = Migrator.new(f, force: args.force?) migrator.migrate end end diff --git a/Library/Homebrew/cmd/reinstall.rb b/Library/Homebrew/cmd/reinstall.rb index 2aca9cb7cd..8b32398e92 100644 --- a/Library/Homebrew/cmd/reinstall.rb +++ b/Library/Homebrew/cmd/reinstall.rb @@ -3,6 +3,7 @@ require "formula_installer" require "development_tools" require "messages" +require "install" require "reinstall" require "cli/parser" require "cleanup" @@ -12,6 +13,8 @@ require "cask/macos" require "upgrade" module Homebrew + extend Install + module_function def reinstall_args @@ -58,7 +61,7 @@ module Homebrew FormulaInstaller.prevent_build_flags unless DevelopmentTools.installed? - Install.perform_preinstall_checks + perform_preinstall_checks resolved_formulae, casks = args.resolved_formulae_casks resolved_formulae.each do |f| @@ -66,14 +69,14 @@ module Homebrew onoe "#{f.full_name} is pinned. You must unpin it to reinstall." next end - Migrator.migrate_if_needed(f) + Migrator.migrate_if_needed(f, force: args.force?) reinstall_formula(f, args: args) Cleanup.install_formula_clean!(f) end check_installed_dependents(args: args) - Homebrew.messages.display_messages + Homebrew.messages.display_messages(display_times: args.display_times?) return if casks.blank? diff --git a/Library/Homebrew/cmd/update-report.rb b/Library/Homebrew/cmd/update-report.rb index 587af66392..c9127e81d8 100644 --- a/Library/Homebrew/cmd/update-report.rb +++ b/Library/Homebrew/cmd/update-report.rb @@ -38,7 +38,7 @@ module Homebrew end def update_report - update_report_args.parse + args = update_report_args.parse if !Utils::Analytics.messages_displayed? && !Utils::Analytics.disabled? && @@ -122,7 +122,7 @@ module Homebrew else hub.dump(updated_formula_report: !args.preinstall?) hub.reporters.each(&:migrate_tap_migration) - hub.reporters.each(&:migrate_formula_rename) + hub.reporters.each { |r| r.migrate_formula_rename(force: args.force?) } CacheStoreDatabase.use(:descriptions) do |db| DescriptionCacheStore.new(db) .update_from_report!(hub) @@ -373,7 +373,7 @@ class Reporter end end - def migrate_formula_rename + def migrate_formula_rename(force:) Formula.installed.each do |formula| next unless Migrator.needs_migration?(formula) @@ -397,7 +397,7 @@ class Reporter next end - Migrator.migrate_if_needed(f) + Migrator.migrate_if_needed(f, force: force) end end diff --git a/Library/Homebrew/cmd/upgrade.rb b/Library/Homebrew/cmd/upgrade.rb index 8eccc812b4..0b50f13034 100644 --- a/Library/Homebrew/cmd/upgrade.rb +++ b/Library/Homebrew/cmd/upgrade.rb @@ -9,6 +9,8 @@ require "cask/utils" require "cask/macos" module Homebrew + extend Install + module_function def upgrade_args @@ -77,7 +79,7 @@ module Homebrew def upgrade_outdated_formulae(formulae) FormulaInstaller.prevent_build_flags unless DevelopmentTools.installed? - Install.perform_preinstall_checks + perform_preinstall_checks if formulae.blank? outdated = Formula.installed.select do |f| @@ -129,7 +131,7 @@ module Homebrew check_installed_dependents(args: args) - Homebrew.messages.display_messages + Homebrew.messages.display_messages(display_times: args.display_times?) end def upgrade_outdated_casks(casks) diff --git a/Library/Homebrew/formula_installer.rb b/Library/Homebrew/formula_installer.rb index c07d59b976..b06c788d83 100644 --- a/Library/Homebrew/formula_installer.rb +++ b/Library/Homebrew/formula_installer.rb @@ -21,6 +21,7 @@ require "cmd/install" require "find" class FormulaInstaller + include Homebrew::Install include FormulaCellarChecks extend Predicable @@ -239,9 +240,7 @@ class FormulaInstaller lock start_time = Time.now - if !formula.bottle_unneeded? && !pour_bottle? && DevelopmentTools.installed? - Homebrew::Install.perform_build_from_source_checks - end + perform_build_from_source_checks if !formula.bottle_unneeded? && !pour_bottle? && DevelopmentTools.installed? # not in initialize so upgrade can unlink the active keg before calling this # function but after instantiating this class so that it can avoid having to diff --git a/Library/Homebrew/install.rb b/Library/Homebrew/install.rb index f68572df08..a6bd00b252 100644 --- a/Library/Homebrew/install.rb +++ b/Library/Homebrew/install.rb @@ -7,8 +7,6 @@ require "development_tools" module Homebrew module Install - module_function - def check_cpu return if Hardware::CPU.intel? && Hardware::CPU.is_64_bit? @@ -40,11 +38,11 @@ module Homebrew end def check_cc_argv - return unless Homebrew.args.cc + return unless (cc = args.cc) @checks ||= Diagnostic::Checks.new opoo <<~EOS - You passed `--cc=#{Homebrew.args.cc}`. + You passed `--cc=#{cc}`. #{@checks.please_create_pull_requests} EOS end diff --git a/Library/Homebrew/messages.rb b/Library/Homebrew/messages.rb index d0b371a2ec..18187a8447 100644 --- a/Library/Homebrew/messages.rb +++ b/Library/Homebrew/messages.rb @@ -20,9 +20,9 @@ class Messages @install_times.push(formula: f.name, time: elapsed_time) end - def display_messages + def display_messages(display_times: false) display_caveats - display_install_times if Homebrew.args.display_times? + display_install_times if display_times end def display_caveats diff --git a/Library/Homebrew/migrator.rb b/Library/Homebrew/migrator.rb index 3329e164bc..30d0603b0e 100644 --- a/Library/Homebrew/migrator.rb +++ b/Library/Homebrew/migrator.rb @@ -97,18 +97,18 @@ class Migrator true end - def self.migrate_if_needed(formula) + def self.migrate_if_needed(formula, force:) return unless Migrator.needs_migration?(formula) begin - migrator = Migrator.new(formula) + migrator = Migrator.new(formula, force: force) migrator.migrate rescue => e onoe e end end - def initialize(formula, force: Homebrew.args.force?) + def initialize(formula, force: false) @oldname = formula.oldname @newname = formula.name raise MigratorNoOldnameError, formula unless oldname diff --git a/Library/Homebrew/test/messages_spec.rb b/Library/Homebrew/test/messages_spec.rb index 9bf48c58aa..fa97096d12 100644 --- a/Library/Homebrew/test/messages_spec.rb +++ b/Library/Homebrew/test/messages_spec.rb @@ -72,27 +72,20 @@ describe Messages do end end - # Homebrew.args OpenStruct usage cannot use verified doubles. - # rubocop:disable RSpec/VerifiedDoubles - context "when the --display-times argument is present" do - before do - allow(Homebrew).to receive(:args).and_return \ - double(display_times?: true, flags_only: ["--display-times"]) - end - - context "when install_times is empty" do - it "doesn't print any output" do - expect { messages.display_messages }.not_to output.to_stdout + context "when the `display_times` argument is true" do + context "when `install_times` is empty" do + it "doesn't print anything" do + expect { messages.display_messages(display_times: true) }.not_to output.to_stdout end end - context "when install_times is present" do + context "when `install_times` is present" do before do messages.formula_installed(test_formula, elapsed_time) end it "prints installation times" do - expect { messages.display_messages }.to output( + expect { messages.display_messages(display_times: true) }.to output( <<~EOS, ==> Installation times foo 1.100 s @@ -102,15 +95,10 @@ describe Messages do end end - context "when the --display-times argument isn't present" do - before do - allow(Homebrew).to receive(:args).and_return(double(display_times?: false)) - end - + context "when the `display_times` argument isn't specified" do it "doesn't print installation times" do expect { messages.display_messages }.not_to output.to_stdout end end - # rubocop:enable RSpec/VerifiedDoubles end end diff --git a/Library/Homebrew/upgrade.rb b/Library/Homebrew/upgrade.rb index 2e4ccb8d58..3a9a211129 100644 --- a/Library/Homebrew/upgrade.rb +++ b/Library/Homebrew/upgrade.rb @@ -26,7 +26,7 @@ module Homebrew end formulae_to_install.each do |f| - Migrator.migrate_if_needed(f) + Migrator.migrate_if_needed(f, force: args.force?) begin upgrade_formula(f, args: args) Cleanup.install_formula_clean!(f) From 24eff8f81ac6bf50916a61bfa28fb9e4d950499a Mon Sep 17 00:00:00 2001 From: Markus Reiter Date: Sun, 26 Jul 2020 07:24:14 +0200 Subject: [PATCH 02/22] Pass `args` in `SoftwareSpec` instead of using global `args`. --- Library/Homebrew/cli/args.rb | 7 +- Library/Homebrew/cli/parser.rb | 2 +- Library/Homebrew/cmd/--cache.rb | 10 +-- Library/Homebrew/formula.rb | 25 ++++-- Library/Homebrew/formulary.rb | 71 ++++++++++-------- Library/Homebrew/software_spec.rb | 8 +- Library/Homebrew/test/formulary_spec.rb | 2 +- Library/Homebrew/test/rubocop_spec.rb | 3 +- ...testball_bottle-0.1.yosemite.bottle.tar.gz | Bin 1731 -> 1991 bytes .../test/support/fixtures/failball.rb | 3 +- .../test/support/fixtures/testball.rb | 3 +- .../test/support/fixtures/testball_bottle.rb | 5 +- 12 files changed, 84 insertions(+), 55 deletions(-) diff --git a/Library/Homebrew/cli/args.rb b/Library/Homebrew/cli/args.rb index cc7a571764..cbc90fe507 100644 --- a/Library/Homebrew/cli/args.rb +++ b/Library/Homebrew/cli/args.rb @@ -86,7 +86,7 @@ module Homebrew require "formula" @formulae ||= (downcased_unique_named - casks).map do |name| - Formulary.factory(name, spec) + Formulary.factory(name, spec, force_bottle: force_bottle?, flags: flags_only) end.uniq(&:name).freeze end @@ -94,7 +94,7 @@ module Homebrew require "formula" @resolved_formulae ||= (downcased_unique_named - casks).map do |name| - Formulary.resolve(name, spec: spec(nil)) + Formulary.resolve(name, spec: spec(nil), force_bottle: force_bottle?, flags: flags_only) end.uniq(&:name).freeze end @@ -104,7 +104,8 @@ module Homebrew casks = [] downcased_unique_named.each do |name| - resolved_formulae << Formulary.resolve(name, spec: spec(nil)) + resolved_formulae << Formulary.resolve(name, spec: spec(nil), + force_bottle: force_bottle?, flags: flags_only) rescue FormulaUnavailableError begin casks << Cask::CaskLoader.load(name) diff --git a/Library/Homebrew/cli/parser.rb b/Library/Homebrew/cli/parser.rb index dafa7a59d2..64a5c3c495 100644 --- a/Library/Homebrew/cli/parser.rb +++ b/Library/Homebrew/cli/parser.rb @@ -360,7 +360,7 @@ module Homebrew named_args.map do |arg| next if arg.match?(HOMEBREW_CASK_TAP_CASK_REGEX) - Formulary.factory(arg, spec) + Formulary.factory(arg, spec, flags: @args.flags_only) end.compact.uniq(&:name) end end diff --git a/Library/Homebrew/cmd/--cache.rb b/Library/Homebrew/cmd/--cache.rb index 191f018c3f..9e2cf7acb5 100644 --- a/Library/Homebrew/cmd/--cache.rb +++ b/Library/Homebrew/cmd/--cache.rb @@ -33,13 +33,13 @@ module Homebrew end def __cache - __cache_args.parse + args = __cache_args.parse if args.no_named? puts HOMEBREW_CACHE elsif args.formula? args.named.each do |name| - print_formula_cache name + print_formula_cache name, args: args end elsif args.cask? args.named.each do |name| @@ -47,7 +47,7 @@ module Homebrew end else args.named.each do |name| - print_formula_cache name + print_formula_cache name, args: args rescue FormulaUnavailableError begin print_cask_cache name @@ -58,8 +58,8 @@ module Homebrew end end - def print_formula_cache(name) - formula = Formulary.factory name + def print_formula_cache(name, args:) + formula = Formulary.factory(name, force_bottle: args.force_bottle?, flags: args.flags_only) if fetch_bottle?(formula) puts formula.bottle.cached_download else diff --git a/Library/Homebrew/formula.rb b/Library/Homebrew/formula.rb index ab4734cf57..e1782990ab 100644 --- a/Library/Homebrew/formula.rb +++ b/Library/Homebrew/formula.rb @@ -101,6 +101,10 @@ class Formula # @private attr_reader :tap + # Whether or not to force the use of a bottle. + # @private + attr_reader :force_bottle + # The stable (and default) {SoftwareSpec} for this {Formula} # This contains all the attributes (e.g. URL, checksum) that apply to the # stable version of this formula. @@ -181,7 +185,7 @@ class Formula alias follow_installed_alias? follow_installed_alias # @private - def initialize(name, path, spec, alias_path: nil) + def initialize(name, path, spec, alias_path: nil, force_bottle: false) @name = name @path = path @alias_path = alias_path @@ -189,6 +193,8 @@ class Formula @revision = self.class.revision || 0 @version_scheme = self.class.version_scheme || 0 + @force_bottle = force_bottle + @tap = if path == Formulary.core_path(name) CoreTap.instance else @@ -273,7 +279,7 @@ class Formula # and is specified to this instance. def installed_alias_path path = build.source["path"] if build.is_a?(Tab) - return unless path&.match?(%r{#{HOMEBREW_TAP_DIR_REGEX}/Aliases}) + return unless path&.to_s&.match?(%r{#{HOMEBREW_TAP_DIR_REGEX}/Aliases}) return unless File.symlink?(path) path @@ -2372,6 +2378,15 @@ class Formula stable.build end + # @private + def build_flags + mod_name = to_s.split("::")[0..-2].join("::") + return [] if mod_name.empty? + + mod = const_get(mod_name) + mod.const_get(:BUILD_FLAGS) + end + # @!attribute [w] stable # Allows adding {.depends_on} and {Patch}es just to the {.stable} {SoftwareSpec}. # This is required instead of using a conditional. @@ -2385,7 +2400,7 @@ class Formula # depends_on "libffi" # end def stable(&block) - @stable ||= SoftwareSpec.new + @stable ||= SoftwareSpec.new(flags: build_flags) return @stable unless block_given? @stable.instance_eval(&block) @@ -2405,7 +2420,7 @@ class Formula # end # @private def devel(&block) - @devel ||= SoftwareSpec.new + @devel ||= SoftwareSpec.new(flags: build_flags) return @devel unless block_given? odeprecated "'devel' blocks in formulae", "'head' blocks or @-versioned formulae" @@ -2425,7 +2440,7 @@ class Formula # or (if autodetect fails): #
head "https://hg.is.awesome.but.git.has.won.example.com/", :using => :hg
def head(val = nil, specs = {}, &block) - @head ||= HeadSoftwareSpec.new + @head ||= HeadSoftwareSpec.new(flags: build_flags) if block_given? @head.instance_eval(&block) elsif val diff --git a/Library/Homebrew/formulary.rb b/Library/Homebrew/formulary.rb index 336f34f757..65ca197f4e 100644 --- a/Library/Homebrew/formulary.rb +++ b/Library/Homebrew/formulary.rb @@ -27,12 +27,14 @@ module Formulary cache.fetch(path) end - def self.load_formula(name, path, contents, namespace) + def self.load_formula(name, path, contents, namespace, flags:) raise "Formula loading disabled by HOMEBREW_DISABLE_LOAD_FORMULA!" if Homebrew::EnvConfig.disable_load_formula? mod = Module.new const_set(namespace, mod) + begin + mod.const_set(:BUILD_FLAGS, flags) mod.module_eval(contents, path) rescue NameError, ArgumentError, ScriptError => e $stderr.puts e.backtrace if Homebrew::EnvConfig.developer? @@ -51,16 +53,16 @@ module Formulary end end - def self.load_formula_from_path(name, path) + def self.load_formula_from_path(name, path, flags:) contents = path.open("r") { |f| ensure_utf8_encoding(f).read } namespace = "FormulaNamespace#{Digest::MD5.hexdigest(path.to_s)}" - klass = load_formula(name, path, contents, namespace) + klass = load_formula(name, path, contents, namespace, flags: flags) cache[path] = klass end - def self.resolve(name, spec: nil) + def self.resolve(name, spec: nil, force_bottle: false, flags: []) if name.include?("/") || File.exist?(name) - f = factory(name, *spec) + f = factory(name, *spec, force_bottle: force_bottle, flags: flags) if f.any_version_installed? tab = Tab.for_formula(f) resolved_spec = spec || tab.spec @@ -73,8 +75,8 @@ module Formulary end else rack = to_rack(name) - alias_path = factory(name).alias_path - f = from_rack(rack, *spec, alias_path: alias_path) + alias_path = factory(name, force_bottle: force_bottle, flags: flags).alias_path + f = from_rack(rack, *spec, alias_path: alias_path, force_bottle: force_bottle, flags: flags) end # If this formula was installed with an alias that has since changed, @@ -121,22 +123,23 @@ module Formulary # # `alias_path` can be overridden here in case an alias was used to refer to # a formula that was loaded in another way. - def get_formula(spec, alias_path: nil) - klass.new(name, path, spec, alias_path: alias_path || self.alias_path) + def get_formula(spec, alias_path: nil, force_bottle: false, flags: []) + klass(flags: flags) + .new(name, path, spec, alias_path: alias_path || self.alias_path, force_bottle: force_bottle) end - def klass - load_file unless Formulary.formula_class_defined?(path) + def klass(flags:) + load_file(flags: flags) unless Formulary.formula_class_defined?(path) Formulary.formula_class_get(path) end private - def load_file + def load_file(flags:) $stderr.puts "#{$PROGRAM_NAME} (#{self.class.name}): loading #{path}" if Homebrew.args.debug? raise FormulaUnavailableError, name unless path.file? - Formulary.load_formula_from_path(name, path) + Formulary.load_formula_from_path(name, path, flags: flags) end end @@ -161,10 +164,10 @@ module Formulary super name, Formulary.path(full_name) end - def get_formula(spec, **) + def get_formula(spec, force_bottle: false, flags: [], **) contents = Utils::Bottles.formula_contents @bottle_filename, name: name formula = begin - Formulary.from_contents name, @bottle_filename, contents, spec + Formulary.from_contents(name, @bottle_filename, contents, spec, force_bottle: force_bottle, flags: flags) rescue FormulaUnreadableError => e opoo <<~EOS Unreadable formula in #{@bottle_filename}: @@ -205,7 +208,7 @@ module Formulary super formula, HOMEBREW_CACHE_FORMULA/File.basename(uri.path) end - def load_file + def load_file(flags:) if url =~ %r{githubusercontent.com/[\w-]+/[\w-]+/[a-f0-9]{40}(/Formula)?/([\w+-.@]+).rb} formula_name = Regexp.last_match(2) odeprecated "Installation of #{formula_name} from a GitHub commit URL", @@ -270,7 +273,7 @@ module Formulary [name, path] end - def get_formula(spec, alias_path: nil) + def get_formula(spec, alias_path: nil, force_bottle: false, flags: []) super rescue FormulaUnreadableError => e raise TapFormulaUnreadableError.new(tap, name, e.formula_error), "", e.backtrace @@ -280,7 +283,7 @@ module Formulary raise TapFormulaUnavailableError.new(tap, name), "", e.backtrace end - def load_file + def load_file(flags:) super rescue MethodDeprecatedError => e e.issues_url = tap.issues_url || tap.to_s @@ -308,10 +311,10 @@ module Formulary super name, path end - def klass + def klass(flags:) $stderr.puts "#{$PROGRAM_NAME} (#{self.class.name}): loading #{path}" if Homebrew.args.debug? - namespace = "FormulaNamespace#{Digest::MD5.hexdigest(contents)}" - Formulary.load_formula(name, path, contents, namespace) + namespace = "FormulaNamespace#{Digest::MD5.hexdigest(contents.to_s)}" + Formulary.load_formula(name, path, contents, namespace, flags: flags) end end @@ -322,7 +325,7 @@ module Formulary # * a formula pathname # * a formula URL # * a local bottle reference - def self.factory(ref, spec = :stable, alias_path: nil, from: nil) + def self.factory(ref, spec = :stable, alias_path: nil, from: nil, force_bottle: false, flags: []) raise ArgumentError, "Formulae must have a ref!" unless ref cache_key = "#{ref}-#{spec}-#{alias_path}-#{from}" @@ -331,7 +334,8 @@ module Formulary return cache[:formulary_factory][cache_key] end - formula = loader_for(ref, from: from).get_formula(spec, alias_path: alias_path) + formula = loader_for(ref, from: from).get_formula(spec, alias_path: alias_path, + force_bottle: force_bottle, flags: flags) if factory_cached? cache[:formulary_factory] ||= {} cache[:formulary_factory][cache_key] ||= formula @@ -345,14 +349,15 @@ module Formulary # The :alias_path option will be used if the formula is found not to be # installed, and discarded if it is installed because the alias_path used # to install the formula will be set instead. - def self.from_rack(rack, spec = nil, alias_path: nil) + def self.from_rack(rack, spec = nil, alias_path: nil, force_bottle: false, flags: []) kegs = rack.directory? ? rack.subdirs.map { |d| Keg.new(d) } : [] keg = kegs.find(&:linked?) || kegs.find(&:optlinked?) || kegs.max_by(&:version) if keg from_keg(keg, spec, alias_path: alias_path) else - factory(rack.basename.to_s, spec || :stable, alias_path: alias_path, from: :rack) + factory(rack.basename.to_s, spec || :stable, alias_path: alias_path, from: :rack, + force_bottle: force_bottle, flags: flags) end end @@ -365,19 +370,22 @@ module Formulary # Return a Formula instance for the given keg. # It will auto resolve formula's spec when requested spec is nil - def self.from_keg(keg, spec = nil, alias_path: nil) + def self.from_keg(keg, spec = nil, alias_path: nil, force_bottle: false, flags: []) tab = Tab.for_keg(keg) tap = tab.tap spec ||= tab.spec f = if tap.nil? - factory(keg.rack.basename.to_s, spec, alias_path: alias_path, from: :keg) + factory(keg.rack.basename.to_s, spec, alias_path: alias_path, from: :keg, + force_bottle: force_bottle, flags: flags) else begin - factory("#{tap}/#{keg.rack.basename}", spec, alias_path: alias_path, from: :keg) + factory("#{tap}/#{keg.rack.basename}", spec, alias_path: alias_path, from: :keg, + force_bottle: force_bottle, flags: flags) rescue FormulaUnavailableError # formula may be migrated to different tap. Try to search in core and all taps. - factory(keg.rack.basename.to_s, spec, alias_path: alias_path, from: :keg) + factory(keg.rack.basename.to_s, spec, alias_path: alias_path, from: :keg, + force_bottle: force_bottle, flags: flags) end end f.build = tab @@ -387,8 +395,9 @@ module Formulary end # Return a Formula instance directly from contents - def self.from_contents(name, path, contents, spec = :stable) - FormulaContentsLoader.new(name, path, contents).get_formula(spec) + def self.from_contents(name, path, contents, spec = :stable, alias_path: nil, force_bottle: false, flags: []) + FormulaContentsLoader.new(name, path, contents) + .get_formula(spec, alias_path: alias_path, force_bottle: force_bottle, flags: flags) end def self.to_rack(ref) diff --git a/Library/Homebrew/software_spec.rb b/Library/Homebrew/software_spec.rb index 130bbd456b..170b4e5d8f 100644 --- a/Library/Homebrew/software_spec.rb +++ b/Library/Homebrew/software_spec.rb @@ -28,14 +28,14 @@ class SoftwareSpec :cached_download, :clear_cache, :checksum, :mirrors, :specs, :using, :version, :mirror, :downloader, *Checksum::TYPES - def initialize + def initialize(flags: []) @resource = Resource.new @resources = {} @dependency_collector = DependencyCollector.new @bottle_specification = BottleSpecification.new @patches = [] @options = Options.new - @flags = Homebrew.args.flags_only + @flags = flags @deprecated_flags = [] @deprecated_options = [] @build = BuildOptions.new(Options.create(@flags), options) @@ -87,7 +87,7 @@ class SoftwareSpec def bottled? bottle_specification.tag?(Utils::Bottles.tag) && \ - (bottle_specification.compatible_cellar? || Homebrew.args.force_bottle?) + (bottle_specification.compatible_cellar? || owner.force_bottle) end def bottle(disable_type = nil, disable_reason = nil, &block) @@ -234,7 +234,7 @@ class SoftwareSpec end class HeadSoftwareSpec < SoftwareSpec - def initialize + def initialize(flags: []) super @resource.version = Version.create("HEAD") end diff --git a/Library/Homebrew/test/formulary_spec.rb b/Library/Homebrew/test/formulary_spec.rb index 5458fc6e02..bbd6aca88a 100644 --- a/Library/Homebrew/test/formulary_spec.rb +++ b/Library/Homebrew/test/formulary_spec.rb @@ -16,7 +16,7 @@ describe Formulary do bottle do cellar :any_skip_relocation root_url "file://#{bottle_dir}" - sha256 "d48bbbe583dcfbfa608579724fc6f0328b3cd316935c6ea22f134610aaf2952f" => :#{Utils::Bottles.tag} + sha256 "8f9aecd233463da6a4ea55f5f88fc5841718c013f3e2a7941350d6130f1dc149" => :#{Utils::Bottles.tag} end def install diff --git a/Library/Homebrew/test/rubocop_spec.rb b/Library/Homebrew/test/rubocop_spec.rb index 533df81076..a5750a430c 100644 --- a/Library/Homebrew/test/rubocop_spec.rb +++ b/Library/Homebrew/test/rubocop_spec.rb @@ -13,7 +13,8 @@ describe "RuboCop" do end it "loads all Formula cops without errors" do - _, _, status = Open3.capture3("rubocop", TEST_FIXTURE_DIR/"testball.rb") + stdout, _, status = Open3.capture3("rubocop", TEST_FIXTURE_DIR/"testball.rb") + expect(stdout).to include("no offenses detected") expect(status).to be_a_success end end diff --git a/Library/Homebrew/test/support/fixtures/bottles/testball_bottle-0.1.yosemite.bottle.tar.gz b/Library/Homebrew/test/support/fixtures/bottles/testball_bottle-0.1.yosemite.bottle.tar.gz index 62ea6c264b94f8b22389d7ff0bdaf5914698136a..ee5eb8b4b4d53133d004a594455e1585fe627d5f 100644 GIT binary patch literal 1991 zcmV;&2RQg2iwFpnCmmk^19W9`bYfv_Y+qt;baZTGEif)IE_rWrWo>D6WiDcGbaZTG zE_7jX0PURLYa_=Uz(;3a@9JE0h8(4|A(?FMApv!@KeQ{`G}O9USBu(bBP*QKOSjSVTi>f5$^O7uKK~zLhMpzklLi!N}q3%OcR(1bI6bufhTMgSCq9@Hq+kQ+4`;>qA z%0{)gvZ7T=-z$~ZtNiuA8;i&(Ou%u8ZTpP#oBvnG&2!J3;>OfJg> zq2<^Hx8O#OljTgW(X<`ngAUWt-7Ojb;x{3hTU=8Q>)^4txV*Mnx>PA$)z&Me%jM0* z#oUT*_`1K7TlN~n@X5^_t@OE`n$P`;a zzmS&;Z2UJ7PJjIjI)%`xZsN5KyopojJ@i#D5}4nDq1W$?rm|SAR#GRGcqf(a=2Ut= zgU~ZDtm7NH2}4L7Y9k*IhnRHaS%D!QNyERJgnhav?6w`)Fgh!{7HJ_QPNc$oxfs^| z$J6>pc>haEZ~K=-*8V5L^UuY@eM1lGGsLWWcwB|fcq|w^{^zx$GvqH82VMWk=ZEzF zl6ZLhFTq=Ywg1U5O8@^ml=RsD98G0c|4$`oKYzL>$U*-g8v=Yj z2Dkrpy|qkqi}-z3%06El$F+Y!R(smNtV%HdZ#|qWALfL&e_6l{x>Ea+sLU&cyeiJA zyr8IpswjE+%emyq=wfjDA6M^xeETnma!>mgRfYBc6Tx)!Ai&kMtS`kyjlY90dwwHw z^cjpTQp2`uhqmt6uag&Cy+QCxnCqz>To%(0FyONe77fI^Q~2s*twL>dTdqwp6a%&Ot4p`3c(f{@c(L_|SNr zJFF+D>yn~ks^Aj+NV>6HgzGen*=i-9tTeMu%o~uy8+J4HBd(RCH);}pCb@1uT~O^f zv3JuaHM_;9w=f5DGp?^kI!EVHRn&Z;@*nj5r%oKlyXpCk_26|3+JiE9{a+UHO1}O5 zM}+`_L?u}Jp9Jsy_dowT1NIb32Ic3#+=YubP(0v9b6_-Wz4-mo4@;G`F2UKsI;q^< zSgu;ytoF#vcHA`H)2OpJsKJc06?TI6%GaMo=%>^^-?N}NjqY@0%pmk_cWZ!-k3q-R zsD1u$n!ELN(!W%!7P~xfS02*zPoeJgTY9K>r~jz@g*5NI3!)tvYp1)-_3F3)I-aKX z5FIrAKaOR~tLtl(PVR*??YNWvGimrFuIo{wsm1R(G(dhP&Bs@|;yWA9Lr$_LVmY22VAn>idWh34fOX&kf;{s!z{f&B!SgY~GX)KJ+OG&uj1UkLsEpG3*? zqjBV-z^99yx%82LD^0^6R{!??FMssiS7h?%?WcbIv*PJA4H-1F+8=?|*M88r^J!d3 z8Z)tJrw7cIX=(v;xfc@R!;`30Z{C4MG@(C?p3_CHhiU%<_S`^hPUW^uB0`}|b07hpMc z(>(#}shjQ#coosT*|YKffo6K2?itvjZqWI6(D{?pP4`77=L<6N_UHXBH{I9$M68l- z%GQD~GBm?>E!*AF>cnXhKiwj))gsr_9M8KEHIuMfLpSRXh@M$R+Lg_szh$QOHVA1= z-`k=mlfd1mYxML?6q0s$;%?i%=OWNzyNDhN3E^hThTmos4mlX|cr)<)k3FWtKj^sg zKL`K+)P4R(QAGh^aT14<#M|-emEsXO2Z|VPkLQSFPzac!r Z(m2a`5GTC+84SkB<^OHLGxGpk005q77SsR$ literal 1731 zcmV;!20Zy6iwFQRO37IO1MQsMZ`)K9z@4>YRX4Uu^Z@~4cU~Wc6cRg$lePlUmS(h~ zU8^?JI<{fi&Q0Uiu`Pde?Z(8UY7$j7J|rag6Oee}5g{H1;{}iqf5Ie~)Q2JMVGO85QLm05vWr_Hp^;3 z%w&Rk9U`X1Y$}z>q|zxOh}n#o;fS;s!ED8MJ;i}g+&M*?uPA0CIoYr+n>vbTId%J^ zOEjr*S`o?z9>q$tjO{Y0|E2j3hL#5^vrZ&aBNJT%D+Dz)h{D?Fsd+e>mlIk!nr*4cOiNKbr{)M!F z&;Ko9r~IFpn3!yak4NS|C9VJdXF&q;FA6OGc>mvfPM!!J_f*9#cT%lvk!B?wc_L`^ z{6A}1MRkeF8vM)~@@300ijVDMSMPt(^Pd2Ma6gbT@cfr5Q^TRlwbdi^54u; z59dQ_oPYSKmonA&zigJ}AKnA;`M)Ln^4A}KAA-6K$^j@xpxlCu8&Jof^g@y4$-%es z@8qW@Y81N~+hlsT0=+_hrm#h)YopEl9*q2QfxJf-y$$iL`sL#s_W`SqZRiBFbJsU? zG}m)C;A^LBoCbX|KO@(niPvCV!N>{y~pM5xZFp43@?KteW z!NzMnnD0#FD~vG~lxjRsW;IQA6Ji2F)73gU?J;Yc&h(P&(Mn>ds)Qg2f*=TjAjrNj z$F1C5{{8;)y{^?u?JF01xSQi0D`P$F%eQ0S{dOSsGwkYEZCk$Ge&d$^Cu|&9i-Xq6 za1Xb39^N?~tT7`q55Ll&TD{KRZXezW_pM$(7i^tfxjVgluRGXz;pXxSOufBljez#o zY~S(^-4}kmJ;MI4L(Z{(?3}0@Xz*@(=c5iNtbK&Q`yG^aD8YLpf*=TjAP9mW2!bF_ z91p7OcO(dcAP9mW2!bF8g6tJ+F7eATj{D+xIRBZozlC-J+DF?su8V|Iw~w`ja{)%8 zHk%VL8MWEGfQuZPo81-6AF!kSY|g+EYlF?7z~=i=o6U<3*B8Ws>CdY*Z8op_aA1;6 z%9dTvS7lWCz>KJmwZ!`4a=JM?NC;(C|VhWlp+&4Gc)MSYEiuaO0w-( zv!+s^(5{qaw!+c(XjPt?3%X;O99Yp!jx7rDVCSL^e{J7$Tb7U(({TNd-n?~JJFoxQ z{QZY;{ZB5PlQ<%_VsX+_zW%52_g}WJkAGYr?E4R4zU${dn~^qu|0R{qWYW0)s}*R5 z;<}^|<$5ScHF=Gkww#J@D4m29X^H5j?&*r5U!kYi4V1i2_${M@j}!I*2I!fDiU}o5 zdij(rpB^2{%knD;x@aqAQD#DM!al74qW$5w72*U;D{j!&PfXo-1>6$iQlpdz!b|8T zNSYdz>4IXAq80RmM4+DV9fR;C-Jt!+legscT8dFN@Tzj_6lm zkS9F#3cuNoTUJt1mM{ZD?DHqnBZIIV$!Lp<;m0UstxUCfh<#qSgFb2&!+3od9-ZNK z^}K;;!w9- Utils::Bottles.tag + sha256 "8f9aecd233463da6a4ea55f5f88fc5841718c013f3e2a7941350d6130f1dc149" => Utils::Bottles.tag end cxxstdlib_check :skip end From 28b007e24b80751e3b7393978f96d2c480053f1b Mon Sep 17 00:00:00 2001 From: Markus Reiter Date: Sun, 26 Jul 2020 09:44:10 +0200 Subject: [PATCH 03/22] Pass `args` in `audit` instead of using global `args`. --- Library/Homebrew/dev-cmd/audit.rb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Library/Homebrew/dev-cmd/audit.rb b/Library/Homebrew/dev-cmd/audit.rb index 97c1f4517f..0c4568cd94 100644 --- a/Library/Homebrew/dev-cmd/audit.rb +++ b/Library/Homebrew/dev-cmd/audit.rb @@ -127,6 +127,7 @@ module Homebrew } options[:style_offenses] = style_results.file_offenses(f.path) if style_results options[:display_cop_names] = args.display_cop_names? + options[:build_stable] = args.build_stable? fa = FormulaAuditor.new(f, options) fa.audit @@ -207,6 +208,7 @@ module Homebrew @new_formula = options[:new_formula] && !@versioned_formula @strict = options[:strict] @online = options[:online] + @build_stable = options[:build_stable] @git = options[:git] @display_cop_names = options[:display_cop_names] @only = options[:only] @@ -248,7 +250,7 @@ module Homebrew unversioned_name = unversioned_formula.basename(".rb") problem "#{formula} is versioned but no #{unversioned_name} formula exists" end - elsif Homebrew.args.build_stable? && formula.stable? && + elsif @build_stable && formula.stable? && !(versioned_formulae = formula.versioned_formulae).empty? versioned_aliases = formula.aliases.grep(/.@\d/) _, last_alias_version = versioned_formulae.map(&:name).last.split("@") From e9ade913c436fe3758598df756536e2f99af8366 Mon Sep 17 00:00:00 2001 From: Markus Reiter Date: Sun, 26 Jul 2020 09:44:16 +0200 Subject: [PATCH 04/22] Pass `args` in `man` instead of using global `args`. --- Library/Homebrew/dev-cmd/man.rb | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/Library/Homebrew/dev-cmd/man.rb b/Library/Homebrew/dev-cmd/man.rb index 8d864a7b29..92f1a88599 100644 --- a/Library/Homebrew/dev-cmd/man.rb +++ b/Library/Homebrew/dev-cmd/man.rb @@ -31,12 +31,12 @@ module Homebrew end def man - man_args.parse + args = man_args.parse odie "`brew man --link` is now done automatically by `brew update`." if args.link? Commands.rebuild_internal_commands_completion_list - regenerate_man_pages + regenerate_man_pages(args: args) if system "git", "-C", HOMEBREW_REPOSITORY, "diff", "--quiet", "docs/Manpage.md", "manpages", "completions" puts "No changes to manpage or completions output detected." @@ -45,15 +45,15 @@ module Homebrew end end - def regenerate_man_pages + def regenerate_man_pages(args:) Homebrew.install_bundler_gems! markup = build_man_page - convert_man_page(markup, TARGET_DOC_PATH/"Manpage.md") - convert_man_page(markup, TARGET_MAN_PATH/"brew.1") + convert_man_page(markup, TARGET_DOC_PATH/"Manpage.md", args: args) + convert_man_page(markup, TARGET_MAN_PATH/"brew.1", args: args) cask_markup = (SOURCE_PATH/"brew-cask.1.md").read - convert_man_page(cask_markup, TARGET_MAN_PATH/"brew-cask.1") + convert_man_page(cask_markup, TARGET_MAN_PATH/"brew-cask.1", args: args) end def build_man_page @@ -94,7 +94,7 @@ module Homebrew path.basename.to_s.sub(/\.(rb|sh)$/, "").sub(/^--/, "~~") end - def convert_man_page(markup, target) + def convert_man_page(markup, target, args:) manual = target.basename(".1") organisation = "Homebrew" @@ -148,7 +148,7 @@ module Homebrew def generate_cmd_manpages(cmd_paths) man_page_lines = [] - man_args = Homebrew.args + # preserve existing manpage order cmd_paths.sort_by(&method(:sort_key_for_path)) .each do |cmd_path| @@ -162,7 +162,7 @@ module Homebrew man_page_lines << cmd_man_page_lines end - Homebrew.args = man_args + man_page_lines.compact.join("\n") end From bd0346e083a62380427500883e148a8eab5ff8fe Mon Sep 17 00:00:00 2001 From: Markus Reiter Date: Sun, 26 Jul 2020 09:44:26 +0200 Subject: [PATCH 05/22] Pass `args` in `pr-automerge` instead of using global `args`. --- Library/Homebrew/dev-cmd/pr-automerge.rb | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/Library/Homebrew/dev-cmd/pr-automerge.rb b/Library/Homebrew/dev-cmd/pr-automerge.rb index 43d96af0ff..62c6db0395 100644 --- a/Library/Homebrew/dev-cmd/pr-automerge.rb +++ b/Library/Homebrew/dev-cmd/pr-automerge.rb @@ -32,15 +32,15 @@ module Homebrew end def pr_automerge - pr_automerge_args.parse + args = pr_automerge_args.parse - without_labels = Homebrew.args.without_labels || ["do not merge", "new formula"] - tap = Tap.fetch(Homebrew.args.tap || CoreTap.instance.name) + without_labels = args.without_labels || ["do not merge", "new formula"] + tap = Tap.fetch(args.tap || CoreTap.instance.name) query = "is:pr is:open repo:#{tap.full_name}" - query += Homebrew.args.ignore_failures? ? " -status:pending" : " status:success" - query += " review:approved" unless Homebrew.args.without_approval? - query += " label:\"#{args.with_label}\"" if Homebrew.args.with_label + query += args.ignore_failures? ? " -status:pending" : " status:success" + query += " review:approved" unless args.without_approval? + query += " label:\"#{args.with_label}\"" if args.with_label without_labels&.each { |label| query += " -label:\"#{label}\"" } odebug "Searching: #{query}" From 291eee74c430516fcd5560af1d7b29341f63a22d Mon Sep 17 00:00:00 2001 From: Markus Reiter Date: Sun, 26 Jul 2020 09:44:46 +0200 Subject: [PATCH 06/22] Pass `args` in `style` instead of using global `args`. --- Library/Homebrew/dev-cmd/style.rb | 2 +- Library/Homebrew/style.rb | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Library/Homebrew/dev-cmd/style.rb b/Library/Homebrew/dev-cmd/style.rb index 80ac45a233..a38f5b2363 100644 --- a/Library/Homebrew/dev-cmd/style.rb +++ b/Library/Homebrew/dev-cmd/style.rb @@ -51,7 +51,7 @@ module Homebrew only_cops = args.only_cops except_cops = args.except_cops - options = { fix: args.fix? } + options = { fix: args.fix?, display_cop_names: args.display_cop_names? } if only_cops options[:only_cops] = only_cops elsif except_cops diff --git a/Library/Homebrew/style.rb b/Library/Homebrew/style.rb index d36ebf37a6..c7a94df76b 100644 --- a/Library/Homebrew/style.rb +++ b/Library/Homebrew/style.rb @@ -16,7 +16,7 @@ module Homebrew check_style_impl(files, :json, **options) end - def check_style_impl(files, output_type, fix: false, except_cops: nil, only_cops: nil) + def check_style_impl(files, output_type, fix: false, except_cops: nil, only_cops: nil, display_cop_names: false) Homebrew.install_bundler_gems! require "rubocop" require "rubocops" @@ -78,7 +78,7 @@ module Homebrew case output_type when :print args << "--debug" if Homebrew.args.debug? - args << "--display-cop-names" if Homebrew.args.display_cop_names? + args << "--display-cop-names" if display_cop_names args << "--format" << "simple" if files.present? system(cache_env, "rubocop", *args) rubocop_success = $CHILD_STATUS.success? From 3a60d50bd3e77458b38fba01e0bddb2b134946fb Mon Sep 17 00:00:00 2001 From: Markus Reiter Date: Sun, 26 Jul 2020 09:44:56 +0200 Subject: [PATCH 07/22] Pass `args` in `reinstall` instead of using global `args`. --- Library/Homebrew/reinstall.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Library/Homebrew/reinstall.rb b/Library/Homebrew/reinstall.rb index b7916a94a7..eaaa82a10a 100644 --- a/Library/Homebrew/reinstall.rb +++ b/Library/Homebrew/reinstall.rb @@ -18,7 +18,7 @@ module Homebrew backup keg end - build_options = BuildOptions.new(Options.create(Homebrew.args.flags_only), f.options) + build_options = BuildOptions.new(Options.create(args.flags_only), f.options) options = build_options.used_options options |= f.build.used_options options &= f.options From 8d52fa909f5047355ed6c97e85a466e5d7ef2550 Mon Sep 17 00:00:00 2001 From: Markus Reiter Date: Sun, 26 Jul 2020 09:45:05 +0200 Subject: [PATCH 08/22] Pass `args` in `postinstall` instead of using global `args`. --- Library/Homebrew/postinstall.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Library/Homebrew/postinstall.rb b/Library/Homebrew/postinstall.rb index d35e3b886c..557fd3387a 100644 --- a/Library/Homebrew/postinstall.rb +++ b/Library/Homebrew/postinstall.rb @@ -10,13 +10,13 @@ require "cli/parser" require "cmd/postinstall" begin - Homebrew.postinstall_args.parse + args = Homebrew.postinstall_args.parse error_pipe = UNIXSocket.open(ENV["HOMEBREW_ERROR_PIPE"], &:recv_io) error_pipe.fcntl(Fcntl::F_SETFD, Fcntl::FD_CLOEXEC) trap("INT", old_trap) - formula = Homebrew.args.resolved_formulae.first + formula = args.resolved_formulae.first formula.extend(Debrew::Formula) if Homebrew.args.debug? formula.run_post_install rescue Exception => e # rubocop:disable Lint/RescueException From b3eca532fcee3322e5a9b364250c603d18d99c6e Mon Sep 17 00:00:00 2001 From: Markus Reiter Date: Sun, 26 Jul 2020 09:45:34 +0200 Subject: [PATCH 09/22] Pass `args` in `install` instead of using global `args`. --- Library/Homebrew/cmd/install.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Library/Homebrew/cmd/install.rb b/Library/Homebrew/cmd/install.rb index 71671228d4..a0da11894a 100644 --- a/Library/Homebrew/cmd/install.rb +++ b/Library/Homebrew/cmd/install.rb @@ -116,13 +116,13 @@ module Homebrew formulae = [] - unless Homebrew.args.casks.empty? + unless args.casks.empty? cask_args = [] cask_args << "--force" if args.force? cask_args << "--debug" if args.debug? cask_args << "--verbose" if args.verbose? - Homebrew.args.casks.each do |c| + args.casks.each do |c| ohai "brew cask install #{c} #{cask_args.join " "}" system("#{HOMEBREW_PREFIX}/bin/brew", "cask", "install", c, *cask_args) end From e14506e589623dee4de3967b9f338fccd97ea7dd Mon Sep 17 00:00:00 2001 From: Markus Reiter Date: Sun, 26 Jul 2020 09:45:26 +0200 Subject: [PATCH 10/22] Pass `args` in `uninstall` instead of using global `args`. --- Library/Homebrew/cmd/uninstall.rb | 25 ++++++++++++--------- Library/Homebrew/test/cmd/uninstall_spec.rb | 14 +++++------- 2 files changed, 19 insertions(+), 20 deletions(-) diff --git a/Library/Homebrew/cmd/uninstall.rb b/Library/Homebrew/cmd/uninstall.rb index 64b59a65d4..bc1703acd3 100644 --- a/Library/Homebrew/cmd/uninstall.rb +++ b/Library/Homebrew/cmd/uninstall.rb @@ -30,7 +30,7 @@ module Homebrew end def uninstall - uninstall_args.parse + args = uninstall_args.parse if args.force? casks = [] @@ -54,7 +54,9 @@ module Homebrew kegs_by_rack = all_kegs.group_by(&:rack) end - handle_unsatisfied_dependents(kegs_by_rack) + handle_unsatisfied_dependents(kegs_by_rack, + ignore_dependencies: args.ignore_dependencies?, + named_args: args.named) return if Homebrew.failed? kegs_by_rack.each do |rack, kegs| @@ -142,40 +144,41 @@ module Homebrew end end - def handle_unsatisfied_dependents(kegs_by_rack) - return if args.ignore_dependencies? + def handle_unsatisfied_dependents(kegs_by_rack, ignore_dependencies: false, named_args: []) + return if ignore_dependencies all_kegs = kegs_by_rack.values.flatten(1) - check_for_dependents all_kegs + check_for_dependents(all_kegs, named_args: named_args) rescue MethodDeprecatedError # Silently ignore deprecations when uninstalling. nil end - def check_for_dependents(kegs) + def check_for_dependents(kegs, named_args: []) return false unless result = Keg.find_some_installed_dependents(kegs) if Homebrew::EnvConfig.developer? - DeveloperDependentsMessage.new(*result).output + DeveloperDependentsMessage.new(*result, named_args: named_args).output else - NondeveloperDependentsMessage.new(*result).output + NondeveloperDependentsMessage.new(*result, named_args: named_args).output end true end class DependentsMessage - attr_reader :reqs, :deps + attr_reader :reqs, :deps, :named_args - def initialize(requireds, dependents) + def initialize(requireds, dependents, named_args: []) @reqs = requireds @deps = dependents + @named_args = named_args end protected def sample_command - "brew uninstall --ignore-dependencies #{Array(Homebrew.args.named).join(" ")}" + "brew uninstall --ignore-dependencies #{named_args.join(" ")}" end def are_required_by_deps diff --git a/Library/Homebrew/test/cmd/uninstall_spec.rb b/Library/Homebrew/test/cmd/uninstall_spec.rb index 696be790e3..f27ff096bf 100644 --- a/Library/Homebrew/test/cmd/uninstall_spec.rb +++ b/Library/Homebrew/test/cmd/uninstall_spec.rb @@ -28,7 +28,7 @@ describe Homebrew do end end - let(:opts) { { dependency.rack => [Keg.new(dependency.installed_prefix)] } } + let(:kegs_by_rack) { { dependency.rack => [Keg.new(dependency.installed_prefix)] } } before do [dependency, dependent].each do |f| @@ -53,7 +53,7 @@ describe Homebrew do ENV["HOMEBREW_DEVELOPER"] = "1" expect { - described_class.handle_unsatisfied_dependents(opts) + described_class.handle_unsatisfied_dependents(kegs_by_rack) }.to output(/Warning/).to_stderr expect(described_class).not_to have_failed @@ -61,19 +61,15 @@ describe Homebrew do specify "when not developer" do expect { - described_class.handle_unsatisfied_dependents(opts) + described_class.handle_unsatisfied_dependents(kegs_by_rack) }.to output(/Error/).to_stderr expect(described_class).to have_failed end - specify "when not developer and --ignore-dependencies is specified" do - described_class.args = described_class.args.dup if described_class.args.frozen? - expect(described_class.args).to receive(:ignore_dependencies?).and_return(true) - described_class.args.freeze - + specify "when not developer and `ignore_dependencies` is true" do expect { - described_class.handle_unsatisfied_dependents(opts) + described_class.handle_unsatisfied_dependents(kegs_by_rack, ignore_dependencies: true) }.not_to output.to_stderr expect(described_class).not_to have_failed From 919adcc216a090cabf9add72946ed788572f6586 Mon Sep 17 00:00:00 2001 From: Markus Reiter Date: Sun, 26 Jul 2020 09:45:18 +0200 Subject: [PATCH 11/22] Pass `args` in `update-report` instead of using global `args`. --- Library/Homebrew/cmd/update-report.rb | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/Library/Homebrew/cmd/update-report.rb b/Library/Homebrew/cmd/update-report.rb index c9127e81d8..abe5cc1c75 100644 --- a/Library/Homebrew/cmd/update-report.rb +++ b/Library/Homebrew/cmd/update-report.rb @@ -104,7 +104,7 @@ module Homebrew end if reporter.updated? updated_taps << tap.name - hub.add(reporter) + hub.add(reporter, preinstall: args.preinstall?) end end @@ -186,7 +186,7 @@ class Reporter raise ReporterRevisionUnsetError, current_revision_var if @current_revision.empty? end - def report + def report(preinstall: false) return @report if @report @report = Hash.new { |h, k| h[k] = [] } @@ -223,7 +223,7 @@ class Reporter name = tap.formula_file_to_name(src) # Skip reporting updated formulae to speed up automatic updates. - if Homebrew.args.preinstall? + if preinstall @report[:M] << name next end @@ -425,9 +425,9 @@ class ReporterHub @hash.fetch(key, []) end - def add(reporter) + def add(reporter, preinstall: false) @reporters << reporter - report = reporter.report.delete_if { |_k, v| v.empty? } + report = reporter.report(preinstall: preinstall).delete_if { |_k, v| v.empty? } @hash.update(report) { |_key, oldval, newval| oldval.concat(newval) } end From 620ca4177e9e987506050d36a506f8b8025ff6ee Mon Sep 17 00:00:00 2001 From: Markus Reiter Date: Sun, 26 Jul 2020 22:00:38 +0200 Subject: [PATCH 12/22] Pass `args` to `FormulaInstaller` instead of using global `args`. --- Library/Homebrew/cmd/--cache.rb | 2 +- Library/Homebrew/cmd/fetch.rb | 4 ++-- Library/Homebrew/cmd/install.rb | 2 +- Library/Homebrew/fetch.rb | 2 +- Library/Homebrew/formula_installer.rb | 29 +++++++++++++++------------ Library/Homebrew/reinstall.rb | 2 +- Library/Homebrew/upgrade.rb | 2 +- 7 files changed, 23 insertions(+), 20 deletions(-) diff --git a/Library/Homebrew/cmd/--cache.rb b/Library/Homebrew/cmd/--cache.rb index 9e2cf7acb5..bd6018efe4 100644 --- a/Library/Homebrew/cmd/--cache.rb +++ b/Library/Homebrew/cmd/--cache.rb @@ -60,7 +60,7 @@ module Homebrew def print_formula_cache(name, args:) formula = Formulary.factory(name, force_bottle: args.force_bottle?, flags: args.flags_only) - if fetch_bottle?(formula) + if fetch_bottle?(formula, args: args) puts formula.bottle.cached_download else puts formula.cached_download diff --git a/Library/Homebrew/cmd/fetch.rb b/Library/Homebrew/cmd/fetch.rb index e0dab2af95..fbf45cfcf2 100644 --- a/Library/Homebrew/cmd/fetch.rb +++ b/Library/Homebrew/cmd/fetch.rb @@ -46,7 +46,7 @@ module Homebrew end def fetch - fetch_args.parse + args = fetch_args.parse if args.deps? bucket = [] @@ -64,7 +64,7 @@ module Homebrew f.print_tap_action verb: "Fetching" fetched_bottle = false - if fetch_bottle?(f) + if fetch_bottle?(f, args: args) begin fetch_formula(f.bottle) rescue Interrupt diff --git a/Library/Homebrew/cmd/install.rb b/Library/Homebrew/cmd/install.rb index a0da11894a..29f6cd51b9 100644 --- a/Library/Homebrew/cmd/install.rb +++ b/Library/Homebrew/cmd/install.rb @@ -325,7 +325,7 @@ module Homebrew build_options = f.build fi = FormulaInstaller.new(f, force_bottle: args.force_bottle?, include_test: args.include_test?, - build_from_source: args.build_from_source?) + build_from_source: args.build_from_source?, args: args) fi.options = build_options.used_options fi.env = args.env fi.force = args.force? diff --git a/Library/Homebrew/fetch.rb b/Library/Homebrew/fetch.rb index 4db267aa72..b6941223cc 100644 --- a/Library/Homebrew/fetch.rb +++ b/Library/Homebrew/fetch.rb @@ -2,7 +2,7 @@ module Homebrew module Fetch - def fetch_bottle?(f) + def fetch_bottle?(f, args:) return true if args.force_bottle? && f.bottle return false unless f.bottle && f.pour_bottle? return false if args.build_formula_from_source?(f) diff --git a/Library/Homebrew/formula_installer.rb b/Library/Homebrew/formula_installer.rb index b06c788d83..126fb949a8 100644 --- a/Library/Homebrew/formula_installer.rb +++ b/Library/Homebrew/formula_installer.rb @@ -39,15 +39,16 @@ class FormulaInstaller end attr_reader :formula - attr_accessor :cc, :env, :options, :build_bottle, :bottle_arch, - :installed_as_dependency, :installed_on_request, :link_keg + attr_accessor :cc, :env, :args, :options, :build_bottle, :bottle_arch, + :installed_as_dependency, :installed_on_request, :link_keg, :other_installers mode_attr_accessor :show_summary_heading, :show_header mode_attr_accessor :build_from_source, :force_bottle, :include_test mode_attr_accessor :ignore_deps, :only_deps, :interactive, :git, :force, :keep_tmp mode_attr_accessor :verbose, :debug, :quiet - def initialize(formula, force_bottle: false, include_test: false, build_from_source: false, cc: nil) + def initialize(formula, force_bottle: false, include_test: false, build_from_source: false, cc: nil, args: nil) + @args = args @formula = formula @env = nil @force = false @@ -96,10 +97,10 @@ class FormulaInstaller # it's necessary to interrupt the user before any sort of installation # can proceed. Only invoked when the user has no developer tools. def self.prevent_build_flags - build_flags = Homebrew.args.collect_build_args - return if build_flags.empty? + build_flags = args&.collect_build_args + return if build_flags.blank? - all_bottled = Homebrew.args.formulae.all?(&:bottled?) + all_bottled = args.formulae.all?(&:bottled?) raise BuildFlagsError.new(build_flags, bottled: all_bottled) end @@ -145,7 +146,7 @@ class FormulaInstaller def install_bottle_for?(dep, build) return pour_bottle? if dep == formula - return false if Homebrew.args.build_formula_from_source?(dep) + return false if args&.build_formula_from_source?(dep) return false unless dep.bottle && dep.pour_bottle? return false unless build.used_options.empty? return false unless dep.bottle.compatible_cellar? @@ -504,7 +505,7 @@ class FormulaInstaller ) keep_build_test = false - keep_build_test ||= dep.test? && include_test? && Homebrew.args.include_formula_test_deps?(dependent) + keep_build_test ||= dep.test? && include_test? && args&.include_formula_test_deps?(dependent) keep_build_test ||= dep.build? && !install_bottle_for?(dependent, build) && !dependent.latest_version_installed? if dep.prune_from_option?(build) @@ -582,8 +583,9 @@ class FormulaInstaller def fetch_dependency(dep) df = dep.to_formula fi = FormulaInstaller.new(df, force_bottle: false, - include_test: Homebrew.args.include_formula_test_deps?(df), - build_from_source: Homebrew.args.build_formula_from_source?(df)) + include_test: args&.include_formula_test_deps?(df), + build_from_source: args&.build_formula_from_source?(df), + args: args) fi.force = force? fi.keep_tmp = keep_tmp? @@ -623,8 +625,9 @@ class FormulaInstaller end fi = FormulaInstaller.new(df, force_bottle: false, - include_test: Homebrew.args.include_formula_test_deps?(df), - build_from_source: Homebrew.args.build_formula_from_source?(df)) + include_test: args&.include_formula_test_deps?(df), + build_from_source: args&.build_formula_from_source?(df), + args: args) fi.options |= tab.used_options fi.options |= Tab.remap_deprecated_options(df.deprecated_options, dep.options) @@ -764,7 +767,7 @@ class FormulaInstaller formula.options.each do |opt| name = opt.name[/^([^=]+)=$/, 1] - value = Homebrew.args.value(name) if name + value = args&.value(name) if name args << "--#{name}=#{value}" if value end diff --git a/Library/Homebrew/reinstall.rb b/Library/Homebrew/reinstall.rb index eaaa82a10a..30c4bb17a1 100644 --- a/Library/Homebrew/reinstall.rb +++ b/Library/Homebrew/reinstall.rb @@ -24,7 +24,7 @@ module Homebrew options &= f.options fi = FormulaInstaller.new(f, force_bottle: args.force_bottle?, include_test: args.include_test?, - build_from_source: args.build_from_source?) + build_from_source: args.build_from_source?, args: args) fi.options = options fi.force = args.force? fi.keep_tmp = args.keep_tmp? diff --git a/Library/Homebrew/upgrade.rb b/Library/Homebrew/upgrade.rb index 3a9a211129..0f590652a8 100644 --- a/Library/Homebrew/upgrade.rb +++ b/Library/Homebrew/upgrade.rb @@ -64,7 +64,7 @@ module Homebrew options &= f.options fi = FormulaInstaller.new(f, force_bottle: args.force_bottle?, include_test: args.include_test?, - build_from_source: args.build_from_source?) + build_from_source: args.build_from_source?, args: args) fi.options = options fi.force = args.force? fi.keep_tmp = args.keep_tmp? From db467497ca883375e2bfe4dda48c3acdb09250fb Mon Sep 17 00:00:00 2001 From: Markus Reiter Date: Sun, 26 Jul 2020 22:27:51 +0200 Subject: [PATCH 13/22] Fix indentation. --- Library/Homebrew/cli/args.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Library/Homebrew/cli/args.rb b/Library/Homebrew/cli/args.rb index cbc90fe507..a184698945 100644 --- a/Library/Homebrew/cli/args.rb +++ b/Library/Homebrew/cli/args.rb @@ -105,7 +105,7 @@ module Homebrew downcased_unique_named.each do |name| resolved_formulae << Formulary.resolve(name, spec: spec(nil), - force_bottle: force_bottle?, flags: flags_only) + force_bottle: force_bottle?, flags: flags_only) rescue FormulaUnavailableError begin casks << Cask::CaskLoader.load(name) From ca18a7267310b2b839b4c7a2625e711e3013df9c Mon Sep 17 00:00:00 2001 From: Markus Reiter Date: Sun, 26 Jul 2020 11:53:05 +0200 Subject: [PATCH 14/22] Refactor `output_unsupported_error`. --- Library/Homebrew/brew.rb | 16 ++++++---------- Library/Homebrew/patch.rb | 5 +++++ Library/Homebrew/test/patching_spec.rb | 6 +++--- 3 files changed, 14 insertions(+), 13 deletions(-) diff --git a/Library/Homebrew/brew.rb b/Library/Homebrew/brew.rb index d86bc8298c..2fba870a71 100644 --- a/Library/Homebrew/brew.rb +++ b/Library/Homebrew/brew.rb @@ -35,13 +35,6 @@ rescue MissingEnvironmentVariables => e exec ENV["HOMEBREW_BREW_FILE"], *ARGV end -def output_unsupported_error - $stderr.puts <<~EOS - Please create pull requests instead of asking for help on Homebrew's GitHub, - Discourse, Twitter or IRC. - EOS -end - begin trap("INT", std_trap) # restore default CTRL-C handler @@ -150,7 +143,12 @@ rescue BuildError => e Utils::Analytics.report_build_error(e) e.dump - output_unsupported_error if e.formula.head? || e.formula.deprecated? || e.formula.disabled? + if e.formula.head? || e.formula.deprecated? || e.formula.disabled? + $stderr.puts <<~EOS + Please create pull requests instead of asking for help on Homebrew's GitHub, + Discourse, Twitter or IRC. + EOS + end exit 1 rescue RuntimeError, SystemCallError => e @@ -159,8 +157,6 @@ rescue RuntimeError, SystemCallError => e onoe e $stderr.puts e.backtrace if Homebrew.args.debug? - output_unsupported_error if Homebrew.args.HEAD? - exit 1 rescue MethodDeprecatedError => e onoe e diff --git a/Library/Homebrew/patch.rb b/Library/Homebrew/patch.rb index 03aea114e4..64ca28f97f 100644 --- a/Library/Homebrew/patch.rb +++ b/Library/Homebrew/patch.rb @@ -159,6 +159,11 @@ class ExternalPatch end end end + rescue ErrorDuringExecution => e + raise unless (f = resource.owner&.owner) + + cmd, *args = e.cmd + raise BuildError.new(f, cmd, args, ENV.to_hash) end def inspect diff --git a/Library/Homebrew/test/patching_spec.rb b/Library/Homebrew/test/patching_spec.rb index ffdf1027dc..737e140676 100644 --- a/Library/Homebrew/test/patching_spec.rb +++ b/Library/Homebrew/test/patching_spec.rb @@ -149,7 +149,7 @@ describe "patching" do end f.brew { |formula, _staging| formula.patch } - }.to raise_error(ErrorDuringExecution) + }.to raise_error(BuildError) end specify "single_patch_dsl_with_incorrect_strip_with_apply" do @@ -163,7 +163,7 @@ describe "patching" do end f.brew { |formula, _staging| formula.patch } - }.to raise_error(ErrorDuringExecution) + }.to raise_error(BuildError) end specify "patch_p0_dsl" do @@ -219,7 +219,7 @@ describe "patching" do end f.brew { |formula, _staging| formula.patch } - }.to raise_error(ErrorDuringExecution) + }.to raise_error(BuildError) end end From 20bd4280ff9f61c09f2268144c1784b8f659e39b Mon Sep 17 00:00:00 2001 From: Markus Reiter Date: Mon, 27 Jul 2020 11:37:07 +0200 Subject: [PATCH 15/22] Pass `args.cc` to `Install`. --- Library/Homebrew/cmd/gist-logs.rb | 4 ++-- Library/Homebrew/cmd/install.rb | 3 +-- Library/Homebrew/cmd/reinstall.rb | 4 +--- Library/Homebrew/cmd/upgrade.rb | 4 +--- Library/Homebrew/extend/os/linux/install.rb | 4 ++-- Library/Homebrew/install.rb | 10 ++++++---- 6 files changed, 13 insertions(+), 16 deletions(-) diff --git a/Library/Homebrew/cmd/gist-logs.rb b/Library/Homebrew/cmd/gist-logs.rb index a7f95f353a..912266b6df 100644 --- a/Library/Homebrew/cmd/gist-logs.rb +++ b/Library/Homebrew/cmd/gist-logs.rb @@ -144,8 +144,8 @@ module Homebrew def gist_logs gist_logs_args.parse - perform_preinstall_checks(all_fatal: true) - perform_build_from_source_checks(all_fatal: true) + Install.perform_preinstall_checks(all_fatal: true) + Install.perform_build_from_source_checks(all_fatal: true) gistify_logs(args.resolved_formulae.first) end end diff --git a/Library/Homebrew/cmd/install.rb b/Library/Homebrew/cmd/install.rb index 29f6cd51b9..52a3b18ca3 100644 --- a/Library/Homebrew/cmd/install.rb +++ b/Library/Homebrew/cmd/install.rb @@ -10,7 +10,6 @@ require "cli/parser" require "upgrade" module Homebrew - extend Install extend Search module_function @@ -256,7 +255,7 @@ module Homebrew return if formulae.empty? - perform_preinstall_checks + Install.perform_preinstall_checks(cc: args.cc) formulae.each do |f| Migrator.migrate_if_needed(f, force: args.force?) diff --git a/Library/Homebrew/cmd/reinstall.rb b/Library/Homebrew/cmd/reinstall.rb index 8b32398e92..0ccecf0973 100644 --- a/Library/Homebrew/cmd/reinstall.rb +++ b/Library/Homebrew/cmd/reinstall.rb @@ -13,8 +13,6 @@ require "cask/macos" require "upgrade" module Homebrew - extend Install - module_function def reinstall_args @@ -61,7 +59,7 @@ module Homebrew FormulaInstaller.prevent_build_flags unless DevelopmentTools.installed? - perform_preinstall_checks + Install.perform_preinstall_checks resolved_formulae, casks = args.resolved_formulae_casks resolved_formulae.each do |f| diff --git a/Library/Homebrew/cmd/upgrade.rb b/Library/Homebrew/cmd/upgrade.rb index 0b50f13034..012172bcc4 100644 --- a/Library/Homebrew/cmd/upgrade.rb +++ b/Library/Homebrew/cmd/upgrade.rb @@ -9,8 +9,6 @@ require "cask/utils" require "cask/macos" module Homebrew - extend Install - module_function def upgrade_args @@ -79,7 +77,7 @@ module Homebrew def upgrade_outdated_formulae(formulae) FormulaInstaller.prevent_build_flags unless DevelopmentTools.installed? - perform_preinstall_checks + Install.perform_preinstall_checks if formulae.blank? outdated = Formula.installed.select do |f| diff --git a/Library/Homebrew/extend/os/linux/install.rb b/Library/Homebrew/extend/os/linux/install.rb index 7940896db0..073c0c813d 100644 --- a/Library/Homebrew/extend/os/linux/install.rb +++ b/Library/Homebrew/extend/os/linux/install.rb @@ -43,8 +43,8 @@ module Homebrew FileUtils.ln_sf ld_so, brew_ld_so end - def perform_preinstall_checks(all_fatal: false) - generic_perform_preinstall_checks(all_fatal: all_fatal) + def perform_preinstall_checks(all_fatal: false, cc: nil) + generic_perform_preinstall_checks(all_fatal: all_fatal, cc: cc) symlink_ld_so end end diff --git a/Library/Homebrew/install.rb b/Library/Homebrew/install.rb index a6bd00b252..f858d8f9d8 100644 --- a/Library/Homebrew/install.rb +++ b/Library/Homebrew/install.rb @@ -7,6 +7,8 @@ require "development_tools" module Homebrew module Install + module_function + def check_cpu return if Hardware::CPU.intel? && Hardware::CPU.is_64_bit? @@ -37,8 +39,8 @@ module Homebrew end end - def check_cc_argv - return unless (cc = args.cc) + def check_cc_argv(cc) + return unless cc @checks ||= Diagnostic::Checks.new opoo <<~EOS @@ -47,10 +49,10 @@ module Homebrew EOS end - def perform_preinstall_checks(all_fatal: false) + def perform_preinstall_checks(all_fatal: false, cc: nil) check_cpu attempt_directory_creation - check_cc_argv + check_cc_argv(cc) diagnostic_checks(:supported_configuration_checks, fatal: all_fatal) diagnostic_checks(:fatal_preinstall_checks) end From bdb986f5723ef15f52254f8618f0cc832b32a89a Mon Sep 17 00:00:00 2001 From: Markus Reiter Date: Mon, 27 Jul 2020 11:42:38 +0200 Subject: [PATCH 16/22] Revert unnecessary change. --- Library/Homebrew/formula.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Library/Homebrew/formula.rb b/Library/Homebrew/formula.rb index e1782990ab..ff180c4d22 100644 --- a/Library/Homebrew/formula.rb +++ b/Library/Homebrew/formula.rb @@ -279,7 +279,7 @@ class Formula # and is specified to this instance. def installed_alias_path path = build.source["path"] if build.is_a?(Tab) - return unless path&.to_s&.match?(%r{#{HOMEBREW_TAP_DIR_REGEX}/Aliases}) + return unless path&.match?(%r{#{HOMEBREW_TAP_DIR_REGEX}/Aliases}) return unless File.symlink?(path) path From 36458b2356388a299d6b4a8b1d1053baf910efae Mon Sep 17 00:00:00 2001 From: Markus Reiter Date: Mon, 27 Jul 2020 11:50:40 +0200 Subject: [PATCH 17/22] Remove unnecessary check. --- Library/Homebrew/patch.rb | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/Library/Homebrew/patch.rb b/Library/Homebrew/patch.rb index 64ca28f97f..f2a92a0616 100644 --- a/Library/Homebrew/patch.rb +++ b/Library/Homebrew/patch.rb @@ -160,8 +160,7 @@ class ExternalPatch end end rescue ErrorDuringExecution => e - raise unless (f = resource.owner&.owner) - + f = resource.owner.owner cmd, *args = e.cmd raise BuildError.new(f, cmd, args, ENV.to_hash) end From c470a6ff433c4f5303ff74417693251cf9724499 Mon Sep 17 00:00:00 2001 From: Markus Reiter Date: Tue, 28 Jul 2020 12:55:46 +0200 Subject: [PATCH 18/22] Pass `args` directly to `prevent_build_flags`. --- Library/Homebrew/cli/args.rb | 13 ------------- Library/Homebrew/cmd/install.rb | 2 +- Library/Homebrew/cmd/reinstall.rb | 2 +- Library/Homebrew/cmd/upgrade.rb | 6 +++--- Library/Homebrew/formula_installer.rb | 18 +++++++++++++----- 5 files changed, 18 insertions(+), 23 deletions(-) diff --git a/Library/Homebrew/cli/args.rb b/Library/Homebrew/cli/args.rb index a184698945..b7dc3e787c 100644 --- a/Library/Homebrew/cli/args.rb +++ b/Library/Homebrew/cli/args.rb @@ -69,19 +69,6 @@ module Homebrew named.blank? end - # If the user passes any flags that trigger building over installing from - # a bottle, they are collected here and returned as an Array for checking. - def collect_build_args - build_flags = [] - - build_flags << "--HEAD" if HEAD? - build_flags << "--universal" if build_universal? - build_flags << "--build-bottle" if build_bottle? - build_flags << "--build-from-source" if build_from_source? - - build_flags - end - def formulae require "formula" diff --git a/Library/Homebrew/cmd/install.rb b/Library/Homebrew/cmd/install.rb index 52a3b18ca3..74bb0bc285 100644 --- a/Library/Homebrew/cmd/install.rb +++ b/Library/Homebrew/cmd/install.rb @@ -129,7 +129,7 @@ module Homebrew # if the user's flags will prevent bottle only-installations when no # developer tools are available, we need to stop them early on - FormulaInstaller.prevent_build_flags unless DevelopmentTools.installed? + FormulaInstaller.prevent_build_flags(args) args.formulae.each do |f| # head-only without --HEAD is an error diff --git a/Library/Homebrew/cmd/reinstall.rb b/Library/Homebrew/cmd/reinstall.rb index 0ccecf0973..ea1bca1ace 100644 --- a/Library/Homebrew/cmd/reinstall.rb +++ b/Library/Homebrew/cmd/reinstall.rb @@ -57,7 +57,7 @@ module Homebrew def reinstall args = reinstall_args.parse - FormulaInstaller.prevent_build_flags unless DevelopmentTools.installed? + FormulaInstaller.prevent_build_flags(args) Install.perform_preinstall_checks diff --git a/Library/Homebrew/cmd/upgrade.rb b/Library/Homebrew/cmd/upgrade.rb index 012172bcc4..aa1a4c51e7 100644 --- a/Library/Homebrew/cmd/upgrade.rb +++ b/Library/Homebrew/cmd/upgrade.rb @@ -70,12 +70,12 @@ module Homebrew named_formulae_specified = !formulae.empty? && casks.empty? named_casks_specified = !casks.empty? && formulae.empty? - upgrade_outdated_formulae(formulae) unless named_casks_specified + upgrade_outdated_formulae(formulae, args: args) unless named_casks_specified upgrade_outdated_casks(casks) unless named_formulae_specified end - def upgrade_outdated_formulae(formulae) - FormulaInstaller.prevent_build_flags unless DevelopmentTools.installed? + def upgrade_outdated_formulae(formulae, args:) + FormulaInstaller.prevent_build_flags(args) Install.perform_preinstall_checks diff --git a/Library/Homebrew/formula_installer.rb b/Library/Homebrew/formula_installer.rb index 126fb949a8..d939251705 100644 --- a/Library/Homebrew/formula_installer.rb +++ b/Library/Homebrew/formula_installer.rb @@ -95,10 +95,18 @@ class FormulaInstaller # When no build tools are available and build flags are passed through ARGV, # it's necessary to interrupt the user before any sort of installation - # can proceed. Only invoked when the user has no developer tools. - def self.prevent_build_flags - build_flags = args&.collect_build_args - return if build_flags.blank? + # can proceed. Only raises when the user has no developer tools. + def self.prevent_build_flags(args) + return if DevelopmentTools.installed? + + build_flags = [] + + build_flags << "--HEAD" if args.HEAD? + build_flags << "--universal" if args.universal? + build_flags << "--build-bottle" if args.build_bottle? + build_flags << "--build-from-source" if args.build_from_source? + + return if build_flags.empty? all_bottled = args.formulae.all?(&:bottled?) raise BuildFlagsError.new(build_flags, bottled: all_bottled) @@ -475,7 +483,7 @@ class FormulaInstaller if req.prune_from_option?(build) Requirement.prune - elsif req.satisfied?(args: Homebrew.args) + elsif req.satisfied?(args: args) Requirement.prune elsif (req.build? || req.test?) && !keep_build_test Requirement.prune From 05365b5542550baec39b7a6d807ea94f47a8c212 Mon Sep 17 00:00:00 2001 From: Markus Reiter Date: Tue, 28 Jul 2020 14:08:40 +0200 Subject: [PATCH 19/22] Pass `args` more explicitly in `FormulaInstaller`. --- Library/Homebrew/build.rb | 12 +++++++-- Library/Homebrew/cli/args.rb | 22 ++++++++-------- Library/Homebrew/cmd/info.rb | 2 +- Library/Homebrew/cmd/install.rb | 12 ++++++--- Library/Homebrew/fetch.rb | 2 +- Library/Homebrew/formula_installer.rb | 25 ++++++++++++------- Library/Homebrew/reinstall.rb | 6 +++-- Library/Homebrew/requirement.rb | 15 ++++++----- .../Homebrew/test/java_requirement_spec.rb | 18 ++++++------- .../test/os/mac/java_requirement_spec.rb | 10 +++----- Library/Homebrew/test/requirement_spec.rb | 20 +++++++-------- .../requirements/linux_requirement_spec.rb | 4 +-- .../requirements/macos_requirement_spec.rb | 8 +++--- .../requirements/osxfuse_requirement_spec.rb | 8 +++--- Library/Homebrew/test/x11_requirement_spec.rb | 8 +++--- 15 files changed, 92 insertions(+), 80 deletions(-) diff --git a/Library/Homebrew/build.rb b/Library/Homebrew/build.rb index ae725d66ed..2313210c8a 100644 --- a/Library/Homebrew/build.rb +++ b/Library/Homebrew/build.rb @@ -97,7 +97,11 @@ class Build bottle_arch: args.bottle_arch, ) post_superenv_hacks - reqs.each { |req| req.modify_build_environment(args: args) } + 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( @@ -106,7 +110,11 @@ class Build build_bottle: args.build_bottle?, bottle_arch: args.bottle_arch, ) - reqs.each { |req| req.modify_build_environment(args: args) } + 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) keg_only_deps.each do |dep| diff --git a/Library/Homebrew/cli/args.rb b/Library/Homebrew/cli/args.rb index b7dc3e787c..db5df5c245 100644 --- a/Library/Homebrew/cli/args.rb +++ b/Library/Homebrew/cli/args.rb @@ -150,18 +150,20 @@ module Homebrew !(HEAD? || devel?) end - # Whether a given formula should be built from source during the current - # installation run. - def build_formula_from_source?(f) - return false if !build_from_source? && !build_bottle? - - formulae.any? { |args_f| args_f.full_name == f.full_name } + def build_from_source_formulae + if build_from_source? || build_bottle? + formulae.map(&:full_name) + else + [] + end end - def include_formula_test_deps?(f) - return false unless include_test? - - formulae.any? { |args_f| args_f.full_name == f.full_name } + def include_test_formulae + if include_test? + formulae.map(&:full_name) + else + [] + end end def value(name) diff --git a/Library/Homebrew/cmd/info.rb b/Library/Homebrew/cmd/info.rb index 8a3cb6ae52..c43101e7f7 100644 --- a/Library/Homebrew/cmd/info.rb +++ b/Library/Homebrew/cmd/info.rb @@ -256,7 +256,7 @@ module Homebrew def decorate_requirements(requirements) req_status = requirements.map do |req| req_s = req.display_s - req.satisfied?(args: args) ? pretty_installed(req_s) : pretty_uninstalled(req_s) + req.satisfied? ? pretty_installed(req_s) : pretty_uninstalled(req_s) end req_status.join(", ") end diff --git a/Library/Homebrew/cmd/install.rb b/Library/Homebrew/cmd/install.rb index 74bb0bc285..6150c0dd9f 100644 --- a/Library/Homebrew/cmd/install.rb +++ b/Library/Homebrew/cmd/install.rb @@ -259,7 +259,7 @@ module Homebrew formulae.each do |f| Migrator.migrate_if_needed(f, force: args.force?) - install_formula(f) + install_formula(f, args: args) Cleanup.install_formula_clean!(f) end @@ -319,12 +319,16 @@ module Homebrew end end - def install_formula(f) + def install_formula(f, args:) f.print_tap_action build_options = f.build - fi = FormulaInstaller.new(f, force_bottle: args.force_bottle?, include_test: args.include_test?, - build_from_source: args.build_from_source?, args: args) + fi = FormulaInstaller.new(f, force_bottle: args.force_bottle?, + include_test: args.include_test?, + include_test_formulae: args.include_test_formulae, + build_from_source: args.build_from_source?, + build_from_source_formulae: args.build_from_source_formulae, + args: args) fi.options = build_options.used_options fi.env = args.env fi.force = args.force? diff --git a/Library/Homebrew/fetch.rb b/Library/Homebrew/fetch.rb index b6941223cc..7b0e76cd85 100644 --- a/Library/Homebrew/fetch.rb +++ b/Library/Homebrew/fetch.rb @@ -5,7 +5,7 @@ module Homebrew def fetch_bottle?(f, args:) return true if args.force_bottle? && f.bottle return false unless f.bottle && f.pour_bottle? - return false if args.build_formula_from_source?(f) + return false if args.build_from_source_formulae.include?(f.full_name) return false unless f.bottle.compatible_cellar? true diff --git a/Library/Homebrew/formula_installer.rb b/Library/Homebrew/formula_installer.rb index d939251705..669df60645 100644 --- a/Library/Homebrew/formula_installer.rb +++ b/Library/Homebrew/formula_installer.rb @@ -40,6 +40,7 @@ class FormulaInstaller attr_reader :formula attr_accessor :cc, :env, :args, :options, :build_bottle, :bottle_arch, + :build_from_source_formulae, :include_test_formulae, :installed_as_dependency, :installed_on_request, :link_keg, :other_installers mode_attr_accessor :show_summary_heading, :show_header @@ -47,7 +48,11 @@ class FormulaInstaller mode_attr_accessor :ignore_deps, :only_deps, :interactive, :git, :force, :keep_tmp mode_attr_accessor :verbose, :debug, :quiet - def initialize(formula, force_bottle: false, include_test: false, build_from_source: false, cc: nil, args: nil) + def initialize(formula, + force_bottle: false, + include_test: false, include_test_formulae: [], + build_from_source: false, build_from_source_formulae: [], + cc: nil, args: nil) @args = args @formula = formula @env = nil @@ -58,10 +63,12 @@ class FormulaInstaller @ignore_deps = false @only_deps = false @build_from_source = build_from_source + @build_from_source_formulae = build_from_source_formulae @build_bottle = false @bottle_arch = nil @force_bottle = force_bottle @include_test = include_test + @include_test_formulae = include_test_formulae @interactive = false @git = false @cc = cc @@ -154,7 +161,7 @@ class FormulaInstaller def install_bottle_for?(dep, build) return pour_bottle? if dep == formula - return false if args&.build_formula_from_source?(dep) + return false if build_from_source_formulae.include?(dep.full_name) return false unless dep.bottle && dep.pour_bottle? return false unless build.used_options.empty? return false unless dep.bottle.compatible_cellar? @@ -483,7 +490,7 @@ class FormulaInstaller if req.prune_from_option?(build) Requirement.prune - elsif req.satisfied?(args: args) + elsif req.satisfied?(env: env, cc: cc, build_bottle: @build_bottle, bottle_arch: bottle_arch) Requirement.prune elsif (req.build? || req.test?) && !keep_build_test Requirement.prune @@ -513,7 +520,7 @@ class FormulaInstaller ) keep_build_test = false - keep_build_test ||= dep.test? && include_test? && args&.include_formula_test_deps?(dependent) + keep_build_test ||= dep.test? && include_test? && include_test_formulae.include?(dependent.full_name) keep_build_test ||= dep.build? && !install_bottle_for?(dependent, build) && !dependent.latest_version_installed? if dep.prune_from_option?(build) @@ -591,8 +598,8 @@ class FormulaInstaller def fetch_dependency(dep) df = dep.to_formula fi = FormulaInstaller.new(df, force_bottle: false, - include_test: args&.include_formula_test_deps?(df), - build_from_source: args&.build_formula_from_source?(df), + include_test: include_test_formulae.include?(df.full_name), + build_from_source: build_from_source_formulae.include?(df.full_name), args: args) fi.force = force? @@ -633,8 +640,8 @@ class FormulaInstaller end fi = FormulaInstaller.new(df, force_bottle: false, - include_test: args&.include_formula_test_deps?(df), - build_from_source: args&.build_formula_from_source?(df), + include_test: include_test_formulae.include?(df.full_name), + build_from_source: build_from_source_formulae.include?(df.full_name), args: args) fi.options |= tab.used_options @@ -775,7 +782,7 @@ class FormulaInstaller formula.options.each do |opt| name = opt.name[/^([^=]+)=$/, 1] - value = args&.value(name) if name + value = self.args&.value(name) if name args << "--#{name}=#{value}" if value end diff --git a/Library/Homebrew/reinstall.rb b/Library/Homebrew/reinstall.rb index 30c4bb17a1..bba654734a 100644 --- a/Library/Homebrew/reinstall.rb +++ b/Library/Homebrew/reinstall.rb @@ -23,8 +23,10 @@ module Homebrew options |= f.build.used_options options &= f.options - fi = FormulaInstaller.new(f, force_bottle: args.force_bottle?, include_test: args.include_test?, - build_from_source: args.build_from_source?, args: args) + fi = FormulaInstaller.new(f, force_bottle: args.force_bottle?, + build_from_source: args.build_from_source?, + build_from_source_formulae: args.build_from_source_formulae, + args: args) fi.options = options fi.force = args.force? fi.keep_tmp = args.keep_tmp? diff --git a/Library/Homebrew/requirement.rb b/Library/Homebrew/requirement.rb index 1458370103..b9e4a09d10 100644 --- a/Library/Homebrew/requirement.rb +++ b/Library/Homebrew/requirement.rb @@ -53,11 +53,14 @@ class Requirement # Overriding {#satisfied?} is unsupported. # Pass a block or boolean to the satisfy DSL method instead. - def satisfied?(args: nil) + def satisfied?(env: nil, cc: nil, build_bottle: false, bottle_arch: nil) satisfy = self.class.satisfy return true unless satisfy - @satisfied_result = satisfy.yielder(args: args) { |p| instance_eval(&p) } + @satisfied_result = + satisfy.yielder(env: env, cc: cc, build_bottle: build_bottle, bottle_arch: bottle_arch) do |p| + instance_eval(&p) + end return false unless @satisfied_result true @@ -81,8 +84,8 @@ class Requirement # Overriding {#modify_build_environment} is unsupported. # Pass a block to the env DSL method instead. - def modify_build_environment(args:) - satisfied?(args: args) + def modify_build_environment(env: nil, cc: nil, build_bottle: false, bottle_arch: nil) + satisfied?(env: env, cc: cc, build_bottle: build_bottle, bottle_arch: bottle_arch) instance_eval(&env_proc) if env_proc # XXX If the satisfy block returns a Pathname, then make sure that it @@ -181,13 +184,13 @@ class Requirement @proc = block end - def yielder(args:) + def yielder(env: nil, cc: nil, build_bottle: false, bottle_arch: nil) if instance_variable_defined?(:@satisfied) @satisfied elsif @options[:build_env] require "extend/ENV" ENV.with_build_environment( - env: args.env, cc: args.cc, build_bottle: args.build_bottle?, bottle_arch: args.bottle_arch, + env: env, cc: cc, build_bottle: build_bottle, bottle_arch: bottle_arch, ) do yield @proc end diff --git a/Library/Homebrew/test/java_requirement_spec.rb b/Library/Homebrew/test/java_requirement_spec.rb index 694fe2f91d..590f27a1d0 100644 --- a/Library/Homebrew/test/java_requirement_spec.rb +++ b/Library/Homebrew/test/java_requirement_spec.rb @@ -41,16 +41,14 @@ describe JavaRequirement do describe "#satisfied?" do subject { described_class.new(%w[1.8]) } - let(:args) { Homebrew::CLI::Args.new } - it "returns false if no `java` executable can be found" do allow(File).to receive(:executable?).and_return(false) - expect(subject).not_to be_satisfied(args: args) + expect(subject).not_to be_satisfied end it "returns true if #preferred_java returns a path" do allow(subject).to receive(:preferred_java).and_return(Pathname.new("/usr/bin/java")) - expect(subject).to be_satisfied(args: args) + expect(subject).to be_satisfied end context "when #possible_javas contains paths" do @@ -74,17 +72,17 @@ describe JavaRequirement do it "returns false if all are lower" do setup_java_with_version "1.6.0_5" - expect(subject).not_to be_satisfied(args: args) + expect(subject).not_to be_satisfied end it "returns true if one is equal" do setup_java_with_version "1.7.0_5" - expect(subject).to be_satisfied(args: args) + expect(subject).to be_satisfied end it "returns false if all are higher" do setup_java_with_version "1.8.0_5" - expect(subject).not_to be_satisfied(args: args) + expect(subject).not_to be_satisfied end end @@ -93,17 +91,17 @@ describe JavaRequirement do it "returns false if all are lower" do setup_java_with_version "1.6.0_5" - expect(subject).not_to be_satisfied(args: args) + expect(subject).not_to be_satisfied end it "returns true if one is equal" do setup_java_with_version "1.7.0_5" - expect(subject).to be_satisfied(args: args) + expect(subject).to be_satisfied end it "returns true if one is higher" do setup_java_with_version "1.8.0_5" - expect(subject).to be_satisfied(args: args) + expect(subject).to be_satisfied end end end diff --git a/Library/Homebrew/test/os/mac/java_requirement_spec.rb b/Library/Homebrew/test/os/mac/java_requirement_spec.rb index 190b7c1aba..65729b23bc 100644 --- a/Library/Homebrew/test/os/mac/java_requirement_spec.rb +++ b/Library/Homebrew/test/os/mac/java_requirement_spec.rb @@ -9,8 +9,6 @@ describe JavaRequirement do let(:java_home) { mktmpdir } - let(:args) { Homebrew::CLI::Args.new } - before do FileUtils.mkdir java_home/"bin" FileUtils.touch java_home/"bin/java" @@ -18,23 +16,23 @@ describe JavaRequirement do end specify "Apple Java environment" do - expect(subject).to be_satisfied(args: args) + expect(subject).to be_satisfied expect(ENV).to receive(:prepend_path) expect(ENV).to receive(:append_to_cflags) - subject.modify_build_environment(args: args) + subject.modify_build_environment expect(ENV["JAVA_HOME"]).to eq(java_home.to_s) end specify "Oracle Java environment" do - expect(subject).to be_satisfied(args: args) + expect(subject).to be_satisfied FileUtils.mkdir java_home/"include" expect(ENV).to receive(:prepend_path) expect(ENV).to receive(:append_to_cflags).twice - subject.modify_build_environment(args: args) + subject.modify_build_environment expect(ENV["JAVA_HOME"]).to eq(java_home.to_s) end end diff --git a/Library/Homebrew/test/requirement_spec.rb b/Library/Homebrew/test/requirement_spec.rb index 12a0e302b3..ffcb3a8de1 100644 --- a/Library/Homebrew/test/requirement_spec.rb +++ b/Library/Homebrew/test/requirement_spec.rb @@ -11,8 +11,6 @@ describe Requirement do let(:klass) { Class.new(described_class) } - let(:args) { Homebrew::CLI::Args.new } - describe "#tags" do subject { described_class.new(tags) } @@ -67,7 +65,7 @@ describe Requirement do end end - it { is_expected.to be_satisfied(args: args) } + it { is_expected.to be_satisfied } end describe "#satisfy with block and build_env returns false" do @@ -79,7 +77,7 @@ describe Requirement do end end - it { is_expected.not_to be_satisfied(args: args) } + it { is_expected.not_to be_satisfied } end describe "#satisfy returns true" do @@ -89,7 +87,7 @@ describe Requirement do end end - it { is_expected.to be_satisfied(args: args) } + it { is_expected.to be_satisfied } end describe "#satisfy returns false" do @@ -99,7 +97,7 @@ describe Requirement do end end - it { is_expected.not_to be_satisfied(args: args) } + it { is_expected.not_to be_satisfied } end describe "#satisfy with block returning true and without :build_env" do @@ -113,7 +111,7 @@ describe Requirement do it "sets up build environment" do expect(ENV).to receive(:with_build_environment).and_call_original - subject.satisfied?(args: args) + subject.satisfied? end end @@ -128,7 +126,7 @@ describe Requirement do it "skips setting up build environment" do expect(ENV).not_to receive(:with_build_environment) - subject.satisfied?(args: args) + subject.satisfied? end end @@ -143,8 +141,8 @@ describe Requirement do it "infers path from #satisfy result" do expect(ENV).to receive(:prepend_path).with("PATH", Pathname.new("/foo/bar")) - subject.satisfied?(args: args) - subject.modify_build_environment(args: args) + subject.satisfied? + subject.modify_build_environment end end end @@ -182,7 +180,7 @@ describe Requirement do let(:klass) { Class.new(described_class) } it "returns nil" do - expect(subject.modify_build_environment(args: args)).to be nil + expect(subject.modify_build_environment).to be nil end end end diff --git a/Library/Homebrew/test/requirements/linux_requirement_spec.rb b/Library/Homebrew/test/requirements/linux_requirement_spec.rb index a6857365df..f328579fa2 100644 --- a/Library/Homebrew/test/requirements/linux_requirement_spec.rb +++ b/Library/Homebrew/test/requirements/linux_requirement_spec.rb @@ -7,10 +7,8 @@ describe LinuxRequirement do subject(:requirement) { described_class.new } describe "#satisfied?" do - let(:args) { Homebrew::CLI::Args.new } - it "returns true on Linux" do - expect(requirement.satisfied?(args: args)).to eq(OS.linux?) + expect(requirement.satisfied?).to eq(OS.linux?) end end end diff --git a/Library/Homebrew/test/requirements/macos_requirement_spec.rb b/Library/Homebrew/test/requirements/macos_requirement_spec.rb index ff160e560f..b966111262 100644 --- a/Library/Homebrew/test/requirements/macos_requirement_spec.rb +++ b/Library/Homebrew/test/requirements/macos_requirement_spec.rb @@ -7,20 +7,18 @@ describe MacOSRequirement do subject(:requirement) { described_class.new } describe "#satisfied?" do - let(:args) { Homebrew::CLI::Args.new } - it "returns true on macOS" do - expect(requirement.satisfied?(args: args)).to eq OS.mac? + expect(requirement.satisfied?).to eq OS.mac? end it "supports version symbols", :needs_macos do requirement = described_class.new([MacOS.version.to_sym]) - expect(requirement).to be_satisfied(args: args) + expect(requirement).to be_satisfied end it "supports maximum versions", :needs_macos do requirement = described_class.new([:catalina], comparator: "<=") - expect(requirement.satisfied?(args: args)).to eq MacOS.version <= :catalina + expect(requirement.satisfied?).to eq MacOS.version <= :catalina end end end diff --git a/Library/Homebrew/test/requirements/osxfuse_requirement_spec.rb b/Library/Homebrew/test/requirements/osxfuse_requirement_spec.rb index a5ceb17909..8c38a45884 100644 --- a/Library/Homebrew/test/requirements/osxfuse_requirement_spec.rb +++ b/Library/Homebrew/test/requirements/osxfuse_requirement_spec.rb @@ -22,23 +22,21 @@ describe OsxfuseRequirement do end describe "#modify_build_environment", :needs_macos do - let(:args) { Homebrew::CLI::Args.new } - it "adds the fuse directories to PKG_CONFIG_PATH" do allow(ENV).to receive(:append_path) - requirement.modify_build_environment(args: args) + requirement.modify_build_environment expect(ENV).to have_received(:append_path).with("PKG_CONFIG_PATH", any_args) end it "adds the fuse directories to HOMEBREW_LIBRARY_PATHS" do allow(ENV).to receive(:append_path) - requirement.modify_build_environment(args: args) + requirement.modify_build_environment expect(ENV).to have_received(:append_path).with("HOMEBREW_LIBRARY_PATHS", any_args) end it "adds the fuse directories to HOMEBREW_INCLUDE_PATHS" do allow(ENV).to receive(:append_path) - requirement.modify_build_environment(args: args) + requirement.modify_build_environment expect(ENV).to have_received(:append_path).with("HOMEBREW_INCLUDE_PATHS", any_args) end end diff --git a/Library/Homebrew/test/x11_requirement_spec.rb b/Library/Homebrew/test/x11_requirement_spec.rb index 133135eb0b..436e0c15ef 100644 --- a/Library/Homebrew/test/x11_requirement_spec.rb +++ b/Library/Homebrew/test/x11_requirement_spec.rb @@ -6,8 +6,6 @@ require "requirements/x11_requirement" describe X11Requirement do let(:default_name) { "x11" } - let(:args) { Homebrew::CLI::Args.new } - describe "#name" do it "defaults to x11" do expect(subject.name).to eq(default_name) @@ -25,7 +23,7 @@ describe X11Requirement do it "calls ENV#x11" do allow(subject).to receive(:satisfied?).and_return(true) expect(ENV).to receive(:x11) - subject.modify_build_environment(args: args) + subject.modify_build_environment end end @@ -33,12 +31,12 @@ describe X11Requirement do it "returns true if X11 is installed" do expect(MacOS::XQuartz).to receive(:version).and_return("2.7.5") expect(MacOS::XQuartz).to receive(:installed?).and_return(true) - expect(subject).to be_satisfied(args: args) + expect(subject).to be_satisfied end it "returns false if X11 is not installed" do expect(MacOS::XQuartz).to receive(:installed?).and_return(false) - expect(subject).not_to be_satisfied(args: args) + expect(subject).not_to be_satisfied end end end From 6b0678e8ed60c031d0852613676717018543831b Mon Sep 17 00:00:00 2001 From: Markus Reiter Date: Wed, 29 Jul 2020 02:19:07 +0200 Subject: [PATCH 20/22] Remove `args` from `FormulaInstaller`. --- Library/Homebrew/cmd/install.rb | 3 +-- Library/Homebrew/formula_installer.rb | 17 ++++------------- Library/Homebrew/reinstall.rb | 3 +-- Library/Homebrew/upgrade.rb | 2 +- 4 files changed, 7 insertions(+), 18 deletions(-) diff --git a/Library/Homebrew/cmd/install.rb b/Library/Homebrew/cmd/install.rb index 6150c0dd9f..893ec43a93 100644 --- a/Library/Homebrew/cmd/install.rb +++ b/Library/Homebrew/cmd/install.rb @@ -327,8 +327,7 @@ module Homebrew include_test: args.include_test?, include_test_formulae: args.include_test_formulae, build_from_source: args.build_from_source?, - build_from_source_formulae: args.build_from_source_formulae, - args: args) + build_from_source_formulae: args.build_from_source_formulae) fi.options = build_options.used_options fi.env = args.env fi.force = args.force? diff --git a/Library/Homebrew/formula_installer.rb b/Library/Homebrew/formula_installer.rb index 669df60645..980ff92b92 100644 --- a/Library/Homebrew/formula_installer.rb +++ b/Library/Homebrew/formula_installer.rb @@ -39,7 +39,7 @@ class FormulaInstaller end attr_reader :formula - attr_accessor :cc, :env, :args, :options, :build_bottle, :bottle_arch, + attr_accessor :cc, :env, :options, :build_bottle, :bottle_arch, :build_from_source_formulae, :include_test_formulae, :installed_as_dependency, :installed_on_request, :link_keg, :other_installers @@ -52,8 +52,7 @@ class FormulaInstaller force_bottle: false, include_test: false, include_test_formulae: [], build_from_source: false, build_from_source_formulae: [], - cc: nil, args: nil) - @args = args + cc: nil) @formula = formula @env = nil @force = false @@ -599,8 +598,7 @@ class FormulaInstaller df = dep.to_formula fi = FormulaInstaller.new(df, force_bottle: false, include_test: include_test_formulae.include?(df.full_name), - build_from_source: build_from_source_formulae.include?(df.full_name), - args: args) + build_from_source: build_from_source_formulae.include?(df.full_name)) fi.force = force? fi.keep_tmp = keep_tmp? @@ -641,8 +639,7 @@ class FormulaInstaller fi = FormulaInstaller.new(df, force_bottle: false, include_test: include_test_formulae.include?(df.full_name), - build_from_source: build_from_source_formulae.include?(df.full_name), - args: args) + build_from_source: build_from_source_formulae.include?(df.full_name)) fi.options |= tab.used_options fi.options |= Tab.remap_deprecated_options(df.deprecated_options, dep.options) @@ -780,12 +777,6 @@ class FormulaInstaller args << "--devel" end - formula.options.each do |opt| - name = opt.name[/^([^=]+)=$/, 1] - value = self.args&.value(name) if name - args << "--#{name}=#{value}" if value - end - args end diff --git a/Library/Homebrew/reinstall.rb b/Library/Homebrew/reinstall.rb index bba654734a..0e9f5ef038 100644 --- a/Library/Homebrew/reinstall.rb +++ b/Library/Homebrew/reinstall.rb @@ -25,8 +25,7 @@ module Homebrew fi = FormulaInstaller.new(f, force_bottle: args.force_bottle?, build_from_source: args.build_from_source?, - build_from_source_formulae: args.build_from_source_formulae, - args: args) + build_from_source_formulae: args.build_from_source_formulae) fi.options = options fi.force = args.force? fi.keep_tmp = args.keep_tmp? diff --git a/Library/Homebrew/upgrade.rb b/Library/Homebrew/upgrade.rb index 0f590652a8..3a9a211129 100644 --- a/Library/Homebrew/upgrade.rb +++ b/Library/Homebrew/upgrade.rb @@ -64,7 +64,7 @@ module Homebrew options &= f.options fi = FormulaInstaller.new(f, force_bottle: args.force_bottle?, include_test: args.include_test?, - build_from_source: args.build_from_source?, args: args) + build_from_source: args.build_from_source?) fi.options = options fi.force = args.force? fi.keep_tmp = args.keep_tmp? From 08e35e9cb4e65c6969016ffaa8af4e1a968ca496 Mon Sep 17 00:00:00 2001 From: Markus Reiter Date: Thu, 30 Jul 2020 03:24:37 +0200 Subject: [PATCH 21/22] Refactor `FormulaLoader#get_formula`. --- Library/Homebrew/formulary.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Library/Homebrew/formulary.rb b/Library/Homebrew/formulary.rb index 65ca197f4e..a812e589c9 100644 --- a/Library/Homebrew/formulary.rb +++ b/Library/Homebrew/formulary.rb @@ -124,8 +124,8 @@ module Formulary # `alias_path` can be overridden here in case an alias was used to refer to # a formula that was loaded in another way. def get_formula(spec, alias_path: nil, force_bottle: false, flags: []) - klass(flags: flags) - .new(name, path, spec, alias_path: alias_path || self.alias_path, force_bottle: force_bottle) + alias_path ||= self.alias_path + klass(flags: flags).new(name, path, spec, alias_path: alias_path, force_bottle: force_bottle) end def klass(flags:) From e07b02fde2a423ef6389330a80f4c3e5e71fcfed Mon Sep 17 00:00:00 2001 From: Markus Reiter Date: Thu, 30 Jul 2020 10:10:42 +0200 Subject: [PATCH 22/22] Comment `BUILD_FLAGS`. --- Library/Homebrew/formula.rb | 7 ++++--- Library/Homebrew/formulary.rb | 2 ++ 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/Library/Homebrew/formula.rb b/Library/Homebrew/formula.rb index ff180c4d22..ad385131e4 100644 --- a/Library/Homebrew/formula.rb +++ b/Library/Homebrew/formula.rb @@ -2378,12 +2378,13 @@ class Formula stable.build end + # Get the `BUILD_FLAGS` from the formula's namespace set in `Formulary::load_formula`. # @private def build_flags - mod_name = to_s.split("::")[0..-2].join("::") - return [] if mod_name.empty? + namespace = to_s.split("::")[0..-2].join("::") + return [] if namespace.empty? - mod = const_get(mod_name) + mod = const_get(namespace) mod.const_get(:BUILD_FLAGS) end diff --git a/Library/Homebrew/formulary.rb b/Library/Homebrew/formulary.rb index a812e589c9..80600d7e34 100644 --- a/Library/Homebrew/formulary.rb +++ b/Library/Homebrew/formulary.rb @@ -34,6 +34,8 @@ module Formulary const_set(namespace, mod) begin + # Set `BUILD_FLAGS` in the formula's namespace so we can + # access them from within the formula's class scope. mod.const_set(:BUILD_FLAGS, flags) mod.module_eval(contents, path) rescue NameError, ArgumentError, ScriptError => e