Pass args to FormulaInstaller instead of using global args.

This commit is contained in:
Markus Reiter 2020-07-25 03:48:33 +02:00
parent 6c050492ee
commit 8a1f8ab858
8 changed files with 67 additions and 50 deletions

View File

@ -94,7 +94,7 @@ module Homebrew
end
def install
install_args.parse
args = install_args.parse
args.named.each do |name|
next if File.exist?(name)
@ -263,7 +263,7 @@ module Homebrew
Cleanup.install_formula_clean!(f)
end
check_installed_dependents
check_installed_dependents(args: args)
Homebrew.messages.display_messages
rescue FormulaUnreadableError, FormulaClassUnavailableError,
@ -323,13 +323,18 @@ module Homebrew
f.print_tap_action
build_options = f.build
fi = FormulaInstaller.new(f)
fi = FormulaInstaller.new(f, force_bottle: args.force_bottle?, include_test: args.include_test?)
fi.options = build_options.used_options
fi.env = args.env
fi.force = args.force?
fi.keep_tmp = args.keep_tmp?
fi.ignore_deps = args.ignore_dependencies?
fi.only_deps = args.only_dependencies?
fi.build_bottle = args.build_bottle?
fi.bottle_arch = args.bottle_arch
fi.interactive = args.interactive?
fi.git = args.git?
fi.cc = args.cc
fi.prelude
fi.fetch
fi.install

View File

@ -22,11 +22,12 @@ module Homebrew
end
def postinstall
postinstall_args.parse
args = postinstall_args.parse
args.resolved_formulae.each do |f|
ohai "Postinstalling #{f}"
fi = FormulaInstaller.new(f)
fi.force = args.force?
fi.post_install
end
end

View File

@ -54,7 +54,7 @@ module Homebrew
end
def reinstall
reinstall_args.parse
args = reinstall_args.parse
FormulaInstaller.prevent_build_flags unless DevelopmentTools.installed?
@ -67,11 +67,11 @@ module Homebrew
next
end
Migrator.migrate_if_needed(f)
reinstall_formula(f)
reinstall_formula(f, args: args)
Cleanup.install_formula_clean!(f)
end
check_installed_dependents
check_installed_dependents(args: args)
Homebrew.messages.display_messages

View File

@ -56,7 +56,7 @@ module Homebrew
end
def upgrade
upgrade_args.parse
args = upgrade_args.parse
FormulaInstaller.prevent_build_flags unless DevelopmentTools.installed?
@ -109,9 +109,9 @@ module Homebrew
puts formulae_upgrades.join("\n")
end
upgrade_formulae(formulae_to_install)
upgrade_formulae(formulae_to_install, args: args)
check_installed_dependents
check_installed_dependents(args: args)
Homebrew.messages.display_messages
end

View File

@ -38,25 +38,31 @@ class FormulaInstaller
end
attr_reader :formula
attr_accessor :options, :build_bottle, :installed_as_dependency, :installed_on_request, :link_keg
attr_accessor :cc, :env, :options, :build_bottle, :bottle_arch,
:installed_as_dependency, :installed_on_request, :link_keg
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
mode_attr_accessor :ignore_deps, :only_deps, :interactive, :git, :force, :keep_tmp
mode_attr_accessor :verbose, :debug, :quiet
def initialize(formula)
def initialize(formula, force_bottle: false, include_test: false, build_from_source: false, cc: nil)
@formula = formula
@env = nil
@force = false
@keep_tmp = false
@link_keg = !formula.keg_only?
@show_header = false
@ignore_deps = false
@only_deps = false
@build_from_source = Homebrew.args.build_from_source?
@build_from_source = build_from_source
@build_bottle = false
@force_bottle = Homebrew.args.force_bottle?
@include_test = Homebrew.args.include_test?
@bottle_arch = nil
@force_bottle = force_bottle
@include_test = include_test
@interactive = false
@git = false
@cc = cc
@verbose = Homebrew.args.verbose?
@quiet = Homebrew.args.quiet?
@debug = Homebrew.args.debug?
@ -108,7 +114,7 @@ class FormulaInstaller
return false if !formula.bottled? && !formula.local_bottle_path
return true if force_bottle?
return false if build_from_source? || build_bottle? || interactive?
return false if Homebrew.args.cc
return false if cc
return false unless options.empty?
return false if formula.bottle_disabled?
@ -280,7 +286,7 @@ class FormulaInstaller
return if only_deps?
if build_bottle? && (arch = Homebrew.args.bottle_arch) && !Hardware::CPU.optimization_flags.include?(arch.to_sym)
if build_bottle? && (arch = bottle_arch) && !Hardware::CPU.optimization_flags.include?(arch.to_sym)
raise "Unrecognized architecture for --bottle-arch: #{arch}"
end
@ -367,7 +373,7 @@ class FormulaInstaller
end
def check_conflicts
return if Homebrew.args.force?
return if force?
conflicts = formula.conflicts.select do |c|
f = Formulary.factory(c.name)
@ -576,11 +582,12 @@ class FormulaInstaller
def fetch_dependency(dep)
df = dep.to_formula
fi = FormulaInstaller.new(df)
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))
fi.build_from_source = Homebrew.args.build_formula_from_source?(df)
fi.force_bottle = false
fi.include_test = Homebrew.args.include_formula_test_deps?(df)
fi.force = force?
fi.keep_tmp = keep_tmp?
fi.verbose = verbose?
fi.quiet = quiet?
fi.debug = debug?
@ -616,14 +623,16 @@ class FormulaInstaller
EOS
end
fi = FormulaInstaller.new(df)
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))
fi.options |= tab.used_options
fi.options |= Tab.remap_deprecated_options(df.deprecated_options, dep.options)
fi.options |= inherited_options
fi.options &= df.options
fi.build_from_source = Homebrew.args.build_formula_from_source?(df)
fi.force_bottle = false
fi.include_test = Homebrew.args.include_formula_test_deps?(df)
fi.force = force?
fi.keep_tmp = keep_tmp?
fi.verbose = verbose?
fi.quiet = quiet?
fi.debug = debug?
@ -732,18 +741,18 @@ class FormulaInstaller
if build_bottle?
args << "--build-bottle"
args << "--bottle-arch=#{Homebrew.args.bottle_arch}" if Homebrew.args.bottle_arch
args << "--bottle-arch=#{bottle_arch}" if bottle_arch
end
args << "--git" if git?
args << "--interactive" if interactive?
args << "--verbose" if verbose?
args << "--debug" if debug?
args << "--cc=#{Homebrew.args.cc}" if Homebrew.args.cc
args << "--keep-tmp" if Homebrew.args.keep_tmp?
args << "--cc=#{cc}" if cc
args << "--keep-tmp" if keep_tmp?
if Homebrew.args.env.present?
args << "--env=#{Homebrew.args.env}"
if env.present?
args << "--env=#{env}"
elsif formula.env.std? || formula.deps.select(&:build?).any? { |d| d.name == "scons" }
args << "--env=std"
end
@ -789,7 +798,7 @@ class FormulaInstaller
sandbox = Sandbox.new
formula.logs.mkpath
sandbox.record_log(formula.logs/"build.sandbox.log")
sandbox.allow_write_path(ENV["HOME"]) if Homebrew.args.interactive?
sandbox.allow_write_path(ENV["HOME"]) if interactive?
sandbox.allow_write_temp_and_cache
sandbox.allow_write_log(formula)
sandbox.allow_cvs

View File

@ -7,7 +7,7 @@ require "messages"
module Homebrew
module_function
def reinstall_formula(f, build_from_source: false)
def reinstall_formula(f, build_from_source: false, args:)
return if args.dry_run?
if f.opt_prefix.directory?
@ -23,11 +23,13 @@ module Homebrew
options |= f.build.used_options
options &= f.options
fi = FormulaInstaller.new(f)
fi = FormulaInstaller.new(f, force_bottle: args.force_bottle?, include_test: args.include_test?)
fi.options = options
fi.build_bottle = Homebrew.args.build_bottle?
fi.interactive = Homebrew.args.interactive?
fi.git = Homebrew.args.git?
fi.force = args.force?
fi.keep_tmp = args.keep_tmp?
fi.build_bottle = args.build_bottle?
fi.interactive = args.interactive?
fi.git = args.git?
fi.link_keg ||= keg_was_linked if keg_had_linked_opt
fi.build_from_source = true if build_from_source
if tab

View File

@ -17,10 +17,10 @@ describe FormulaInstaller do
match(&:poured_from_bottle)
end
def temporary_install(formula)
def temporary_install(formula, **options)
expect(formula).not_to be_latest_version_installed
installer = described_class.new(formula)
installer = described_class.new(formula, **options)
installer.fetch
installer.install
@ -89,9 +89,7 @@ describe FormulaInstaller do
end
specify "Formula is not poured from bottle when compiler specified" do
expect(Homebrew.args.cc).to be nil
Homebrew.install_args.parse(["--cc=clang", "testball_bottle"])
temporary_install(TestballBottle.new) do |f|
temporary_install(TestballBottle.new, cc: "clang") do |f|
tab = Tab.for_formula(f)
expect(tab.compiler).to eq("clang")
end

View File

@ -9,7 +9,7 @@ require "cleanup"
module Homebrew
module_function
def upgrade_formulae(formulae_to_install)
def upgrade_formulae(formulae_to_install, args:)
return if formulae_to_install.empty?
return if args.dry_run?
@ -28,7 +28,7 @@ module Homebrew
formulae_to_install.each do |f|
Migrator.migrate_if_needed(f)
begin
upgrade_formula(f)
upgrade_formula(f, args: args)
Cleanup.install_formula_clean!(f)
rescue UnsatisfiedRequirements => e
Homebrew.failed = true
@ -37,7 +37,7 @@ module Homebrew
end
end
def upgrade_formula(f)
def upgrade_formula(f, args:)
return if args.dry_run?
if f.opt_prefix.directory?
@ -63,8 +63,10 @@ module Homebrew
options |= f.build.used_options
options &= f.options
fi = FormulaInstaller.new(f)
fi = FormulaInstaller.new(f, force_bottle: args.force_bottle?, include_test: args.include_test?)
fi.options = options
fi.force = args.force?
fi.keep_tmp = args.keep_tmp?
fi.build_bottle = args.build_bottle?
fi.installed_on_request = args.named.present?
fi.link_keg ||= keg_was_linked if keg_had_linked_opt
@ -112,7 +114,7 @@ module Homebrew
end
end
def check_installed_dependents
def check_installed_dependents(args:)
installed_formulae = FormulaInstaller.installed.to_a
return if installed_formulae.empty?
@ -156,7 +158,7 @@ module Homebrew
puts formulae_upgrades.join(", ")
end
upgrade_formulae(upgradeable_dependents)
upgrade_formulae(upgradeable_dependents, args: args)
# Assess the dependents tree again now we've upgraded.
oh1 "Checking for dependents of upgraded formulae..." unless args.dry_run?
@ -213,7 +215,7 @@ module Homebrew
return if args.dry_run?
reinstallable_broken_dependents.each do |f|
reinstall_formula(f, build_from_source: true)
reinstall_formula(f, build_from_source: true, args: args)
rescue FormulaInstallationAlreadyAttemptedError
# We already attempted to reinstall f as part of the dependency tree of
# another formula. In that case, don't generate an error, just move on.