rsconstruct 0.2.10

Rust based fast build system
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
/// Macro to generate `ProductDiscovery` trait implementations for checker processors.
///
/// Eliminates boilerplate for `description()`, `auto_detect()`, `required_tools()`,
/// `discover()`, `execute()`, `config_json()`, `hidden()`, and batch support.
///
/// # Required parameters
/// - `$processor:ty` — the processor struct type
/// - `config: $config_field:ident` — name of the config field on the struct
/// - `description: $desc:expr` — human-readable description string
/// - `name: $name:expr` — processor name passed to `discover_checker_products()`
/// - `execute: $execute:ident` — method on self for single-product execution
///
/// # Optional parameters (in any order after required ones)
/// - `guard: $guard_method:ident` — method on self returning bool; gates `auto_detect()` and `discover()`
/// - `tools: [$($tool:expr),+]` — string literal expressions for `required_tools()`
/// - `tool_field: $field:ident` — config sub-field to clone as a tool name
/// - `tool_field_extra: $field:ident [$($extra:expr),+]` — config field plus extra static tools
/// - `config_json: true` — emit `config_json()` using `serde_json::to_string`
/// - `hidden: true` — `hidden()` returns true
/// - `batch: $batch_method:ident` — method on self for batch execution
macro_rules! impl_checker {
    // --- @build: generate the impl block ---
    (@build $processor:ty, $config_field:ident, $desc:expr, $name:expr,
     guard: [$($guard:ident)?],
     tools_kind: $tools_kind:tt,
     config_json: $cj:tt,
     hidden: $hid:tt,
     batch: [$($batch:ident)?],
     execute: $execute:ident,
    ) => {
        impl $crate::processors::ProductDiscovery for $processor {
            fn description(&self) -> &str {
                $desc
            }

            impl_checker!(@hidden $hid);

            fn auto_detect(&self, file_index: &$crate::file_index::FileIndex) -> bool {
                impl_checker!(@auto_detect self, file_index, $config_field, [$($guard)?])
            }

            fn required_tools(&self) -> Vec<String> {
                impl_checker!(@tools self, $config_field, $tools_kind)
            }

            fn discover(
                &self,
                graph: &mut $crate::graph::BuildGraph,
                file_index: &$crate::file_index::FileIndex,
            ) -> anyhow::Result<()> {
                impl_checker!(@discover self, graph, file_index, $config_field, $name, [$($guard)?])
            }

            fn execute(&self, product: &$crate::graph::Product) -> anyhow::Result<()> {
                self.$execute(product)
            }

            impl_checker!(@config_json self, $config_field, $cj);

            impl_checker!(@batch self, [$($batch)?]);
        }
    };

    // --- hidden ---
    (@hidden true) => {
        fn hidden(&self) -> bool { true }
    };
    (@hidden false) => {};

    // --- auto_detect ---
    (@auto_detect $self:ident, $fi:ident, $cfg:ident, [$guard:ident]) => {
        $self.$guard() && !$fi.scan(&$self.$cfg.scan, true).is_empty()
    };
    (@auto_detect $self:ident, $fi:ident, $cfg:ident, []) => {
        !$fi.scan(&$self.$cfg.scan, true).is_empty()
    };

    // --- tools ---
    // No tools
    (@tools $self:ident, $cfg:ident, [none]) => {
        Vec::new()
    };
    // Static tool names (expressions that may reference $self.$cfg)
    (@tools $self:ident, $cfg:ident, [literal: $($tool:expr),+]) => {
        vec![$($tool),+]
    };
    // Dynamic tool name from a config field
    (@tools $self:ident, $cfg:ident, [field: $tool_field:ident]) => {
        vec![$self.$cfg.$tool_field.clone()]
    };
    // Dynamic tool name from a config field plus extra static tools
    (@tools $self:ident, $cfg:ident, [field_and_extra: $tool_field:ident, [$($extra:expr),+]]) => {
        vec![$self.$cfg.$tool_field.clone(), $($extra),+]
    };

    // --- discover ---
    // With guard
    (@discover $self:ident, $graph:ident, $fi:ident, $cfg:ident, $name:expr, [$guard:ident]) => {{
        if !$self.$guard() {
            return Ok(());
        }
        let mut extra_inputs = $self.$cfg.extra_inputs.clone();
        for ai in &$self.$cfg.auto_inputs {
            extra_inputs.extend($crate::processors::config_file_inputs(ai));
        }
        $crate::processors::discover_checker_products(
            $graph, &$self.$cfg.scan, $fi, &extra_inputs, &$self.$cfg, $name,
        )
    }};
    // No guard
    (@discover $self:ident, $graph:ident, $fi:ident, $cfg:ident, $name:expr, []) => {{
        let mut extra_inputs = $self.$cfg.extra_inputs.clone();
        for ai in &$self.$cfg.auto_inputs {
            extra_inputs.extend($crate::processors::config_file_inputs(ai));
        }
        $crate::processors::discover_checker_products(
            $graph, &$self.$cfg.scan, $fi, &extra_inputs, &$self.$cfg, $name,
        )
    }};

    // --- config_json ---
    (@config_json $self:ident, $cfg:ident, true) => {
        fn config_json(&self) -> Option<String> {
            serde_json::to_string(&self.$cfg).ok()
        }
    };
    (@config_json $self:ident, $cfg:ident, false) => {};

    // --- batch ---
    (@batch $self:ident, [$batch:ident]) => {
        fn supports_batch(&self) -> bool { true }

        fn execute_batch(&self, products: &[&$crate::graph::Product]) -> Vec<anyhow::Result<()>> {
            $crate::processors::execute_checker_batch(
                products,
                |files| self.$batch(files),
            )
        }
    };
    (@batch $self:ident, []) => {};

    // --- Entry point: parse options using TT muncher ---
    ($processor:ty,
     config: $config_field:ident,
     description: $desc:expr,
     name: $name:expr,
     execute: $execute:ident
     $(, $($rest:tt)*)?
    ) => {
        impl_checker!(@parse $processor, $config_field, $desc, $name, $execute,
            guard: [],
            tools_kind: [none],
            config_json: false,
            hidden: false,
            batch: [],
            ; $($($rest)*)?
        );
    };

    // Parse guard
    (@parse $processor:ty, $config_field:ident, $desc:expr, $name:expr, $execute:ident,
     guard: [],
     tools_kind: $tk:tt,
     config_json: $cj:tt,
     hidden: $hid:tt,
     batch: [$($batch:ident)?],
     ; guard: $guard:ident $(, $($rest:tt)*)?
    ) => {
        impl_checker!(@parse $processor, $config_field, $desc, $name, $execute,
            guard: [$guard],
            tools_kind: $tk,
            config_json: $cj,
            hidden: $hid,
            batch: [$($batch)?],
            ; $($($rest)*)?
        );
    };

    // Parse tools (literal expressions like "cppcheck".to_string())
    (@parse $processor:ty, $config_field:ident, $desc:expr, $name:expr, $execute:ident,
     guard: [$($guard:ident)?],
     tools_kind: [none],
     config_json: $cj:tt,
     hidden: $hid:tt,
     batch: [$($batch:ident)?],
     ; tools: [$($tool:expr),+] $(, $($rest:tt)*)?
    ) => {
        impl_checker!(@parse $processor, $config_field, $desc, $name, $execute,
            guard: [$($guard)?],
            tools_kind: [literal: $($tool),+],
            config_json: $cj,
            hidden: $hid,
            batch: [$($batch)?],
            ; $($($rest)*)?
        );
    };

    // Parse tool_field (field name on config struct, e.g. `linter` → self.config.linter.clone())
    (@parse $processor:ty, $config_field:ident, $desc:expr, $name:expr, $execute:ident,
     guard: [$($guard:ident)?],
     tools_kind: [none],
     config_json: $cj:tt,
     hidden: $hid:tt,
     batch: [$($batch:ident)?],
     ; tool_field: $tool_field:ident $(, $($rest:tt)*)?
    ) => {
        impl_checker!(@parse $processor, $config_field, $desc, $name, $execute,
            guard: [$($guard)?],
            tools_kind: [field: $tool_field],
            config_json: $cj,
            hidden: $hid,
            batch: [$($batch)?],
            ; $($($rest)*)?
        );
    };

    // Parse tool_field_extra (field name + extra static tools, e.g. `tool_field_extra: linter ["python3".to_string()]`)
    (@parse $processor:ty, $config_field:ident, $desc:expr, $name:expr, $execute:ident,
     guard: [$($guard:ident)?],
     tools_kind: [none],
     config_json: $cj:tt,
     hidden: $hid:tt,
     batch: [$($batch:ident)?],
     ; tool_field_extra: $tool_field:ident [$($extra:expr),+] $(, $($rest:tt)*)?
    ) => {
        impl_checker!(@parse $processor, $config_field, $desc, $name, $execute,
            guard: [$($guard)?],
            tools_kind: [field_and_extra: $tool_field, [$($extra),+]],
            config_json: $cj,
            hidden: $hid,
            batch: [$($batch)?],
            ; $($($rest)*)?
        );
    };

    // Parse config_json
    (@parse $processor:ty, $config_field:ident, $desc:expr, $name:expr, $execute:ident,
     guard: [$($guard:ident)?],
     tools_kind: $tk:tt,
     config_json: false,
     hidden: $hid:tt,
     batch: [$($batch:ident)?],
     ; config_json: true $(, $($rest:tt)*)?
    ) => {
        impl_checker!(@parse $processor, $config_field, $desc, $name, $execute,
            guard: [$($guard)?],
            tools_kind: $tk,
            config_json: true,
            hidden: $hid,
            batch: [$($batch)?],
            ; $($($rest)*)?
        );
    };

    // Parse hidden
    (@parse $processor:ty, $config_field:ident, $desc:expr, $name:expr, $execute:ident,
     guard: [$($guard:ident)?],
     tools_kind: $tk:tt,
     config_json: $cj:tt,
     hidden: false,
     batch: [$($batch:ident)?],
     ; hidden: true $(, $($rest:tt)*)?
    ) => {
        impl_checker!(@parse $processor, $config_field, $desc, $name, $execute,
            guard: [$($guard)?],
            tools_kind: $tk,
            config_json: $cj,
            hidden: true,
            batch: [$($batch)?],
            ; $($($rest)*)?
        );
    };

    // Parse batch
    (@parse $processor:ty, $config_field:ident, $desc:expr, $name:expr, $execute:ident,
     guard: [$($guard:ident)?],
     tools_kind: $tk:tt,
     config_json: $cj:tt,
     hidden: $hid:tt,
     batch: [],
     ; batch: $batch_method:ident $(, $($rest:tt)*)?
    ) => {
        impl_checker!(@parse $processor, $config_field, $desc, $name, $execute,
            guard: [$($guard)?],
            tools_kind: $tk,
            config_json: $cj,
            hidden: $hid,
            batch: [$batch_method],
            ; $($($rest)*)?
        );
    };

    // Terminal: no more tokens to parse
    (@parse $processor:ty, $config_field:ident, $desc:expr, $name:expr, $execute:ident,
     guard: [$($guard:ident)?],
     tools_kind: $tk:tt,
     config_json: $cj:tt,
     hidden: $hid:tt,
     batch: [$($batch:ident)?],
     ;
    ) => {
        impl_checker!(@build $processor, $config_field, $desc, $name,
            guard: [$($guard)?],
            tools_kind: $tk,
            config_json: $cj,
            hidden: $hid,
            batch: [$($batch)?],
            execute: $execute,
        );
    };
}

mod aspell;
mod ascii_check;
mod checkpatch;
mod clippy;
mod clang_tidy;
mod cppcheck;
mod cpplint;

mod make;
mod markdownlint;
mod mdl;
mod mypy;


mod pylint;
mod pyrefly;
mod ruff;
mod rumdl;
mod script_check;
mod shellcheck;
mod sleep;
mod spellcheck;
mod yamllint;
mod jsonlint;
mod taplo;
mod jq;
mod json_schema;
mod luacheck;
mod eslint;
mod htmlhint;
mod htmllint;
mod jshint;
mod jslint;
mod standard;
mod stylelint;
mod tidy;
mod php_lint;
mod perlcritic;
mod xmllint;
mod checkstyle;
mod yq;
mod cmake;
mod hadolint;
mod jekyll;
mod slidev;

pub use aspell::AspellProcessor;
pub use ascii_check::AsciiCheckProcessor;
pub use checkpatch::CheckpatchProcessor;
pub use clippy::ClippyProcessor;
pub use clang_tidy::ClangTidyProcessor;
pub use cppcheck::CppcheckProcessor;
pub use cpplint::CpplintProcessor;

pub use make::MakeProcessor;
pub use markdownlint::MarkdownlintProcessor;
pub use mdl::MdlProcessor;
pub use mypy::MypyProcessor;


pub use pylint::PylintProcessor;
pub use pyrefly::PyreflyProcessor;
pub use ruff::RuffProcessor;
pub use rumdl::RumdlProcessor;
pub use script_check::ScriptCheckProcessor;
pub use shellcheck::ShellcheckProcessor;
pub use sleep::SleepProcessor;
pub use spellcheck::SpellcheckProcessor;
pub use yamllint::YamllintProcessor;
pub use jq::JqProcessor;
pub use jsonlint::JsonlintProcessor;
pub use luacheck::LuacheckProcessor;
pub use taplo::TaploProcessor;
pub use json_schema::JsonSchemaProcessor;
pub use eslint::EslintProcessor;
pub use htmlhint::HtmlhintProcessor;
pub use htmllint::HtmllintProcessor;
pub use jshint::JshintProcessor;
pub use jslint::JslintProcessor;
pub use standard::StandardProcessor;
pub use stylelint::StylelintProcessor;
pub use tidy::TidyProcessor;
pub use php_lint::PhpLintProcessor;
pub use perlcritic::PerlcriticProcessor;
pub use xmllint::XmllintProcessor;
pub use checkstyle::CheckstyleProcessor;
pub use yq::YqProcessor;
pub use cmake::CmakeProcessor;
pub use hadolint::HadolintProcessor;
pub use jekyll::JekyllProcessor;
pub use slidev::SlidevProcessor;