diff options
Diffstat (limited to 'guix')
-rw-r--r-- | guix/build/gnu-build-system.scm | 3 | ||||
-rw-r--r-- | guix/build/haskell-build-system.scm | 98 | ||||
-rw-r--r-- | guix/build/utils.scm | 9 | ||||
-rw-r--r-- | guix/search-paths.scm | 6 |
4 files changed, 88 insertions, 28 deletions
diff --git a/guix/build/gnu-build-system.scm b/guix/build/gnu-build-system.scm index ff7646b22c..92e15d131e 100644 --- a/guix/build/gnu-build-system.scm +++ b/guix/build/gnu-build-system.scm @@ -576,6 +576,9 @@ in order. Return #t if all the PHASES succeeded, #f otherwise." ;; Encoding/decoding errors shouldn't be silent. (fluid-set! %default-port-conversion-strategy 'error) + ;; Avoid non-determinism related to generated timestamps. + (setenv "SOURCE_DATE_EPOCH" "1") + ;; The trick is to #:allow-other-keys everywhere, so that each procedure in ;; PHASES can pick the keyword arguments it's interested in. (every (match-lambda diff --git a/guix/build/haskell-build-system.scm b/guix/build/haskell-build-system.scm index 4506e96af9..8e2aee381d 100644 --- a/guix/build/haskell-build-system.scm +++ b/guix/build/haskell-build-system.scm @@ -1,5 +1,6 @@ ;;; GNU Guix --- Functional package management for GNU ;;; Copyright © 2015 Federico Beffa <beffa@fbengineering.ch> +;;; Copyright © 2015 Eric Bavier <bavier@member.fsf.org> ;;; Copyright © 2015 Paul van der Walt <paul@denknerd.org> ;;; ;;; This file is part of GNU Guix. @@ -25,6 +26,7 @@ #:use-module (ice-9 rdelim) #:use-module (ice-9 regex) #:use-module (ice-9 match) + #:use-module (ice-9 vlist) #:export (%standard-phases haskell-build)) @@ -78,6 +80,7 @@ and parameters ~s~%" (((_ . dir) ...) dir) (_ '()))) + (ghc-path (getenv "GHC_PACKAGE_PATH")) (params (append `(,(string-append "--prefix=" out)) `(,(string-append "--libdir=" (or lib out) "/lib")) `(,(string-append "--bindir=" (or bin out) "/bin")) @@ -97,6 +100,10 @@ and parameters ~s~%" '("--enable-tests") '()) configure-flags))) + ;; Cabal errors if GHC_PACKAGE_PATH is set during 'configure', so unset + ;; and restore it. + (unsetenv "GHC_PACKAGE_PATH") + ;; For packages where the Cabal build-type is set to "Configure", ;; ./configure will be executed. In these cases, the following ;; environment variable is needed to be able to find the shell executable. @@ -105,7 +112,9 @@ and parameters ~s~%" ;; <https://www.haskell.org/cabal/users-guide/developing-packages.html>. (when (file-exists? "configure") (setenv "CONFIG_SHELL" "sh")) - (run-setuphs "configure" params))) + (run-setuphs "configure" params) + + (setenv "GHC_PACKAGE_PATH" ghc-path))) (define* (build #:rest empty) "Build a given Haskell package." @@ -143,6 +152,12 @@ first match and return the content of the group." (format #t "Compiler ~a not supported~%" name-version))))) +;;; TODO: Move this to (guix build utils)? +(define-syntax-rule (with-null-error-port exp) + "Evaluate EXP with the error port pointing to the bit bucket." + (with-error-to-port (%make-void-port "w") + (lambda () exp))) + (define (make-ghc-package-database system inputs outputs) "Generate the GHC package database." (let* ((haskell (assoc-ref inputs "haskell")) @@ -150,44 +165,89 @@ first match and return the content of the group." (((_ . dir) ...) dir) (_ '()))) - (conf-dirs (search-path-as-list - `(,(string-append "lib/" - (package-name-version haskell) - "/package.conf.d")) - input-dirs)) + ;; Silence 'find-files' (see 'evaluate-search-paths') + (conf-dirs (with-null-error-port + (search-path-as-list + `(,(string-append "lib/" (package-name-version haskell))) + input-dirs #:pattern ".*\\.conf.d$"))) (conf-files (append-map (cut find-files <> "\\.conf$") conf-dirs))) (mkdir-p %tmp-db-dir) (for-each (lambda (file) - (copy-file file - (string-append %tmp-db-dir "/" (basename file)))) + (let ((dest (string-append %tmp-db-dir "/" (basename file)))) + (unless (file-exists? dest) + (copy-file file dest)))) conf-files) (zero? (system* "ghc-pkg" (string-append "--package-db=" %tmp-db-dir) "recache")))) (define* (register #:key name system inputs outputs #:allow-other-keys) - "Generate the compiler registration file for a given Haskell package. Don't -generate the cache as it would clash in user profiles." + "Generate the compiler registration and binary package database files for a +given Haskell package." + + (define (conf-depends conf-file) + ;; Return a list of pkg-ids from the "depends" field in CONF-FILE + (let ((port (open-input-file conf-file)) + (field-rx (make-regexp "^(.*):"))) + (let loop ((collecting #f) + (deps '())) + (let* ((line (read-line port)) + (field (and=> (regexp-exec field-rx line) + (cut match:substring <> 1)))) + (cond + ((and=> field (cut string=? <> "depends")) + ;; The first dependency is listed on the same line as "depends:", + ;; so drop those characters. A line may list more than one .conf. + (let ((d (string-tokenize (string-drop line 8)))) + (loop #t (append d deps)))) + ((and collecting field) + (begin + (close-port port) + (reverse! deps))) + (collecting + (loop #t (append (string-tokenize line) deps))) + (else (loop #f deps))))))) + + (define (install-transitive-deps conf-file src dest) + ;; Copy .conf files from SRC to DEST for dependencies in CONF-FILE, and + ;; their dependencies, etc. + (let loop ((seen vlist-null) + (lst (conf-depends conf-file))) + (match lst + (() #t) ;done + ((id . tail) + (if (not (vhash-assoc id seen)) + (let ((dep-conf (string-append src "/" id ".conf")) + (dep-conf* (string-append dest "/" id ".conf"))) + (copy-file dep-conf dep-conf*) ;XXX: maybe symlink instead? + (loop (vhash-cons id #t seen) + (append lst (conf-depends dep-conf)))) + (loop seen tail)))))) + (let* ((out (assoc-ref outputs "out")) (haskell (assoc-ref inputs "haskell")) (lib (string-append out "/lib")) (config-dir (string-append lib "/" (package-name-version haskell) - "/package.conf.d")) + "/" name ".conf.d")) (id-rx (make-regexp "^id: *(.*)$")) (config-file (string-append out "/" name ".conf")) (params (list (string-append "--gen-pkg-config=" config-file)))) (run-setuphs "register" params) ;; The conf file is created only when there is a library to register. - (when (file-exists? config-file) - (mkdir-p config-dir) - (let ((config-file-name+id - (call-with-ascii-input-file config-file (cut grep id-rx <>)))) - (rename-file config-file - (string-append config-dir "/" config-file-name+id - ".conf")))) - #t)) + (or (not (file-exists? config-file)) + (begin + (mkdir-p config-dir) + (let* ((config-file-name+id + (call-with-ascii-input-file config-file (cut grep id-rx <>)))) + (install-transitive-deps config-file %tmp-db-dir config-dir) + (rename-file config-file + (string-append config-dir "/" + config-file-name+id ".conf")) + (zero? (system* "ghc-pkg" + (string-append "--package-db=" config-dir) + "recache"))))))) (define* (check #:key tests? test-target #:allow-other-keys) "Run the test suite of a given Haskell package." diff --git a/guix/build/utils.scm b/guix/build/utils.scm index e3f9edc5b5..2988193fce 100644 --- a/guix/build/utils.scm +++ b/guix/build/utils.scm @@ -385,10 +385,13 @@ for under the directories designated by FILES. For example: (append-map (lambda (input) (append-map (lambda (file) (let ((file (string-append input "/" file))) - ;; XXX: By using 'find-files', we implicitly - ;; assume #:type 'regular. (if pattern - (find-files file pattern) + (find-files file (lambda (file stat) + (and stat + (eq? type (stat:type stat)) + ((file-name-predicate pattern) file stat))) + #:stat stat + #:directories? #t) (let ((stat (stat file #f))) (if (and stat (eq? type (stat:type stat))) (list file) diff --git a/guix/search-paths.scm b/guix/search-paths.scm index 7fd15d440c..7a6fe67959 100644 --- a/guix/search-paths.scm +++ b/guix/search-paths.scm @@ -139,12 +139,6 @@ report only settings not already effective." (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)) - ;; XXX: Silence 'find-files' when it stumbles upon non-existent ;; directories (see ;; <http://lists.gnu.org/archive/html/guix-devel/2015-01/msg00269.html>.) |