[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: |
Sat, 13 Jun 2020 21:44:51 +0200 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/26.3 (gnu/linux) |
Hi,
Konrad Hinsen <konrad.hinsen@fastmail.net> skribis:
>> “When one or more @var{file} argument is provided, each @var{file} is
>> executed as a Guile program:”
>
> No, that's no longer true. Only one script can be run at a time, because
>
> guix repl script1.scm script2.scm
>
> now means "run script1.scm with script2.scm as its argument". And therefore...
Ah OK, sorry for the confusion.
>>> + (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.
>
> That's what I thought (and tried) as well, at first. Problems:
>
> - It doesn't work when run via pre-inst-env with a non-absolute
> filename for the script. The script is looked up relative
> to the directory containing repl.scm.
Oh right, that’s because we’re using ‘load’. We should instead do:
(load-in-vicinity "." file)
Alternatively, (primitive-load file), but in that case the script would
be systematically interpreted.
> - The script filename is also the first item of (command-line)
> when called inside the script, and that's useful only it it's
> an absolute filename.
In what way is it useful?
>>> +cat > "$tmpfile"<<EOF
>>> +#!/usr/bin/env -S guix repl --
>>
>> Rather:
>>
>> #!$(type -P env)
>
> I didn't know that was possible on a shebang line!
It’s not, but here it’s evaluated as part of the here-document
expansion.
Thanks!
Ludo’.