From 60ec30d41eeee3ea71e8d0755f41d2780aae2052 Mon Sep 17 00:00:00 2001 From: Rylan Polster Date: Tue, 18 Aug 2020 10:58:32 -0400 Subject: [PATCH] formula: update license specification --- Library/.rubocop.yml | 4 ++++ Library/Homebrew/.rubocop.yml | 8 ++++++++ Library/Homebrew/cmd/info.rb | 9 ++------- Library/Homebrew/formula.rb | 22 ++++++++++++---------- Library/Homebrew/formula_installer.rb | 14 ++++++++++---- 5 files changed, 36 insertions(+), 21 deletions(-) diff --git a/Library/.rubocop.yml b/Library/.rubocop.yml index 0c51ee156..dc1ee29a3 100644 --- a/Library/.rubocop.yml +++ b/Library/.rubocop.yml @@ -68,6 +68,10 @@ Style/HashTransformKeys: Style/HashTransformValues: Enabled: true +# Allow for license expressions +Style/HashAsLastArrayItem: + Enabled: false + # Enabled now LineLength is lowish. Style/IfUnlessModifier: Enabled: true diff --git a/Library/Homebrew/.rubocop.yml b/Library/Homebrew/.rubocop.yml index 6799841ae..d517069b8 100644 --- a/Library/Homebrew/.rubocop.yml +++ b/Library/Homebrew/.rubocop.yml @@ -61,6 +61,8 @@ Metrics/MethodLength: Metrics/ModuleLength: Enabled: true Max: 600 + Exclude: + - 'test/**/*' Metrics/PerceivedComplexity: Enabled: true Max: 90 @@ -143,3 +145,9 @@ Style/GuardClause: # so many of these in formulae but none in here Style/StringConcatenation: Enabled: true + +# don't want this for formulae but re-enabled for Library/Homebrew +Style/HashAsLastArrayItem: + Enabled: true + Exclude: + - 'test/utils/spdx_spec.rb' diff --git a/Library/Homebrew/cmd/info.rb b/Library/Homebrew/cmd/info.rb index 42089d4d8..c5884e0e0 100644 --- a/Library/Homebrew/cmd/info.rb +++ b/Library/Homebrew/cmd/info.rb @@ -8,6 +8,7 @@ require "formula" require "keg" require "tab" require "json" +require "utils/spdx" module Homebrew module_function @@ -211,13 +212,7 @@ module Homebrew puts "From: #{Formatter.url(github_info(f))}" - if f.license.present? - licenses = f.license - .map(&:to_s) - .join(", ") - .sub("public_domain", "Public Domain") - puts "License: #{licenses}" - end + puts "License: #{SPDX.license_expression_to_string f.license}" if f.license.present? unless f.deps.empty? ohai "Dependencies" diff --git a/Library/Homebrew/formula.rb b/Library/Homebrew/formula.rb index 9cdf6324b..cf1b784e8 100644 --- a/Library/Homebrew/formula.rb +++ b/Library/Homebrew/formula.rb @@ -2219,18 +2219,20 @@ class Formula # @!attribute [w] # The SPDX ID of the open-source license that the formula uses. # Shows when running `brew info`. - # 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. + # Use `:any`, `:all` or `:with` to describe complex license expressions. + # `:any` should be used when the user can choose which license to use. + # `:all` should be used when the user must use all licenses. + # `:with` should be used to specify a valid SPDX exception. + # Add `+` to an identifier to indicate that the formulae can be + # licensed under later versions of the same license. + # @see https://spdx.github.io/spdx-spec/appendix-IV-SPDX-license-expressions/ SPDX license expression guide #
license "BSD-2-Clause"
- #
license ["MIT", "GPL-2.0"]
+ #
license "EPL-1.0+"
+ #
license any_of: ["MIT", "GPL-2.0-only"]
+ #
license all_of: ["MIT", "GPL-2.0-only"]
+ #
license "GPL-2.0-only" => { with: "LLVM-exception" }
#
license :public_domain
- def license(args = nil) - if args.nil? - @licenses - else - @licenses = Array(args) - end - end + attr_rw :license # @!attribute [w] homepage # The homepage for the software. Used by users to get more information diff --git a/Library/Homebrew/formula_installer.rb b/Library/Homebrew/formula_installer.rb index bb207ba2e..57a62988e 100644 --- a/Library/Homebrew/formula_installer.rb +++ b/Library/Homebrew/formula_installer.rb @@ -19,6 +19,7 @@ require "messages" require "cask/cask_loader" require "cmd/install" require "find" +require "utils/spdx" class FormulaInstaller include FormulaCellarChecks @@ -1130,24 +1131,29 @@ class FormulaInstaller .to_s .sub("Public Domain", "public_domain") .split(" ") + .to_h do |license| + [license, SPDX.license_version_info(license)] + end + 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.to_s) } + next unless SPDX.licenses_forbid_installation? dep_f.license, forbidden_licenses raise CannotInstallFormulaError, <<~EOS - The installation of #{formula.name} has a dependency on #{dep.name} where all its licenses are forbidden: #{dep_f.license}. + The installation of #{formula.name} has a dependency on #{dep.name} where all its licenses are forbidden: + #{SPDX.license_expression_to_string dep_f.license}. EOS end return if @only_deps - return unless formula.license.all? { |license| forbidden_licenses.include?(license.to_s) } + return unless SPDX.licenses_forbid_installation? formula.license, forbidden_licenses raise CannotInstallFormulaError, <<~EOS - #{formula.name}'s licenses are all forbidden: #{formula.license}. + #{formula.name}'s licenses are all forbidden: #{SPDX.license_expression_to_string formula.license}. EOS end end