(zilch lang ninja build): support phony rules

This commit is contained in:
puck 2025-05-09 13:09:49 +00:00
parent 355af66489
commit 7cdf45ef96

View file

@ -49,12 +49,19 @@
(define (append-file path)
(define input-file (mapping-ref edges path (lambda () (mapping-ref/default edges (normalize-path path) #f))))
; if input-file is 'base, this is part of the base vfs; we don't filter that right now.
(unless (eq? input-file 'base)
(if input-file
; This file is produced by another build edge. Add it to our input vfs.
(cond
; if input-file is 'base, this is part of the base vfs; we don't filter that right now.
((eq? input-file 'base) #f)
; Phony rule; pass through the inputs literally.
((and (pair? input-file) (eq? (car input-file) 'phony)) (for-each append-file (cdr input-file)))
; This file is produced by another build edge. Add it to our input vfs.
(input-file
(let ((prev-copy-input-files copy-input-files))
(set! copy-input-files #~,(string-append #$prev-copy-input-files "\n" "$COREUTILS/mkdir -p bdir/" relative-to-root "/$($COREUTILS/dirname " path "); $COREUTILS/cp -rf " #$(force input-file) " bdir/" relative-to-root "/" path))); (set! vfs (vfs-append-file vfs (normalize-path path) (force input-file)))
(set! copy-input-files #~,(string-append #$prev-copy-input-files "\n" "$COREUTILS/mkdir -p bdir/" relative-to-root "/$($COREUTILS/dirname " path "); $COREUTILS/cp -rf " #$(force input-file) " bdir/" relative-to-root "/" path))))
(else
(unless (string-prefix? "/nix/store" path)
(error "Path doesn't exist as build edge" path))))
@ -138,8 +145,13 @@
(for-each
(lambda (edge)
(define processed (delay (derivation-for-edge environment vfs-store-path relative-to edges edge)))
(for-each (lambda (v) (set! edges (mapping-set! edges v (delay #~,(string-append #$(force processed) "/" v)))))
(append (build-edge-outputs edge) (build-edge-implicit-outputs edge))))
(if (build-edge-resolved edge)
(for-each (lambda (v) (set! edges (mapping-set! edges v (delay #~,(string-append #$(force processed) "/" v)))))
(append (build-edge-outputs edge) (build-edge-implicit-outputs edge)))
; This edge is phony; mark the edge as having its outputs.
(for-each (lambda (v) (set! edges (mapping-set! edges v (cons 'phony (build-edge-inputs edge)))))
(append (build-edge-outputs edge) (build-edge-implicit-outputs edge)))))
(build-file-build-edges file))
(define edge-ref (lambda (path) (force (mapping-ref/default edges path #f))))