From: Brice Waegeneire <brice@waegenei.re>
To: 37928@debbugs.gnu.org
Subject: [bug#37928] [PATCH v2] import: crate: Better handle license expressions.
Date: Tue, 26 Nov 2019 21:17:21 +0100 [thread overview]
Message-ID: <20191126201721.7370-2-brice@waegenei.re> (raw)
In-Reply-To: <20191126201721.7370-1-brice@waegenei.re>
* 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")
--
2.19.2
next prev parent reply other threads:[~2019-11-26 20:18 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-10-25 20:27 [bug#37927] Brice Waegeneire
2019-10-25 20:27 ` [bug#37928] [PATCH] import: crate: Fix licenses Brice Waegeneire
2019-11-04 22:27 ` [bug#37927] " Ludovic Courtès
2019-11-16 16:37 ` Ludovic Courtès
2019-11-26 20:17 ` [bug#37928] Brice Waegeneire
2019-11-26 20:17 ` Brice Waegeneire [this message]
2019-12-11 11:24 ` bug#37927: [bug#37928] [PATCH v2] import: crate: Better handle license expressions Ludovic Courtès
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20191126201721.7370-2-brice@waegenei.re \
--to=brice@waegenei.re \
--cc=37928@debbugs.gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/guix.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.