Merge pull request #8972 from Rylan12/license-add-cannot-represent
Add more license symbol functionality
This commit is contained in:
commit
c4ae961efa
@ -1139,11 +1139,12 @@ class FormulaInstaller
|
||||
end
|
||||
|
||||
def forbidden_license_check
|
||||
forbidden_licenses = Homebrew::EnvConfig.forbidden_licenses
|
||||
.to_s
|
||||
.sub("Public Domain", "public_domain")
|
||||
.split(" ")
|
||||
.to_h do |license|
|
||||
forbidden_licenses = Homebrew::EnvConfig.forbidden_licenses.to_s.dup
|
||||
SPDX::ALLOWED_LICENSE_SYMBOLS.each do |s|
|
||||
pattern = /#{s.to_s.tr("_", " ")}/i
|
||||
forbidden_licenses.sub!(pattern, s.to_s)
|
||||
end
|
||||
forbidden_licenses = forbidden_licenses.split(" ").to_h do |license|
|
||||
[license, SPDX.license_version_info(license)]
|
||||
end
|
||||
|
||||
|
||||
@ -91,6 +91,10 @@ describe SPDX do
|
||||
it "returns :public_domain" do
|
||||
expect(described_class.parse_license_expression(:public_domain).first).to eq [:public_domain]
|
||||
end
|
||||
|
||||
it "returns :cannot_represent" do
|
||||
expect(described_class.parse_license_expression(:cannot_represent).first).to eq [:cannot_represent]
|
||||
end
|
||||
end
|
||||
|
||||
describe ".valid_license?" do
|
||||
@ -113,6 +117,14 @@ describe SPDX do
|
||||
it "returns true for :public_domain" do
|
||||
expect(described_class.valid_license?(:public_domain)).to eq true
|
||||
end
|
||||
|
||||
it "returns true for :cannot_represent" do
|
||||
expect(described_class.valid_license?(:cannot_represent)).to eq true
|
||||
end
|
||||
|
||||
it "returns false for invalid symbol" do
|
||||
expect(described_class.valid_license?(:invalid_symbol)).to eq false
|
||||
end
|
||||
end
|
||||
|
||||
describe ".deprecated_license?" do
|
||||
@ -131,6 +143,10 @@ describe SPDX do
|
||||
it "returns false for :public_domain" do
|
||||
expect(described_class.deprecated_license?(:public_domain)).to eq false
|
||||
end
|
||||
|
||||
it "returns false for :cannot_represent" do
|
||||
expect(described_class.deprecated_license?(:cannot_represent)).to eq false
|
||||
end
|
||||
end
|
||||
|
||||
describe ".valid_license_exception?" do
|
||||
@ -187,9 +203,13 @@ describe SPDX do
|
||||
it "returns :public_domain" do
|
||||
expect(described_class.license_expression_to_string(:public_domain)).to eq "Public Domain"
|
||||
end
|
||||
|
||||
it "returns :cannot_represent" do
|
||||
expect(described_class.license_expression_to_string(:cannot_represent)).to eq "Cannot Represent"
|
||||
end
|
||||
end
|
||||
|
||||
describe ".license_version_info_info" do
|
||||
describe ".license_version_info" do
|
||||
it "returns license without version" do
|
||||
expect(described_class.license_version_info("MIT")).to eq ["MIT"]
|
||||
end
|
||||
|
||||
@ -15,6 +15,10 @@ module SPDX
|
||||
|
||||
DATA_PATH = (HOMEBREW_DATA_PATH/"spdx").freeze
|
||||
API_URL = "https://api.github.com/repos/spdx/license-list-data/releases/latest"
|
||||
ALLOWED_LICENSE_SYMBOLS = [
|
||||
:public_domain,
|
||||
:cannot_represent,
|
||||
].freeze
|
||||
|
||||
def license_data
|
||||
@license_data ||= JSON.parse (DATA_PATH/"spdx_licenses.json").read
|
||||
@ -64,14 +68,14 @@ module SPDX
|
||||
end
|
||||
|
||||
def valid_license?(license)
|
||||
return true if license == :public_domain
|
||||
return ALLOWED_LICENSE_SYMBOLS.include? license if license.is_a? Symbol
|
||||
|
||||
license = license.delete_suffix "+"
|
||||
license_data["licenses"].any? { |spdx_license| spdx_license["licenseId"] == license }
|
||||
end
|
||||
|
||||
def deprecated_license?(license)
|
||||
return false if license == :public_domain
|
||||
return false if ALLOWED_LICENSE_SYMBOLS.include? license
|
||||
return false unless valid_license?(license)
|
||||
|
||||
license_data["licenses"].none? do |spdx_license|
|
||||
@ -89,8 +93,8 @@ module SPDX
|
||||
case license_expression
|
||||
when String
|
||||
license_expression
|
||||
when :public_domain
|
||||
"Public Domain"
|
||||
when Symbol
|
||||
license_expression.to_s.tr("_", " ").titleize
|
||||
when Hash
|
||||
expressions = []
|
||||
|
||||
@ -125,7 +129,7 @@ module SPDX
|
||||
end
|
||||
|
||||
def license_version_info(license)
|
||||
return [license] if license == :public_domain
|
||||
return [license] if ALLOWED_LICENSE_SYMBOLS.include? license
|
||||
|
||||
match = license.match(/-(?<version>[0-9.]+)(?:-.*?)??(?<or_later>\+|-only|-or-later)?$/)
|
||||
return [license] if match.blank?
|
||||
|
||||
@ -18,6 +18,12 @@ The public domain can be indicated using a symbol:
|
||||
license :public_domain
|
||||
```
|
||||
|
||||
If the license for a formula cannot be represented using an SPDX expression:
|
||||
|
||||
```ruby
|
||||
license :cannot_represent
|
||||
```
|
||||
|
||||
## Complex SPDX License Expressions
|
||||
|
||||
Some formulae have multiple licenses that need to be combined in different ways. In these cases, a more complex license expression can be used. These expressions are based on the [SPDX License Expression Guidelines](https://spdx.github.io/spdx-spec/appendix-IV-SPDX-license-expressions/).
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user