mirror of
https://git.in.rschanz.org/ryan77627/guix.git
synced 2025-01-11 13:49:23 -05:00
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.
This commit is contained in:
parent
0a04234081
commit
561eaf7144
1 changed files with 34 additions and 35 deletions
|
@ -206,6 +206,9 @@ (define (list->string lst)
|
||||||
(define (write-list lst)
|
(define (write-list lst)
|
||||||
(display (list->string lst) port))
|
(display (list->string lst) port))
|
||||||
|
|
||||||
|
;; Note: lists are sorted alphabetically, to conform with the behavior of
|
||||||
|
;; C++ `std::map' in Nix itself.
|
||||||
|
|
||||||
(match drv
|
(match drv
|
||||||
(($ <derivation> outputs inputs sources
|
(($ <derivation> outputs inputs sources
|
||||||
system builder args env-vars)
|
system builder args env-vars)
|
||||||
|
@ -217,22 +220,30 @@ (define (write-list lst)
|
||||||
(or (and=> hash-algo symbol->string) "")
|
(or (and=> hash-algo symbol->string) "")
|
||||||
(or (and=> hash bytevector->base16-string)
|
(or (and=> hash bytevector->base16-string)
|
||||||
""))))
|
""))))
|
||||||
outputs))
|
(sort outputs
|
||||||
|
(lambda (o1 o2)
|
||||||
|
(string<? (car o1) (car o2))))))
|
||||||
(display "," port)
|
(display "," port)
|
||||||
(write-list (map (match-lambda
|
(write-list (map (match-lambda
|
||||||
(($ <derivation-input> path sub-drvs)
|
(($ <derivation-input> path sub-drvs)
|
||||||
(format #f "(~s,~a)" path
|
(format #f "(~s,~a)" path
|
||||||
(list->string (map object->string sub-drvs)))))
|
(list->string (map object->string
|
||||||
inputs))
|
(sort sub-drvs string<?))))))
|
||||||
|
(sort inputs
|
||||||
|
(lambda (i1 i2)
|
||||||
|
(string<? (derivation-input-path i1)
|
||||||
|
(derivation-input-path i2))))))
|
||||||
(display "," port)
|
(display "," port)
|
||||||
(write-list (map object->string sources))
|
(write-list (map object->string (sort sources string<?)))
|
||||||
(format port ",~s,~s," system builder)
|
(format port ",~s,~s," system builder)
|
||||||
(write-list (map object->string args))
|
(write-list (map object->string args))
|
||||||
(display "," port)
|
(display "," port)
|
||||||
(write-list (map (match-lambda
|
(write-list (map (match-lambda
|
||||||
((name . value)
|
((name . value)
|
||||||
(format #f "(~s,~s)" name value)))
|
(format #f "(~s,~s)" name value)))
|
||||||
env-vars))
|
(sort env-vars
|
||||||
|
(lambda (e1 e2)
|
||||||
|
(string<? (car e1) (car e2))))))
|
||||||
(display ")" port))))
|
(display ")" port))))
|
||||||
|
|
||||||
(define* (derivation-path->output-path path #:optional (output "out"))
|
(define* (derivation-path->output-path path #:optional (output "out"))
|
||||||
|
@ -278,26 +289,17 @@ (define derivation-hash ; `hashDerivationModulo' in derivations.cc
|
||||||
system builder args env-vars)
|
system builder args env-vars)
|
||||||
;; A regular derivation: replace the path of each input with that
|
;; A regular derivation: replace the path of each input with that
|
||||||
;; input's hash; return the hash of serialization of the resulting
|
;; input's hash; return the hash of serialization of the resulting
|
||||||
;; derivation. Note: inputs are sorted as in the order of their hex
|
;; derivation.
|
||||||
;; hash representation because that's what the C++ `std::map' code
|
(let* ((inputs (map (match-lambda
|
||||||
;; does.
|
(($ <derivation-input> path sub-drvs)
|
||||||
(let* ((inputs (sort (map (match-lambda
|
(let ((hash (call-with-input-file path
|
||||||
(($ <derivation-input> path sub-drvs)
|
(compose bytevector->base16-string
|
||||||
(let ((hash (call-with-input-file path
|
derivation-hash
|
||||||
(compose bytevector->base16-string
|
read-derivation))))
|
||||||
derivation-hash
|
(make-derivation-input hash sub-drvs))))
|
||||||
read-derivation))))
|
inputs))
|
||||||
(make-derivation-input hash sub-drvs))))
|
(drv (make-derivation outputs inputs sources
|
||||||
inputs)
|
system builder args env-vars)))
|
||||||
(lambda (i1 i2)
|
|
||||||
(string<? (derivation-input-path i1)
|
|
||||||
(derivation-input-path i2)))))
|
|
||||||
(sources (sort sources string<?))
|
|
||||||
(outputs (sort outputs
|
|
||||||
(lambda (o1 o2)
|
|
||||||
(string<? (car o1) (car o2)))))
|
|
||||||
(drv (make-derivation outputs inputs sources
|
|
||||||
system builder args env-vars)))
|
|
||||||
(sha256
|
(sha256
|
||||||
(string->utf8 (call-with-output-string
|
(string->utf8 (call-with-output-string
|
||||||
(cut write-derivation drv <>))))))))))
|
(cut write-derivation drv <>))))))))))
|
||||||
|
@ -354,22 +356,19 @@ (define (add-output-paths drv)
|
||||||
|
|
||||||
(define (env-vars-with-empty-outputs)
|
(define (env-vars-with-empty-outputs)
|
||||||
;; Return a variant of ENV-VARS where each OUTPUTS is associated with an
|
;; 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
|
;; empty string, even outputs that do not appear in ENV-VARS.
|
||||||
;; result is sorted alphabetically, as with C++ `std::map'.
|
|
||||||
(let ((e (map (match-lambda
|
(let ((e (map (match-lambda
|
||||||
((name . val)
|
((name . val)
|
||||||
(if (member name outputs)
|
(if (member name outputs)
|
||||||
(cons name "")
|
(cons name "")
|
||||||
(cons name val))))
|
(cons name val))))
|
||||||
env-vars)))
|
env-vars)))
|
||||||
(sort (fold (lambda (output-name env-vars)
|
(fold (lambda (output-name env-vars)
|
||||||
(if (assoc output-name env-vars)
|
(if (assoc output-name env-vars)
|
||||||
env-vars
|
env-vars
|
||||||
(append env-vars `((,output-name . "")))))
|
(append env-vars `((,output-name . "")))))
|
||||||
e
|
e
|
||||||
outputs)
|
outputs)))
|
||||||
(lambda (e1 e2)
|
|
||||||
(string<? (car e1) (car e2))))))
|
|
||||||
|
|
||||||
(let* ((outputs (map (lambda (name)
|
(let* ((outputs (map (lambda (name)
|
||||||
;; Return outputs with an empty path.
|
;; Return outputs with an empty path.
|
||||||
|
|
Loading…
Reference in a new issue