Fix ocamldep-postproc in case-insensitive, case-preserving filesystems.#150
Fix ocamldep-postproc in case-insensitive, case-preserving filesystems.#150mfp wants to merge 1 commit intoocaml-omake:masterfrom
Conversation
| [name1; name2] | ||
| else | ||
| [name2; name1] in | ||
| let names = (* check name with uncapitalized case first *) [name1; name2] in |
There was a problem hiding this comment.
This change was required for omake's bootstrapping to work.
| let unix_filename_exists path = | ||
| let basedir = Filename.dirname path in | ||
| let basename = Filename.basename path in | ||
| basename = "." || basename = ".." || Array.exists (String.equal basename) (Sys.readdir basedir) |
There was a problem hiding this comment.
readdir inside stat (wrapper) sounds expensive
There was a problem hiding this comment.
It is :-(, but I'm not aware of any BSD/POSIX syscall/API to obtain the original capitalization -- I read even realpath(3) lies. And I don't know how to determine whether the filesystem is case-insensitive to restrict the above check to that case (without write ops that is). At least it's performed only when there's a successful (l)stat.
The only alternative I can think of is finding the mount point, probing the FS and caching this info, but it still feels a bit dirty.
|
I'd rather say that this is a bug/problem in |
On case-insensitive, case-preserving filesystems,
omakefinds invalid dependencies corresponding to paths that do not exist on disk since they have the wrong capitalization.In particular, given module
Athat depends onB, and the corresponding source filesa.mlandb.ml, if you have a target likeOCamlPackage(runtime, a b),omakewill invokeocamlcas inocamlc -pack -o runtime.cmo B.cmo a.cmo. Now, on a case-insensitive, case-preserving filesystem,b.cmocan be open(2)ed under bothb.cmoandB.cmopaths, butocamlcfails -- it must be doingreaddirand seesB.cmois missing.This is caused by a bug in the
ocamldep-postprocbuiltin. I verified this by overriding its definition in an affected codebase (extprot) under macOS to useOCamlScannerPostproc, which did work.This PR fixes the builtin itself.
Credits
The work on this PR was performed on behalf of Ahrefs open-source work day:
https://twitter.com/javierwchavarri/status/1466774912148910088