guix-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

06/07: import: crate: Correct interpretation of dual-licensing strings.


From: guix-commits
Subject: 06/07: import: crate: Correct interpretation of dual-licensing strings.
Date: Wed, 4 Sep 2019 07:02:41 -0400 (EDT)

civodul pushed a commit to branch master
in repository guix.

commit 191668bc9759dc87a27b5f4d55d214cc655f197f
Author: Ludovic Courtès <address@hidden>
Date:   Sun Sep 1 16:32:11 2019 +0200

    import: crate: Correct interpretation of dual-licensing strings.
    
    * guix/import/crate.scm (%dual-license-rx): New variable.
    (crate->guix-package)[string->license]: Rewrite to match it.
    * tests/crate.scm (test-crate): Adjust "license" field to current
    practice.
---
 guix/import/crate.scm | 11 ++++++++++-
 tests/crate.scm       |  2 +-
 2 files changed, 11 insertions(+), 2 deletions(-)

diff --git a/guix/import/crate.scm b/guix/import/crate.scm
index b674323..f6057db 100644
--- a/guix/import/crate.scm
+++ b/guix/import/crate.scm
@@ -32,6 +32,7 @@
   #:use-module (guix upstream)
   #:use-module (guix utils)
   #:use-module (ice-9 match)
+  #:use-module (ice-9 regex)
   #:use-module (json)
   #:use-module (srfi srfi-1)
   #:use-module (srfi srfi-2)
@@ -175,11 +176,19 @@ and LICENSE."
          (close-port port)
          pkg))
 
+(define %dual-license-rx
+  ;; Dual licensing is represented by a string such as "MIT OR Apache-2.0".
+  ;; This regexp matches that.
+  (make-regexp "^(.*) OR (.*)$"))
+
 (define (crate->guix-package crate-name)
   "Fetch the metadata for CRATE-NAME from crates.io, and return the
 `package' s-expression corresponding to that package, or #f on failure."
   (define (string->license string)
-    (map spdx-string->license (string-split string #\/)))
+    (match (regexp-exec %dual-license-rx string)
+      (#f (list (spdx-string->license string)))
+      (m  (list (spdx-string->license (match:substring m 1))
+                (spdx-string->license (match:substring m 2))))))
 
   (define (normal-dependency? dependency)
     (eq? (crate-dependency-kind dependency) 'normal))
diff --git a/tests/crate.scm b/tests/crate.scm
index 8a232ba..c14862a 100644
--- a/tests/crate.scm
+++ b/tests/crate.scm
@@ -41,7 +41,7 @@
     \"actual_versions\": [
       { \"id\": \"foo\",
         \"num\": \"1.0.0\",
-        \"license\": \"MIT/Apache-2.0\",
+        \"license\": \"MIT OR Apache-2.0\",
         \"links\": {
           \"dependencies\": \"/api/v1/crates/foo/1.0.0/dependencies\"
         }



reply via email to

[Prev in Thread] Current Thread [Next in Thread]