aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--doc/guix.texi7
-rw-r--r--guix-build.in39
-rw-r--r--tests/guix-build.sh10
3 files changed, 44 insertions, 12 deletions
diff --git a/doc/guix.texi b/doc/guix.texi
index 88909c42a9..8b496308d7 100644
--- a/doc/guix.texi
+++ b/doc/guix.texi
@@ -989,8 +989,9 @@ guix-build @var{options} @var{package-or-derivation}@dots{}
@end example
@var{package-or-derivation} may be either the name of a package found in
-the software distribution such as @code{coreutils}, or a derivation such
-as @file{/nix/store/xxx-coreutils-8.19.drv}. Alternatively, the
+the software distribution such as @code{coreutils} or
+@code{coreutils-8.20}, or a derivation such as
+@file{/nix/store/@dots{}-coreutils-8.19.drv}. Alternatively, the
@code{--expression} option may be used to specify a Scheme expression
that evaluates to a package; this is useful when disambiguation among
several same-named packages or package variants is needed.
@@ -1003,7 +1004,7 @@ The @var{options} may be zero or more of the following:
@itemx -e @var{expr}
Build the package @var{expr} evaluates to.
-For example, @var{expr} may be @code{(@@ (distro packages guile)
+For example, @var{expr} may be @code{(@@ (gnu packages guile)
guile-1.8)}, which unambiguously designates this specific variant of
version 1.8 of Guile.
diff --git a/guix-build.in b/guix-build.in
index e3894b8af2..7f278a5733 100644
--- a/guix-build.in
+++ b/guix-build.in
@@ -38,6 +38,7 @@ exec ${GUILE-@GUILE@} -L "@guilemoduledir@" -l "$0" \
#:use-module (ice-9 format)
#:use-module (ice-9 match)
#:use-module (srfi srfi-1)
+ #:use-module (srfi srfi-11)
#:use-module (srfi srfi-26)
#:use-module (srfi srfi-34)
#:use-module (srfi srfi-37)
@@ -195,6 +196,30 @@ Build the given PACKAGE-OR-DERIVATION and return their output paths.\n"))
root (strerror (system-error-errno args)))
(exit 1)))))
+ (define (find-package request)
+ ;; Return a package matching REQUEST. REQUEST may be a package
+ ;; name, or a package name followed by a hyphen and a version
+ ;; number.
+ (let-values (((name version)
+ (package-name->name+version request)))
+ (match (find-packages-by-name name version)
+ ((p) ; one match
+ p)
+ ((p _ ...) ; several matches
+ (format (current-error-port)
+ (_ "warning: ambiguous package specification `~a'~%")
+ request)
+ (format (current-error-port)
+ (_ "warning: choosing ~a from ~a~%")
+ (package-full-name p)
+ (location->string (package-location p)))
+ p)
+ (_ ; no matches
+ (if version
+ (leave (_ "~A: package not found for version ~a~%")
+ name version)
+ (leave (_ "~A: unknown package~%") name))))))
+
(setlocale LC_ALL "")
(textdomain "guix")
(setvbuf (current-output-port) _IOLBF)
@@ -212,14 +237,12 @@ Build the given PACKAGE-OR-DERIVATION and return their output paths.\n"))
(('argument . (? derivation-path? drv))
drv)
(('argument . (? string? x))
- (match (find-packages-by-name x)
- ((p _ ...)
- (if src?
- (let ((s (package-source p)))
- (package-source-derivation (%store) s))
- (package-derivation (%store) p sys)))
- (_
- (leave (_ "~A: unknown package~%") x))))
+ (let ((p (find-package x)))
+ (if src?
+ (let ((s (package-source p)))
+ (package-source-derivation
+ (%store) s))
+ (package-derivation (%store) p sys))))
(_ #f))
opts))
(req (append-map (lambda (drv-path)
diff --git a/tests/guix-build.sh b/tests/guix-build.sh
index fccf2168b1..5718b07d0c 100644
--- a/tests/guix-build.sh
+++ b/tests/guix-build.sh
@@ -1,5 +1,5 @@
# GNU Guix --- Functional package management for GNU
-# Copyright © 2012 Ludovic Courtès <ludo@gnu.org>
+# Copyright © 2012, 2013 Ludovic Courtès <ludo@gnu.org>
#
# This file is part of GNU Guix.
#
@@ -50,3 +50,11 @@ if guix-build -r "$result" -e '(@@ (gnu packages base) %bootstrap-guile)'
then false; else true; fi
rm -f "$result"
+
+# Parsing package names and versions.
+guix-build -n time # PASS
+guix-build -n time-1.7 # PASS, version found
+if guix-build -n time-3.2; # FAIL, version not found
+then false; else true; fi
+if guix-build -n something-that-will-never-exist; # FAIL
+then false; else true; fi