guix package: '--search-paths' can report combined search paths.

Partly fixes <http://bugs.gnu.org/20255>.

* guix/scripts/package.scm (search-path-environment-variables): Change
  'profile' to 'profiles'; expect it to be a list.
  (display-search-paths): Likewise.
  (%default-options): Remove 'profile' entry.
  (%options) <--profile>: Keep previous values associated with 'profile'
  in RESULT.
  (guix-package)[process-actions, process-query]: Handle the possible
  lack of 'profile' pair in OPTS.
This commit is contained in:
Ludovic Courtès 2015-11-10 22:00:53 +01:00
parent 21059b26b0
commit fc2d233964
3 changed files with 60 additions and 30 deletions

View file

@ -1347,6 +1347,20 @@ 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}.
This option can also be used to compute the @emph{combined} search paths
of several profiles. Consider this example:
@example
$ guix package -p foo -i guile
$ guix package -p bar -i guile-json
$ guix package -p foo -p bar --search-paths
@end example
The last command above reports about the @code{GUILE_LOAD_PATH}
variable, even though, taken individually, neither @file{foo} nor
@file{bar} would lead to that recommendation.
@item --profile=@var{profile}
@itemx -p @var{profile}
Use @var{profile} instead of the user's default profile.

View file

@ -186,11 +186,11 @@ (define (upgradeable? name current-version current-path)
;;; Search paths.
;;;
(define* (search-path-environment-variables entries profile
(define* (search-path-environment-variables entries profiles
#: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
ENTRIES, a list of manifest entries, in PROFILES. Use GETENV to determine the
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."
@ -205,15 +205,15 @@ (define* (search-path-environment-variables entries profile
(environment-variable-definition variable value
#:separator sep
#:kind kind))))
(evaluate-search-paths search-paths (list profile)
(evaluate-search-paths search-paths profiles
getenv))))
(define* (display-search-paths entries profile
(define* (display-search-paths entries profiles
#: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
(let* ((profiles (map user-friendly-profile profiles))
(settings (search-path-environment-variables entries profiles
#:kind kind)))
(unless (null? settings)
(format #t (_ "The following environment variable definitions may be needed:~%"))
@ -226,8 +226,7 @@ (define* (display-search-paths entries profile
(define %default-options
;; Alist of default option values.
`((profile . ,%current-profile)
(max-silent-time . 3600)
`((max-silent-time . 3600)
(verbosity . 0)
(substitutes? . #t)))
@ -386,7 +385,7 @@ (define %options
(option '(#\p "profile") #t #f
(lambda (opt name arg result arg-handler)
(values (alist-cons 'profile (canonicalize-profile arg)
(alist-delete 'profile result))
result)
#f)))
(option '(#\n "dry-run") #f #f
(lambda (opt name arg result arg-handler)
@ -601,7 +600,7 @@ (define (process-actions opts)
;; Process any install/remove/upgrade action from OPTS.
(define dry-run? (assoc-ref opts 'dry-run?))
(define profile (assoc-ref opts 'profile))
(define profile (or (assoc-ref opts 'profile) %current-profile))
(define (build-and-use-profile manifest)
(let* ((bootstrap? (assoc-ref opts 'bootstrap?)))
@ -645,7 +644,7 @@ (define (build-and-use-profile manifest)
"~a packages in profile~%"
count)
count)
(display-search-paths entries profile)))))))))
(display-search-paths entries (list profile))))))))))
;; First roll back if asked to.
(cond ((and (assoc-ref opts 'roll-back?)
@ -674,12 +673,12 @@ (define (build-and-use-profile manifest)
(not dry-run?))
(for-each
(match-lambda
(('delete-generations . pattern)
(delete-matching-generations (%store) profile pattern)
(('delete-generations . pattern)
(delete-matching-generations (%store) profile pattern)
(process-actions
(alist-delete 'delete-generations opts)))
(_ #f))
(process-actions
(alist-delete 'delete-generations opts)))
(_ #f))
opts))
((assoc-ref opts 'manifest)
(let* ((file-name (assoc-ref opts 'manifest))
@ -709,7 +708,14 @@ (define (build-and-use-profile manifest)
(define (process-query opts)
;; Process any query specified by OPTS. Return #t when a query was
;; actually processed, #f otherwise.
(let ((profile (assoc-ref opts 'profile)))
(let* ((profiles (match (filter-map (match-lambda
(('profile . p) p)
(_ #f))
opts)
(() (list %current-profile))
(lst lst)))
(profile (match profiles
((head tail ...) head))))
(match (assoc-ref opts 'query)
(('list-generations pattern)
(define (list-generation number)
@ -718,7 +724,7 @@ (define (list-generation number)
(display-profile-content profile number)
(newline)))
(cond ((not (file-exists? profile)) ; XXX: race condition
(cond ((not (file-exists? profile)) ; XXX: race condition
(raise (condition (&profile-not-found-error
(profile profile)))))
((string-null? pattern)
@ -741,11 +747,11 @@ (define (list-generation number)
(installed (manifest-entries manifest)))
(leave-on-EPIPE
(for-each (match-lambda
(($ <manifest-entry> name version output path _)
(when (or (not regexp)
(regexp-exec regexp name))
(format #t "~a\t~a\t~a\t~a~%"
name (or version "?") output path))))
(($ <manifest-entry> name version output path _)
(when (or (not regexp)
(regexp-exec regexp name))
(format #t "~a\t~a\t~a\t~a~%"
name (or version "?") output path))))
;; Show most recently installed packages last.
(reverse installed)))
@ -793,12 +799,12 @@ (define (list-generation number)
#t))
(('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)
#:kind kind)))
(let* ((manifests (map profile-manifest profiles))
(entries (append-map manifest-entries manifests))
(profiles (map user-friendly-profile profiles))
(settings (search-path-environment-variables entries profiles
(const #f)
#:kind kind)))
(format #t "~{~a~%~}" settings)
#t))

View file

@ -46,9 +46,10 @@ fi
profile="t-profile-$$"
profile_alt="t-profile-alt-$$"
rm -f "$profile"
trap 'rm -f "$profile" "$profile-"[0-9]* ; rm -rf t-home-'"$$" EXIT
trap 'rm -f "$profile" "$profile_alt" "$profile-"[0-9]* ; rm -rf t-home-'"$$" EXIT
guix package --bootstrap -p "$profile" -i guile-bootstrap
@ -156,6 +157,15 @@ guix package -p "$profile" --switch-generation=2
guix package -p "$profile" --delete-generations=3
test -z "`guix package -p "$profile" -l 3`"
# Search path of combined profiles. 'LIBRARY_PATH' should show up only in the
# combination, not in the individual profiles.
rm "$profile"
guix package --bootstrap -p "$profile" -i guile-bootstrap
guix package --bootstrap -p "$profile_alt" -i gcc-bootstrap
if guix package -p "$profile" --search-paths | grep LIBRARY_PATH
then false; fi
guix package -p "$profile" -p "$profile_alt" --search-paths \
| grep "LIBRARY_PATH.*$profile/lib"
#
# Try with the default profile.