Moved code from install -> formula_installer

This commit is contained in:
lionellloh 2020-07-07 21:51:15 +08:00
parent 56bde378f3
commit f0222c3eb7
2 changed files with 27 additions and 28 deletions

View File

@ -259,7 +259,6 @@ module Homebrew
formulae.each do |f|
Migrator.migrate_if_needed(f)
forbidden_license_check(f)
install_formula(f)
Cleanup.install_formula_clean!(f)
end
@ -342,30 +341,4 @@ module Homebrew
rescue CannotInstallFormulaError => e
ofail e.message
end
def env_forbidden_licenses
Homebrew::EnvConfig.forbidden_licenses.split(" ")
end
def forbidden_license_check(f)
return if ENV["HOMEBREW_FORBIDDEN_LICENSES"].blank?
forbidden_licenses = env_forbidden_licenses
if forbidden_licenses.include? f.license
raise CannotInstallFormulaError, <<~EOS
#{f.name} has a forbidden license #{f.license}.
EOS
end
fi = FormulaInstaller.new(f)
fi.compute_dependencies.each do |dep, _|
dep_f = dep.to_formula
next unless forbidden_licenses.include? dep_f.license
raise CannotInstallFormulaError, <<~EOS
The installation of #{f.name} has a dependency on #{dep.name} with a forbidden license #{dep_f.license}.
EOS
end
end
end

View File

@ -149,7 +149,7 @@ class FormulaInstaller
def prelude
Tab.clear_cache
verify_deps_exist unless ignore_deps?
Homebrew.forbidden_license_check(formula)
forbidden_license_check(formula)
check_install_sanity
end
@ -1105,4 +1105,30 @@ class FormulaInstaller
$stderr.puts @requirement_messages
end
def env_forbidden_licenses
Homebrew::EnvConfig.forbidden_licenses.split(" ")
end
def forbidden_license_check(f)
return if ENV["HOMEBREW_FORBIDDEN_LICENSES"].blank?
forbidden_licenses = env_forbidden_licenses
if forbidden_licenses.include? f.license
raise CannotInstallFormulaError, <<~EOS
#{f.name} has a forbidden license #{f.license}.
EOS
end
fi = FormulaInstaller.new(f)
fi.compute_dependencies.each do |dep, _|
dep_f = dep.to_formula
next unless forbidden_licenses.include? dep_f.license
raise CannotInstallFormulaError, <<~EOS
The installation of #{f.name} has a dependency on #{dep.name} with a forbidden license #{dep_f.license}.
EOS
end
end
end