diff --git a/CHANGES.md b/CHANGES.md index 998b1659a21..e2a97a4c98e 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -92,6 +92,10 @@ relies on the version written in the `dune-project` file and no longer read `VERSION` or similar files (#2541, @diml) +- On Windows, an .exe suffix is no longer added implicitly to binary names that + already end in .exe. Second, when resolving binary names, .opt variants are no + longer chosen automatically. (#2543, @nojb) + 1.11.0 (23/07/2019) ------------------- diff --git a/src/dune/context.ml b/src/dune/context.ml index 157555151b7..03369df0d74 100644 --- a/src/dune/context.ml +++ b/src/dune/context.ml @@ -151,7 +151,20 @@ let opam_config_var ~env ~cache var = | Error _ -> None ) ) -let which ~cache ~path x = Table.find_or_add cache x ~f:(Bin.which ~path) +let best_prog dir prog = + let fn = Path.relative dir (prog ^ ".opt" ^ Bin.exe) in + if Bin.exists fn then + Some fn + else + let fn = Path.relative dir (prog ^ Bin.exe) in + if Bin.exists fn then + Some fn + else + None + +let which ~path prog = List.find_map path ~f:(fun dir -> best_prog dir prog) + +let which ~cache ~path x = Table.find_or_add cache x ~f:(which ~path) let ocamlpath_sep = if Sys.cygwin then @@ -273,7 +286,7 @@ let create ~(kind : Kind.t) ~path ~env ~env_nodes ~name ~merlin ~targets let get_ocaml_tool prog = match get_tool_using_findlib_config prog with | None -> - Bin.best_prog dir prog + best_prog dir prog | Some _ as x -> x in diff --git a/src/stdune/bin.ml b/src/stdune/bin.ml index b4f9ad2930d..df2eaf0fff9 100644 --- a/src/stdune/bin.ml +++ b/src/stdune/bin.ml @@ -31,25 +31,17 @@ let exists fn = | _ -> true -let best_prog dir prog = - let fn = Path.relative dir (prog ^ ".opt" ^ exe) in - if exists fn then - Some fn +let add_exe prog = + if String.is_suffix (String.lowercase prog) ~suffix:exe then + prog else - let fn = Path.relative dir (prog ^ exe) in - if exists fn then - Some fn - else - None + prog ^ exe let which ~path prog = - let rec search = function - | [] -> - None - | dir :: rest -> ( - match best_prog dir prog with None -> search rest | Some fn -> Some fn ) - in - search path + let prog = add_exe prog in + List.find_map path ~f:(fun dir -> + let fn = Path.relative dir prog in + Option.some_if (exists fn) fn) let make ~path = match which ~path "gmake" with None -> which ~path "make" | some -> some diff --git a/src/stdune/bin.mli b/src/stdune/bin.mli index dfab1048ea3..e0b93b55c9c 100644 --- a/src/stdune/bin.mli +++ b/src/stdune/bin.mli @@ -13,12 +13,11 @@ val cons_path : Path.t -> _PATH:string option -> string (** Extension to append to executable filenames *) val exe : string +(** Check if a file exists *) +val exists : Path.t -> bool + (** Look for a program in the PATH *) val which : path:Path.t list -> string -> Path.t option -(** Return the .opt version of a tool if available. If the tool is not - available at all in the given directory, returns [None]. *) -val best_prog : Path.t -> string -> Path.t option - (** "make" program *) val make : path:Path.t list -> Path.t option