From af07095516b56dcdd38bf1874da27de9c4c841f6 Mon Sep 17 00:00:00 2001 From: Ludovic Courtès Date: Sat, 27 Dec 2014 23:22:08 +0100 Subject: packages: Add 'file-type' field to 'search-path-specification'. Fixes . * guix/packages.scm (): Rename 'directories' field to 'files'. Add 'file-type'. (search-path-specification->sexp): Honor 'file-type'. * gnu/packages/autotools.scm, gnu/packages/bootstrap.scm, gnu/packages/cross-base.scm, gnu/packages/games.scm, gnu/packages/gcc.scm, gnu/packages/glib.scm, gnu/packages/guile.scm, gnu/packages/man.scm, gnu/packages/perl.scm, gnu/packages/pkg-config.scm, gnu/packages/python.scm, gnu/packages/ruby.scm, gnu/packages/xfce.scm: Change 'directories' to 'files'. * tests/packages.scm ("search paths"): Change 'directories' field to 'files'. * guix/scripts/environment.scm (for-each-search-path): Likewise. --- guix/scripts/environment.scm | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'guix/scripts') diff --git a/guix/scripts/environment.scm b/guix/scripts/environment.scm index c388b0c52c..412b8be658 100644 --- a/guix/scripts/environment.scm +++ b/guix/scripts/environment.scm @@ -54,8 +54,7 @@ path value is appended." value))))) (cons* (search-path-specification (variable "PATH") - (directories '("bin" "sbin")) - (separator ":")) + (files '("bin" "sbin"))) (delete-duplicates (append-map package-native-search-paths inputs)))))) -- cgit v1.2.3 From bd2fc4d81342dc15feba2998835e69dabee08864 Mon Sep 17 00:00:00 2001 From: Ludovic Courtès Date: Sat, 27 Dec 2014 23:24:35 +0100 Subject: utils: Export 'search-path-as-list'. * guix/build/utils.scm (search-path-as-list): Make public. * guix/scripts/environment.scm (for-each-search-path): Use it. --- guix/build/utils.scm | 1 + guix/scripts/environment.scm | 5 ++--- 2 files changed, 3 insertions(+), 3 deletions(-) (limited to 'guix/scripts') diff --git a/guix/build/utils.scm b/guix/build/utils.scm index 47bcb3e8a1..86b7ca0155 100644 --- a/guix/build/utils.scm +++ b/guix/build/utils.scm @@ -45,6 +45,7 @@ delete-file-recursively find-files + search-path-as-list set-path-environment-variable search-path-as-string->list list->search-path-as-string diff --git a/guix/scripts/environment.scm b/guix/scripts/environment.scm index 412b8be658..b3a79d9251 100644 --- a/guix/scripts/environment.scm +++ b/guix/scripts/environment.scm @@ -45,9 +45,8 @@ path value is appended." (($ variable directories separator) (let* ((current (getenv variable)) - (path ((@@ (guix build utils) search-path-as-list) - directories paths)) - (value (list->search-path-as-string path separator))) + (path (search-path-as-list directories paths)) + (value (list->search-path-as-string path separator))) (proc variable (if (and current (not pure?)) (string-append value separator current) -- cgit v1.2.3 From cc9a5c1454f49850c078045c88a300c1195eabc8 Mon Sep 17 00:00:00 2001 From: Ludovic Courtès Date: Sat, 27 Dec 2014 23:46:10 +0100 Subject: guix package: Use 'search-path-as-list' instead of custom code. This will handle the new 'file-type' and 'file-pattern' fields correctly. * guix/scripts/package.scm (search-path-environment-variables)[search-path-definition]: Rewrite in terms of 'search-path-as-list'. --- guix/scripts/package.scm | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) (limited to 'guix/scripts') diff --git a/guix/scripts/package.scm b/guix/scripts/package.scm index 21dc66cb75..2f694cd55f 100644 --- a/guix/scripts/package.scm +++ b/guix/scripts/package.scm @@ -29,7 +29,8 @@ #:use-module (guix utils) #:use-module (guix config) #:use-module (guix scripts build) - #:use-module ((guix build utils) #:select (directory-exists? mkdir-p)) + #:use-module ((guix build utils) + #:select (directory-exists? mkdir-p search-path-as-list)) #:use-module (ice-9 format) #:use-module (ice-9 match) #:use-module (ice-9 regex) @@ -362,19 +363,19 @@ current settings and report only settings not already effective." (define search-path-definition (match-lambda - (($ variable directories separator) - (let ((values (or (and=> (getenv variable) - (cut string-tokenize* <> separator)) - '())) - (directories (filter file-exists? - (map (cut string-append profile - "/" <>) - directories)))) - (if (every (cut member <> values) directories) + (($ variable files separator + type pattern) + (let ((values (or (and=> (getenv variable) + (cut string-tokenize* <> separator)) + '())) + (path (search-path-as-list files (list profile) + #:type type + #:pattern pattern))) + (if (every (cut member <> values) path) #f (format #f "export ~a=\"~a\"" variable - (string-join directories separator))))))) + (string-join path separator))))))) (let* ((packages (filter-map manifest-entry->package entries)) (search-paths (delete-duplicates -- cgit v1.2.3 From cf81a2363989429f4af518e92e7404655d45dbc7 Mon Sep 17 00:00:00 2001 From: Ludovic Courtès Date: Sat, 3 Jan 2015 19:46:07 +0100 Subject: guix package: Follow symlinks for pattern search paths. * guix/scripts/package.scm (search-path-environment-variables): Add local 'files' variable. * tests/packages.scm ("--search-paths with pattern"): New test. --- guix/scripts/package.scm | 17 ++++++++++------ tests/packages.scm | 51 ++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 62 insertions(+), 6 deletions(-) (limited to 'guix/scripts') diff --git a/guix/scripts/package.scm b/guix/scripts/package.scm index 2f694cd55f..30b0658198 100644 --- a/guix/scripts/package.scm +++ b/guix/scripts/package.scm @@ -365,12 +365,17 @@ current settings and report only settings not already effective." (match-lambda (($ variable files separator type pattern) - (let ((values (or (and=> (getenv variable) - (cut string-tokenize* <> separator)) - '())) - (path (search-path-as-list files (list profile) - #:type type - #:pattern pattern))) + (let* ((values (or (and=> (getenv variable) + (cut string-tokenize* <> separator)) + '())) + ;; Add a trailing slash to force symlinks to be treated as + ;; directories when 'find-files' traverses them. + (files (if pattern + (map (cut string-append <> "/") files) + files)) + (path (search-path-as-list files (list profile) + #:type type + #:pattern pattern))) (if (every (cut member <> values) path) #f (format #f "export ~a=\"~a\"" diff --git a/tests/packages.scm b/tests/packages.scm index bb83032602..72c69ff653 100644 --- a/tests/packages.scm +++ b/tests/packages.scm @@ -19,6 +19,7 @@ (define-module (test-packages) #:use-module (guix tests) #:use-module (guix store) + #:use-module (guix monads) #:use-module ((guix utils) ;; Rename the 'location' binding to allow proper syntax ;; matching when setting the 'location' field of a package. @@ -31,10 +32,13 @@ #:use-module (guix build-system) #:use-module (guix build-system trivial) #:use-module (guix build-system gnu) + #:use-module (guix profiles) + #:use-module (guix scripts package) #:use-module (gnu packages) #:use-module (gnu packages base) #:use-module (gnu packages guile) #:use-module (gnu packages bootstrap) + #:use-module (gnu packages xml) #:use-module (srfi srfi-1) #:use-module (srfi srfi-26) #:use-module (srfi srfi-34) @@ -527,6 +531,53 @@ (((? (cut eq? hello <>))) #t) (wrong (pk 'find-packages-by-name wrong #f)))) +(test-assert "--search-paths with pattern" + ;; Make sure 'guix package --search-paths' correctly reports environment + ;; variables when file patterns are used (in particular, it must follow + ;; symlinks when looking for 'catalog.xml'.) To do that, we rely on the + ;; libxml2 package specification, which contains such a definition. + (let* ((p1 (package + (name "foo") (version "0") (source #f) + (build-system trivial-build-system) + (arguments + `(#:guile ,%bootstrap-guile + #:modules ((guix build utils)) + #:builder (begin + (use-modules (guix build utils)) + (let ((out (assoc-ref %outputs "out"))) + (mkdir-p (string-append out "/xml/bar/baz")) + (call-with-output-file + (string-append out "/xml/bar/baz/catalog.xml") + (lambda (port) + (display "xml? wat?!" port))))))) + (synopsis #f) (description #f) + (home-page #f) (license #f))) + (p2 (package + ;; Provide a fake libxml2 to avoid building the real one. This + ;; is OK because 'guix package' gets search path specifications + ;; from the same-named package found in the distro. + (name "libxml2") (version "0.0.0") (source #f) + (build-system trivial-build-system) + (arguments + `(#:guile ,%bootstrap-guile + #:builder (mkdir (assoc-ref %outputs "out")))) + (native-search-paths (package-native-search-paths libxml2)) + (synopsis #f) (description #f) + (home-page #f) (license #f))) + (prof (run-with-store %store + (profile-derivation + (manifest (map package->manifest-entry + (list p1 p2))) + #:info-dir? #f) + #:guile-for-build (%guile-for-build)))) + (build-derivations %store (list prof)) + (string-match (format #f "^export XML_CATALOG_FILES=\"~a/xml/+bar/baz/catalog\\.xml\"\n" + (derivation->output-path prof)) + (with-output-to-string + (lambda () + (guix-package "-p" (derivation->output-path prof) + "--search-paths")))))) + (test-end "packages") -- cgit v1.2.3