From 7acb3005f82ffae91c563c7e8c15d9a809e3bf8e Mon Sep 17 00:00:00 2001 From: Puck Meerburg Date: Sat, 26 Jul 2025 15:42:17 +0000 Subject: [PATCH] (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 --- lang/ninja/src/build.sld | 58 +++++++++++++++++++++------------------- 1 file changed, 30 insertions(+), 28 deletions(-) diff --git a/lang/ninja/src/build.sld b/lang/ninja/src/build.sld index febfffc..2f54ada 100644 --- a/lang/ninja/src/build.sld +++ b/lang/ninja/src/build.sld @@ -40,13 +40,12 @@ (phony-inputs built-edge-phony-inputs)) (define-record-type - (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? (config build-env-config) (vfs build-env-vfs set-build-env-vfs!) (header-files build-env-header-files set-build-env-header-files!) (build-dir build-env-build-dir) - (base-paths build-env-base-paths set-build-env-base-paths!) (parsed-depfiles build-env-parsed-depfiles) (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. ((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. ((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. (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/" (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 (unless (string-prefix? "/nix/store" path) @@ -347,9 +340,6 @@ (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 (mapping (make-default-comparator))) (mapping-for-each @@ -360,16 +350,33 @@ ((string=? relative-to "") #f) ((string-prefix? relative-to path) (set! path (string-copy path (string-length relative-to)))) (else (set! path (string-append "../" path)))) - (if (eq? loc 'directory) - (set! base-paths (mapping-set! base-paths path (delay (vfs-to-store (vfs-subdir (ninja-build-config-root-dir conf) vfs-path))))) - (set! base-paths (mapping-set! base-paths path loc))) - (set! edges (mapping-set! edges path (cons (if (string-prefix? "meson-private/" path) 'base-path 'base) #f))) + (define new-copy-path + (if (eq? loc 'directory) + (delay (vfs-to-store (vfs-subdir (ninja-build-config-root-dir conf) vfs-path))) + 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))) (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).. (mapping-for-each @@ -380,14 +387,9 @@ edges) ; Then mark them (to avoid having an ongoing for-each whilst modifying the mapping) (for-each - (lambda (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)))) + elide-path (build-env-header-files env)) - (set! filtered-vfs (mapping-delete! filtered-vfs (cons "build" "meson-private"))) (for-each (lambda (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.. (when (and data (eq? (car data) 'base) (can-safely-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))))) + (elide-path path))) (append (build-edge-inputs edge) (build-edge-implicit-dependencies edge) (build-edge-order-only-dependencies 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)))) all-outputs))) (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 (mapping-filter! (lambda (kv loc)