diff options
author | 2015-05-20 14:36:41 +0200 | |
---|---|---|
committer | 2015-05-20 22:48:06 +0200 | |
commit | 69941d4e195650bf59285b897c14d6287defea0f (patch) | |
tree | 572c43bd2c6ca5fd53d364a90b21e390bc50a87e | |
parent | 5a52a74592496353d562d9f3e958fb59ab585531 (diff) |
Continuing incomplete 4b5af0d6e9ec1 (on MacOS X, ensuring that files
found in the file system have the expected lowercase/uppercase
spelling)
-rw-r--r-- | lib/envars.ml | 19 | ||||
-rw-r--r-- | lib/system.ml | 7 | ||||
-rw-r--r-- | lib/system.mli | 2 |
3 files changed, 21 insertions, 7 deletions
diff --git a/lib/envars.ml b/lib/envars.ml index b0eed8386..ac0b6f722 100644 --- a/lib/envars.ml +++ b/lib/envars.ml @@ -39,12 +39,25 @@ let path_to_list p = let user_path () = path_to_list (Sys.getenv "PATH") (* may raise Not_found *) + (* Duplicated from system.ml to minimize dependencies *) +let file_exists_respecting_case f = + if Coq_config.arch = "Darwin" then + (* ensure that the file exists with expected case on the + case-insensitive but case-preserving default MacOS file system *) + let rec aux f = + let bf = Filename.basename f in + let df = Filename.dirname f in + String.equal df "." || String.equal df "/" || + aux df && Array.exists (String.equal bf) (Sys.readdir df) + in aux f + else Sys.file_exists f + let rec which l f = match l with | [] -> raise Not_found | p :: tl -> - if Sys.file_exists (p / f) then + if file_exists_respecting_case (p / f) then p else which tl f @@ -102,7 +115,7 @@ let _ = If the check fails, then [oth ()] is evaluated. *) let check_file_else ~dir ~file oth = let path = if Coq_config.local then coqroot else coqroot / dir in - if Sys.file_exists (path / file) then path else oth () + if file_exists_respecting_case (path / file) then path else oth () let guess_coqlib fail = let prelude = "theories/Init/Prelude.vo" in @@ -134,7 +147,7 @@ let coqpath = let coqpath = getenv_else "COQPATH" (fun () -> "") in let make_search_path path = let paths = path_to_list path in - let valid_paths = List.filter Sys.file_exists paths in + let valid_paths = List.filter file_exists_respecting_case paths in List.rev valid_paths in make_search_path coqpath diff --git a/lib/system.ml b/lib/system.ml index 6364035e1..1a67120b6 100644 --- a/lib/system.ml +++ b/lib/system.ml @@ -53,12 +53,11 @@ let all_subdirs ~unix_path:root = if exists_dir root then traverse root []; List.rev !l -let file_really_exists f = +let file_exists_respecting_case f = if Coq_config.arch = "Darwin" then (* ensure that the file exists with expected case on the case-insensitive but case-preserving default MacOS file system *) let rec aux f = - Printf.eprintf ".%!"; let bf = Filename.basename f in let df = Filename.dirname f in String.equal df "." || String.equal df "/" || @@ -90,7 +89,7 @@ let where_in_path ?(warn=true) path filename = in check_and_warn (search path (fun lpe -> let f = Filename.concat lpe filename in - if Sys.file_exists f then [lpe,f] else [])) + if file_exists_respecting_case f then [lpe,f] else [])) let where_in_path_rex path rex = search path (fun lpe -> @@ -106,7 +105,7 @@ let where_in_path_rex path rex = let find_file_in_path ?(warn=true) paths filename = if not (Filename.is_implicit filename) then - if Sys.file_exists filename then + if file_exists_respecting_case filename then let root = Filename.dirname filename in root, filename else diff --git a/lib/system.mli b/lib/system.mli index a3d66d577..051e92f16 100644 --- a/lib/system.mli +++ b/lib/system.mli @@ -29,6 +29,8 @@ val exists_dir : string -> bool val find_file_in_path : ?warn:bool -> CUnix.load_path -> string -> CUnix.physical_path * string +val file_exists_respecting_case : string -> bool + (** {6 I/O functions } *) (** Generic input and output functions, parameterized by a magic number and a suffix. The intern functions raise the exception [Bad_magic_number] |