(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
|
|
@ -53,7 +53,7 @@
|
||||||
(define source (and (assoc 'source options) (cdr (assoc 'source options))))
|
(define source (and (assoc 'source options) (cdr (assoc 'source options))))
|
||||||
|
|
||||||
(define config-path (if (assoc 'config-file options) (cdr (assoc 'config-file options)) "zilch.scm"))
|
(define config-path (if (assoc 'config-file options) (cdr (assoc 'config-file options)) "zilch.scm"))
|
||||||
(define config (parse-ninja-config `(override-source: ,source ,@(call-with-input-file config-path read))))
|
(define config (parse-ninja-config config-path `(override-source: ,(and source (vfs-from-directory source)) ,@(call-with-input-file config-path read))))
|
||||||
|
|
||||||
(when (and (ninja-build-config-depfile-path config) (file-exists? (ninja-build-config-depfile-path config)))
|
(when (and (ninja-build-config-depfile-path config) (file-exists? (ninja-build-config-depfile-path config)))
|
||||||
(set-ninja-build-config-depfile! config (alist->mapping (make-default-comparator) (call-with-input-file (ninja-build-config-depfile-path config) read))))
|
(set-ninja-build-config-depfile! config (alist->mapping (make-default-comparator) (call-with-input-file (ninja-build-config-depfile-path config) read))))
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,7 @@
|
||||||
(import
|
(import
|
||||||
(scheme base) (scheme eval)
|
(scheme base) (scheme eval)
|
||||||
(zilch magic) (zilch nixpkgs) (zilch vfs)
|
(zilch magic) (zilch nixpkgs) (zilch vfs)
|
||||||
(srfi 88)
|
(srfi 88) (srfi 152)
|
||||||
(prefix (only scheme eval) scheme-))
|
(prefix (only scheme eval) scheme-))
|
||||||
|
|
||||||
(export
|
(export
|
||||||
|
|
@ -39,7 +39,14 @@
|
||||||
(disallow-elide ninja-build-config-disallow-elide set-ninja-build-config-disallow-elide!)
|
(disallow-elide ninja-build-config-disallow-elide set-ninja-build-config-disallow-elide!)
|
||||||
(rewrites ninja-build-config-rewrites set-ninja-build-config-rewrites!))
|
(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
|
(cond
|
||||||
((null? data) conf)
|
((null? data) conf)
|
||||||
((null? (cdr data)) (error "Expected even list of directives in Zilch Ninja config"))
|
((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! conf (environment-for-derivation drv))
|
||||||
(set-ninja-build-config-environment-drv! conf (store-path-drv drv)))
|
(set-ninja-build-config-environment-drv! conf (store-path-drv drv)))
|
||||||
(set-ninja-build-config-environment! conf (list-ref data 1)))
|
(set-ninja-build-config-environment! conf (list-ref data 1)))
|
||||||
(parse-config-inner conf (cddr data)))
|
(parse-config-inner path conf (cddr data)))
|
||||||
((#:root)
|
((#: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)))
|
(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)
|
((#: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)))
|
(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 conf (cddr data)))
|
(parse-config-inner path conf (cddr data)))
|
||||||
((#:depfile-path)
|
((#:depfile-path)
|
||||||
(set-ninja-build-config-depfile-path! conf (list-ref data 1))
|
(set-ninja-build-config-depfile-path! conf (relative-to-file path (list-ref data 1)))
|
||||||
(parse-config-inner conf (cddr data)))
|
(parse-config-inner path conf (cddr data)))
|
||||||
((#:depfile)
|
((#:depfile)
|
||||||
(set-ninja-build-config-depfile! conf (list-ref data 1))
|
(set-ninja-build-config-depfile! conf (list-ref data 1))
|
||||||
(parse-config-inner conf (cddr data)))
|
(parse-config-inner path conf (cddr data)))
|
||||||
((#:patch)
|
((#:patch)
|
||||||
(let*
|
(let*
|
||||||
((patch-base (list-ref data 1))
|
((patch-base (list-ref data 1))
|
||||||
|
|
@ -75,7 +82,7 @@
|
||||||
(scheme-eval patch-base))
|
(scheme-eval patch-base))
|
||||||
(else patch-base))))
|
(else patch-base))))
|
||||||
(set-ninja-build-config-patches! conf (cons processed-patch (ninja-build-config-patches conf))))
|
(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)
|
((#:disallow-elide)
|
||||||
(let*
|
(let*
|
||||||
((thunk (list-ref data 1))
|
((thunk (list-ref data 1))
|
||||||
|
|
@ -85,7 +92,7 @@
|
||||||
(scheme-eval thunk))
|
(scheme-eval thunk))
|
||||||
(else thunk))))
|
(else thunk))))
|
||||||
(set-ninja-build-config-disallow-elide! conf processed-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)
|
((#:target #:targets)
|
||||||
(when (eq? (ninja-build-config-targets conf) #f)
|
(when (eq? (ninja-build-config-targets conf) #f)
|
||||||
(set-ninja-build-config-targets! conf '()))
|
(set-ninja-build-config-targets! conf '()))
|
||||||
|
|
@ -93,12 +100,12 @@
|
||||||
((val (list-ref data 1))
|
((val (list-ref data 1))
|
||||||
(list-val (if (list? val) val (list val))))
|
(list-val (if (list? val) val (list val))))
|
||||||
(set-ninja-build-config-targets! conf (append list-val (ninja-build-config-targets conf))))
|
(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)
|
((#:rewrite)
|
||||||
(let*
|
(let*
|
||||||
((val (list-ref data 1)))
|
((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))))
|
(set-ninja-build-config-rewrites! conf (cons (cons (car val) (parse-ninja-config path (cdr val))) (ninja-build-config-rewrites conf))))
|
||||||
(parse-config-inner conf (cddr data)))
|
(parse-config-inner path conf (cddr data)))
|
||||||
(else (error (string-append "Unknown directive " (keyword->string (car data)) " parsing Zilch Ninja config")))))))
|
(else (error (string-append "Unknown directive " (keyword->string (car data)) " parsing Zilch Ninja config")))))))
|
||||||
|
|
||||||
;; Parses a Zilch Ninja configuration file.
|
;; Parses a Zilch Ninja configuration file.
|
||||||
|
|
@ -132,10 +139,12 @@
|
||||||
;; - `rewrite: ("<derivation name>" . <nested config>): A nested Zilch
|
;; - `rewrite: ("<derivation name>" . <nested config>): A nested Zilch
|
||||||
;; Ninja configuration to swap out the input derivation with equivalent
|
;; Ninja configuration to swap out the input derivation with equivalent
|
||||||
;; name.
|
;; 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)
|
(unless (list? config)
|
||||||
(error "expected Zilch Ninja config to be a list"))
|
(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.
|
;; `source-paths`: mapping of original store path to virtual path.
|
||||||
;; `finalized-drv`: promise of a <finalized-drv>
|
;; `finalized-drv`: promise of a <finalized-drv>
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue