@@ -37,11 +37,6 @@ let cmt_rule =
3737 )
3838 | }
3939
40- let cstubs_alias_rule =
41- (* for BEAR *)
42- Sexplib.Sexp. of_string
43- {| (rule (alias cstubs) (deps (:ofiles)) (action (echo " for BEAR" ))) | }
44-
4540(* can be long running, ensure we see something when running dune with '--no-buffer',
4641 add a 2nd debug target
4742
@@ -72,6 +67,39 @@ let analyze_alias_rule =
7267 )
7368 | }
7469
70+ let incgen_rule =
71+ Sexplib.Sexp. of_string_many
72+ {|
73+ (rule
74+ (enabled_if (and % {bin- available :lintcstubs- dune- rules} % {bin- available :lintcstubs}))
75+ (deps
76+ (:mlfiles
77+ (glob_files_rec *. ml))
78+ (:cfiles
79+ (glob_files_rec *. c)))
80+ (action
81+ (with - stdout- to
82+ dune.analysis.inc.gen
83+ (run % {bin :lintcstubs- dune- rules} % {mlfiles} % {cfiles}))))
84+
85+ (rule
86+ (alias runtest)
87+ (package lintcstubs)
88+ (enabled_if % {bin- available :lintcstubs})
89+ (action
90+ (diff dune.analysis.inc dune.analysis.inc.gen)))
91+
92+ (rule
93+ (target compile_commands.json)
94+ (action
95+ (pipe- stdout
96+ (run dune rules)
97+ (run % {bin :dune- compiledb})
98+ )
99+ )
100+ )
101+ | }
102+
75103let group_by_dirs paths =
76104 Seq. fold_left
77105 (fun acc path ->
@@ -101,17 +129,15 @@ let () =
101129 f x |> Result. get_ok
102130 in
103131 let files_seq = List. to_seq files in
104- let o_files =
105- files_seq
106- |> Seq. filter Fpath. (has_ext " c" )
107- |> Seq. map (Fpath. set_ext " o" )
108- |> group_by_dirs
109- in
110132 let ml_files_primitives =
111133 files_seq
112134 |> Seq. filter Fpath. (has_ext " ml" )
113135 |> Seq. filter (filter Filter_primitives. has_primitives)
114136 in
137+ Format. printf " @[<h>; AUTO-GENERATED by %a@]@,; DO NOT EDIT@."
138+ (Format. pp_print_list ~pp_sep: Format. pp_print_space Format. pp_print_string)
139+ (Array. to_list Sys. argv) ;
140+ List. iter (Format. printf " %a@." Sexplib.Sexp. pp_hum) incgen_rule ;
115141 group_by_dirs ml_files_primitives
116142 |> Fpath.Map. iter @@ fun dir mls ->
117143 let to_cmtfile mlfile =
@@ -135,14 +161,6 @@ let () =
135161 |> apply_template' " %{model}" model_file
136162 )
137163 in
138- let o_files_in_dir =
139- Fpath.Map. find dir o_files |> Option. value ~default: Fpath.Set. empty
140- in
141- let cstubs_alias_rules =
142- cstubs_alias_rule
143- |> apply_template " :ofiles"
144- (Fpath.Set. to_seq o_files_in_dir |> List. of_seq)
145- in
146164 let log_file = Fpath. (dir / " lintcstubs.log" ) in
147165 let sarif_file = Fpath. set_ext " .sarif" log_file in
148166 let analyze_rule =
@@ -158,7 +176,5 @@ let () =
158176 cmt_rules
159177 |> List. iter @@ fun cmt_rule ->
160178 Format. printf " %a@." Sexplib.Sexp. pp_hum cmt_rule ;
161- if not (Fpath.Set. is_empty o_files_in_dir) then
162- Format. printf " %a@." Sexplib.Sexp. pp_hum cstubs_alias_rules ;
163179 Format. printf " %a@." Sexplib.Sexp. pp_hum analyze_rule ;
164180 Format. printf " %a@." Sexplib.Sexp. pp_hum analyze_alias_rule
0 commit comments