guix-build: Allow version-qualified package names.
* guix-build.in (guix-build)[find-package]: New procedure. Use it instead of using `find-packages-by-name' directly. Suggested by Andreas Enge <andreas@enge.fr>. * tests/guix-build.sh: Add tests. * doc/guix.texi (Invoking guix-build): Add `coreutils-8.20' as an example. Fix guile-1.8 example.
This commit is contained in:
		
							parent
							
								
									476f8ea33c
								
							
						
					
					
						commit
						5401dd7595
					
				
					 3 changed files with 44 additions and 12 deletions
				
			
		| 
						 | 
					@ -989,8 +989,9 @@ guix-build @var{options} @var{package-or-derivation}@dots{}
 | 
				
			||||||
@end example
 | 
					@end example
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@var{package-or-derivation} may be either the name of a package found in
 | 
					@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
 | 
					the software distribution such as @code{coreutils} or
 | 
				
			||||||
as @file{/nix/store/xxx-coreutils-8.19.drv}.  Alternatively, the
 | 
					@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
 | 
					@code{--expression} option may be used to specify a Scheme expression
 | 
				
			||||||
that evaluates to a package; this is useful when disambiguation among
 | 
					that evaluates to a package; this is useful when disambiguation among
 | 
				
			||||||
several same-named packages or package variants is needed.
 | 
					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}
 | 
					@itemx -e @var{expr}
 | 
				
			||||||
Build the package @var{expr} evaluates to.
 | 
					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
 | 
					guile-1.8)}, which unambiguously designates this specific variant of
 | 
				
			||||||
version 1.8 of Guile.
 | 
					version 1.8 of Guile.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -38,6 +38,7 @@ exec ${GUILE-@GUILE@} -L "@guilemoduledir@" -l "$0"    \
 | 
				
			||||||
  #:use-module (ice-9 format)
 | 
					  #:use-module (ice-9 format)
 | 
				
			||||||
  #:use-module (ice-9 match)
 | 
					  #:use-module (ice-9 match)
 | 
				
			||||||
  #:use-module (srfi srfi-1)
 | 
					  #:use-module (srfi srfi-1)
 | 
				
			||||||
 | 
					  #:use-module (srfi srfi-11)
 | 
				
			||||||
  #:use-module (srfi srfi-26)
 | 
					  #:use-module (srfi srfi-26)
 | 
				
			||||||
  #:use-module (srfi srfi-34)
 | 
					  #:use-module (srfi srfi-34)
 | 
				
			||||||
  #:use-module (srfi srfi-37)
 | 
					  #: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)))
 | 
					                 root (strerror (system-error-errno args)))
 | 
				
			||||||
         (exit 1)))))
 | 
					         (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 "")
 | 
					  (setlocale LC_ALL "")
 | 
				
			||||||
  (textdomain "guix")
 | 
					  (textdomain "guix")
 | 
				
			||||||
  (setvbuf (current-output-port) _IOLBF)
 | 
					  (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))
 | 
					                                  (('argument . (? derivation-path? drv))
 | 
				
			||||||
                                   drv)
 | 
					                                   drv)
 | 
				
			||||||
                                  (('argument . (? string? x))
 | 
					                                  (('argument . (? string? x))
 | 
				
			||||||
                                   (match (find-packages-by-name x)
 | 
					                                   (let ((p (find-package x)))
 | 
				
			||||||
                                     ((p _ ...)
 | 
					 | 
				
			||||||
                                     (if src?
 | 
					                                     (if src?
 | 
				
			||||||
                                         (let ((s (package-source p)))
 | 
					                                         (let ((s (package-source p)))
 | 
				
			||||||
                                            (package-source-derivation (%store) s))
 | 
					                                           (package-source-derivation
 | 
				
			||||||
                                          (package-derivation (%store) p sys)))
 | 
					                                            (%store) s))
 | 
				
			||||||
                                     (_
 | 
					                                         (package-derivation (%store) p sys))))
 | 
				
			||||||
                                      (leave (_ "~A: unknown package~%") x))))
 | 
					 | 
				
			||||||
                                  (_ #f))
 | 
					                                  (_ #f))
 | 
				
			||||||
                                 opts))
 | 
					                                 opts))
 | 
				
			||||||
               (req  (append-map (lambda (drv-path)
 | 
					               (req  (append-map (lambda (drv-path)
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -1,5 +1,5 @@
 | 
				
			||||||
# GNU Guix --- Functional package management for GNU
 | 
					# 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.
 | 
					# 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
 | 
					then false; else true; fi
 | 
				
			||||||
 | 
					
 | 
				
			||||||
rm -f "$result"
 | 
					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
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Reference in a new issue