(zilch ninja): resolve depfile and source overrides relative to zilch file
Change-Id: I6a6a6964b712289cfd408a02f3b6951e1de53e97
This commit is contained in:
parent
0023f3def8
commit
3a6e716a5e
2 changed files with 26 additions and 17 deletions
|
|
@ -3,7 +3,7 @@
|
|||
(import
|
||||
(scheme base) (scheme eval)
|
||||
(zilch magic) (zilch nixpkgs) (zilch vfs)
|
||||
(srfi 88)
|
||||
(srfi 88) (srfi 152)
|
||||
(prefix (only scheme eval) scheme-))
|
||||
|
||||
(export
|
||||
|
|
@ -39,7 +39,14 @@
|
|||
(disallow-elide ninja-build-config-disallow-elide set-ninja-build-config-disallow-elide!)
|
||||
(rewrites ninja-build-config-rewrites set-ninja-build-config-rewrites!))
|
||||
|
||||
(define (parse-config-inner conf data)
|
||||
(define (relative-to-file path path2)
|
||||
(if (string-prefix? "/" path2) path2
|
||||
(let ((last-slash (string-contains-right path "/")))
|
||||
(if last-slash
|
||||
(string-append (string-copy path 0 last-slash) "/" path2)
|
||||
path2))))
|
||||
|
||||
(define (parse-config-inner path conf data)
|
||||
(cond
|
||||
((null? data) conf)
|
||||
((null? (cdr data)) (error "Expected even list of directives in Zilch Ninja config"))
|
||||
|
|
@ -51,19 +58,19 @@
|
|||
(set-ninja-build-config-environment! conf (environment-for-derivation drv))
|
||||
(set-ninja-build-config-environment-drv! conf (store-path-drv drv)))
|
||||
(set-ninja-build-config-environment! conf (list-ref data 1)))
|
||||
(parse-config-inner conf (cddr data)))
|
||||
(parse-config-inner path conf (cddr data)))
|
||||
((#:root)
|
||||
(set-ninja-build-config-root-dir! conf (if (string? (list-ref data 1)) (vfs-from-directory (list-ref data 1)) (list-ref data 1)))
|
||||
(parse-config-inner conf (cddr data)))
|
||||
(parse-config-inner path conf (cddr data)))
|
||||
((#:override-source)
|
||||
(set-ninja-build-config-override-source! conf (if (string? (list-ref data 1)) (vfs-from-directory (list-ref data 1)) (list-ref data 1)))
|
||||
(parse-config-inner conf (cddr data)))
|
||||
(set-ninja-build-config-override-source! conf (if (string? (list-ref data 1)) (vfs-from-directory (relative-to-file path (list-ref data 1))) (list-ref data 1)))
|
||||
(parse-config-inner path conf (cddr data)))
|
||||
((#:depfile-path)
|
||||
(set-ninja-build-config-depfile-path! conf (list-ref data 1))
|
||||
(parse-config-inner conf (cddr data)))
|
||||
(set-ninja-build-config-depfile-path! conf (relative-to-file path (list-ref data 1)))
|
||||
(parse-config-inner path conf (cddr data)))
|
||||
((#:depfile)
|
||||
(set-ninja-build-config-depfile! conf (list-ref data 1))
|
||||
(parse-config-inner conf (cddr data)))
|
||||
(parse-config-inner path conf (cddr data)))
|
||||
((#:patch)
|
||||
(let*
|
||||
((patch-base (list-ref data 1))
|
||||
|
|
@ -75,7 +82,7 @@
|
|||
(scheme-eval patch-base))
|
||||
(else patch-base))))
|
||||
(set-ninja-build-config-patches! conf (cons processed-patch (ninja-build-config-patches conf))))
|
||||
(parse-config-inner conf (cddr data)))
|
||||
(parse-config-inner path conf (cddr data)))
|
||||
((#:disallow-elide)
|
||||
(let*
|
||||
((thunk (list-ref data 1))
|
||||
|
|
@ -85,7 +92,7 @@
|
|||
(scheme-eval thunk))
|
||||
(else thunk))))
|
||||
(set-ninja-build-config-disallow-elide! conf processed-thunk))
|
||||
(parse-config-inner conf (cddr data)))
|
||||
(parse-config-inner path conf (cddr data)))
|
||||
((#:target #:targets)
|
||||
(when (eq? (ninja-build-config-targets conf) #f)
|
||||
(set-ninja-build-config-targets! conf '()))
|
||||
|
|
@ -93,12 +100,12 @@
|
|||
((val (list-ref data 1))
|
||||
(list-val (if (list? val) val (list val))))
|
||||
(set-ninja-build-config-targets! conf (append list-val (ninja-build-config-targets conf))))
|
||||
(parse-config-inner conf (cddr data)))
|
||||
(parse-config-inner path conf (cddr data)))
|
||||
((#:rewrite)
|
||||
(let*
|
||||
((val (list-ref data 1)))
|
||||
(set-ninja-build-config-rewrites! conf (cons (cons (car val) (parse-ninja-config (cdr val))) (ninja-build-config-rewrites conf))))
|
||||
(parse-config-inner conf (cddr data)))
|
||||
(set-ninja-build-config-rewrites! conf (cons (cons (car val) (parse-ninja-config path (cdr val))) (ninja-build-config-rewrites conf))))
|
||||
(parse-config-inner path conf (cddr data)))
|
||||
(else (error (string-append "Unknown directive " (keyword->string (car data)) " parsing Zilch Ninja config")))))))
|
||||
|
||||
;; Parses a Zilch Ninja configuration file.
|
||||
|
|
@ -132,10 +139,12 @@
|
|||
;; - `rewrite: ("<derivation name>" . <nested config>): A nested Zilch
|
||||
;; Ninja configuration to swap out the input derivation with equivalent
|
||||
;; name.
|
||||
(define (parse-ninja-config config)
|
||||
;;
|
||||
;; `path` is the path this file was located at, used to resolve relative paths for depfiles.
|
||||
(define (parse-ninja-config path config)
|
||||
(unless (list? config)
|
||||
(error "expected Zilch Ninja config to be a list"))
|
||||
(parse-config-inner (make-ninja-build-config #f #f #f '() #f #f #f #f #f '()) config))
|
||||
(parse-config-inner path (make-ninja-build-config #f #f #f '() #f #f #f #f #f '()) config))
|
||||
|
||||
;; `source-paths`: mapping of original store path to virtual path.
|
||||
;; `finalized-drv`: promise of a <finalized-drv>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue