guix build: '-f' accepts file-like objects.

* guix/scripts/build.scm (options->things-to-build)[validate-type]:
Check for 'file-like?'.
(options->derivations): Accept 'file-like?'.
* tests/guix-build.sh: Add a test with 'computed-file'.
* doc/guix.texi (Additional Build Options): Mention file-like objects.
This commit is contained in:
Ludovic Courtès 2018-10-09 18:52:37 +02:00
parent 64965a068d
commit b33e191c86
No known key found for this signature in database
GPG key ID: 090B11993D9AEBB5
3 changed files with 11 additions and 4 deletions

View file

@ -6365,9 +6365,8 @@ retrieved using the @option{--log-file} option.
@item --file=@var{file}
@itemx -f @var{file}
Build the package or derivation that the code within @var{file}
evaluates to.
Build the package, derivation, or other file-like object that the code within
@var{file} evaluates to (@pxref{G-Expressions, file-like objects}).
As an example, @var{file} might contain a package definition like this
(@pxref{Defining Packages}):

View file

@ -623,7 +623,7 @@ (define (options->things-to-build opts)
"Read the arguments from OPTS and return a list of high-level objects to
build---packages, gexps, derivations, and so on."
(define (validate-type x)
(unless (or (package? x) (derivation? x) (gexp? x) (procedure? x))
(unless (or (derivation? x) (file-like? x) (gexp? x) (procedure? x))
(leave (G_ "~s: not something we can build~%") x)))
(define (ensure-list x)
@ -700,6 +700,10 @@ (define graft? (assoc-ref opts 'graft?))
(set-guile-for-build (default-guile))
(proc))
#:system system)))
((? file-like? obj)
(list (run-with-store store
(lower-object obj system
#:target (assoc-ref opts 'target)))))
((? gexp? gexp)
(list (run-with-store store
(mbegin %store-monad

View file

@ -221,6 +221,10 @@ guix build -e "(begin
guix build -e '#~(mkdir #$output)' -d
guix build -e '#~(mkdir #$output)' -d | grep 'gexp\.drv'
# Same with a file-like object.
guix build -e '(computed-file "foo" #~(mkdir #$output))' -d
guix build -e '(computed-file "foo" #~(mkdir #$output))' -d | grep 'foo\.drv'
# Building from a package file.
cat > "$module_dir/package.scm"<<EOF
(use-modules (gnu))