import/utils: alist->package: Ignore known inputs.

* guix/import/utils.scm (alist->package): Accept optional list of known
inputs, which are excluded from the specification lookup.
* guix/import/print.scm (package->code)[package-lists->code]: Handle inputs
which are just symbols.
This commit is contained in:
Ricardo Wurmus 2020-04-15 00:41:03 +02:00
parent 86a3b540d0
commit 3532fc39ff
No known key found for this signature in database
GPG key ID: 197A5888235FACAC
2 changed files with 18 additions and 11 deletions

View file

@ -92,6 +92,8 @@ (define (source->code source version)
(define (package-lists->code lsts) (define (package-lists->code lsts)
(list 'quasiquote (list 'quasiquote
(map (match-lambda (map (match-lambda
((? symbol? s)
(list (symbol->string s) (list 'unquote s)))
((label pkg . out) ((label pkg . out)
(let ((mod (package-module-name pkg))) (let ((mod (package-module-name pkg)))
(cons* label (cons* label

View file

@ -2,7 +2,7 @@
;;; Copyright © 2012, 2013, 2018, 2019, 2020 Ludovic Courtès <ludo@gnu.org> ;;; Copyright © 2012, 2013, 2018, 2019, 2020 Ludovic Courtès <ludo@gnu.org>
;;; Copyright © 2016 Jelle Licht <jlicht@fsfe.org> ;;; Copyright © 2016 Jelle Licht <jlicht@fsfe.org>
;;; Copyright © 2016 David Craven <david@craven.ch> ;;; Copyright © 2016 David Craven <david@craven.ch>
;;; Copyright © 2017, 2019 Ricardo Wurmus <rekado@elephly.net> ;;; Copyright © 2017, 2019, 2020 Ricardo Wurmus <rekado@elephly.net>
;;; Copyright © 2018 Oleg Pykhalov <go.wigust@gmail.com> ;;; Copyright © 2018 Oleg Pykhalov <go.wigust@gmail.com>
;;; Copyright © 2019 Robert Vollmert <rob@vllmrt.net> ;;; Copyright © 2019 Robert Vollmert <rob@vllmrt.net>
;;; ;;;
@ -310,7 +310,18 @@ (define (source-spec->object source)
(uri (assoc-ref orig "uri")) (uri (assoc-ref orig "uri"))
(sha256 sha)))))) (sha256 sha))))))
(define (alist->package meta) (define* (alist->package meta #:optional (known-inputs '()))
"Return a package value generated from the alist META. If the list of
strings KNOWN-INPUTS is provided, do not treat the mentioned inputs as
specifications to look up and replace them with plain symbols instead."
(define (process-inputs which)
(let-values (((regular known)
(lset-diff+intersection
string=?
(vector->list (or (assoc-ref meta which) #()))
known-inputs)))
(append (specs->package-lists regular)
(map string->symbol known))))
(package (package
(name (assoc-ref meta "name")) (name (assoc-ref meta "name"))
(version (assoc-ref meta "version")) (version (assoc-ref meta "version"))
@ -318,15 +329,9 @@ (define (alist->package meta)
(build-system (build-system
(lookup-build-system-by-name (lookup-build-system-by-name
(string->symbol (assoc-ref meta "build-system")))) (string->symbol (assoc-ref meta "build-system"))))
(native-inputs (native-inputs (process-inputs "native-inputs"))
(specs->package-lists (inputs (process-inputs "inputs"))
(vector->list (or (assoc-ref meta "native-inputs") '#())))) (propagated-inputs (process-inputs "propagated-inputs"))
(inputs
(specs->package-lists
(vector->list (or (assoc-ref meta "inputs") '#()))))
(propagated-inputs
(specs->package-lists
(vector->list (or (assoc-ref meta "propagated-inputs") '#()))))
(home-page (home-page
(assoc-ref meta "home-page")) (assoc-ref meta "home-page"))
(synopsis (synopsis