scripts: environment: Use system* instead of system.
This allows for direct program invokation without needing a shell to act as a command interpreter. * guix/scripts/environment.scm (%default-shell): New variable. (show-help): Adjust description. Remove '--exec' reference. (%default-options): Use '%default-shell'. (%options): Adjust '--exec' to run command via the default shell. (parse-args): New procedure. (guix-environment): Use 'parse-args'. Use 'system*' instead of 'system'. * tests/guix-environment.sh: Add test for '--' command invokation. * doc/guix.texi ("Invoking guix environment"): Use new syntax. Remove '--exec' documentation.master
parent
bbd00d2012
commit
1de2fe95e0
|
@ -4538,11 +4538,12 @@ and Emacs are available:
|
||||||
guix environment guile emacs
|
guix environment guile emacs
|
||||||
@end example
|
@end example
|
||||||
|
|
||||||
Sometimes an interactive shell session is not desired. The
|
Sometimes an interactive shell session is not desired. An arbitrary
|
||||||
@code{--exec} option can be used to specify the command to run instead.
|
command may be invoked by placing the @code{--} token to separate the
|
||||||
|
command from the rest of the arguments:
|
||||||
|
|
||||||
@example
|
@example
|
||||||
guix environment guile --exec=make
|
guix environment guile -- make -j4
|
||||||
@end example
|
@end example
|
||||||
|
|
||||||
In other situations, it is more convenient to specify the list of
|
In other situations, it is more convenient to specify the list of
|
||||||
|
@ -4551,7 +4552,7 @@ runs @command{python} from an environment containing Python@tie{}2.7 and
|
||||||
NumPy:
|
NumPy:
|
||||||
|
|
||||||
@example
|
@example
|
||||||
guix environment --ad-hoc python2-numpy python-2.7 -E python
|
guix environment --ad-hoc python2-numpy python-2.7 -- python
|
||||||
@end example
|
@end example
|
||||||
|
|
||||||
The available options are summarized below.
|
The available options are summarized below.
|
||||||
|
@ -4582,11 +4583,6 @@ As an example, @var{file} might contain a definition like this
|
||||||
@verbatiminclude environment-gdb.scm
|
@verbatiminclude environment-gdb.scm
|
||||||
@end example
|
@end example
|
||||||
|
|
||||||
|
|
||||||
@item --exec=@var{command}
|
|
||||||
@item -E @var{command}
|
|
||||||
Execute @var{command} in the new environment.
|
|
||||||
|
|
||||||
@item --ad-hoc
|
@item --ad-hoc
|
||||||
Include all specified packages in the resulting environment, as if an
|
Include all specified packages in the resulting environment, as if an
|
||||||
@i{ad hoc} package were defined with them as inputs. This option is
|
@i{ad hoc} package were defined with them as inputs. This option is
|
||||||
|
@ -4596,7 +4592,7 @@ package expression to contain the desired inputs.
|
||||||
For instance, the command:
|
For instance, the command:
|
||||||
|
|
||||||
@example
|
@example
|
||||||
guix environment --ad-hoc guile guile-sdl -E guile
|
guix environment --ad-hoc guile guile-sdl -- guile
|
||||||
@end example
|
@end example
|
||||||
|
|
||||||
runs @command{guile} in an environment where Guile and Guile-SDL are
|
runs @command{guile} in an environment where Guile and Guile-SDL are
|
||||||
|
|
|
@ -57,6 +57,9 @@ OUTPUT) tuples."
|
||||||
(define %precious-variables
|
(define %precious-variables
|
||||||
'("HOME" "USER" "LOGNAME" "DISPLAY" "TERM" "TZ" "PAGER"))
|
'("HOME" "USER" "LOGNAME" "DISPLAY" "TERM" "TZ" "PAGER"))
|
||||||
|
|
||||||
|
(define %default-shell
|
||||||
|
(or (getenv "SHELL") "/bin/sh"))
|
||||||
|
|
||||||
(define (purify-environment)
|
(define (purify-environment)
|
||||||
"Unset almost all environment variables. A small number of variables such
|
"Unset almost all environment variables. A small number of variables such
|
||||||
as 'HOME' and 'USER' are left untouched."
|
as 'HOME' and 'USER' are left untouched."
|
||||||
|
@ -103,17 +106,15 @@ existing environment variables with additional search paths."
|
||||||
,@(package-transitive-propagated-inputs package)))
|
,@(package-transitive-propagated-inputs package)))
|
||||||
|
|
||||||
(define (show-help)
|
(define (show-help)
|
||||||
(display (_ "Usage: guix environment [OPTION]... PACKAGE...
|
(display (_ "Usage: guix environment [OPTION]... PACKAGE... [-- COMMAND...]
|
||||||
Build an environment that includes the dependencies of PACKAGE and execute a
|
Build an environment that includes the dependencies of PACKAGE and execute
|
||||||
shell command in that environment.\n"))
|
COMMAND or an interactive shell in that environment.\n"))
|
||||||
(display (_ "
|
(display (_ "
|
||||||
-e, --expression=EXPR create environment for the package that EXPR
|
-e, --expression=EXPR create environment for the package that EXPR
|
||||||
evaluates to"))
|
evaluates to"))
|
||||||
(display (_ "
|
(display (_ "
|
||||||
-l, --load=FILE create environment for the package that the code within
|
-l, --load=FILE create environment for the package that the code within
|
||||||
FILE evaluates to"))
|
FILE evaluates to"))
|
||||||
(display (_ "
|
|
||||||
-E, --exec=COMMAND execute COMMAND in new environment"))
|
|
||||||
(display (_ "
|
(display (_ "
|
||||||
--ad-hoc include all specified packages in the environment instead
|
--ad-hoc include all specified packages in the environment instead
|
||||||
of only their inputs"))
|
of only their inputs"))
|
||||||
|
@ -135,7 +136,7 @@ shell command in that environment.\n"))
|
||||||
|
|
||||||
(define %default-options
|
(define %default-options
|
||||||
;; Default to opening a new shell.
|
;; Default to opening a new shell.
|
||||||
`((exec . ,(or (getenv "SHELL") "/bin/sh"))
|
`((exec . (,%default-shell))
|
||||||
(system . ,(%current-system))
|
(system . ,(%current-system))
|
||||||
(substitutes? . #t)
|
(substitutes? . #t)
|
||||||
(max-silent-time . 3600)
|
(max-silent-time . 3600)
|
||||||
|
@ -153,9 +154,9 @@ shell command in that environment.\n"))
|
||||||
(option '("pure") #f #f
|
(option '("pure") #f #f
|
||||||
(lambda (opt name arg result)
|
(lambda (opt name arg result)
|
||||||
(alist-cons 'pure #t result)))
|
(alist-cons 'pure #t result)))
|
||||||
(option '(#\E "exec") #t #f
|
(option '(#\E "exec") #t #f ; deprecated
|
||||||
(lambda (opt name arg result)
|
(lambda (opt name arg result)
|
||||||
(alist-cons 'exec arg result)))
|
(alist-cons 'exec (list %default-shell "-c" arg) result)))
|
||||||
(option '("search-paths") #f #f
|
(option '("search-paths") #f #f
|
||||||
(lambda (opt name arg result)
|
(lambda (opt name arg result)
|
||||||
(alist-cons 'search-paths #t result)))
|
(alist-cons 'search-paths #t result)))
|
||||||
|
@ -230,14 +231,24 @@ OUTPUT) tuples, using the build options in OPTS."
|
||||||
(built-derivations derivations)
|
(built-derivations derivations)
|
||||||
(return derivations))))))))
|
(return derivations))))))))
|
||||||
|
|
||||||
;; Entry point.
|
(define (parse-args args)
|
||||||
(define (guix-environment . args)
|
"Parse the list of command line arguments ARGS."
|
||||||
(define (handle-argument arg result)
|
(define (handle-argument arg result)
|
||||||
(alist-cons 'package arg result))
|
(alist-cons 'package arg result))
|
||||||
|
|
||||||
|
;; The '--' token is used to separate the command to run from the rest of
|
||||||
|
;; the operands.
|
||||||
|
(let-values (((args command) (split args "--")))
|
||||||
|
(let ((opts (parse-command-line args %options (list %default-options)
|
||||||
|
#:argument-handler handle-argument)))
|
||||||
|
(if (null? command)
|
||||||
|
opts
|
||||||
|
(alist-cons 'exec command opts)))))
|
||||||
|
|
||||||
|
;; Entry point.
|
||||||
|
(define (guix-environment . args)
|
||||||
(with-error-handling
|
(with-error-handling
|
||||||
(let* ((opts (parse-command-line args %options (list %default-options)
|
(let* ((opts (parse-args args))
|
||||||
#:argument-handler handle-argument))
|
|
||||||
(pure? (assoc-ref opts 'pure))
|
(pure? (assoc-ref opts 'pure))
|
||||||
(ad-hoc? (assoc-ref opts 'ad-hoc?))
|
(ad-hoc? (assoc-ref opts 'ad-hoc?))
|
||||||
(command (assoc-ref opts 'exec))
|
(command (assoc-ref opts 'exec))
|
||||||
|
@ -282,4 +293,7 @@ OUTPUT) tuples, using the build options in OPTS."
|
||||||
(return #t))
|
(return #t))
|
||||||
(else
|
(else
|
||||||
(create-environment inputs paths pure?)
|
(create-environment inputs paths pure?)
|
||||||
(return (exit (status:exit-val (system command)))))))))))))
|
(return
|
||||||
|
(exit
|
||||||
|
(status:exit-val
|
||||||
|
(apply system* command)))))))))))))
|
||||||
|
|
|
@ -40,7 +40,15 @@ test "`wc -l < "$tmpdir/a"`" = 1
|
||||||
cmp "$tmpdir/a" "$tmpdir/b"
|
cmp "$tmpdir/a" "$tmpdir/b"
|
||||||
|
|
||||||
# Make sure the exit value is preserved.
|
# Make sure the exit value is preserved.
|
||||||
if guix environment --ad-hoc guile-bootstrap --pure -E 'guile -c "(exit 42)"'
|
if guix environment --ad-hoc guile-bootstrap --pure -- guile -c '(exit 42)'
|
||||||
|
then
|
||||||
|
false
|
||||||
|
else
|
||||||
|
test $? = 42
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Same as above, but with deprecated -E flag.
|
||||||
|
if guix environment --ad-hoc guile-bootstrap --pure -E "guile -c '(exit 42)'"
|
||||||
then
|
then
|
||||||
false
|
false
|
||||||
else
|
else
|
||||||
|
@ -66,7 +74,7 @@ then
|
||||||
# as returned by '--search-paths'.
|
# as returned by '--search-paths'.
|
||||||
guix environment -e '(@@ (gnu packages commencement) gnu-make-boot0)' \
|
guix environment -e '(@@ (gnu packages commencement) gnu-make-boot0)' \
|
||||||
--no-substitutes --pure \
|
--no-substitutes --pure \
|
||||||
--exec='echo $PATH $CPATH $LIBRARY_PATH' > "$tmpdir/b"
|
-- /bin/sh -c 'echo $PATH $CPATH $LIBRARY_PATH' > "$tmpdir/b"
|
||||||
( . "$tmpdir/a" ; echo $PATH $CPATH $LIBRARY_PATH ) > "$tmpdir/c"
|
( . "$tmpdir/a" ; echo $PATH $CPATH $LIBRARY_PATH ) > "$tmpdir/c"
|
||||||
cmp "$tmpdir/b" "$tmpdir/c"
|
cmp "$tmpdir/b" "$tmpdir/c"
|
||||||
|
|
||||||
|
|
Reference in New Issue