Re: [PATCH 2/2] guix: build: Add transitive source building.

2015-05-01 Thread Ludovic Courtès
Eric Bavier bav...@member.fsf.org skribis:

 * guix/scripts/build.scm (%options, options-derivations): Add --sources
   option.
 * doc/guix.texi (Invoking guix build): Document --sources option.
 * tests/guix-build.sh: Add tests.

LGTM!

Thank you for reviving these patches!

Ludo’.



Re: [PATCH 2/2] guix: build: Add transitive source building.

2015-04-24 Thread Eric Bavier
Revisiting this (old) thread...

Eric Bavier bav...@member.fsf.org skribis:

 * guix/scripts/build.scm (%options): Add --sources option.
   (package-sources, package-direct-sources)
   (package-transitive-sources, package-source-derivations): New
   procedures.
   (options-derivations)[--sources]: Use them.
 * doc/guix.texi (Invoking guix build): Document --sources option.
 * tests/guix-build.sh: Add tests.

[...]

 @item --sources
 +An extension of the @code{--source} option.  If a package's source is

What about starting with a couple of sentences that better describe what
it does and what the use case is, like:

  Fetch and return the source of @var{package-or-derivation} and all
their dependencies, recursively.  This is a handy way to obtain a
  local copy of all the source code needed to build @var{packages},
allowing you to eventually build them even without network
access.

I liked your wording, so I used it ;)

BTW, what happens when one passes arguments that are not packages?
Like:

  guix build --sources /gnu/store/...-foo.drv

It behaves in the way 'guix build -S' currently behaves with a
derivation, it just builds the derivation.  It might be interesting if
it examined the derivation and built any sources associated with it, but
that can be a later patch.

 +  --sources[=TYPE]   build source derivations; TYPE may
 optionally be one
 + of \package\, \all\ (default), or
 \transitive\.))

No period.

Good catch, thanks.

 +(define (package-sources package)

This procedure appears to be unused (and is awkward anyway ;-)).

Removed.

 +(define (package-direct-sources package)
 +  Return all source origins associated with PACKAGE; including
 origins in
 +PACKAGE's inputs.
 +  `(,@(or (and= (package-source package) list) '())
 +,@(filter-map (match-lambda
 +   ((_ (? origin? orig) _ ...)
 +orig)
 +   (_ #f))
 +  (package-direct-inputs package
 +
 +(define (package-transitive-sources package)
 +  Return PACKAGE's direct sources, and its input sources,
 recursively.
 +  (delete-duplicates
 +   (concatenate (filter-map (match-lambda
 + ((_ (? origin? orig) _ ...)
 +  (list orig))
 + ((_ (? package? p) _ ...)
 +  (package-direct-sources p))
 + (_ #f))
 +(bag-transitive-inputs
 + (package-bag package))

Perhaps these two could go to (guix packages), with a test in
tests/packages.scm.

Done in patch [1/2].

 +# foo.tar.gz
 +guix build -d -S foo
 +guix build -d -S foo | grep -e 'foo\.tar\.gz'

Nice tests, thanks for taking the time!

No problem.  I kinda like writing tests. :)


Eric Bavier (2):
  guix: packages: Add package-direct-sources and
package-transitive-sources.
  guix: build: Add transitive source building.

 doc/guix.texi  |   43 +
 guix/packages.scm  |   24 ++
 guix/scripts/build.scm |   55 +--
 guix/tests.scm |   10 +-
 tests/guix-build.sh|   82 
 tests/packages.scm |   30 +
 6 files changed, 226 insertions(+), 18 deletions(-)

-- 
1.7.9.5




[PATCH 2/2] guix: build: Add transitive source building.

2015-04-24 Thread Eric Bavier
* guix/scripts/build.scm (%options, options-derivations): Add --sources
  option.
* doc/guix.texi (Invoking guix build): Document --sources option.
* tests/guix-build.sh: Add tests.
---
 doc/guix.texi  |   43 +
 guix/scripts/build.scm |   55 ++--
 tests/guix-build.sh|   82 
 3 files changed, 163 insertions(+), 17 deletions(-)

diff --git a/doc/guix.texi b/doc/guix.texi
index 4269d4f..6636792 100644
--- a/doc/guix.texi
+++ b/doc/guix.texi
@@ -2924,6 +2924,49 @@ The returned source tarball is the result of applying 
any patches and
 code snippets specified in the package's @code{origin} (@pxref{Defining
 Packages}).
 
+@item --sources
+Fetch and return the source of @var{package-or-derivation} and all their
+dependencies, recursively.  This is a handy way to obtain a local copy
+of all the source code needed to build @var{packages}, allowing you to
+eventually build them even without network access.  It is an extension
+of the @code{--source} option and can accept one of the following
+optional argument values:
+
+@table @code
+@item package
+This value causes the @code{--sources} option to behave in the same way
+as the @code{--source} option.
+
+@item all
+Build all packages' source derivations, including any source that might
+be listed as @code{inputs}.  This is the default value.
+
+@example
+$ guix build --sources tzdata
+The following derivations will be built:
+   /gnu/store/@dots{}-tzdata2015b.tar.gz.drv
+   /gnu/store/@dots{}-tzcode2015b.tar.gz.drv
+@end example
+
+@item transitive
+Build all packages' source derivations, as well as all source
+derivations for packages' transitive inputs.  This can be used e.g. to
+prefetch package source for later offline building.
+
+@example
+$ guix build --sources=transitive tzdata
+The following derivations will be built:
+   /gnu/store/@dots{}-tzcode2015b.tar.gz.drv
+   /gnu/store/@dots{}-findutils-4.4.2.tar.xz.drv
+   /gnu/store/@dots{}-grep-2.21.tar.xz.drv
+   /gnu/store/@dots{}-coreutils-8.23.tar.xz.drv
+   /gnu/store/@dots{}-make-4.1.tar.xz.drv
+   /gnu/store/@dots{}-bash-4.3.tar.xz.drv
+@dots{}
+@end example
+
+@end table
+
 @item --system=@var{system}
 @itemx -s @var{system}
 Attempt to build for @var{system}---e.g., @code{i686-linux}---instead of
diff --git a/guix/scripts/build.scm b/guix/scripts/build.scm
index 370c2a3..9366ab6 100644
--- a/guix/scripts/build.scm
+++ b/guix/scripts/build.scm
@@ -228,6 +228,9 @@ Build the given PACKAGE-OR-DERIVATION and return their 
output paths.\n))
   (display (_ 
   -S, --source   build the packages' source derivations))
   (display (_ 
+  --sources[=TYPE]   build source derivations; TYPE may optionally be one
+ of \package\, \all\ (default), or 
\transitive\))
+  (display (_ 
   -s, --system=SYSTEMattempt to build for SYSTEM--e.g., \i686-linux\))
   (display (_ 
   --target=TRIPLET   cross-build for TRIPLET--e.g., \armel-linux-gnu\))
@@ -262,10 +265,22 @@ Build the given PACKAGE-OR-DERIVATION and return their 
output paths.\n))
  (option '(#\V version) #f #f
  (lambda args
(show-version-and-exit guix build)))
-
  (option '(#\S source) #f #f
  (lambda (opt name arg result)
-   (alist-cons 'source? #t result)))
+   (alist-cons 'source #t result)))
+ (option '(sources) #f #t
+ (lambda (opt name arg result)
+   (match arg
+ (package
+  (alist-cons 'source #t result))
+ ((or all #f)
+  (alist-cons 'source package-direct-sources result))
+ (transitive
+  (alist-cons 'source package-transitive-sources result))
+ (else
+  (leave (_ invalid argument: '~a' option argument: ~a, ~
+must be one of 'package', 'all', or 'transitive'~%)
+ name arg)
  (option '(#\s system) #t #f
  (lambda (opt name arg result)
(alist-cons 'system arg
@@ -308,28 +323,34 @@ build.
   (triplet
(cut package-cross-derivation   triplet 
 
-  (define src?   (assoc-ref opts 'source?))
+  (define src(assoc-ref opts 'source))
   (define sys(assoc-ref opts 'system))
   (define graft? (assoc-ref opts 'graft?))
 
   (parameterize ((%graft? graft?))
 (let ((opts (options/with-source store
  (options/resolve-packages store opts
-  (filter-map (match-lambda
-   (('argument . (? package? p))
-(if src?
+  (concatenate
+   (filter-map (match-lambda
+(('argument . (? package? p))
+ (match src
+   (#f
+(list (package-derivation store p sys)))
+  

[PATCH 2/2] guix: build: Add transitive source building.

2015-02-24 Thread Eric Bavier
* guix/scripts/build.scm (%options): Add --sources option.
  (package-sources, package-direct-sources)
  (package-transitive-sources, package-source-derivations): New
  procedures.
  (options-derivations)[--sources]: Use them.
* doc/guix.texi (Invoking guix build): Document --sources option.
* tests/guix-build.sh: Add tests.
---
 doc/guix.texi  |   42 +++
 guix/scripts/build.scm |   88 ++--
 tests/guix-build.sh|   84 +
 3 files changed, 196 insertions(+), 18 deletions(-)

diff --git a/doc/guix.texi b/doc/guix.texi
index 0842c91..90d4704 100644
--- a/doc/guix.texi
+++ b/doc/guix.texi
@@ -2757,6 +2757,48 @@ The returned source tarball is the result of applying 
any patches and
 code snippets specified in the package's @code{origin} (@pxref{Defining
 Packages}).
 
+@item --sources
+An extension of the @code{--source} option.  If a package's source is
+patched, this option will cause its unpatched source derivation to also
+be built.  The @code{--sources} option can accept one of the following
+optional argument values:
+
+@table @code
+@item package
+This value causes the @code{--sources} option to behave mostly in the
+same way as the @code{--source} option.  It may additionally build
+packages' unpatched source derivations if those exist.
+
+@item all
+Build all packages' source derivations, including any source that might
+be listed as @code{inputs}.  This is the default value.
+
+@example
+$ guix build --sources tzdata
+The following derivations will be built:
+   /gnu/store/@dots{}-tzdata2014j.tar.gz.drv
+   /gnu/store/@dots{}-tzcode2014j.tar.gz.drv
+@end example
+
+@item transitive
+Build all packages' source derivations, as well as all source
+derivations for packages' transitive inputs.  This can be used .e.g. to
+prefetch package source for later offline building.
+
+@example
+$ guix build --sources=transitive tzdata
+The following derivations will be built:
+   /gnu/store/@dots{}-file-5.22.tar.gz.drv
+   /gnu/store/@dots{}-findutils-4.4.2.tar.xz.drv
+   /gnu/store/@dots{}-grep-2.21.tar.xz.drv
+   /gnu/store/@dots{}-coreutils-8.23.tar.xz.drv
+   /gnu/store/@dots{}-make-4.1.tar.xz.drv
+   /gnu/store/@dots{}-bash-4.3.tar.xz.drv
+@dots{}
+@end example
+
+@end table
+
 @item --system=@var{system}
 @itemx -s @var{system}
 Attempt to build for @var{system}---e.g., @code{i686-linux}---instead of
diff --git a/guix/scripts/build.scm b/guix/scripts/build.scm
index 07ced30..4d81b9b 100644
--- a/guix/scripts/build.scm
+++ b/guix/scripts/build.scm
@@ -228,6 +228,9 @@ Build the given PACKAGE-OR-DERIVATION and return their 
output paths.\n))
   (display (_ 
   -S, --source   build the packages' source derivations))
   (display (_ 
+  --sources[=TYPE]   build source derivations; TYPE may optionally be one
+ of \package\, \all\ (default), or 
\transitive\.))
+  (display (_ 
   -s, --system=SYSTEMattempt to build for SYSTEM--e.g., \i686-linux\))
   (display (_ 
   --target=TRIPLET   cross-build for TRIPLET--e.g., \armel-linux-gnu\))
@@ -262,10 +265,22 @@ Build the given PACKAGE-OR-DERIVATION and return their 
output paths.\n))
  (option '(#\V version) #f #f
  (lambda args
(show-version-and-exit guix build)))
-
  (option '(#\S source) #f #f
  (lambda (opt name arg result)
-   (alist-cons 'source? #t result)))
+   (alist-cons 'source package-sources result)))
+ (option '(sources) #f #t
+ (lambda (opt name arg result)
+   (match arg
+ (package
+  (alist-cons 'source package-sources result))
+ ((or all #f)
+  (alist-cons 'source package-direct-sources result))
+ (transitive
+  (alist-cons 'source package-transitive-sources result))
+ (else
+  (leave (_ invalid argument: '~a' option argument: ~a, ~
+must be one of 'package', 'all', or 'transitive'~%)
+ name arg)
  (option '(#\s system) #t #f
  (lambda (opt name arg result)
(alist-cons 'system arg
@@ -299,6 +314,40 @@ Build the given PACKAGE-OR-DERIVATION and return their 
output paths.\n))
 
  %standard-build-options))
 
+(define (package-sources package)
+  Like package-source but returns its results as a list
+  (list (package-source package)))
+
+(define (package-direct-sources package)
+  Return all source origins associated with PACKAGE; including origins in
+PACKAGE's inputs.
+  `(,@(or (and= (package-source package) list) '())
+,@(filter-map (match-lambda
+   ((_ (? origin? orig) _ ...)
+orig)
+   (_ #f))
+  (package-direct-inputs package
+
+(define