From a161829927fcd13d7a91cbc707db402577e95867 Mon Sep 17 00:00:00 2001 From: lionellloh Date: Tue, 7 Jul 2020 16:09:20 +0800 Subject: [PATCH] forbidden-license: include method in module scope for module-wide access --- Library/Homebrew/cmd/install.rb | 33 ++++++++++++++++----------- Library/Homebrew/formula_installer.rb | 2 ++ 2 files changed, 22 insertions(+), 13 deletions(-) diff --git a/Library/Homebrew/cmd/install.rb b/Library/Homebrew/cmd/install.rb index fe1eea882c..2072b7fa05 100644 --- a/Library/Homebrew/cmd/install.rb +++ b/Library/Homebrew/cmd/install.rb @@ -342,24 +342,31 @@ module Homebrew rescue CannotInstallFormulaError => e ofail e.message end -end -def forbidden_license_check(f) - forbidden_licenses = ENV["HOMEBREW_FORBIDDEN_LICENSES"].split(" ") + def get_forbidden_licenses + Homebrew::EnvConfig.forbidden_licenses.split(" ") + end - if forbidden_licenses.include? f.license - raise CannotInstallFormulaError, <<~EOS + def forbidden_license_check(f) + forbidden_licenses = get_forbidden_licenses + + if forbidden_licenses.include? f.license + raise CannotInstallFormulaError, <<~EOS #{f.name} has a forbidden license #{f.license}. - EOS - end + 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 + 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 + raise CannotInstallFormulaError, <<~EOS The installation of #{f.name} has a dependency on #{dep.name} with a forbidden license #{dep_f.license}. - EOS + EOS + end end + end + + diff --git a/Library/Homebrew/formula_installer.rb b/Library/Homebrew/formula_installer.rb index c6a7318e6c..e7fa45da2b 100644 --- a/Library/Homebrew/formula_installer.rb +++ b/Library/Homebrew/formula_installer.rb @@ -148,6 +148,8 @@ class FormulaInstaller def prelude Tab.clear_cache verify_deps_exist unless ignore_deps? + Homebrew.forbidden_license_check(formula) unless ENV["HOMEBREW_FORBIDDEN_LICENSES"].blank? + check_install_sanity end