File tree 7 files changed +52
-8
lines changed
test/blackbox-tests/test-cases/github4682.t
7 files changed +52
-8
lines changed Original file line number Diff line number Diff line change @@ -154,6 +154,9 @@ Unreleased
154
154
- Fix ` root_module ` when used in public libraries (#4685 , fixes #4684 ,
155
155
@rgrinberg , @CraigFe )
156
156
157
+ - Fix ` root_module ` when used with preprocessing (#4683 , fixes #4682 ,
158
+ @rgrinberg , @CraigFe )
159
+
157
160
2.9.0 (unreleased)
158
161
------------------
159
162
Original file line number Diff line number Diff line change @@ -46,7 +46,7 @@ module Modules = struct
46
46
let rev_map =
47
47
let rev_modules =
48
48
let by_name buildable =
49
- Modules. fold_user_written ~init: [] ~f: (fun m acc ->
49
+ Modules. fold_user_available ~init: [] ~f: (fun m acc ->
50
50
(Module. name m, buildable) :: acc)
51
51
in
52
52
List. rev_append
@@ -104,7 +104,7 @@ module Artifacts = struct
104
104
in
105
105
let modules =
106
106
let by_name modules obj_dir =
107
- Modules_group. fold_user_written ~init: modules ~f: (fun m modules ->
107
+ Modules_group. fold_user_available ~init: modules ~f: (fun m modules ->
108
108
Module_name.Map. add_exn modules (Module. name m) (obj_dir, m))
109
109
in
110
110
let init =
Original file line number Diff line number Diff line change @@ -656,7 +656,34 @@ let wrapped_compat = function
656
656
Module_name.Map. empty
657
657
| Wrapped w -> w.wrapped_compat
658
658
659
+ let rec fold_user_available t ~f ~init =
660
+ match t with
661
+ | Stdlib w -> Stdlib. fold w ~init ~f
662
+ | Singleton m -> f m init
663
+ | Wrapped { modules; _ }
664
+ | Unwrapped modules ->
665
+ Module_name.Map. fold modules ~init ~f
666
+ | Impl { impl; vlib = _ } ->
667
+ (* XXX shouldn't we folding over [vlib] as well? *)
668
+ fold_user_available impl ~f ~init
669
+
670
+ let is_user_written m =
671
+ match Module. kind m with
672
+ | Root -> false
673
+ | Wrapped_compat
674
+ | Alias ->
675
+ (* Logically, this shold be [acc]. But this is unreachable these are stored
676
+ separately *)
677
+ assert false
678
+ | _ -> true
679
+
659
680
let rec fold_user_written t ~f ~init =
681
+ let f m acc =
682
+ if is_user_written m then
683
+ f m acc
684
+ else
685
+ acc
686
+ in
660
687
match t with
661
688
| Stdlib w -> Stdlib. fold w ~init ~f
662
689
| Singleton m -> f m init
@@ -666,6 +693,12 @@ let rec fold_user_written t ~f ~init =
666
693
| Impl { impl; vlib = _ } -> fold_user_written impl ~f ~init
667
694
668
695
let rec map_user_written t ~f =
696
+ let f m =
697
+ if is_user_written m then
698
+ f m
699
+ else
700
+ Memo.Build. return m
701
+ in
669
702
let open Memo.Build.O in
670
703
match t with
671
704
| Singleton m ->
Original file line number Diff line number Diff line change @@ -55,6 +55,8 @@ val fold_user_written : t -> f:(Module.t -> 'acc -> 'acc) -> init:'acc -> 'acc
55
55
val map_user_written :
56
56
t -> f :(Module .t -> Module .t Memo.Build .t ) -> t Memo.Build .t
57
57
58
+ val fold_user_available : t -> f :(Module .t -> 'acc -> 'acc ) -> init :'acc -> 'acc
59
+
58
60
(* * Returns all the compatibility modules. *)
59
61
val wrapped_compat : t -> Module.Name_map .t
60
62
Original file line number Diff line number Diff line change 1
1
(library
2
2
(name ppx)
3
3
(kind ppx_rewriter)
4
- (libraries lib)
5
4
(ppx.driver (main Ppx.main)))
Original file line number Diff line number Diff line change 1
- let main () = ()
1
+ let main () =
2
+ let out = ref " " in
3
+ let args =
4
+ [ (" -o" , Arg. Set_string out, " " )
5
+ ; (" --impl" , Arg. Set_string (ref " " ), " " )
6
+ ; (" --as-ppx" , Arg. Set (ref false ), " " )
7
+ ]
8
+ in
9
+ let anon _ = () in
10
+ Arg. parse (Arg. align args) anon " " ;
11
+ let out = open_out ! out in
12
+ close_out out;
Original file line number Diff line number Diff line change @@ -2,7 +2,3 @@ Attempting to use `(root_module ...)` with an executable that uses PPX results
2
2
in an unexpected build failure:
3
3
4
4
$ dune build
5
- Error: Multiple rules generated for _build/ default / root. pp. ml-gen:
6
- - dune: 5
7
- - <none >: 1
8
- [1 ]
You can’t perform that action at this time.
0 commit comments