Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve/fix HOMEBREW_FORBIDDEN_LICENSES handling #18587

Merged
merged 1 commit into from
Oct 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Library/Homebrew/env_config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ module EnvConfig
"formula or cask if it or any of its dependencies is on this list.",
},
HOMEBREW_FORBIDDEN_LICENSES: {
description: "A space-separated list of licenses. Homebrew will refuse to install a " \
description: "A space-separated list of SPDX license identifiers. Homebrew will refuse to install a " \
"formula if it or any of its dependencies has a license on this list.",
},
HOMEBREW_FORBIDDEN_OWNER: {
Expand Down
25 changes: 21 additions & 4 deletions Library/Homebrew/formula_installer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1482,8 +1482,25 @@
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)]

invalid_licenses = []
forbidden_licenses = forbidden_licenses.split.each_with_object({}) do |license, hash|
unless SPDX.valid_license?(license)
invalid_licenses << license
next

Check warning on line 1490 in Library/Homebrew/formula_installer.rb

View check run for this annotation

Codecov / codecov/patch

Library/Homebrew/formula_installer.rb#L1490

Added line #L1490 was not covered by tests
end

hash[license] = SPDX.license_version_info(license)
end

if invalid_licenses.present?
opoo <<~EOS
HOMEBREW_FORBIDDEN_LICENSES contains invalid license identifiers: #{invalid_licenses.to_sentence}
These licenses will not be forbidden. See the valid SPDX license identifiers at:
#{Formatter.url("https://spdx.org/licenses/")}
And the licenses for a formula with:
brew info <formula>
EOS
end

return if forbidden_licenses.blank?
Expand All @@ -1501,7 +1518,7 @@
raise CannotInstallFormulaError, <<~EOS
The installation of #{formula.name} has a dependency on #{dep.name} where all
its licenses were forbidden by #{owner} in `HOMEBREW_FORBIDDEN_LICENSES`:
#{SPDX.license_expression_to_string dep_f.license}.#{owner_contact}
#{SPDX.license_expression_to_string dep_f.license}#{owner_contact}
EOS
end
end
Expand All @@ -1512,7 +1529,7 @@

raise CannotInstallFormulaError, <<~EOS
#{formula.name}'s licenses are all forbidden by #{owner} in `HOMEBREW_FORBIDDEN_LICENSES`:
#{SPDX.license_expression_to_string formula.license}.#{owner_contact}
#{SPDX.license_expression_to_string formula.license}#{owner_contact}
EOS
end

Expand Down
4 changes: 2 additions & 2 deletions docs/Manpage.md
Original file line number Diff line number Diff line change
Expand Up @@ -3798,8 +3798,8 @@ command execution e.g. `$(cat file)`.

`HOMEBREW_FORBIDDEN_LICENSES`

: A space-separated list of licenses. Homebrew will refuse to install a formula
if it or any of its dependencies has a license on this list.
: A space-separated list of SPDX license identifiers. Homebrew will refuse to
install a formula if it or any of its dependencies has a license on this list.

`HOMEBREW_FORBIDDEN_OWNER`

Expand Down
2 changes: 1 addition & 1 deletion manpages/brew.1
Original file line number Diff line number Diff line change
Expand Up @@ -2470,7 +2470,7 @@ A space\-separated list of casks\. Homebrew will refuse to install a cask if it
A space\-separated list of formulae\. Homebrew will refuse to install a formula or cask if it or any of its dependencies is on this list\.
.TP
\fBHOMEBREW_FORBIDDEN_LICENSES\fP
A space\-separated list of licenses\. Homebrew will refuse to install a formula if it or any of its dependencies has a license on this list\.
A space\-separated list of SPDX license identifiers\. Homebrew will refuse to install a formula if it or any of its dependencies has a license on this list\.
.TP
\fBHOMEBREW_FORBIDDEN_OWNER\fP
The person who has set any \fBHOMEBREW_FORBIDDEN_*\fP variables\.
Expand Down
Loading