guix build: Add -L/--load-path as a common option.

* guix/scripts/build.scm (show-build-options-help): Document -L.
  (%standard-build-options): Add -L/--load-path.
* tests/guix-package.sh: Test it.
This commit is contained in:
Ludovic Courtès 2014-09-24 11:26:30 +02:00
parent c107b54108
commit 300868ba57
3 changed files with 48 additions and 6 deletions

View file

@ -2492,6 +2492,14 @@ following:
@table @code
@item --load-path=@var{directory}
@itemx -L @var{directory}
Add @var{directory} to the front of the package module search path
(@pxref{Package Modules}).
This allows users to define their own packages and make them visible to
the command-line tools.
@item --keep-failed
@itemx -K
Keep the build tree of failed builds. Thus, if a build fail, its build
@ -3951,17 +3959,22 @@ Reference Manual}). For instance, the @code{(gnu packages emacs)}
module exports a variable named @code{emacs}, which is bound to a
@code{<package>} object (@pxref{Defining Packages}).
The @code{(gnu packages @dots{})} module name space is special: it is
The @code{(gnu packages @dots{})} module name space is
automatically scanned for packages by the command-line tools. For
instance, when running @code{guix package -i emacs}, all the @code{(gnu
packages @dots{})} modules are scanned until one that exports a package
object whose name is @code{emacs} is found. This package search
facility is implemented in the @code{(gnu packages)} module.
@cindex customization, of packages
Users can store package definitions in modules with different
names---e.g., @code{(my-packages emacs)}. In that case, commands such
as @command{guix package} and @command{guix build} have to be used with
the @code{-e} option so that they know where to find the package.
names---e.g., @code{(my-packages emacs)}. These package definitions
will not be visible by default. Thus, users can invoke commands such as
@command{guix package} and @command{guix build} have to be used with the
@code{-e} option so that they know where to find the package, or use the
@code{-L} option of these commands to make those modules visible
(@pxref{Invoking guix build, @code{--load-path}}). The latter makes it
easy to customize the distribution.
The distribution is fully @dfn{bootstrapped} and @dfn{self-contained}:
each package is built based solely on other packages in the

View file

@ -33,7 +33,7 @@ (define-module (guix scripts build)
#:use-module (srfi srfi-26)
#:use-module (srfi srfi-34)
#:use-module (srfi srfi-37)
#:autoload (gnu packages) (specification->package)
#:autoload (gnu packages) (specification->package %package-module-path)
#:autoload (guix download) (download-to-store)
#:export (%standard-build-options
set-build-options-from-command-line
@ -99,6 +99,8 @@ (define (show-build-options-help)
"Display on the current output port help about the standard command-line
options handled by 'set-build-options-from-command-line', and listed in
'%standard-build-options'."
(display (_ "
-L, --load-path=DIR prepend DIR to the package module search path"))
(display (_ "
-K, --keep-failed keep build tree of failed builds"))
(display (_ "
@ -136,7 +138,15 @@ (define (set-build-options-from-command-line store opts)
(define %standard-build-options
;; List of standard command-line options for tools that build something.
(list (option '(#\K "keep-failed") #f #f
(list (option '(#\L "load-path") #t #f
(lambda (opt name arg result . rest)
;; XXX: Imperatively modify the search paths.
(%package-module-path (cons arg (%package-module-path)))
(set! %load-path (cons arg %load-path))
(set! %load-compiled-path (cons arg %load-compiled-path))
(apply values (cons result rest))))
(option '(#\K "keep-failed") #f #f
(lambda (opt name arg result . rest)
(apply values
(alist-cons 'keep-failed? #t result)

View file

@ -255,3 +255,22 @@ set -o pipefail || true
guix package -A g | head -1 2> "$HOME/err1"
guix package -I | head -1 2> "$HOME/err2"
test "`cat "$HOME/err1" "$HOME/err2"`" = ""
# Make sure '-L' extends the package module search path.
module_dir="t-guix-package-$$"
mkdir "$module_dir"
trap "rm -rf $module_dir" EXIT
cat > "$module_dir/foo.scm"<<EOF
(define-module (foo)
#:use-module (guix packages)
#:use-module (gnu packages emacs))
(define-public x
(package (inherit emacs)
(name "emacs-foo-bar")
(version "42")))
EOF
guix package -A emacs-foo-bar -L "$module_dir" | grep 42
guix package -i emacs-foo-bar-42 -n -L "$module_dir"