Browse Source

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.
gn-latest-20200428
Ludovic Courtès 9 years ago
parent
commit
5401dd7595
3 changed files with 44 additions and 12 deletions
  1. +4
    -3
      doc/guix.texi
  2. +31
    -8
      guix-build.in
  3. +9
    -1
      tests/guix-build.sh

+ 4
- 3
doc/guix.texi View File

@ -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.


+ 31
- 8
guix-build.in View File

@ -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)


+ 9
- 1
tests/guix-build.sh View File

@ -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

Loading…
Cancel
Save