From fb0268da7eeb298a1f13c1809855eedee975200b Mon Sep 17 00:00:00 2001 From: Mike McQuaid Date: Tue, 4 Aug 2020 10:47:41 +0100 Subject: [PATCH] license: handle "Public Domain". Allow `:public_domain` to be used as a `license` value and ensure that it's handled correctly by `brew info`, `brew audit` and `brew install`. --- Library/Homebrew/cmd/info.rb | 8 +++++++- Library/Homebrew/dev-cmd/audit.rb | 8 ++++---- Library/Homebrew/formula.rb | 2 ++ Library/Homebrew/formula_installer.rb | 9 ++++++--- docs/Formula-Cookbook.md | 2 +- 5 files changed, 20 insertions(+), 9 deletions(-) diff --git a/Library/Homebrew/cmd/info.rb b/Library/Homebrew/cmd/info.rb index d975d131f9..42089d4d87 100644 --- a/Library/Homebrew/cmd/info.rb +++ b/Library/Homebrew/cmd/info.rb @@ -211,7 +211,13 @@ module Homebrew puts "From: #{Formatter.url(github_info(f))}" - puts "License: #{f.license.join(", ")}" if f.license + if f.license.present? + licenses = f.license + .map(&:to_s) + .join(", ") + .sub("public_domain", "Public Domain") + puts "License: #{licenses}" + end unless f.deps.empty? ohai "Dependencies" diff --git a/Library/Homebrew/dev-cmd/audit.rb b/Library/Homebrew/dev-cmd/audit.rb index ba44997d7e..3ca72994b1 100644 --- a/Library/Homebrew/dev-cmd/audit.rb +++ b/Library/Homebrew/dev-cmd/audit.rb @@ -337,12 +337,12 @@ module Homebrew def audit_license if formula.license.present? - non_standard_licenses = [] - formula.license.each do |license| + non_standard_licenses = formula.license.map do |license| + next if license == :public_domain next if @spdx_data["licenses"].any? { |spdx| spdx["licenseId"] == license } - non_standard_licenses << license - end + license + end.compact if non_standard_licenses.present? problem "Formula #{formula.name} contains non-standard SPDX licenses: #{non_standard_licenses}." diff --git a/Library/Homebrew/formula.rb b/Library/Homebrew/formula.rb index 735f333424..10ab763470 100644 --- a/Library/Homebrew/formula.rb +++ b/Library/Homebrew/formula.rb @@ -2221,6 +2221,8 @@ class Formula # Multiple licenses means that the software is licensed under multiple licenses. # Do not use multiple licenses if e.g. different parts are under different licenses. #
license "BSD-2-Clause"
+ #
license ["MIT", "GPL-2.0"]
+ #
license :public_domain
def license(args = nil) if args.nil? @licenses diff --git a/Library/Homebrew/formula_installer.rb b/Library/Homebrew/formula_installer.rb index d9b5e6d1c3..e70d60089e 100644 --- a/Library/Homebrew/formula_installer.rb +++ b/Library/Homebrew/formula_installer.rb @@ -1129,14 +1129,17 @@ class FormulaInstaller end def forbidden_license_check - forbidden_licenses = Homebrew::EnvConfig.forbidden_licenses.to_s.split(" ") + forbidden_licenses = Homebrew::EnvConfig.forbidden_licenses + .to_s + .sub("Public Domain", "public_domain") + .split(" ") return if forbidden_licenses.blank? compute_dependencies.each do |dep, _| next if @ignore_deps dep_f = dep.to_formula - next unless dep_f.license.all? { |license| forbidden_licenses.include? license } + next unless dep_f.license.all? { |license| forbidden_licenses.include?(license.to_s) } raise CannotInstallFormulaError, <<~EOS The installation of #{formula.name} has a dependency on #{dep.name} where all its licenses are forbidden: #{dep_f.license}. @@ -1144,7 +1147,7 @@ class FormulaInstaller end return if @only_deps - return unless formula.license.all? { |license| forbidden_licenses.include? license } + return unless formula.license.all? { |license| forbidden_licenses.include?(license.to_s) } raise CannotInstallFormulaError, <<~EOS #{formula.name}'s licenses are all forbidden: #{formula.license}. diff --git a/docs/Formula-Cookbook.md b/docs/Formula-Cookbook.md index f3fad76169..30b373e6e1 100644 --- a/docs/Formula-Cookbook.md +++ b/docs/Formula-Cookbook.md @@ -91,7 +91,7 @@ Try to summarise from the [`homepage`](https://rubydoc.brew.sh/Formula#homepage% **We don’t accept new formulae into Homebrew/homebrew-core without a [`license`](https://rubydoc.brew.sh/Formula#license-class_method)!** -Find the license identifier from the [SPDX License List](https://spdx.org/licenses/). We only accept licenses from this list that are a [Debian Free Software Guidelines license](https://wiki.debian.org/DFSGLicenses). +Find the license identifier from the [SPDX License List](https://spdx.org/licenses/) (or `:public_domain` for software in the public domain). We only accept licenses from this list that are a [Debian Free Software Guidelines license](https://wiki.debian.org/DFSGLicenses) (or public domain based on [the Debian Free Software Guidelines on Public Domain software](https://wiki.debian.org/DFSGLicenses#Public_Domain)). If the software is available under multiple licenses, you should list them all in an array: