| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
module F = Format |
| 7 |
|
| 8 |
type 'a pp = Format.formatter -> 'a -> unit |
| 9 |
|
| 10 |
module Rule = struct |
| 11 |
type t = |
| 12 |
{ targets : string list |
| 13 |
; deps : string list |
| 14 |
; action : string |
| 15 |
; alias : string option |
| 16 |
} |
| 17 |
|
| 18 |
let pp_sep fmt () = F.fprintf fmt "@;" |
| 19 |
let ppl = F.pp_print_list ~pp_sep F.pp_print_string |
| 20 |
let pp_alias fmt = function |
| 21 |
| None -> () |
| 22 |
| Some alias -> F.fprintf fmt "(alias %s)@\n" alias |
| 23 |
|
| 24 |
let pp fmt { alias; targets; deps; action } = |
| 25 |
F.fprintf fmt |
| 26 |
"@[(rule@\n @[%a(targets @[%a@])@\n(deps @[%a@])@\n(action @[%a@])@])@]@\n" |
| 27 |
pp_alias alias ppl targets ppl deps F.pp_print_string action |
| 28 |
end |
| 29 |
|
| 30 |
module Install = struct |
| 31 |
type t = |
| 32 |
{ section : string |
| 33 |
; package : string |
| 34 |
; files : (string * string) list |
| 35 |
|
| 36 |
} |
| 37 |
|
| 38 |
let pp_install_file fmt (source, target) = |
| 39 |
F.fprintf fmt "(%s as %s)" source target |
| 40 |
|
| 41 |
let pp fmt { section; package; files } = |
| 42 |
F.fprintf fmt |
| 43 |
"@[(install@\n @[(section @[%s@])@\n(package @[%s@])@\n(files @[%a@])@])@]@\n" |
| 44 |
section package (F.pp_print_list pp_install_file) files |
| 45 |
|
| 46 |
end |
| 47 |
|
| 48 |
module Subdir = struct |
| 49 |
|
| 50 |
type 'a t = { subdir : string; payload : 'a } |
| 51 |
|
| 52 |
let pp ppf fmt { subdir; payload } = |
| 53 |
if String.equal subdir "" then |
| 54 |
ppf fmt payload |
| 55 |
else |
| 56 |
Fun.protect ~finally:(fun () -> F.fprintf fmt "@])@\n") |
| 57 |
(fun () -> |
| 58 |
F.fprintf fmt "(subdir %s@\n @[" subdir; |
| 59 |
ppf fmt payload) |
| 60 |
|
| 61 |
end |