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.
This commit is contained in:
Ludovic Courtès 2019-09-01 16:32:11 +02:00
parent 2791870d09
commit 191668bc97
No known key found for this signature in database
GPG Key ID: 090B11993D9AEBB5
2 changed files with 11 additions and 2 deletions

View File

@ -32,6 +32,7 @@
#:use-module (guix upstream) #:use-module (guix upstream)
#:use-module (guix utils) #:use-module (guix utils)
#:use-module (ice-9 match) #:use-module (ice-9 match)
#:use-module (ice-9 regex)
#:use-module (json) #:use-module (json)
#:use-module (srfi srfi-1) #:use-module (srfi srfi-1)
#:use-module (srfi srfi-2) #:use-module (srfi srfi-2)
@ -175,11 +176,19 @@ and LICENSE."
(close-port port) (close-port port)
pkg)) 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) (define (crate->guix-package crate-name)
"Fetch the metadata for CRATE-NAME from crates.io, and return the "Fetch the metadata for CRATE-NAME from crates.io, and return the
`package' s-expression corresponding to that package, or #f on failure." `package' s-expression corresponding to that package, or #f on failure."
(define (string->license string) (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) (define (normal-dependency? dependency)
(eq? (crate-dependency-kind dependency) 'normal)) (eq? (crate-dependency-kind dependency) 'normal))

View File

@ -41,7 +41,7 @@
\"actual_versions\": [ \"actual_versions\": [
{ \"id\": \"foo\", { \"id\": \"foo\",
\"num\": \"1.0.0\", \"num\": \"1.0.0\",
\"license\": \"MIT/Apache-2.0\", \"license\": \"MIT OR Apache-2.0\",
\"links\": { \"links\": {
\"dependencies\": \"/api/v1/crates/foo/1.0.0/dependencies\" \"dependencies\": \"/api/v1/crates/foo/1.0.0/dependencies\"
} }