rsconstruct 0.3.12

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
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
/// Macro to generate `ProductDiscovery` trait implementations for checker processors.
///
/// Eliminates boilerplate for `description()`, `auto_detect()`, `required_tools()`,
/// `discover()`, `execute()`, `config_json()`, 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`
/// - `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,
     batch: [$($batch:ident)?],
     execute: $execute:ident,
    ) => {
        impl $crate::processors::ProductDiscovery for $processor {
            fn description(&self) -> &str {
                $desc
            }

            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, $config_field, [$($batch)?]);
        }
    };

    // --- auto_detect ---
    (@auto_detect $self:ident, $fi:ident, $cfg:ident, [scan_root]) => {
        $crate::processors::scan_root_valid(&$self.$cfg.scan) && !$fi.scan(&$self.$cfg.scan, true).is_empty()
    };
    (@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 ---
    // Shared body: build extra_inputs and call discover_checker_products
    (@discover_body $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,
        )
    }};
    // With scan_root guard (built-in)
    (@discover $self:ident, $graph:ident, $fi:ident, $cfg:ident, $name:expr, [scan_root]) => {{
        if !$crate::processors::scan_root_valid(&$self.$cfg.scan) {
            return Ok(());
        }
        impl_checker!(@discover_body $self, $graph, $fi, $cfg, $name)
    }};
    // With custom guard method
    (@discover $self:ident, $graph:ident, $fi:ident, $cfg:ident, $name:expr, [$guard:ident]) => {{
        if !$self.$guard() {
            return Ok(());
        }
        impl_checker!(@discover_body $self, $graph, $fi, $cfg, $name)
    }};
    // No guard
    (@discover $self:ident, $graph:ident, $fi:ident, $cfg:ident, $name:expr, []) => {{
        impl_checker!(@discover_body $self, $graph, $fi, $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, $cfg:ident, [$batch:ident]) => {
        fn supports_batch(&self) -> bool { self.$cfg.batch }

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

            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,

     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,

            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,

     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,

            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,

     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,

            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,

     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,

            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,

     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,

            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,

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

            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,

     batch: [$($batch:ident)?],
     ;
    ) => {
        impl_checker!(@build $processor, $config_field, $desc, $name,
            guard: [$($guard)?],
            tools_kind: $tk,
            config_json: $cj,

            batch: [$($batch)?],
            execute: $execute,
        );
    };
}

/// Generate a complete trivial checker processor from just its parameters.
///
/// This eliminates boilerplate for the ~20 checkers that only call `run_checker()`.
/// Each trivial checker file becomes a single macro invocation instead of ~35 lines.
///
/// # Parameters
/// - `$processor:ident` — processor struct name
/// - `$config:ty` — config struct type
/// - `$desc:expr` — description string
/// - `$name:expr` — processor name constant
///
/// # Tool specification (one required)
/// - `tool_field: $field:ident` — tool name from config field (e.g. `linter`)
/// - `tool_field_extra: $field:ident [$($extra:expr),+]` — config field + extra tools
/// - `tools: [$($tool:expr),+]` — static tool name expressions
///
/// # Optional
/// - `subcommand: $sub:expr` — subcommand string (e.g. "check")
/// - `prepend_args: [$($arg:expr),+]` — args prepended before config args
macro_rules! simple_checker {
    // Internal: generate struct + methods + impl_checker
    (@gen $processor:ident, $config:ty, $desc:expr, $name:expr,
     subcommand: [$($sub:expr)?],
     prepend_args: [$($pa:expr),*],
     tool_kind: $tool_kind:tt,
    ) => {
        pub struct $processor {
            config: $config,
        }

        impl $processor {
            pub fn new(config: $config) -> Self {
                Self { config }
            }

            fn execute_product(&self, product: &$crate::graph::Product) -> anyhow::Result<()> {
                self.check_files(&[product.primary_input()])
            }

            fn check_files(&self, files: &[&std::path::Path]) -> anyhow::Result<()> {
                simple_checker!(@run_checker self, files, [$($sub)?], [$($pa),*], $tool_kind)
            }
        }

        simple_checker!(@impl_checker $processor, $desc, $name, $tool_kind);
    };

    // --- run_checker dispatch ---
    // Tool from config field
    (@run_checker $self:ident, $files:ident, [$($sub:expr)?], [$($pa:expr),*], [field: $field:ident]) => {{
        simple_checker!(@do_run_checker &$self.config.$field, [$($sub)?], &$self.config.args, $files, [$($pa),*])
    }};
    // Tool from config field with extra tools (extra tools only affect required_tools, not the command)
    (@run_checker $self:ident, $files:ident, [$($sub:expr)?], [$($pa:expr),*], [field_extra: $field:ident, [$($extra:expr),+]]) => {{
        simple_checker!(@do_run_checker &$self.config.$field, [$($sub)?], &$self.config.args, $files, [$($pa),*])
    }};
    // Static tool name (first tool expression is the command)
    (@run_checker $self:ident, $files:ident, [$($sub:expr)?], [$($pa:expr),*], [static_tool: $tool:expr $(, $extra:expr)*]) => {{
        let tool_name = $tool;
        simple_checker!(@do_run_checker &tool_name, [$($sub)?], &$self.config.args, $files, [$($pa),*])
    }};

    // --- do_run_checker: handle subcommand and prepend_args ---
    (@do_run_checker $tool:expr, [], $args:expr, $files:ident, []) => {
        $crate::processors::run_checker($tool, None, $args, $files)
    };
    (@do_run_checker $tool:expr, [$sub:expr], $args:expr, $files:ident, []) => {
        $crate::processors::run_checker($tool, Some($sub), $args, $files)
    };
    (@do_run_checker $tool:expr, [], $args:expr, $files:ident, [$($pa:expr),+]) => {{
        let mut combined_args: Vec<String> = vec![$($pa.to_string()),+];
        combined_args.extend_from_slice($args);
        $crate::processors::run_checker($tool, None, &combined_args, $files)
    }};
    (@do_run_checker $tool:expr, [$sub:expr], $args:expr, $files:ident, [$($pa:expr),+]) => {{
        let mut combined_args: Vec<String> = vec![$($pa.to_string()),+];
        combined_args.extend_from_slice($args);
        $crate::processors::run_checker($tool, Some($sub), &combined_args, $files)
    }};

    // --- impl_checker dispatch ---
    (@impl_checker $processor:ident, $desc:expr, $name:expr, [field: $field:ident]) => {
        impl_checker!($processor,
            config: config,
            description: $desc,
            name: $name,
            execute: execute_product,
            tool_field: $field,
            config_json: true,
            batch: check_files,
        );
    };
    (@impl_checker $processor:ident, $desc:expr, $name:expr, [field_extra: $field:ident, [$($extra:expr),+]]) => {
        impl_checker!($processor,
            config: config,
            description: $desc,
            name: $name,
            execute: execute_product,
            tool_field_extra: $field [$($extra),+],
            config_json: true,
            batch: check_files,
        );
    };
    (@impl_checker $processor:ident, $desc:expr, $name:expr, [static_tool: $($tool:expr),+]) => {
        impl_checker!($processor,
            config: config,
            description: $desc,
            name: $name,
            execute: execute_product,
            tools: [$($tool),+],
            config_json: true,
            batch: check_files,
        );
    };

    // --- Public entry points ---

    // tool_field variant (no subcommand, no prepend_args)
    ($processor:ident, $config:ty, $desc:expr, $name:expr,
     tool_field: $field:ident $(,)?
    ) => {
        simple_checker!(@gen $processor, $config, $desc, $name,
            subcommand: [], prepend_args: [], tool_kind: [field: $field],);
    };
    // tool_field with subcommand
    ($processor:ident, $config:ty, $desc:expr, $name:expr,
     tool_field: $field:ident, subcommand: $sub:expr $(,)?
    ) => {
        simple_checker!(@gen $processor, $config, $desc, $name,
            subcommand: [$sub], prepend_args: [], tool_kind: [field: $field],);
    };
    // tool_field with subcommand + prepend_args
    ($processor:ident, $config:ty, $desc:expr, $name:expr,
     tool_field: $field:ident, subcommand: $sub:expr, prepend_args: [$($pa:expr),+ $(,)?] $(,)?
    ) => {
        simple_checker!(@gen $processor, $config, $desc, $name,
            subcommand: [$sub], prepend_args: [$($pa),+], tool_kind: [field: $field],);
    };
    // tool_field with prepend_args (no subcommand)
    ($processor:ident, $config:ty, $desc:expr, $name:expr,
     tool_field: $field:ident, prepend_args: [$($pa:expr),+ $(,)?] $(,)?
    ) => {
        simple_checker!(@gen $processor, $config, $desc, $name,
            subcommand: [], prepend_args: [$($pa),+], tool_kind: [field: $field],);
    };
    // tool_field_extra variant
    ($processor:ident, $config:ty, $desc:expr, $name:expr,
     tool_field_extra: $field:ident [$($extra:expr),+] $(,)?
    ) => {
        simple_checker!(@gen $processor, $config, $desc, $name,
            subcommand: [], prepend_args: [], tool_kind: [field_extra: $field, [$($extra),+]],);
    };
    // tools variant (no subcommand)
    ($processor:ident, $config:ty, $desc:expr, $name:expr,
     tools: [$($tool:expr),+] $(,)?
    ) => {
        simple_checker!(@gen $processor, $config, $desc, $name,
            subcommand: [], prepend_args: [], tool_kind: [static_tool: $($tool),+],);
    };
    // tools with subcommand
    ($processor:ident, $config:ty, $desc:expr, $name:expr,
     tools: [$($tool:expr),+], subcommand: $sub:expr $(,)?
    ) => {
        simple_checker!(@gen $processor, $config, $desc, $name,
            subcommand: [$sub], prepend_args: [], tool_kind: [static_tool: $($tool),+],);
    };
    // tools with prepend_args (no subcommand)
    ($processor:ident, $config:ty, $desc:expr, $name:expr,
     tools: [$($tool:expr),+], prepend_args: [$($pa:expr),+ $(,)?] $(,)?
    ) => {
        simple_checker!(@gen $processor, $config, $desc, $name,
            subcommand: [], prepend_args: [$($pa),+], tool_kind: [static_tool: $($tool),+],);
    };
}

mod aspell;
mod ascii;
mod black;
mod checkpatch;
mod clippy;
mod clang_tidy;
mod cppcheck;
mod cpplint;
mod doctest;

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


mod pylint;
mod pytest;
mod pyrefly;
mod ruff;
mod rumdl;
mod script;
mod shellcheck;
mod zspell;
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 slidev;
pub(crate) mod terms;

pub use aspell::AspellProcessor;
pub use ascii::AsciiProcessor;
pub use black::BlackProcessor;
pub use checkpatch::CheckpatchProcessor;
pub use clippy::ClippyProcessor;
pub use clang_tidy::ClangTidyProcessor;
pub use cppcheck::CppcheckProcessor;
pub use cpplint::CpplintProcessor;
pub use doctest::DoctestProcessor;

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


pub use pylint::PylintProcessor;
pub use pytest::PytestProcessor;
pub use pyrefly::PyreflyProcessor;
pub use ruff::RuffProcessor;
pub use rumdl::RumdlProcessor;
pub use script::ScriptProcessor;
pub use shellcheck::ShellcheckProcessor;
pub use zspell::ZspellProcessor;
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 slidev::SlidevProcessor;
pub use terms::TermsProcessor;