Skip to content

Commit c9a837d

Browse files
authored
refactor(ppx): reuse preprocessing context (#16308)
Reuse one build context across preprocessing setup and generated PPX commands. Signed-off-by: Antonio Nuno Monteiro <anmonteiro@gmail.com>
1 parent 3fbadfe commit c9a837d

1 file changed

Lines changed: 9 additions & 8 deletions

File tree

src/dune_rules/pp_spec_rules.ml

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,7 @@ let lint_module sctx ~sandbox ~pps_sandbox ~dir ~expander ~lint ~lib_name ~scope
219219

220220
let pp_one_module
221221
sctx
222+
~context
222223
~lib_name
223224
~scope
224225
~preprocessor_deps
@@ -230,6 +231,7 @@ let pp_one_module
230231
(pp : _ Preprocess.Without_future_syntax.t)
231232
=
232233
let open Action_builder.O in
234+
let command_dir = Context.build_dir context |> Path.build in
233235
match pp with
234236
| No_preprocessing ->
235237
Staged.stage
@@ -271,7 +273,7 @@ let pp_one_module
271273
"ppx command"
272274
(let* exe, driver, flags =
273275
Ppx_driver.ppx_driver_and_flags
274-
(Super_context.context sctx)
276+
context
275277
~expander
276278
~loc
277279
~scope
@@ -286,7 +288,7 @@ let pp_one_module
286288
~standard:(Action_builder.return [ "--as-ppx" ])
287289
and* () = preprocessor_deps in
288290
Command.expand_no_targets
289-
~dir:(Super_context.context sctx |> Context.build_dir |> Path.build)
291+
~dir:command_dir
290292
(S [ Dep (Path.build exe); As driver_flags; As flags ])
291293
>>| Appendable_list.to_list)
292294
in
@@ -319,7 +321,7 @@ let pp_one_module
319321
(let* () = Action_builder.return () in
320322
let* exe, driver, flags =
321323
Ppx_driver.ppx_driver_and_flags
322-
(Super_context.context sctx)
324+
context
323325
~expander
324326
~loc
325327
~lib_name
@@ -364,11 +366,8 @@ let pp_one_module
364366
(let open Action_builder.O in
365367
preprocessor_deps
366368
>>> let* exe, flags, args = driver_and_flags in
367-
let dir =
368-
Super_context.context sctx |> Context.build_dir |> Path.build
369-
in
370369
Command.run'
371-
~dir
370+
~dir:command_dir
372371
~sandbox
373372
~env
374373
(Ok (Path.build exe))
@@ -395,7 +394,8 @@ let make
395394
~scope
396395
=
397396
let preprocessor_deps = preprocessor_deps @ instrumentation_deps in
398-
let+ ocaml = Context.ocaml (Super_context.context sctx) in
397+
let context = Super_context.context sctx in
398+
let+ ocaml = Context.ocaml context in
399399
let preprocess =
400400
Module_name.Per_item.map preprocess ~f:(fun pp ->
401401
Preprocess.remove_future_syntax ~for_:Compiler pp ocaml.version)
@@ -435,6 +435,7 @@ let make
435435
Staged.unstage
436436
@@ pp_one_module
437437
sctx
438+
~context
438439
~lib_name
439440
~scope
440441
~preprocessor_deps

0 commit comments

Comments
 (0)