Skip to content

Commit ed1866f

Browse files
Changed init config
Signed-off-by: Athish Pranav D <athishanna@gmail.com>
1 parent fd81e9b commit ed1866f

2 files changed

Lines changed: 26 additions & 35 deletions

File tree

bin/exec.ml

Lines changed: 24 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -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

252248
module 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 =

otherlibs/stdune/src/path.ml

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1204,28 +1204,15 @@ let explode_exn t =
12041204
| None -> Code_error.raise "Path.explode_exn" [ "path", to_dyn t ]
12051205
;;
12061206

1207-
let rec relative_to_source_in_build_or_external ?error_loc ~dir s =
1207+
let relative_to_source_in_build_or_external ?error_loc ~dir s =
12081208
match Build.extract_build_context dir with
12091209
| None -> relative ?error_loc (In_build_dir dir) s
12101210
| Some (bctxt, source) ->
12111211
let path = relative ?error_loc (In_source_tree source) s in
12121212
(match path with
12131213
| In_source_tree s ->
12141214
In_build_dir (Build.relative (Build.of_string bctxt) (Source0.to_string s))
1215-
| In_build_dir _ -> path
1216-
| External _ ->
1217-
let cwd =
1218-
to_absolute_filename
1219-
(of_filename_relative_to_initial_cwd Filename.current_dir_name)
1220-
in
1221-
let cwd_len = String.length cwd in
1222-
if String.starts_with ~prefix:cwd s
1223-
then
1224-
relative_to_source_in_build_or_external
1225-
?error_loc
1226-
~dir
1227-
(String.sub s ~pos:(cwd_len + 1) ~len:(String.length s - cwd_len - 1))
1228-
else path)
1215+
| In_build_dir _ | External _ -> path)
12291216
;;
12301217

12311218
let exists t =

0 commit comments

Comments
 (0)