(zilch lang ninja build): Remove base-path logic

This replaces it by just using the existing copy logic.
Removing the base-path logic makes it easier to add
non-build-dir-rooted files.

Change-Id: I6a6a6964ef300cae2e180970048c8a4881c88e19
This commit is contained in:
puck 2025-07-26 15:42:17 +00:00
parent feeb14eed5
commit 7acb3005f8

View file

@ -40,13 +40,12 @@
(phony-inputs built-edge-phony-inputs)) (phony-inputs built-edge-phony-inputs))
(define-record-type <build-env> (define-record-type <build-env>
(make-build-env config vfs header-files build-dir base-paths parsed-depfiles collected-deps) (make-build-env config vfs header-files build-dir parsed-depfiles collected-deps)
build-env? build-env?
(config build-env-config) (config build-env-config)
(vfs build-env-vfs set-build-env-vfs!) (vfs build-env-vfs set-build-env-vfs!)
(header-files build-env-header-files set-build-env-header-files!) (header-files build-env-header-files set-build-env-header-files!)
(build-dir build-env-build-dir) (build-dir build-env-build-dir)
(base-paths build-env-base-paths set-build-env-base-paths!)
(parsed-depfiles build-env-parsed-depfiles) (parsed-depfiles build-env-parsed-depfiles)
(collected-deps build-env-collected-deps set-build-env-collected-deps!)) (collected-deps build-env-collected-deps set-build-env-collected-deps!))
@ -100,19 +99,13 @@
; if input-file is 'base, this is part of the base vfs; we don't filter that right now. ; if input-file is 'base, this is part of the base vfs; we don't filter that right now.
((eq? input-file 'base) #f) ((eq? input-file 'base) #f)
; a base-path path we'll have to copy from the store.
((eq? input-file 'base-path)
(let ((base-path-obj (mapping-ref (build-env-base-paths env) path (lambda () (mapping-ref (build-env-base-paths env) (normalize-path path)))))
(prev-copy-input-files copy-input-files))
(set! copy-input-files #~,(string-append #$prev-copy-input-files "\n" "$COREUTILS/mkdir -p bdir/" (build-env-build-dir env) "/$($COREUTILS/dirname " path "); $COREUTILS/cp -rf " #$(force base-path-obj) " bdir/" (build-env-build-dir env) "/" path))))
; Phony rule; pass through the inputs literally. ; Phony rule; pass through the inputs literally.
((eq? input-file 'phony) (for-each append-file (built-edge-phony-inputs input-edge))) ((eq? input-file 'phony) (for-each append-file (built-edge-phony-inputs input-edge)))
; This file is produced by another build edge. Add it to our input vfs. ; This file is produced by another build edge. Add it to our input vfs.
(input-file (input-file
(let ((prev-copy-input-files copy-input-files)) (let ((prev-copy-input-files copy-input-files))
(set! copy-input-files #~,(string-append #$prev-copy-input-files "\n" "$COREUTILS/mkdir -p bdir/" (build-env-build-dir env) "/$($COREUTILS/dirname " path "); $COREUTILS/cp -rf " #$(force input-file) " bdir/" (build-env-build-dir env) "/" path)))) (set! copy-input-files #~,(string-append #$prev-copy-input-files "\n" "$COREUTILS/mkdir -p bdir/" (build-env-build-dir env) "/$($COREUTILS/dirname " path "); $COREUTILS/cp -rf --preserve=timestamps " #$(force input-file) " bdir/" (build-env-build-dir env) "/" path))))
(else (else
(unless (string-prefix? "/nix/store" path) (unless (string-prefix? "/nix/store" path)
@ -347,9 +340,6 @@
(define edges (mapping (make-default-comparator))) (define edges (mapping (make-default-comparator)))
; record edges for each path in the base vfs.
(define base-paths
(mapping (make-default-comparator)))
(define path-to-vfs (define path-to-vfs
(mapping (make-default-comparator))) (mapping (make-default-comparator)))
(mapping-for-each (mapping-for-each
@ -360,16 +350,33 @@
((string=? relative-to "") #f) ((string=? relative-to "") #f)
((string-prefix? relative-to path) (set! path (string-copy path (string-length relative-to)))) ((string-prefix? relative-to path) (set! path (string-copy path (string-length relative-to))))
(else (set! path (string-append "../" path)))) (else (set! path (string-append "../" path))))
(if (eq? loc 'directory) (define new-copy-path
(set! base-paths (mapping-set! base-paths path (delay (vfs-to-store (vfs-subdir (ninja-build-config-root-dir conf) vfs-path))))) (if (eq? loc 'directory)
(set! base-paths (mapping-set! base-paths path loc))) (delay (vfs-to-store (vfs-subdir (ninja-build-config-root-dir conf) vfs-path)))
(set! edges (mapping-set! edges path (cons (if (string-prefix? "meson-private/" path) 'base-path 'base) #f))) loc))
(set! edges (mapping-set! edges path (cons (if (string-prefix? "meson-private/" path) new-copy-path 'base) #f)))
(set! path-to-vfs (mapping-set! path-to-vfs path kv))) (set! path-to-vfs (mapping-set! path-to-vfs path kv)))
(vfs-contents (ninja-build-config-root-dir conf))) (vfs-contents (ninja-build-config-root-dir conf)))
(define filtered-vfs (mapping-copy (vfs-contents (ninja-build-config-root-dir conf)))) (define filtered-vfs (mapping-copy (vfs-contents (ninja-build-config-root-dir conf))))
(define env (make-build-env conf #f '() relative-to base-paths (or (ninja-build-config-depfile conf) (mapping (make-default-comparator))) (mapping (make-default-comparator)))) (define env (make-build-env conf #f '() relative-to (or (ninja-build-config-depfile conf) (mapping (make-default-comparator))) (mapping (make-default-comparator))))
(set! edges (mapping-set! edges "meson-private" (cons 'base-path #f))) (define (elide-vfs rel-path kv)
(define vfs-path (if (string=? (car kv) "") (cdr kv) (string-append (car kv) "/" (cdr kv))))
(define val (mapping-ref/default filtered-vfs kv #f))
(define new-copy-path
(if (eq? val 'directory)
(delay (vfs-to-store (vfs-subdir (ninja-build-config-root-dir conf) vfs-path)))
val))
(when new-copy-path
(set! edges (mapping-set! edges rel-path (cons new-copy-path #f)))
(set! filtered-vfs (mapping-delete! filtered-vfs kv))))
; Elides a store path by path, relative to the ninja file's directory.
(define (elide-path path)
(let ((vfs-path (mapping-ref/default path-to-vfs path #f)))
(and vfs-path (elide-vfs path vfs-path))))
(elide-path "meson-private")
; First record all paths we are planning on eliding (for being headers).. ; First record all paths we are planning on eliding (for being headers)..
(mapping-for-each (mapping-for-each
@ -380,14 +387,9 @@
edges) edges)
; Then mark them (to avoid having an ongoing for-each whilst modifying the mapping) ; Then mark them (to avoid having an ongoing for-each whilst modifying the mapping)
(for-each (for-each
(lambda (path) elide-path
; Mark it as 'base-path (needs copying, and not in main vfs)
(set! edges (mapping-set! edges path (cons 'base-path #f)))
; Remove from filtered-vfs.
(set! filtered-vfs (mapping-delete! filtered-vfs (mapping-ref path-to-vfs path))))
(build-env-header-files env)) (build-env-header-files env))
(set! filtered-vfs (mapping-delete! filtered-vfs (cons "build" "meson-private")))
(for-each (for-each
(lambda (edge) (lambda (edge)
(define built-edge (delay (build-edge env edges edge))) (define built-edge (delay (build-edge env edges edge)))
@ -410,10 +412,7 @@
; If this path is in the VFS, and can be elided.. ; If this path is in the VFS, and can be elided..
(when (and data (eq? (car data) 'base) (can-safely-elide path)) (when (and data (eq? (car data) 'base) (can-safely-elide path))
; Mark it as 'base-path (needs copying, and not in main vfs) (elide-path path)))
(set! edges (mapping-set! edges path (cons 'base-path #f)))
; Remove from filtered-vfs.
(set! filtered-vfs (mapping-delete! filtered-vfs (mapping-ref path-to-vfs path)))))
(append (build-edge-inputs edge) (build-edge-implicit-dependencies edge) (build-edge-order-only-dependencies edge)))) (append (build-edge-inputs edge) (build-edge-implicit-dependencies edge) (build-edge-order-only-dependencies edge))))
; Record output edges of this build edge. ; Record output edges of this build edge.
@ -425,6 +424,9 @@
(for-each (lambda (v) (set! edges (mapping-set! edges v (cons 'phony built-edge)))) (for-each (lambda (v) (set! edges (mapping-set! edges v (cons 'phony built-edge))))
all-outputs))) all-outputs)))
(build-file-build-edges file)) (build-file-build-edges file))
; Finish VFS filtering by taking out everything under build/meson-private.
; This operates on the absolute VFS paths.
(set! filtered-vfs (set! filtered-vfs
(mapping-filter! (mapping-filter!
(lambda (kv loc) (lambda (kv loc)