【发布时间】:2021-04-27 11:29:25
【问题描述】:
为了使我们的代码适用于多个 ocamlgraph 版本,我们在 one of our files 中使用了这个 sn-p
#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
在我们的 dune 文件中,我们使用 cppo 对其进行预处理,如下所示:
(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))))
现在我们要使用dune build @fmt。问题是,ocamlformat 不理解尚未预处理的文件。一种解决方法是将受影响的文件添加到.ocamlformat-ignore,但该文件相当大,因此很遗憾没有自动格式化。
这个问题有简单的解决方案吗?也许有一个常见的模式可以用沙丘解决这个问题?
【问题讨论】:
标签: ocaml ocaml-dune