diff mbox series

[bug#40629,4/5] scripts/build: options->things-to-build: Handle .json files.

Message ID 20200414171959.3428-4-rekado@elephly.net
State Accepted
Headers show
Series [bug#40629,1/5] import/print: Return license with prefix. | expand

Checks

Context Check Description
cbaines/comparison success View comparision
cbaines/git branch success View Git branch
cbaines/applying patch success View Laminar job

Commit Message

Ricardo Wurmus April 14, 2020, 5:19 p.m. UTC
* guix/scripts/build.scm (options->things-to-build): Handle files that end on
.json.
---
 guix/scripts/build.scm | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

Comments

Ludovic Courtès April 16, 2020, 9:45 p.m. UTC | #1
Hello!

Ricardo Wurmus <rekado@elephly.net> skribis:

> +                 (let ((file (or (and (string-suffix? ".json" file)
> +                                      (json->scheme-file file))
> +                                 file)))
> +                   (ensure-list (load* file (make-user-module '())))))

It would be nice if we could avoid writing to a file and then reading it
back, perhaps by having a variant of ‘load*’ that takes an sexp instead
of a file name.  (That could also allow us to improve error reporting
because we could attach source properties to the sexp that match the
original JSON file.)

Ludo’.
Ludovic Courtès April 16, 2020, 9:53 p.m. UTC | #2
Ricardo Wurmus <rekado@elephly.net> skribis:

> +                 (let ((file (or (and (string-suffix? ".json" file)
> +                                      (json->scheme-file file))
> +                                 file)))
> +                   (ensure-list (load* file (make-user-module '())))))

Actually, perhaps we could have a file handler alist, like:

  `((".json" ,load-json)
    (_ ,(cute load* <> (make-user-module '()))))

That could be shared with (guix scripts package), and ‘load-json’ could
do something that avoids going through a file.

Late feedback, nightly thoughts.  :-)

Ludo’.
diff mbox series

Patch

diff --git a/guix/scripts/build.scm b/guix/scripts/build.scm
index 79bd84a1a0..8ff2fd1910 100644
--- a/guix/scripts/build.scm
+++ b/guix/scripts/build.scm
@@ -2,6 +2,7 @@ 
 ;;; Copyright © 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019, 2020 Ludovic Courtès <ludo@gnu.org>
 ;;; Copyright © 2013 Mark H Weaver <mhw@netris.org>
 ;;; Copyright © 2020 Marius Bakke <mbakke@fastmail.com>
+;;; Copyright © 2020 Ricardo Wurmus <rekado@elephly.net>
 ;;;
 ;;; This file is part of GNU Guix.
 ;;;
@@ -21,6 +22,7 @@ 
 (define-module (guix scripts build)
   #:use-module (guix ui)
   #:use-module (guix scripts)
+  #:use-module (guix import json)
   #:use-module (guix store)
   #:use-module (guix derivations)
   #:use-module (guix packages)
@@ -834,7 +836,10 @@  build---packages, gexps, derivations, and so on."
                        (else
                         (list (specification->package spec)))))
                 (('file . file)
-                 (ensure-list (load* file (make-user-module '()))))
+                 (let ((file (or (and (string-suffix? ".json" file)
+                                      (json->scheme-file file))
+                                 file)))
+                   (ensure-list (load* file (make-user-module '())))))
                 (('manifest . manifest)
                  (map manifest-entry-item
                       (manifest-entries