(zilch lang ninja): document

Change-Id: I6a6a6964dcc713504ec57f40981a601696a573af
This commit is contained in:
puck 2025-07-03 18:57:48 +00:00
parent 154ba9be1c
commit 93a1ebba00
11 changed files with 329 additions and 43 deletions

View file

@ -1,3 +1,4 @@
;; Parses the Zilch-specific Ninja configuration.
(define-library (zilch lang ninja config)
(import
(scheme base) (scheme eval)
@ -6,7 +7,7 @@
(prefix (only scheme eval) scheme-))
(export
ninja-build-config?
<ninja-build-config> ninja-build-config?
ninja-build-config-environment ninja-build-config-environment-drv
ninja-build-config-root-dir ninja-build-config-patches ninja-build-config-targets
ninja-build-config-override-source ninja-build-config-depfile ninja-build-config-depfile-path
@ -17,6 +18,8 @@
parse-ninja-config)
(begin
;; Represents a parsed Ninja build configuration.
;; See `parse-ninja-config` for the definition of these fields.
(define-record-type <ninja-build-config>
(make-ninja-build-config environment environment-drv root-dir patches targets override-source depfile depfile-path disallow-elide)
ninja-build-config?
@ -86,7 +89,35 @@
(set-ninja-build-config-targets! conf (append list-val (ninja-build-config-targets conf))))
(parse-config-inner conf (cddr data)))
(else (error (string-append "Unknown directive " (keyword->string (car data)) " parsing Zilch Ninja config")))))))
;; Parses a Zilch Ninja configuration file.
;;
;; A Zilch Ninja configuration file is a list containing repeated keys and values.
;;
;; - `env:`/`environment: ...`: The environment to be used when processing
;; the Ninja file. If the environment is a string, it is assumed to be a
;; Nix expression resolving to a derivation, and will be evaluated in the
;; context of Nixpkgs. Otherwise, it is assumed to be a (optionally
;; `zexp`) alist of environment variables.
;; - `root: dir`: The root directory that contains both the source and
;; necessary Ninja build files. If string, assumed to be a directory
;; relative to the working directory; assumed to be a `<vfs>` otherwise.
;; - `override-source: dir`: The source override directory. Only used by
;; `build-nixpkgs-drv-reproducibly`, ignored otherwise.
;; - `depfile-path: path`: The location of a depfile cache to use, as a
;; string relative to the current working directory. Only used by
;; `zilch-cli-ninja`.
;; - `depfile: #<mapping>`: An SRFI146 mapping output file names to a list
;; of input dependencies. Used to elide inputs where possible.
;; - `patch: proc`: A patch procedure (or a list which evaluates to one).
;; A patch procedure takes a `<build-edge>, and outputs `#f` or a string
;; of shell commands to run before evaluating the rule's command.
;; - `disallow-elide: proc`: A procedure that takes the path of a file and
;; can return `#t` to reject its elision. Used to special-case files that
;; would normally be elided, but shouldn't, in cases where the depfile is
;; incorrect.
;; - `target: "foo"`/`targets: '("foo" "bar")`: Build these targets instead
;; of the default specified in the Ninja file.
(define (parse-ninja-config config)
(unless (list? config)
(error "expected Zilch Ninja config to be a list"))