[bug#58621,3/3] import/utils: spdx-string->license: Support '+' operator.
Commit Message
Previously, '+' was supported only via special cases for deprecated
GNU identifiers like 'GPL-N+'. This commit adds support
for other uses of '+', such as 'AFL-2.0+' and 'LPPL-1.0+'.
Strictly speaking, '+' is an operator, not part of the SPDX license
identifier, but it is useful to handle it here.
* guix/import/utils.scm (spdx-string->license): Support '+' operator.
---
guix/import/utils.scm | 24 +++++++++++++++---------
1 file changed, 15 insertions(+), 9 deletions(-)
Comments
Hi,
Applied all three patches. I added trivial tests for
‘spdx-string->license’ and changed ‘substring’ to ‘string-drop-right’,
which I find clearer.
Philip McGrath <philip@philipmcgrath.com> skribis:
> + (and (string-suffix? "+" str)
> + ;; We try the form with the + to support deprecated identifiers for
> + ;; GNU licenses (see above). Here, we handle other uses of +.
> + (spdx-string->license
> + (substring str 0 (- (string-length str) 1)))))))
I guess we can remove the “+” forms from the alist now?
Thanks,
Ludo’.
Hi,
On Friday, November 18, 2022 8:45:26 AM EST Ludovic Courtès wrote:
> Hi,
>
> Applied all three patches. I added trivial tests for
> ‘spdx-string->license’ and changed ‘substring’ to ‘string-drop-right’,
> which I find clearer.
>
Thanks!
> Philip McGrath <philip@philipmcgrath.com> skribis:
> > + (and (string-suffix? "+" str)
> > + ;; We try the form with the + to support deprecated identifiers
> > for + ;; GNU licenses (see above). Here, we handle other uses
> > of +. + (spdx-string->license
> > + (substring str 0 (- (string-length str) 1)))))))
>
> I guess we can remove the “+” forms from the alist now?
>
I think we still want the "+" forms in the alist so that we continue convert
"GPL-2.0+" as though it were "GPL-2.0-or-later", not "GPL-2.0-only".
Some upstreams probably wrote "GPL-2.0" out of confusion even though they
intended to allow "any later version" (and maybe even said so in prose), which
is why the "+" operator was deprecated for GNU licenses.
If upstream wrote "GPL-2.0+", though, that does communicate "or, at your
option, any later version"; since that's the more compatible case, it seemed
useful to retain that information when we have it.
Ideally, upstream projects should move away from the deprecated identifiers
(the Racket tooling I've written will complain), but they still seem to come
up often enough in the wild to be worth handling as special cases.
-Philip
Hi,
Philip McGrath <philip@philipmcgrath.com> skribis:
> On Friday, November 18, 2022 8:45:26 AM EST Ludovic Courtès wrote:
[...]
>> Philip McGrath <philip@philipmcgrath.com> skribis:
>> > + (and (string-suffix? "+" str)
>> > + ;; We try the form with the + to support deprecated identifiers
>> > for + ;; GNU licenses (see above). Here, we handle other uses
>> > of +. + (spdx-string->license
>> > + (substring str 0 (- (string-length str) 1)))))))
>>
>> I guess we can remove the “+” forms from the alist now?
>>
>
> I think we still want the "+" forms in the alist so that we continue convert
> "GPL-2.0+" as though it were "GPL-2.0-or-later", not "GPL-2.0-only".
Oh right. Then I wonder why the code above (with ‘substring’) doesn’t
replace “+” with “-or-later”?
Ludo’.
@@ -139,10 +139,11 @@ (define %spdx-license-identifiers
;; Please update guix/licenses.scm when modifying
;; this list to avoid mismatches.
;;
- ;; "GPL-N+" has been deprecated in favour of "GPL-N-or-later".
- ;; "GPL-N" has been deprecated in favour of "GPL-N-only"
- ;; or "GPL-N-or-later" as appropriate. Likewise for LGPL
- ;; and AGPL.
+ ;; "GPL-N+" has been deprecated in favour of "GPL-N-or-later". "GPL-N" has
+ ;; been deprecated in favour of "GPL-N-only" or "GPL-N-or-later" as
+ ;; appropriate. Likewise for LGPL and AGPL. However, we list the
+ ;; deprecated forms here (with and without the "+" operator) to get better
+ ;; results from old license expressions.
'(("AGPL-1.0" . license:agpl1)
("AGPL-1.0-only" . license:agpl1)
("AGPL-3.0" . license:agpl3)
@@ -255,10 +256,11 @@ (define %spdx-license-identifiers
("Zlib" . license:zlib)))
(define (spdx-string->license str)
- "Convert STR, an SPDX license identifier, to a symbol like 'license:gpl3+
-giving the prefixed name of a license object exported from (guix licenses).
-Return #f if STR does not match any known SPDX license identifiers. Per the
-SPDX specification, license identifiers are compared case-insensitively."
+ "Convert STR, an SPDX license identifier (possibly with a postfix +
+operator), to a symbol like 'license:gpl3+ giving the prefixed name of a
+license object exported from (guix licenses). Return #f if STR does not match
+any known SPDX license identifiers. Per the SPDX specification, license
+identifiers are compared case-insensitively."
;; https://spdx.github.io/spdx-spec/v2.3/SPDX-license-expressions/#d2-case-sensitivity
;; Operators AND, OR, and WITH are case-sensitive, but identifiers are
;; case-insensitive for matching, though the canonical case is used in URIs.
@@ -266,7 +268,11 @@ (define (spdx-string->license str)
((_ . license)
license)
(#f
- #f)))
+ (and (string-suffix? "+" str)
+ ;; We try the form with the + to support deprecated identifiers for
+ ;; GNU licenses (see above). Here, we handle other uses of +.
+ (spdx-string->license
+ (substring str 0 (- (string-length str) 1)))))))
(define (license->symbol license)
"Convert LICENSE object to a prefixed symbol representing the variable the