From 91e63f9caea7df74d239a42503a06a64793350c9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ludovic=20Court=C3=A8s?= Date: Tue, 12 Apr 2011 08:05:20 +0000 Subject: [PATCH] gnupdate: Handle `repeated' nodes referring to a drv not encountered yet. * maintainers/scripts/gnu/gnupdate (xml-element->snix): Return an `unresolved' node when the repeated derivation hasn't been encountered yet. (resolve): New procedure. (xml->snix): Use it. svn path=/nixpkgs/trunk/; revision=26790 --- maintainers/scripts/gnu/gnupdate | 47 ++++++++++++++++++++++++++++---- 1 file changed, 42 insertions(+), 5 deletions(-) diff --git a/maintainers/scripts/gnu/gnupdate b/maintainers/scripts/gnu/gnupdate index a6923506dbb..5eb22cb5963 100755 --- a/maintainers/scripts/gnu/gnupdate +++ b/maintainers/scripts/gnu/gnupdate @@ -117,8 +117,19 @@ exec ${GUILE-guile} -L "$PWD" -l "$0" \ (if (pair? body) (values `(derivation ,drv-path ,out-path ,(cdr body)) derivations) - (error "no previous occurrence of derivation" - drv-path))) + + ;; DRV-PATH hasn't been encountered yet but may be later + ;; (see .) + ;; Return an `unresolved' node. + (values `(unresolved + ,(lambda (derivations) + (let ((body (vhash-assoc drv-path derivations))) + (if (pair? body) + `(derivation ,drv-path ,out-path + ,(cdr body)) + (error "no previous occurrence of derivation" + drv-path))))) + derivations))) (values `(derivation ,drv-path ,out-path ,body) (vhash-cons drv-path body derivations))))) ((ellipsis) @@ -146,6 +157,32 @@ exec ${GUILE-guile} -L "$PWD" -l "$0" \ (values `(varpat ,(assq-ref attributes 'name)) derivations)) (else (error "unhandled Nix XML element" elem)))) +(define (resolve snix derivations) + "Return a new SNix tree where `unresolved' nodes from SNIX have been +replaced by the result of their application to DERIVATIONS, a vhash." + (let loop ((node snix) + (seen vlist-null)) + (if (vhash-assq node seen) + (values node seen) + (match node + (('unresolved proc) + (let ((n (proc derivations))) + (values n seen))) + ((tag body ...) + (let ((body+seen (fold (lambda (n body+seen) + (call-with-values + (lambda () + (loop n (cdr body+seen))) + (lambda (n* seen) + (cons (cons n* (car body+seen)) + (vhash-consq n #t seen))))) + (cons '() (vhash-consq node #t seen)) + body))) + (values (cons tag (reverse (car body+seen))) + (vhash-consq node #t (cdr body+seen))))) + (anything + (values anything seen)))))) + (define xml->snix ;; Return the SNix represention of TREE, an SXML tree as returned by ;; parsing the XML output of `nix-instantiate' on Nixpkgs. @@ -173,9 +210,9 @@ exec ${GUILE-guile} -L "$PWD" -l "$0" \ ;; Discard inter-node strings, which are blanks. seed)))) (lambda (port) - ;; Discard the second value returned by the parser (the derivation - ;; vhash). - (caar (parse port (cons '() vlist-null)))))) + (match (parse port (cons '() vlist-null)) + (((snix) . derivations) + (resolve snix derivations)))))) (define (call-with-package snix proc) (match snix