guix-patches
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[bug#41253] [PATCH v4] guix repl: Add script execution.


From: Ludovic Courtès
Subject: [bug#41253] [PATCH v4] guix repl: Add script execution.
Date: Fri, 12 Jun 2020 17:58:37 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/26.3 (gnu/linux)

Hi, and sorry for the delay!

Konrad Hinsen <konrad.hinsen@fastmail.net> skribis:

> * guix/scripts/repl.scm: Add filename options for script execution.
> * doc/guix.texi (Invoking guix repl): Document it.
> * tests/guix-repl.sh: Test it.
> * Makefile.am: (SH_TESTS): Add it.

I have some comments regarding style and how to deal with multiple
scripts, but I think we’re pretty much there.

> +The general syntax is:
> +
> +@example
> +guix repl @var{options} @var{file} @var{args}

Should be: [@var{file} @var{args}@dots{}]
The square brackets show it’s optional.

> +When a @var{file} argument is provided, @var{file} is
> +executed as a Guile scripts:

“When one or more @var{file} argument is provided, each @var{file} is
executed as a Guile program:”

> +  (define script (reverse
> +                  (map cdr
> +                       (filter (lambda (opt)
> +                                 (eq? (car opt) 'script))
> +                               opts))))

To avoid car/cdr (info "(guix) Data Types and Pattern Matching"), I
suggest something along these lines:

  (define scripts  ;plural, no?
    (reverse
     (filter-map (match-lambda
                   (('script . script) script)
                   (_ #f))
                 opts)))

> +  (define script-file
> +    (let ((file (car script))
> +          (directory (getcwd)))
> +      (canonicalize-path
> +       (cond ((string-prefix? "/" file) file)
> +             (else (string-append directory "/" file))))))

I think we can just use file names as they arrive, without attempting to
canonicalize them or anything.

> +    (unless (null? script)
> +      ;; Run script
> +      (save-module-excursion
> +       (lambda ()
> +         (set-program-arguments (cons script-file (cdr script)))
> +         (set-user-module)
> +         (load script-file))))

=> (for-each load scripts)
    
> +cat > "$tmpfile"<<EOF
> +#!/usr/bin/env -S guix repl --

Rather:

  #!$(type -P env)

This will ensure it works even in Guix build environments.

Could you send an updated patch?

Thank you!

Ludo’.





reply via email to

[Prev in Thread] Current Thread [Next in Thread]