diff --git a/CHANGES.md b/CHANGES.md index 81dc16cae5b..aaf56c5e8d8 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,3 +1,10 @@ +Unreleased +---------- + +- Fixed a bug that could result in needless recompilation under Windows due to + case differences in the result of `Sys.getcwd` (observed under `emacs`). + (#3966, @nojb). + 2.8.2 (21/01/2021) ------------------ diff --git a/bin/common.ml b/bin/common.ml index cac11b66a7c..9b0fa2da61f 100644 --- a/bin/common.ml +++ b/bin/common.ml @@ -86,9 +86,18 @@ let prefix_target common s = common.target_prefix ^ s let instrument_with t = t.instrument_with +(* To avoid needless recompilations under Windows, where the case of + [Sys.getcwd] can vary between different invocations of [dune], normalize to + lowercase. *) +let normalize_path p = + if Sys.win32 then + Path.External.lowercase_ascii p + else + p + let set_dirs c = if c.root.dir <> Filename.current_dir_name then Sys.chdir c.root.dir; - Path.set_root (Path.External.cwd ()); + Path.set_root (normalize_path (Path.External.cwd ())); Path.Build.set_build_dir (Path.Build.Kind.of_string c.build_dir) let set_common_other ?log_file c ~targets = diff --git a/src/stdune/path.ml b/src/stdune/path.ml index fb10e1add8d..af3928e0fe3 100644 --- a/src/stdune/path.ml +++ b/src/stdune/path.ml @@ -50,6 +50,8 @@ module External : sig val cwd : unit -> t val as_local : t -> string + + val lowercase_ascii : t -> t end = struct module T = Interned.No_interning @@ -164,6 +166,8 @@ end = struct else String.is_prefix ~prefix:(to_string a ^ "/") (to_string b) + let lowercase_ascii t = make (String.lowercase_ascii (to_string t)) + module Set = struct include T.Set diff --git a/src/stdune/path.mli b/src/stdune/path.mli index 07b8b06cf2b..e171b14ef8e 100644 --- a/src/stdune/path.mli +++ b/src/stdune/path.mli @@ -111,6 +111,8 @@ module External : sig val relative : t -> string -> t val mkdir_p : ?perms:int -> t -> unit + + val lowercase_ascii : t -> t end module Build : sig