From patchwork Tue Nov 26 20:17:21 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Brice Waegeneire X-Patchwork-Id: 16251 Return-Path: X-Original-To: patchwork@mira.cbaines.net Delivered-To: patchwork@mira.cbaines.net Received: by mira.cbaines.net (Postfix, from userid 113) id 6D954177CC; Tue, 26 Nov 2019 20:18:24 +0000 (GMT) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on mira.cbaines.net X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=unavailable autolearn_force=no version=3.4.0 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mira.cbaines.net (Postfix) with ESMTP id 304D7177C9 for ; Tue, 26 Nov 2019 20:18:24 +0000 (GMT) Received: from localhost ([::1]:58732 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iZhHz-0001PS-K6 for patchwork@mira.cbaines.net; Tue, 26 Nov 2019 15:18:23 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:41597) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iZhHk-0001P1-6p for guix-patches@gnu.org; Tue, 26 Nov 2019 15:18:10 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iZhHh-00008j-Ta for guix-patches@gnu.org; Tue, 26 Nov 2019 15:18:08 -0500 Received: from debbugs.gnu.org ([209.51.188.43]:47060) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1iZhHe-00005m-Gx for guix-patches@gnu.org; Tue, 26 Nov 2019 15:18:03 -0500 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1iZhHe-0003Sk-Dx for guix-patches@gnu.org; Tue, 26 Nov 2019 15:18:02 -0500 X-Loop: help-debbugs@gnu.org Subject: [bug#37928] [PATCH v2] import: crate: Better handle license expressions. Resent-From: Brice Waegeneire Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Tue, 26 Nov 2019 20:18:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 37928 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: 37928@debbugs.gnu.org Received: via spool by 37928-submit@debbugs.gnu.org id=B37928.157479946113035 (code B ref 37928); Tue, 26 Nov 2019 20:18:02 +0000 Received: (at 37928) by debbugs.gnu.org; 26 Nov 2019 20:17:41 +0000 Received: from localhost ([127.0.0.1]:53031 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1iZhHJ-0003O0-9l for submit@debbugs.gnu.org; Tue, 26 Nov 2019 15:17:41 -0500 Received: from relay3-d.mail.gandi.net ([217.70.183.195]:41829) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1iZhHH-0003ML-2G for 37928@debbugs.gnu.org; Tue, 26 Nov 2019 15:17:39 -0500 X-Originating-IP: 78.237.113.178 Received: from localhost (luy13-1-78-237-113-178.fbx.proxad.net [78.237.113.178]) (Authenticated sender: brice@waegenei.re) by relay3-d.mail.gandi.net (Postfix) with ESMTPSA id A632060006 for <37928@debbugs.gnu.org>; Tue, 26 Nov 2019 20:17:37 +0000 (UTC) From: Brice Waegeneire Date: Tue, 26 Nov 2019 21:17:21 +0100 Message-Id: <20191126201721.7370-2-brice@waegenei.re> X-Mailer: git-send-email 2.19.2 In-Reply-To: <20191126201721.7370-1-brice@waegenei.re> References: <20191126201721.7370-1-brice@waegenei.re> MIME-Version: 1.0 X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.51.188.43 X-BeenThere: guix-patches@gnu.org List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guix-patches-bounces+patchwork=mira.cbaines.net@gnu.org Sender: "Guix-patches" X-getmail-retrieved-from-mailbox: Patches * guix/import/crate.scm (%dual-license-rx): Removed function. (crate->guix-package): Handle most of the multi-licensing cases. * tests/crate.scm (licenses): Add tests for some licenses. --- guix/import/crate.scm | 17 ++++++++--------- tests/crate.scm | 23 +++++++++++++++++++++++ 2 files changed, 31 insertions(+), 9 deletions(-) diff --git a/guix/import/crate.scm b/guix/import/crate.scm index 8dc014d232..0915d8295a 100644 --- a/guix/import/crate.scm +++ b/guix/import/crate.scm @@ -178,21 +178,20 @@ 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 (string->license string) + (map + spdx-string->license + (filter (lambda (license) + (and (not (string-null? license)) + (not (any (lambda (elem) (string=? elem license)) + '("AND" "OR" "WITH"))))) + (string-split string (string->char-set " /"))))) (define* (crate->guix-package crate-name #:optional version) "Fetch the metadata for CRATE-NAME from crates.io, and return the `package' s-expression corresponding to that package, or #f on failure. When VERSION is specified, attempt to fetch that version; otherwise fetch the latest version of CRATE-NAME." - (define (string->license 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 c14862ad9f..baad2d0c44 100644 --- a/tests/crate.scm +++ b/tests/crate.scm @@ -63,6 +63,9 @@ (define test-source-hash "") +(define string->license + (@@ (guix import crate) string->license)) + (test-begin "crate") (test-equal "guix-package->crate-name" @@ -111,4 +114,24 @@ (x (pk 'fail x #f))))) +(test-equal "licenses: MIT OR Apache-2.0" + '(license:expat license:asl2.0) + (string->license "MIT OR Apache-2.0")) + +(test-equal "licenses: Apache-2.0 / MIT" + '(license:asl2.0 license:expat) + (string->license "Apache-2.0 / MIT")) + +(test-equal "licenses: Apache-2.0 WITH LLVM-exception" + '(license:asl2.0 #f) + (string->license "Apache-2.0 WITH LLVM-exception")) + +(test-equal "licenses: MIT/Apache-2.0 AND BSD-2-Clause" + '(license:expat license:asl2.0 #f) + (string->license "MIT/Apache-2.0 AND BSD-2-Clause")) + +(test-equal "licenses: MIT/Apache-2.0" + '(license:expat license:asl2.0) + (string->license "MIT/Apache-2.0")) + (test-end "crate")