(zilch lang ninja build): add "may fail" to edge-ref

Change-Id: I6a6a69642d0f1daf57c0dee4a0291595f1c13cb2
This commit is contained in:
puck 2025-10-01 14:59:25 +00:00
parent 5485b0f4ce
commit a57b991013

View file

@ -2,6 +2,7 @@
(define-library (zilch lang ninja build)
(import
(scheme base) (scheme lazy) (scheme file)
(scheme case-lambda)
(zilch file) (zilch magic) (scheme char)
(zilch nix drv) (zilch nix path)
(zilch nixpkgs) (zilch zexpr) (zilch vfs)
@ -536,8 +537,10 @@
(set-build-env-vfs! env (vfs-to-store (make-vfs filtered-vfs)))
(define edge-ref
(lambda (path)
(define edge (mapping-ref edges path (lambda () (mapping-ref edges (normalize-path path) (lambda () (error "Target doesn't exist" path))))))
(cons (if (promise? (car edge)) (force (car edge)) (car edge)) (force (cdr edge)))))
(case-lambda
((path) (edge-ref path #f))
((path may-fail)
(define edge (mapping-ref edges path (lambda () (mapping-ref edges (normalize-path path) (lambda () (if may-fail #f (error "Target doesn't exist" path)))))))
(and edge (cons (if (promise? (car edge)) (force (car edge)) (car edge)) (force (cdr edge)))))))
(define defaults (build-file-default-targets file))
(values edge-ref defaults (lambda () (build-env-collected-deps env))))))