Subject: [bug#42338] [PATCH 6/9] guix: import: composer: More robust string->license.

From: Nicolas Graves <[email-masked]>
Date: Thu, 2 Nov 2023 16:04:26 +0100

* guix/import/composer.scm (string->license): Use spdx-string->license. Fall
back to unknown-license!.
---
 guix/import/composer.scm | 28 +++++++++++++++-------------
 1 file changed, 15 insertions(+), 13 deletions(-)

diff --git a/guix/import/composer.scm b/guix/import/composer.scm
index 3acbbecf82..49f16caedf 100644
--- a/guix/import/composer.scm
+++ b/guix/import/composer.scm
@@ -109,7 +109,10 @@ (define-json-mapping <composer-package> make-composer-package composer-package?
   (dev-require composer-package-dev-require "require-dev" json->require)
   (license     composer-package-license "license"
                (lambda (vector)
-                 (map string->license (vector->list vector)))))
+                 (let ((l (map string->license (vector->list vector))))
+                   (if (eq? (length l) 1)
+                       (car l)
+                       `(list ,@l))))))
 
 (define* (composer-fetch name #:optional version)
   "Return an alist representation of the Composer metadata for the package NAME,
@@ -194,10 +197,8 @@ (define (make-php-sexp composer-package)
                (synopsis "")
                (description ,(composer-package-description composer-package))
                (home-page ,(composer-package-homepage composer-package))
-               (license ,(match (composer-package-license composer-package)
-                           (() #f)
-                           ((license) license)
-                           (_ license)))))))))
+               (license ,(or (composer-package-license composer-package)
+                             'unknown-license!))))))))
 
 (define composer->guix-package
   (memoize
@@ -234,14 +235,15 @@ (define (guix-package->composer-name package)
 
 (define (string->license str)
   "Convert the string STR into a license object."
-  (match str
-    ("GNU LGPL" 'license:lgpl2.0)
-    ("GPL" 'license:gpl3)
-    ((or "BSD" "BSD License" "BSD-3-Clause") 'license:bsd-3)
-    ((or "MIT" "MIT license" "Expat license") 'license:expat)
-    ("Public domain" 'license:public-domain)
-    ((or "Apache License, Version 2.0" "Apache 2.0") 'license:asl2.0)
-    (_ #f)))
+  (or (spdx-string->license str)
+      (match str
+        ("GNU LGPL" 'license:lgpl2.0)
+        ("GPL" 'license:gpl3)
+        ((or "BSD" "BSD License") 'license:bsd-3)
+        ((or "MIT" "MIT license" "Expat license") 'license:expat)
+        ("Public domain" 'license:public-domain)
+        ((or "Apache License, Version 2.0" "Apache 2.0") 'license:asl2.0)
+        (_ 'unknown-license!))))
 
 (define (php-package? package)
   "Return true if PACKAGE is a PHP package from Packagist."
-- 
2.41.0