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/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 b152473f79..0f5353dc25 100644 --- a/Library/Homebrew/cli/args.rb +++ b/Library/Homebrew/cli/args.rb @@ -70,24 +70,11 @@ 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" @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 @@ -113,7 +100,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 @@ -123,7 +110,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) @@ -181,18 +169,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/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..bd6018efe4 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,9 +58,9 @@ module Homebrew end end - def print_formula_cache(name) - formula = Formulary.factory name - if fetch_bottle?(formula) + def print_formula_cache(name, args:) + formula = Formulary.factory(name, force_bottle: args.force_bottle?, flags: args.flags_only) + 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/gist-logs.rb b/Library/Homebrew/cmd/gist-logs.rb index 346ee8ab6e..912266b6df 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 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 7725ef1a11..893ec43a93 100644 --- a/Library/Homebrew/cmd/install.rb +++ b/Library/Homebrew/cmd/install.rb @@ -10,10 +10,10 @@ require "cli/parser" require "upgrade" module Homebrew - module_function - extend Search + module_function + def install_args Homebrew::CLI::Parser.new do usage_banner <<~EOS @@ -115,13 +115,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 @@ -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 @@ -255,17 +255,17 @@ module Homebrew return if formulae.empty? - Install.perform_preinstall_checks + Install.perform_preinstall_checks(cc: args.cc) formulae.each do |f| - Migrator.migrate_if_needed(f) - install_formula(f) + Migrator.migrate_if_needed(f, force: args.force?) + install_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?) rescue FormulaUnreadableError, FormulaClassUnavailableError, TapFormulaUnreadableError, TapFormulaClassUnavailableError => e # Need to rescue before `FormulaUnavailableError` (superclass of this) @@ -319,12 +319,15 @@ 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?) + 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) fi.options = build_options.used_options fi.env = args.env fi.force = args.force? 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..ea1bca1ace 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" @@ -56,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 @@ -66,14 +67,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/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/cmd/update-report.rb b/Library/Homebrew/cmd/update-report.rb index 587af66392..abe5cc1c75 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? && @@ -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 @@ -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) @@ -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 @@ -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 @@ -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 diff --git a/Library/Homebrew/cmd/upgrade.rb b/Library/Homebrew/cmd/upgrade.rb index 8eccc812b4..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 @@ -129,7 +129,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/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("@") 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 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}" 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/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/fetch.rb b/Library/Homebrew/fetch.rb index 4db267aa72..7b0e76cd85 100644 --- a/Library/Homebrew/fetch.rb +++ b/Library/Homebrew/fetch.rb @@ -2,10 +2,10 @@ 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) + 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.rb b/Library/Homebrew/formula.rb index ab4734cf57..ad385131e4 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 @@ -2372,6 +2378,16 @@ class Formula stable.build end + # Get the `BUILD_FLAGS` from the formula's namespace set in `Formulary::load_formula`. + # @private + def build_flags + namespace = to_s.split("::")[0..-2].join("::") + return [] if namespace.empty? + + mod = const_get(namespace) + 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 +2401,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 +2421,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 +2441,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/formula_installer.rb b/Library/Homebrew/formula_installer.rb index c07d59b976..980ff92b92 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 @@ -39,14 +40,19 @@ class FormulaInstaller attr_reader :formula attr_accessor :cc, :env, :options, :build_bottle, :bottle_arch, - :installed_as_dependency, :installed_on_request, :link_keg + :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 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, include_test_formulae: [], + build_from_source: false, build_from_source_formulae: [], + cc: nil) @formula = formula @env = nil @force = false @@ -56,10 +62,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 @@ -93,12 +101,20 @@ 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 = Homebrew.args.collect_build_args + # 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 = Homebrew.args.formulae.all?(&:bottled?) + all_bottled = args.formulae.all?(&:bottled?) raise BuildFlagsError.new(build_flags, bottled: all_bottled) end @@ -144,7 +160,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 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? @@ -239,9 +255,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 @@ -475,7 +489,7 @@ class FormulaInstaller if req.prune_from_option?(build) Requirement.prune - elsif req.satisfied?(args: Homebrew.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 @@ -505,7 +519,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? && 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) @@ -583,8 +597,8 @@ 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: include_test_formulae.include?(df.full_name), + build_from_source: build_from_source_formulae.include?(df.full_name)) fi.force = force? fi.keep_tmp = keep_tmp? @@ -624,8 +638,8 @@ 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: include_test_formulae.include?(df.full_name), + 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) @@ -763,12 +777,6 @@ class FormulaInstaller args << "--devel" end - formula.options.each do |opt| - name = opt.name[/^([^=]+)=$/, 1] - value = Homebrew.args.value(name) if name - args << "--#{name}=#{value}" if value - end - args end diff --git a/Library/Homebrew/formulary.rb b/Library/Homebrew/formulary.rb index 336f34f757..80600d7e34 100644 --- a/Library/Homebrew/formulary.rb +++ b/Library/Homebrew/formulary.rb @@ -27,12 +27,16 @@ 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 + # 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 $stderr.puts e.backtrace if Homebrew::EnvConfig.developer? @@ -51,16 +55,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 +77,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 +125,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: []) + alias_path ||= self.alias_path + klass(flags: flags).new(name, path, spec, alias_path: 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 +166,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 +210,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 +275,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 +285,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 +313,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 +327,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 +336,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 +351,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 +372,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 +397,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/install.rb b/Library/Homebrew/install.rb index f68572df08..f858d8f9d8 100644 --- a/Library/Homebrew/install.rb +++ b/Library/Homebrew/install.rb @@ -39,20 +39,20 @@ module Homebrew end end - def check_cc_argv - return unless Homebrew.args.cc + def check_cc_argv(cc) + return unless cc @checks ||= Diagnostic::Checks.new opoo <<~EOS - You passed `--cc=#{Homebrew.args.cc}`. + You passed `--cc=#{cc}`. #{@checks.please_create_pull_requests} 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 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/patch.rb b/Library/Homebrew/patch.rb index 03aea114e4..f2a92a0616 100644 --- a/Library/Homebrew/patch.rb +++ b/Library/Homebrew/patch.rb @@ -159,6 +159,10 @@ class ExternalPatch end end end + rescue ErrorDuringExecution => e + 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/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 diff --git a/Library/Homebrew/reinstall.rb b/Library/Homebrew/reinstall.rb index b7916a94a7..0e9f5ef038 100644 --- a/Library/Homebrew/reinstall.rb +++ b/Library/Homebrew/reinstall.rb @@ -18,13 +18,14 @@ 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 - fi = FormulaInstaller.new(f, force_bottle: args.force_bottle?, include_test: args.include_test?, - build_from_source: args.build_from_source?) + 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) 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 ae63d77839..5a96adccce 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 @@ -185,13 +188,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/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/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? 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 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/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/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/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/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 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/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 62ea6c264b..ee5eb8b4b4 100644 Binary files a/Library/Homebrew/test/support/fixtures/bottles/testball_bottle-0.1.yosemite.bottle.tar.gz and b/Library/Homebrew/test/support/fixtures/bottles/testball_bottle-0.1.yosemite.bottle.tar.gz differ diff --git a/Library/Homebrew/test/support/fixtures/failball.rb b/Library/Homebrew/test/support/fixtures/failball.rb index 439645df26..5ba1692eff 100644 --- a/Library/Homebrew/test/support/fixtures/failball.rb +++ b/Library/Homebrew/test/support/fixtures/failball.rb @@ -1,7 +1,8 @@ # frozen_string_literal: true class Failball < Formula - def initialize(name = "failball", path = Pathname.new(__FILE__).expand_path, spec = :stable, alias_path: nil) + def initialize(name = "failball", path = Pathname.new(__FILE__).expand_path, spec = :stable, + alias_path: nil, force_bottle: false) self.class.instance_eval do stable.url "file://#{TEST_FIXTURE_DIR}/tarballs/testball-0.1.tbz" stable.sha256 TESTBALL_SHA256 diff --git a/Library/Homebrew/test/support/fixtures/testball.rb b/Library/Homebrew/test/support/fixtures/testball.rb index c2d4aa2bbc..27ff8dafc0 100644 --- a/Library/Homebrew/test/support/fixtures/testball.rb +++ b/Library/Homebrew/test/support/fixtures/testball.rb @@ -1,7 +1,8 @@ # frozen_string_literal: true class Testball < Formula - def initialize(name = "testball", path = Pathname.new(__FILE__).expand_path, spec = :stable, alias_path: nil) + def initialize(name = "testball", path = Pathname.new(__FILE__).expand_path, spec = :stable, + alias_path: nil, force_bottle: false) self.class.instance_eval do stable.url "file://#{TEST_FIXTURE_DIR}/tarballs/testball-0.1.tbz" stable.sha256 TESTBALL_SHA256 diff --git a/Library/Homebrew/test/support/fixtures/testball_bottle.rb b/Library/Homebrew/test/support/fixtures/testball_bottle.rb index f6268ed4fc..76d8d7e7c0 100644 --- a/Library/Homebrew/test/support/fixtures/testball_bottle.rb +++ b/Library/Homebrew/test/support/fixtures/testball_bottle.rb @@ -1,14 +1,15 @@ # frozen_string_literal: true class TestballBottle < Formula - def initialize(name = "testball_bottle", path = Pathname.new(__FILE__).expand_path, spec = :stable, alias_path: nil) + def initialize(name = "testball_bottle", path = Pathname.new(__FILE__).expand_path, spec = :stable, + alias_path: nil, force_bottle: false) self.class.instance_eval do stable.url "file://#{TEST_FIXTURE_DIR}/tarballs/testball-0.1.tbz" stable.sha256 TESTBALL_SHA256 stable.bottle do cellar :any_skip_relocation root_url "file://#{TEST_FIXTURE_DIR}/bottles" - sha256 "d48bbbe583dcfbfa608579724fc6f0328b3cd316935c6ea22f134610aaf2952f" => Utils::Bottles.tag + sha256 "8f9aecd233463da6a4ea55f5f88fc5841718c013f3e2a7941350d6130f1dc149" => Utils::Bottles.tag end cxxstdlib_check :skip 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 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)