@@ -115,19 +115,25 @@ let build_prog ~no_rebuild ~prog p =
115115 p
116116;;
117117
118- let get_path_and_build_if_necessary sctx ~no_rebuild ~dir ~prog =
118+ let dir_of_context common sctx =
119+ let context = Dune_rules.Super_context. context sctx in
120+ Path.Build. relative (Context. build_dir context) (Common. prefix_target common " " )
121+ ;;
122+
123+ let get_path common sctx ~prog =
119124 let open Memo.O in
125+ let dir = dir_of_context common sctx in
120126 match Filename. analyze_program_name prog with
121127 | In_path ->
122128 Super_context. resolve_program_memo sctx ~dir ~loc: None prog
123129 >> = (function
124130 | Error (_ : Action.Prog.Not_found.t ) -> not_found_with_suggestions ~dir ~prog
125- | Ok p -> build_prog ~no_rebuild ~prog p)
131+ | Ok p -> Memo. return p)
126132 | Relative_to_current_dir ->
127133 let path = Path. relative_to_source_in_build_or_external ~dir prog in
128134 Build_system. file_exists path
129135 >> = (function
130- | true -> build_prog ~no_rebuild ~prog path
136+ | true -> Memo. return path
131137 | false -> not_found_with_suggestions ~dir ~prog )
132138 | Absolute ->
133139 (match
@@ -144,19 +150,24 @@ let get_path_and_build_if_necessary sctx ~no_rebuild ~dir ~prog =
144150 | None -> not_found_with_suggestions ~dir ~prog )
145151;;
146152
147- let step ~ setup ~ prog ~ args ~ common ~ no_rebuild ~context ~ on_exit () =
153+ let get_path_and_build_if_necessary common sctx ~ no_rebuild ~prog =
148154 let open Memo.O in
149- let * sctx = setup >> | Import.Main. find_scontext_exn ~name: context in
150- let * env = Super_context. context_env sctx in
151- let expand = Cmd_arg. expand ~root: (Common. root common) ~sctx in
155+ let * path = get_path common sctx ~prog in
156+ match Filename. analyze_program_name prog with
157+ | In_path | Relative_to_current_dir -> build_prog ~no_rebuild ~prog path
158+ | Absolute -> Memo. return path
159+ ;;
160+
161+ let step ~prog ~args ~common ~no_rebuild ~context ~on_exit () =
162+ let open Memo.O in
163+ let * sctx = Super_context. find_exn context in
152164 let * path =
153- let dir =
154- let context = Dune_rules.Super_context. context sctx in
155- Path.Build. relative (Context. build_dir context) (Common. prefix_target common " " )
156- in
157- let * prog = expand prog in
158- get_path_and_build_if_necessary sctx ~no_rebuild ~dir ~prog
159- and * args = Memo. parallel_map args ~f: expand in
165+ let * prog = Cmd_arg. expand ~root: (Common. root common) ~sctx prog in
166+ get_path_and_build_if_necessary common sctx ~no_rebuild ~prog
167+ and * args =
168+ Memo. parallel_map args ~f: (Cmd_arg. expand ~root: (Common. root common) ~sctx )
169+ in
170+ let * env = Super_context. context_env sctx in
160171 Memo. of_non_reproducible_fiber
161172 @@ Dune_engine.Process. run_inherit_std_in_out
162173 ~dir: (Path. of_string Fpath. initial_cwd)
@@ -252,12 +263,11 @@ let exec_building_directly ~common ~config ~context ~prog ~args ~no_rebuild =
252263 Scheduler. go_with_rpc_server_and_console_status_reporting ~common ~config
253264 @@ fun () ->
254265 let open Fiber.O in
255- let * setup = Import.Main. setup () in
256266 let on_exit = Console. printf " Program exited with code [%d]" in
257267 Scheduler.Run. poll
258268 @@
259269 let * () = Fiber. return @@ Scheduler. maybe_clear_screen ~details_hum: [] config in
260- build @@ step ~setup ~ prog ~args ~common ~no_rebuild ~context ~on_exit
270+ build @@ step ~prog ~args ~common ~no_rebuild ~context ~on_exit
261271 | No ->
262272 Scheduler. go_with_rpc_server ~common ~config
263273 @@ fun () ->
@@ -266,16 +276,13 @@ let exec_building_directly ~common ~config ~context ~prog ~args ~no_rebuild =
266276 build_exn (fun () ->
267277 let open Memo.O in
268278 let * sctx = setup >> | Import.Main. find_scontext_exn ~name: context in
269- let * env = Super_context. context_env sctx in
270- let expand = Cmd_arg. expand ~root: (Common. root common) ~sctx in
271- let * prog =
272- let dir =
273- let context = Dune_rules.Super_context. context sctx in
274- Path.Build. relative (Context. build_dir context) (Common. prefix_target common " " )
275- in
276- let * prog = expand prog in
277- get_path_and_build_if_necessary sctx ~no_rebuild ~dir ~prog >> | Path. to_string
278- and * args = Memo. parallel_map ~f: expand args in
279+ let * env = Super_context. context_env sctx
280+ and * prog =
281+ let * prog = Cmd_arg. expand ~root: (Common. root common) ~sctx prog in
282+ get_path_and_build_if_necessary common sctx ~no_rebuild ~prog >> | Path. to_string
283+ and * args =
284+ Memo. parallel_map ~f: (Cmd_arg. expand ~root: (Common. root common) ~sctx ) args
285+ in
279286 restore_cwd_and_execve (Common. root common) prog args env)
280287;;
281288
0 commit comments