@@ -115,19 +115,28 @@ 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 context =
119119 let open Memo.O in
120+ let + sctx = Super_context. find_exn context in
121+ let context = Dune_rules.Super_context. context sctx in
122+ Path.Build. relative (Context. build_dir context) (Common. prefix_target common " " )
123+ ;;
124+
125+ let get_path common context ~prog =
126+ let open Memo.O in
127+ let * sctx = Super_context. find_exn context
128+ and * dir = dir_of_context common context in
120129 match Filename. analyze_program_name prog with
121130 | In_path ->
122131 Super_context. resolve_program_memo sctx ~dir ~loc: None prog
123132 >> = (function
124133 | Error (_ : Action.Prog.Not_found.t ) -> not_found_with_suggestions ~dir ~prog
125- | Ok p -> build_prog ~no_rebuild ~prog p)
134+ | Ok p -> Memo. return p)
126135 | Relative_to_current_dir ->
127136 let path = Path. relative_to_source_in_build_or_external ~dir prog in
128137 Build_system. file_exists path
129138 >> = (function
130- | true -> build_prog ~no_rebuild ~prog path
139+ | true -> Memo. return path
131140 | false -> not_found_with_suggestions ~dir ~prog )
132141 | Absolute ->
133142 (match
@@ -144,19 +153,24 @@ let get_path_and_build_if_necessary sctx ~no_rebuild ~dir ~prog =
144153 | None -> not_found_with_suggestions ~dir ~prog )
145154;;
146155
147- let step ~ setup ~ prog ~ args ~ common ~ no_rebuild ~ context ~on_exit () =
156+ let get_path_and_build_if_necessary common context ~no_rebuild ~ prog =
148157 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
158+ let * path = get_path common context ~prog in
159+ match Filename. analyze_program_name prog with
160+ | In_path | Relative_to_current_dir -> build_prog ~no_rebuild ~prog path
161+ | Absolute -> Memo. return path
162+ ;;
163+
164+ let step ~prog ~args ~common ~no_rebuild ~context ~on_exit () =
165+ let open Memo.O in
166+ let * sctx = Super_context. find_exn context in
152167 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
168+ let * prog = Cmd_arg. expand ~root: (Common. root common) ~sctx prog in
169+ get_path_and_build_if_necessary common context ~no_rebuild ~prog
170+ and * args =
171+ Memo. parallel_map args ~f: (Cmd_arg. expand ~root: (Common. root common) ~sctx )
172+ in
173+ let * env = Super_context. context_env sctx in
160174 Memo. of_non_reproducible_fiber
161175 @@ Dune_engine.Process. run_inherit_std_in_out
162176 ~dir: (Path. of_string Fpath. initial_cwd)
@@ -252,12 +266,11 @@ let exec_building_directly ~common ~config ~context ~prog ~args ~no_rebuild =
252266 Scheduler. go_with_rpc_server_and_console_status_reporting ~common ~config
253267 @@ fun () ->
254268 let open Fiber.O in
255- let * setup = Import.Main. setup () in
256269 let on_exit = Console. printf " Program exited with code [%d]" in
257270 Scheduler.Run. poll
258271 @@
259272 let * () = Fiber. return @@ Scheduler. maybe_clear_screen ~details_hum: [] config in
260- build @@ step ~setup ~ prog ~args ~common ~no_rebuild ~context ~on_exit
273+ build @@ step ~prog ~args ~common ~no_rebuild ~context ~on_exit
261274 | No ->
262275 Scheduler. go_with_rpc_server ~common ~config
263276 @@ fun () ->
@@ -266,16 +279,14 @@ let exec_building_directly ~common ~config ~context ~prog ~args ~no_rebuild =
266279 build_exn (fun () ->
267280 let open Memo.O in
268281 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
282+ let * env = Super_context. context_env sctx
283+ and * prog =
284+ let * prog = Cmd_arg. expand ~root: (Common. root common) ~sctx prog in
285+ get_path_and_build_if_necessary common context ~no_rebuild ~prog
286+ >> | Path. to_string
287+ and * args =
288+ Memo. parallel_map ~f: (Cmd_arg. expand ~root: (Common. root common) ~sctx ) args
289+ in
279290 restore_cwd_and_execve (Common. root common) prog args env)
280291;;
281292
0 commit comments