[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH 03/12] import: utils: Add some utilities.
From: |
David Craven |
Subject: |
[PATCH 03/12] import: utils: Add some utilities. |
Date: |
Sun, 11 Dec 2016 18:25:28 +0100 |
* gnu/import/utils.scm (json-fetch, maybe-inputs, maybe-native-inputs,
package->definition): New variables.
---
guix/import/utils.scm | 43 +++++++++++++++++++++++++++++++++++++++++++
1 file changed, 43 insertions(+)
diff --git a/guix/import/utils.scm b/guix/import/utils.scm
index 057c2d9c7..e2e90676a 100644
--- a/guix/import/utils.scm
+++ b/guix/import/utils.scm
@@ -22,6 +22,8 @@
#:use-module (guix base32)
#:use-module ((guix build download) #:prefix build:)
#:use-module (guix hash)
+ #:use-module (guix http-client)
+ #:use-module (json)
#:use-module ((guix licenses) #:prefix license:)
#:use-module (guix utils)
#:use-module (ice-9 match)
@@ -34,8 +36,13 @@
assoc-ref*
url-fetch
+ json-fetch
guix-hash-url
+ maybe-inputs
+ maybe-native-inputs
+ package->definition
+
spdx-string->license
license->symbol
@@ -205,3 +212,39 @@ into a proper sentence and by using two spaces between
sentences."
;; Use double spacing between sentences
(regexp-substitute/global #f "\\. \\b"
cleaned 'pre ". " 'post)))
+
+(define (package-names->package-inputs names)
+ (map (lambda (input)
+ (list input (list 'unquote (string->symbol input))))
+ names))
+
+(define (maybe-inputs package-names)
+ "Given a list of PACKAGE-NAMES, tries to generate the 'inputs' field of a
+package definition."
+ (match (package-names->package-inputs package-names)
+ (()
+ '())
+ ((package-inputs ...)
+ `((inputs (,'quasiquote ,package-inputs))))))
+
+(define (maybe-native-inputs package-names)
+ "Given a list of PACKAGE-NAMES, tries to generate the 'inputs' field of a
+package definition."
+ (match (package-names->package-inputs package-names)
+ (()
+ '())
+ ((package-inputs ...)
+ `((native-inputs (,'quasiquote ,package-inputs))))))
+
+(define* (json-fetch url)
+ "Return an alist representation of the url metadata."
+ (let* ((port (http-fetch url))
+ (result (json->scm port)))
+ (close-port port)
+ (hash-table->alist result)))
+
+(define (package->definition guix-package)
+ (match guix-package
+ (('package ('name (? string? name)) _ ...)
+ `(define-public ,(string->symbol name)
+ ,guix-package))))
--
2.11.0
- [PATCH 00/12] Rust build system v2., David Craven, 2016/12/11
- [PATCH 03/12] import: utils: Add some utilities.,
David Craven <=
- [PATCH 02/12] build-system: Add cargo build system., David Craven, 2016/12/11
- [PATCH 05/12] import: Add updater for rust crates., David Craven, 2016/12/11
- [PATCH 06/12] gnu: llvm: Enable install utils., David Craven, 2016/12/11
- [PATCH 04/12] import: Add importer for rust crates., David Craven, 2016/12/11