@@ -227,26 +227,22 @@ let get_path_and_build_if_necessary sctx ~no_rebuild ~dir ~prog =
227227 | Some path -> build_prog ~no_rebuild ~prog path
228228 | None -> not_found ~dir ~prog )
229229 | Absolute ->
230- let path = Path. of_string prog in
231- if Path. exists path
232- then Memo. return path
233- else (
234- let path = Path. relative_to_source_in_build_or_external ~dir prog in
235- Build_system. file_exists path
236- >> = (function
237- | true -> Memo. return (Some path)
238- | false ->
239- if not (Filename. check_suffix prog " .exe" )
240- then Memo. return None
241- else (
242- let path = Path. extend_basename path ~suffix: " .exe" in
243- Build_system. file_exists path
244- >> | function
245- | true -> Some path
246- | false -> None ))
247- >> = function
248- | Some path -> Memo. return path
249- | None -> not_found ~dir ~prog )
230+ (match
231+ let path = Path. of_string prog in
232+ if Path. exists path
233+ then Some path
234+ else (
235+ let path = Path. extend_basename path ~suffix: Bin. exe in
236+ if Path. exists path
237+ then Some path
238+ else (
239+ let path =
240+ Path. relative_to_source_in_build_or_external ~dir (Filename. basename prog)
241+ in
242+ Option. some_if (Path. exists path) path))
243+ with
244+ | Some prog -> Memo. return prog
245+ | None -> not_found ~dir ~prog )
250246;;
251247
252248module Exec_context = struct
@@ -344,6 +340,14 @@ let term =
344340 (* TODO we should make sure to finalize the current backend before exiting dune.
345341 For watch mode, we should finalize the backend and then restart it in between
346342 runs. *)
343+ let builder =
344+ match prog with
345+ | Cmd_arg. Terminal prog ->
346+ if String. starts_with ~prefix: " /" prog
347+ then Common.Builder. set_root builder (Filename. dirname prog)
348+ else builder
349+ | _ -> builder
350+ in
347351 let common, config = Common. init builder in
348352 let exec_context = Exec_context. init ~common ~context ~no_rebuild ~prog ~args in
349353 let f =
0 commit comments