@@ -111,19 +111,26 @@ let build_prog ~no_rebuild ~prog p =
111
111
p
112
112
;;
113
113
114
- let get_path_and_build_if_necessary sctx ~no_rebuild ~dir ~prog =
114
+ let expand ~sctx common cmd_arg = Cmd_arg. expand ~root: (Common. root common) ~sctx cmd_arg
115
+
116
+ let get_path common ctx_name ~prog =
115
117
let open Memo.O in
118
+ let * sctx = Super_context. find_exn ctx_name in
119
+ let dir =
120
+ let context = Dune_rules.Super_context. context sctx in
121
+ Path.Build. relative (Context. build_dir context) (Common. prefix_target common " " )
122
+ in
116
123
match Filename. analyze_program_name prog with
117
124
| In_path ->
118
125
Super_context. resolve_program_memo sctx ~dir ~loc: None prog
119
126
>> = (function
120
127
| Error (_ : Action.Prog.Not_found.t ) -> not_found ~dir ~prog
121
- | Ok p -> build_prog ~no_rebuild ~prog p)
128
+ | Ok p -> Memo. return p)
122
129
| Relative_to_current_dir ->
123
130
let path = Path. relative_to_source_in_build_or_external ~dir prog in
124
131
Build_system. file_exists path
125
132
>> = (function
126
- | true -> build_prog ~no_rebuild ~prog path
133
+ | true -> Memo. return path
127
134
| false -> not_found ~dir ~prog )
128
135
| Absolute ->
129
136
(match
@@ -140,19 +147,22 @@ let get_path_and_build_if_necessary sctx ~no_rebuild ~dir ~prog =
140
147
| None -> not_found ~dir ~prog )
141
148
;;
142
149
143
- let step ~ setup ~ prog ~ args ~ common ~ no_rebuild ~context ~ on_exit () =
150
+ let get_path_and_build_if_necessary common ctx_name ~ no_rebuild ~prog =
144
151
let open Memo.O in
145
- let * sctx = setup >> | Import.Main. find_scontext_exn ~name: context in
146
- let * env = Super_context. context_env sctx in
147
- let expand = Cmd_arg. expand ~root: (Common. root common) ~sctx in
152
+ let * path = get_path common ctx_name ~prog in
153
+ match Filename. analyze_program_name prog with
154
+ | In_path | Relative_to_current_dir -> build_prog ~no_rebuild ~prog path
155
+ | Absolute -> Memo. return path
156
+ ;;
157
+
158
+ let step ~prog ~args ~common ~no_rebuild ~ctx_name ~on_exit () =
159
+ let open Memo.O in
160
+ let * sctx = Super_context. find_exn ctx_name in
148
161
let * path =
149
- let dir =
150
- let context = Dune_rules.Super_context. context sctx in
151
- Path.Build. relative (Context. build_dir context) (Common. prefix_target common " " )
152
- in
153
- let * prog = expand prog in
154
- get_path_and_build_if_necessary sctx ~no_rebuild ~dir ~prog
155
- and * args = Memo. parallel_map args ~f: expand in
162
+ let * prog = expand ~sctx common prog in
163
+ get_path_and_build_if_necessary common ctx_name ~no_rebuild ~prog
164
+ and * args = Memo. parallel_map args ~f: (expand ~sctx common) in
165
+ let * env = Super_context. context_env sctx in
156
166
Memo. of_non_reproducible_fiber
157
167
@@ Dune_engine.Process. run_inherit_std_in_out
158
168
~dir: (Path. of_string Fpath. initial_cwd)
@@ -166,7 +176,7 @@ let step ~setup ~prog ~args ~common ~no_rebuild ~context ~on_exit () =
166
176
167
177
let term : unit Term.t =
168
178
let + builder = Common.Builder. term
169
- and + context = Common. context_arg ~doc: {| Run the command in this build context.| }
179
+ and + ctx_name = Common. context_arg ~doc: {| Run the command in this build context.| }
170
180
and + prog = Arg. (required & pos 0 (some Cmd_arg. conv) None (Arg. info [] ~docv: " PROG" ))
171
181
and + no_rebuild =
172
182
Arg. (value & flag & info [ " no-build" ] ~doc: " don't rebuild target before executing" )
@@ -182,30 +192,25 @@ let term : unit Term.t =
182
192
Scheduler. go_with_rpc_server_and_console_status_reporting ~common ~config
183
193
@@ fun () ->
184
194
let open Fiber.O in
185
- let * setup = Import.Main. setup () in
186
195
let on_exit = Console. printf " Program exited with code [%d]" in
187
196
Scheduler.Run. poll
188
197
@@
189
198
let * () = Fiber. return @@ Scheduler. maybe_clear_screen ~details_hum: [] config in
190
- build @@ step ~setup ~ prog ~args ~common ~no_rebuild ~context ~on_exit
199
+ build @@ step ~prog ~args ~common ~no_rebuild ~ctx_name ~on_exit
191
200
| No ->
192
201
Scheduler. go_with_rpc_server ~common ~config
193
202
@@ fun () ->
194
203
let open Fiber.O in
195
204
let * setup = Import.Main. setup () in
196
205
build_exn (fun () ->
197
206
let open Memo.O in
198
- let * sctx = setup >> | Import.Main. find_scontext_exn ~name: context in
199
- let * env = Super_context. context_env sctx in
200
- let expand = Cmd_arg. expand ~root: (Common. root common) ~sctx in
201
- let * prog =
202
- let dir =
203
- let context = Dune_rules.Super_context. context sctx in
204
- Path.Build. relative (Context. build_dir context) (Common. prefix_target common " " )
205
- in
206
- let * prog = expand prog in
207
- get_path_and_build_if_necessary sctx ~no_rebuild ~dir ~prog >> | Path. to_string
208
- and * args = Memo. parallel_map ~f: expand args in
207
+ let * sctx = setup >> | Import.Main. find_scontext_exn ~name: ctx_name in
208
+ let * env = Super_context. context_env sctx
209
+ and * prog =
210
+ let * prog = expand ~sctx common prog in
211
+ get_path_and_build_if_necessary common ctx_name ~no_rebuild ~prog
212
+ >> | Path. to_string
213
+ and * args = Memo. parallel_map ~f: (expand ~sctx common) args in
209
214
restore_cwd_and_execve (Common. root common) prog args env)
210
215
;;
211
216
0 commit comments