Topological-sort check inputs to ocamlc linking step

I’m not sure if there is a tool out there that does this, so before I go and write it, I figured I should ask:

Often I write an ocaml link-step, e.g.

ocamlc <yadda yadda yadda> a.cmo b.cmo c.cmo -o argle.byte

[or the equivalent for -a]
and find that the inputs are in a wrong order. And it’s always a bit of a pain to figure out what order is compatible. It seems clear that one can write a tool (I’ve used the binary-manipulation apparatus before to look at deps) to calculate whether a given order is correct, but I haven’t seen a tool that does it. Obviously one can’t reorder inputs to a compatible topological order, b/c there are possible side-effects in the order of linking files. But one could certainly detect that a given order is wrong, and inform the user of which input-pairs were out-of-order.

Is there a tool that does this? I can’t find one. If not, I guess I’m gonna write one.

Ocamldot perhaps?

I’ve used ocamldot (had to upgrade it, b/c it had fallen behind current ocaml) but that just draws graphs. Imagine the following:

(1) you write your makefile
(2) you have lines like

ocamlfind ... args .... <various .cmo .cma .cma .cmxa files> .... more args ....

(3) you prepend “topo-check” to the beginning of each line, viz.

topo-check ocamlfind ... args .... <various .cmo .cma .cma .cmxa files> .... more args ....

and it (a) pulls out all those file-names, (b) checks that their order is consistent with their dependencies, and © if so, executes the command, (d) otherwise giving a complaint describing which pairs of files are out-of-order.

This seems very straightfoward, but in the interest of not duplicating work …

1 Like