From 561eaf7144755716ed65ba5ceb73d1672695050a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ludovic=20Court=C3=A8s?= Date: Sun, 1 Jul 2012 22:55:49 +0200 Subject: [PATCH] derivation: Move sorting code to `write-derivation'. * guix/derivations.scm (write-derivation): Sorte OUTPUTS, INPUTS, SOURCES, and ENV-VARS alphabetically. (derivation-hash): Leave INPUTS, SOURCES, and OUTPUTS unsorted. (derivation)[env-vars-with-empty-outputs]: Leave ENV-VARS unsorted. --- guix/derivations.scm | 69 ++++++++++++++++++++++---------------------- 1 file changed, 34 insertions(+), 35 deletions(-) diff --git a/guix/derivations.scm b/guix/derivations.scm index f85666bcb9..11d47e9702 100644 --- a/guix/derivations.scm +++ b/guix/derivations.scm @@ -206,6 +206,9 @@ (define (list->string lst) (define (write-list lst) (display (list->string lst) port)) + ;; Note: lists are sorted alphabetically, to conform with the behavior of + ;; C++ `std::map' in Nix itself. + (match drv (($ outputs inputs sources system builder args env-vars) @@ -217,22 +220,30 @@ (define (write-list lst) (or (and=> hash-algo symbol->string) "") (or (and=> hash bytevector->base16-string) "")))) - outputs)) + (sort outputs + (lambda (o1 o2) + (string path sub-drvs) (format #f "(~s,~a)" path - (list->string (map object->string sub-drvs))))) - inputs)) + (list->string (map object->string + (sort sub-drvs stringstring sources)) + (write-list (map object->string (sort sources stringstring args)) (display "," port) (write-list (map (match-lambda ((name . value) (format #f "(~s,~s)" name value))) - env-vars)) + (sort env-vars + (lambda (e1 e2) + (stringoutput-path path #:optional (output "out")) @@ -278,26 +289,17 @@ (define derivation-hash ; `hashDerivationModulo' in derivations.cc system builder args env-vars) ;; A regular derivation: replace the path of each input with that ;; input's hash; return the hash of serialization of the resulting - ;; derivation. Note: inputs are sorted as in the order of their hex - ;; hash representation because that's what the C++ `std::map' code - ;; does. - (let* ((inputs (sort (map (match-lambda - (($ path sub-drvs) - (let ((hash (call-with-input-file path - (compose bytevector->base16-string - derivation-hash - read-derivation)))) - (make-derivation-input hash sub-drvs)))) - inputs) - (lambda (i1 i2) - (string path sub-drvs) + (let ((hash (call-with-input-file path + (compose bytevector->base16-string + derivation-hash + read-derivation)))) + (make-derivation-input hash sub-drvs)))) + inputs)) + (drv (make-derivation outputs inputs sources + system builder args env-vars))) (sha256 (string->utf8 (call-with-output-string (cut write-derivation drv <>)))))))))) @@ -354,22 +356,19 @@ (define (add-output-paths drv) (define (env-vars-with-empty-outputs) ;; Return a variant of ENV-VARS where each OUTPUTS is associated with an - ;; empty string, even outputs that do not appear in ENV-VARS. Note: the - ;; result is sorted alphabetically, as with C++ `std::map'. + ;; empty string, even outputs that do not appear in ENV-VARS. (let ((e (map (match-lambda ((name . val) (if (member name outputs) (cons name "") (cons name val)))) env-vars))) - (sort (fold (lambda (output-name env-vars) - (if (assoc output-name env-vars) - env-vars - (append env-vars `((,output-name . ""))))) - e - outputs) - (lambda (e1 e2) - (string