ocamlbuild icon indicating copy to clipboard operation
ocamlbuild copied to clipboard

compute path equivalence correctly

Open agarwal opened this issue 9 years ago • 3 comments

I created a rule to produce file ./foo.mlpack, but ocamlbuild failed to produce it. Eventually I determined it is because it doesn't realize this is equilvalent to foo.mlpack.

agarwal avatar Apr 25 '16 20:04 agarwal

Probably this is the source of the issue:

# Ocamlbuild_pack.Pathname.compare "./foo" "foo";;
- : int = -1

In my opinion, Pathname.t should be abstract. A build system is a good example of where file paths should be treated with greater rigor (for example as done in phat).

agarwal avatar Apr 25 '16 21:04 agarwal

I agree that it would be nice if Path were abstract; the change would be hard to manage in terms of backward compatibility, though. One solution may be to provide another pathname module that is abstract, and and gradually convert the code in ocamlbuild itself and in plugins.

OCamlbuild has path normalization functions that should erase the difference between those two paths. Calling Pathname.normalize on the path argument of your static_file function should be enough -- and more portable than your current approach.

gasche avatar Apr 25 '16 22:04 gasche

I did check out Path.normalize, but this made me not use it:

# Pathname.normalize "../lib";;
Exception: (Failure "Pathname.normalize_list: .. is forbidden here"). 

I would need to use Pathname.parent to get my desired overall functionality, but that returns exactly the above string:

# Pathname.parent "lib";;
- : string = "../lib"

So it all seems a bit fragile as I'm sure my solution is too.

agarwal avatar Apr 25 '16 22:04 agarwal