Merge pull request #7871 from MLH-Fellowship/license-forbidden

License forbidden
This commit is contained in:
Mike McQuaid 2020-07-10 15:38:51 +01:00 committed by GitHub
commit a2ae8741a9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 43 additions and 0 deletions

View File

@ -111,6 +111,10 @@ module Homebrew
description: "Output this many lines of output on formula `system` failures.",
default: 15,
},
HOMEBREW_FORBIDDEN_LICENSES: {
description: "A space-separated list of licenses. Homebrew will refuse to install a " \
"formula if that formula or any of its dependencies has a license on this list.",
},
HOMEBREW_FORCE_BREWED_CURL: {
description: "If set, always use a Homebrew-installed `curl`(1) rather than the system version. " \
"Automatically set if the system version of `curl` is too old.",

View File

@ -17,6 +17,7 @@ require "linkage_checker"
require "install"
require "messages"
require "cask/cask_loader"
require "cmd/install"
require "find"
class FormulaInstaller
@ -148,6 +149,8 @@ class FormulaInstaller
def prelude
Tab.clear_cache
verify_deps_exist unless ignore_deps?
forbidden_license_check
check_install_sanity
end
@ -1102,4 +1105,27 @@ class FormulaInstaller
$stderr.puts @requirement_messages
end
def forbidden_license_check
forbidden_licenses = Homebrew::EnvConfig.forbidden_licenses.to_s.split(" ")
return if forbidden_licenses.blank?
compute_dependencies.each do |dep, _|
next if @ignore_deps
dep_f = dep.to_formula
next unless forbidden_licenses.include? dep_f.license
raise CannotInstallFormulaError, <<~EOS
The installation of #{formula.name} has a dependency on #{dep.name} with a forbidden license #{dep_f.license}.
EOS
end
return if @only_deps
return unless forbidden_licenses.include? formula.license
raise CannotInstallFormulaError, <<~EOS
#{formula.name} has a forbidden license #{formula.license}.
EOS
end
end

View File

@ -161,6 +161,12 @@ RSpec.shared_context "integration test" do
content = <<~RUBY
url "https://brew.sh/#{name}-1.0"
RUBY
when "package_license"
content = <<~RUBY
url "https://brew.sh/#patchelf-1.0"
license "0BSD"
RUBY
end
Formulary.core_path(name).tap do |formula_path|

View File

@ -1394,6 +1394,9 @@ Note that environment variables must have a value set to be detected. For exampl
*Default:* `15`.
* `HOMEBREW_FORBIDDEN_LICENSES`:
A space-separated list of licenses. Homebrew will refuse to install a formula if that formula or any of its dependencies has a license on this list.
* `HOMEBREW_FORCE_BREWED_CURL`:
If set, always use a Homebrew-installed `curl`(1) rather than the system version. Automatically set if the system version of `curl` is too old.

View File

@ -1799,6 +1799,10 @@ Output this many lines of output on formula \fBsystem\fR failures\.
\fIDefault:\fR \fB15\fR\.
.
.TP
\fBHOMEBREW_FORBIDDEN_LICENSES\fR
A space\-separated list of licenses\. Homebrew will refuse to install a formula if that formula or any of its dependencies has a license on this list\.
.
.TP
\fBHOMEBREW_FORCE_BREWED_CURL\fR
If set, always use a Homebrew\-installed \fBcurl\fR(1) rather than the system version\. Automatically set if the system version of \fBcurl\fR is too old\.
.