From mboxrd@z Thu Jan 1 00:00:00 1970 From: David Thompson Subject: [PATCH] scripts: build: Add --file option. Date: Mon, 26 Oct 2015 18:23:33 -0400 Message-ID: <878u6pxo9m.fsf@izanagi.i-did-not-set--mail-host-address--so-tickle-me> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:47655) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZqqB0-0001Qd-2y for guix-devel@gnu.org; Mon, 26 Oct 2015 18:23:39 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZqqAw-0008BG-Ui for guix-devel@gnu.org; Mon, 26 Oct 2015 18:23:38 -0400 Received: from mail-qg0-x22e.google.com ([2607:f8b0:400d:c04::22e]:36396) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZqqAw-0008BA-Oo for guix-devel@gnu.org; Mon, 26 Oct 2015 18:23:34 -0400 Received: by qgad10 with SMTP id d10so132270598qga.3 for ; Mon, 26 Oct 2015 15:23:34 -0700 (PDT) Received: from izanagi ([38.88.209.18]) by smtp.gmail.com with ESMTPSA id f7sm13942363qka.41.2015.10.26.15.23.33 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 26 Oct 2015 15:23:33 -0700 (PDT) List-Id: "Development of GNU Guix and the GNU System distribution." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guix-devel-bounces+gcggd-guix-devel=m.gmane.org@gnu.org Sender: guix-devel-bounces+gcggd-guix-devel=m.gmane.org@gnu.org To: guix-devel@gnu.org --=-=-= Content-Type: text/plain This is to accompany the --install-from-file option I added to 'guix package' awhile back. Makes it easy for folks to build one-off package files like the 'guix.scm' files I keep in my personal repos. --=-=-= Content-Type: text/x-patch Content-Disposition: inline; filename=0001-scripts-build-Add-file-option.patch >From d3dd1b2d05f17702f7fa6095132db00e2146e702 Mon Sep 17 00:00:00 2001 From: David Thompson Date: Mon, 26 Oct 2015 18:09:28 -0400 Subject: [PATCH] scripts: build: Add --file option. * guix/scripts/build.scm (show-help): Add help text for --file option. (%options): Add --file option. (options/resolve-packages): Handle 'file' options. * tests/guix-build.sh: Add tests. * doc/guix.texi ("invoking guix build"): Add doc. --- doc/guix.texi | 13 +++++++++++++ guix/scripts/build.scm | 45 ++++++++++++++++++++++++++++----------------- tests/guix-build.sh | 27 +++++++++++++++++++++++++++ 3 files changed, 68 insertions(+), 17 deletions(-) diff --git a/doc/guix.texi b/doc/guix.texi index 7715b72..abd8de3 100644 --- a/doc/guix.texi +++ b/doc/guix.texi @@ -3615,6 +3615,19 @@ The @var{options} may be zero or more of the following: @table @code +@item --file=@var{file} +@itemx -e @var{file} + +Build the package or derivation that the code within @var{file} +evaluates to. + +As an example, @var{file} might contain a package definition like this +(@pxref{Defining Packages}): + +@example +@verbatiminclude package-hello.scm +@end example + @item --expression=@var{expr} @itemx -e @var{expr} Build the package or derivation @var{expr} evaluates to. diff --git a/guix/scripts/build.scm b/guix/scripts/build.scm index a357cf8..ee7e5b9 100644 --- a/guix/scripts/build.scm +++ b/guix/scripts/build.scm @@ -290,6 +290,9 @@ Build the given PACKAGE-OR-DERIVATION and return their output paths.\n")) (display (_ " -e, --expression=EXPR build the package or derivation EXPR evaluates to")) (display (_ " + -f, --file=FILE build the package or derivation that the code within + FILE evaluates to")) + (display (_ " -S, --source build the packages' source derivations")) (display (_ " --sources[=TYPE] build source derivations; TYPE may optionally be one @@ -359,6 +362,9 @@ must be one of 'package', 'all', or 'transitive'~%") (option '(#\e "expression") #t #f (lambda (opt name arg result) (alist-cons 'expression arg result))) + (option '(#\f "file") #t #f + (lambda (opt name arg result) + (alist-cons 'file arg result))) (option '(#\n "dry-run") #f #f (lambda (opt name arg result) (alist-cons 'dry-run? #t result))) @@ -422,29 +428,34 @@ packages." (define system (or (assoc-ref opts 'system) (%current-system))) + (define (object->argument obj) + (match obj + ((? package? p) + `(argument . ,p)) + ((? procedure? proc) + (let ((drv (run-with-store store + (mbegin %store-monad + (set-guile-for-build (default-guile)) + (proc)) + #:system system))) + `(argument . ,drv))) + ((? gexp? gexp) + (let ((drv (run-with-store store + (mbegin %store-monad + (set-guile-for-build (default-guile)) + (gexp->derivation "gexp" gexp + #:system system))))) + `(argument . ,drv))))) + (map (match-lambda (('argument . (? string? spec)) (if (store-path? spec) `(argument . ,spec) `(argument . ,(specification->package spec)))) + (('file . file) + (object->argument (load* file (make-user-module '())))) (('expression . str) - (match (read/eval str) - ((? package? p) - `(argument . ,p)) - ((? procedure? proc) - (let ((drv (run-with-store store - (mbegin %store-monad - (set-guile-for-build (default-guile)) - (proc)) - #:system system))) - `(argument . ,drv))) - ((? gexp? gexp) - (let ((drv (run-with-store store - (mbegin %store-monad - (set-guile-for-build (default-guile)) - (gexp->derivation "gexp" gexp - #:system system))))) - `(argument . ,drv))))) + (object->argument (read/eval str))) (opt opt)) opts)) diff --git a/tests/guix-build.sh b/tests/guix-build.sh index a72ce09..f7fb3c5 100644 --- a/tests/guix-build.sh +++ b/tests/guix-build.sh @@ -167,6 +167,33 @@ guix build -e "(begin guix build -e '#~(mkdir #$output)' -d guix build -e '#~(mkdir #$output)' -d | grep 'gexp\.drv' +# Building from a package file. +cat > "$module_dir/package.scm"< "$module_dir/proc.scm"<derivation "test" + (gexp (mkdir (ungexp output))))) +EOF +guix build --file="$module_dir/proc.scm" --dry-run + +# Building from a gexp file. +cat > "$module_dir/gexp.scm"<