to make our code work with multiple ocamlgraph versions, we are using this snippet in one of our files
#if OCAMLGRAPH_VERSION >= (2,0,0)
let module Dom = Dominator.Make_graph(struct
include G
let empty () = create ()
let add_edge g v1 v2 = add_edge g v1 v2; g
end) in
#elif OCAMLGRAPH_VERSION >= (1,8,6)
let module Dom = Dominator.Make_graph(G) in
#else
let module Dom = Dominator.Make(G) in
#endif
And in our dune
file we preprocess this with cppo like this:
(library
[...]
(preprocess (action (run %{bin:cppo} -V OCAMLGRAPH:%{read:ocamlgraph.version} %{input-file})))
(rule
(target ocamlgraph.version)
(action (with-stdout-to %{target} (run ocamlfind query -format %v ocamlgraph))))
Now we want to use dune build @fmt
. The problem is, that ocamlformat doesn't understand files that have yet to be preprocessed. One workaround would be to add the affected file to .ocamlformat-ignore
but the file is rather large so it would be a pity to not have it auto-formatted.
Is there an easy solution to this problem? Maybe there is a common pattern how this can be solved with dune?
question from:
https://stackoverflow.com/questions/65854619/use-ocamlformat-with-cppo-and-dune 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…