From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:470:142:3::10]:43571) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1i4RHs-00067l-DP for guix-patches@gnu.org; Sun, 01 Sep 2019 10:57:05 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1i4RHr-0004ui-GI for guix-patches@gnu.org; Sun, 01 Sep 2019 10:57:04 -0400 Received: from debbugs.gnu.org ([209.51.188.43]:48236) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1i4RHr-0004uV-Cx for guix-patches@gnu.org; Sun, 01 Sep 2019 10:57:03 -0400 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1i4RHr-0008Q5-BR for guix-patches@gnu.org; Sun, 01 Sep 2019 10:57:03 -0400 Subject: [bug#37254] [PATCH 4/4] import: crate: Correct interpretation of dual-licensing strings. Resent-Message-ID: From: Ludovic =?UTF-8?Q?Court=C3=A8s?= Date: Sun, 1 Sep 2019 16:56:03 +0200 Message-Id: <20190901145603.15515-4-ludo@gnu.org> In-Reply-To: <20190901145603.15515-1-ludo@gnu.org> References: <20190901145603.15515-1-ludo@gnu.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guix-patches-bounces+kyle=kyleam.com@gnu.org Sender: "Guix-patches" To: 37254@debbugs.gnu.org * 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 bcd5068e6c..a1cbf33361 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 (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 8a232ba06c..c14862ad9f 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\" } -- 2.23.0