From mboxrd@z Thu Jan 1 00:00:00 1970 From: David Craven Subject: [PATCH 05/12] import: utils: Refactor license->symbol. Date: Thu, 22 Sep 2016 15:18:56 +0200 Message-ID: <20160922131903.1606-5-david@craven.ch> References: <20160922131903.1606-1-david@craven.ch> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:43296) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bn3ui-0004UJ-T3 for guix-devel@gnu.org; Thu, 22 Sep 2016 09:20:03 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bn3uT-0001aj-Ft for guix-devel@gnu.org; Thu, 22 Sep 2016 09:19:44 -0400 Received: from so254-10.mailgun.net ([198.61.254.10]:47524) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bn3uS-0001XA-4A for guix-devel@gnu.org; Thu, 22 Sep 2016 09:19:29 -0400 In-Reply-To: <20160922131903.1606-1-david@craven.ch> List-Id: "Development of GNU Guix and the GNU System distribution." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guix-devel-bounces+gcggd-guix-devel=m.gmane.org@gnu.org Sender: "Guix-devel" To: guix-devel@gnu.org * guix/import/utils.scm (license->symbol): Work for all licenses. * tests/import-utils.scm (license->symbol): Add test. --- guix/import/utils.scm | 14 +++++--------- tests/import-utils.scm | 5 +++++ 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/guix/import/utils.scm b/guix/import/utils.scm index ca00baf..8dab72a 100644 --- a/guix/import/utils.scm +++ b/guix/import/utils.scm @@ -3,6 +3,7 @@ ;;; Copyright © 2014 David Thompson ;;; Copyright © 2015 Eric Bavier ;;; Copyright © 2016 Jelle Licht +;;; Copyright © 2016 David Craven ;;; ;;; This file is part of GNU Guix. ;;; @@ -178,15 +179,10 @@ recursively apply the procedure to the sub-list." (define (license->symbol license) "Convert license to a symbol representing the variable the object is bound to in the (guix licenses) module, or #f if there is no such known license." - ;; TODO: Traverse list public variables in (guix licenses) instead so we - ;; don't have to maintain a list manualy. - (assoc-ref `((,license:lgpl2.0 . license:lgpl2.0) - (,license:gpl3 . license:gpl3) - (,license:bsd-3 . license:bsd-3) - (,license:expat . license:expat) - (,license:public-domain . license:public-domain) - (,license:asl2.0 . license:asl2.0)) - license)) + (define licenses + (module-map (lambda (sym var) `(,(variable-ref var) . ,sym)) + (resolve-interface '(guix licenses) #:prefix 'license:))) + (assoc-ref licenses license)) (define (snake-case str) "Return a downcased version of the string STR where underscores are replaced diff --git a/tests/import-utils.scm b/tests/import-utils.scm index 3b11875..8d44b9e 100644 --- a/tests/import-utils.scm +++ b/tests/import-utils.scm @@ -20,6 +20,7 @@ (define-module (test-import-utils) #:use-module (guix tests) #:use-module (guix import utils) + #:use-module ((guix licenses) #:prefix license:) #:use-module (srfi srfi-64)) (test-begin "import-utils") @@ -33,4 +34,8 @@ "This package provides a function to establish world peace" (beautify-description "A function to establish world peace")) +(test-equal "license->symbol" + 'license:lgpl2.0 + (license->symbol license:lgpl2.0)) + (test-end "import-utils") -- 2.9.0