aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLudovic Courtès <ludo@gnu.org>2015-05-20 11:52:45 +0200
committerLudovic Courtès <ludo@gnu.org>2015-05-20 12:13:39 +0200
commitdbc31ab25c355eae373e1766b4a77fccbe462bf3 (patch)
treebadd7863749d9f3783eae95a33751abf0bfe0857
parent755e1147aa33d1c305bb9db6c5e03cf1063079fc (diff)
downloadgnu-guix-dbc31ab25c355eae373e1766b4a77fccbe462bf3.tar
gnu-guix-dbc31ab25c355eae373e1766b4a77fccbe462bf3.tar.gz
guix package: Add optional argument to --search-paths.
* guix/scripts/package.scm (search-path-environment-variables): Add #:kind parameter. Pass it to 'environment-variable-definition'. (display-search-paths): Add #:kind parameter and pass it to 'search-path-environment-variables'. (%options): Add an optional parameter for "--search-paths". (guix-package)[process-query]: Handle it. * tests/guix-package-net.sh: Adjust existing test. * tests/guix-package.sh: Adjust existing tests and add new test. * doc/guix.texi (Invoking guix package): Document it.
-rw-r--r--doc/guix.texi14
-rw-r--r--guix/scripts/package.scm38
-rw-r--r--tests/guix-package-net.sh2
-rw-r--r--tests/guix-package.sh9
4 files changed, 48 insertions, 15 deletions
diff --git a/doc/guix.texi b/doc/guix.texi
index 8e1bdb6f93..53c9fb2d44 100644
--- a/doc/guix.texi
+++ b/doc/guix.texi
@@ -1098,7 +1098,7 @@ The difference between @code{--roll-back} and
not make a zeroth generation, so if a specified generation does not
exist, the current generation will not be changed.
-@item --search-paths
+@item --search-paths[=@var{kind}]
@cindex search paths
Report environment variable definitions, in Bash syntax, that may be
needed in order to use the set of installed packages. These environment
@@ -1113,6 +1113,18 @@ library are installed in the profile, then @code{--search-paths} will
suggest setting these variables to @code{@var{profile}/include} and
@code{@var{profile}/lib}, respectively.
+The typical use case is to define these environment variables in the
+shell:
+
+@example
+$ eval `guix package --search-paths`
+@end example
+
+@var{kind} may be one of @code{exact}, @code{prefix}, or @code{suffix},
+meaning that the returned environment variable definitions will either
+be exact settings, or prefixes or suffixes of the current value of these
+variables. When omitted, @var{kind} defaults to @code{exact}.
+
@item --profile=@var{profile}
@itemx -p @var{profile}
Use @var{profile} instead of the user's default profile.
diff --git a/guix/scripts/package.scm b/guix/scripts/package.scm
index 300af681c2..d6d7c66cf3 100644
--- a/guix/scripts/package.scm
+++ b/guix/scripts/package.scm
@@ -376,10 +376,13 @@ an output path different than CURRENT-PATH."
;;;
(define* (search-path-environment-variables entries profile
- #:optional (getenv getenv))
+ #:optional (getenv getenv)
+ #:key (kind 'exact))
"Return environment variable definitions that may be needed for the use of
ENTRIES, a list of manifest entries, in PROFILE. Use GETENV to determine the
-current settings and report only settings not already effective."
+current settings and report only settings not already effective. KIND
+must be one of 'exact, 'prefix, or 'suffix, depending on the kind of search
+path definition to be returned."
(let ((search-paths (delete-duplicates
(cons $PATH
(append-map manifest-entry-search-paths
@@ -388,17 +391,19 @@ current settings and report only settings not already effective."
((spec . value)
(let ((variable (search-path-specification-variable spec))
(sep (search-path-specification-separator spec)))
- ;; TODO: Offer the choice between exact/prefix/suffix.
(environment-variable-definition variable value
- #:separator sep))))
+ #:separator sep
+ #:kind kind))))
(evaluate-search-paths search-paths (list profile)
getenv))))
-(define (display-search-paths entries profile)
+(define* (display-search-paths entries profile
+ #:key (kind 'exact))
"Display the search path environment variables that may need to be set for
ENTRIES, a list of manifest entries, in the context of PROFILE."
(let* ((profile (user-friendly-profile profile))
- (settings (search-path-environment-variables entries profile)))
+ (settings (search-path-environment-variables entries profile
+ #:kind kind)))
(unless (null? settings)
(format #t (_ "The following environment variable definitions may be needed:~%"))
(format #t "~{ ~a~%~}" settings))))
@@ -533,10 +538,20 @@ Install, remove, or upgrade PACKAGES in a single transaction.\n"))
(lambda (opt name arg result arg-handler)
(values (alist-cons 'switch-generation arg result)
#f)))
- (option '("search-paths") #f #f
+ (option '("search-paths") #f #t
(lambda (opt name arg result arg-handler)
- (values (cons `(query search-paths) result)
- #f)))
+ (let ((kind (match arg
+ ((or "exact" "prefix" "suffix")
+ (string->symbol arg))
+ (#f
+ 'exact)
+ (x
+ (leave (_ "~a: unsupported \
+kind of search path~%")
+ x)))))
+ (values (cons `(query search-paths ,kind)
+ result)
+ #f))))
(option '(#\p "profile") #t #f
(lambda (opt name arg result arg-handler)
(values (alist-cons 'profile (canonicalize-profile arg)
@@ -977,12 +992,13 @@ more information.~%"))
(find-packages-by-name name version)))
#t))
- (('search-paths)
+ (('search-paths kind)
(let* ((manifest (profile-manifest profile))
(entries (manifest-entries manifest))
(profile (user-friendly-profile profile))
(settings (search-path-environment-variables entries profile
- (const #f))))
+ (const #f)
+ #:kind kind)))
(format #t "~{~a~%~}" settings)
#t))
diff --git a/tests/guix-package-net.sh b/tests/guix-package-net.sh
index cf3233bee2..14222cfd25 100644
--- a/tests/guix-package-net.sh
+++ b/tests/guix-package-net.sh
@@ -147,7 +147,7 @@ test "`readlink_base "$profile"`" = "$profile-2-link"
# Make sure LIBRARY_PATH gets listed by `--search-paths'.
guix package --bootstrap -p "$profile" -i guile-bootstrap -i gcc-bootstrap
-guix package --search-paths -p "$profile" | grep LIBRARY_PATH
+guix package -p "$profile" --search-paths | grep LIBRARY_PATH
# Roll back so we can delete #3 below.
guix package -p "$profile" --switch-generation=2
diff --git a/tests/guix-package.sh b/tests/guix-package.sh
index a732110d5c..d420b8076d 100644
--- a/tests/guix-package.sh
+++ b/tests/guix-package.sh
@@ -52,8 +52,13 @@ test -L "$profile" && test -L "$profile-1-link"
test -f "$profile/bin/guile"
# No search path env. var. here.
-guix package --search-paths -p "$profile"
-test "`guix package --search-paths -p "$profile" | wc -l`" = 0
+guix package -p "$profile" --search-paths
+guix package -p "$profile" --search-paths | grep '^export PATH='
+test "`guix package -p "$profile" --search-paths | wc -l`" = 1 # $PATH
+( set -e; set -x; \
+ eval `guix package --search-paths=prefix -p "$PWD/$profile"`; \
+ test "`type -P guile`" = "$PWD/$profile/bin/guile" ; \
+ type -P rm )
# Exit with 1 when a generation does not exist.
if guix package -p "$profile" --delete-generations=42;