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