Oregami
Repositories/oxedyne/fe2o3

oxedyne/fe2o3/fe2o3_jdat/src/bin/lint_mutable.rs

2.1 KiB, 1 run

created by r1870400018:75195, which is this file's identity for as long as the history lasts, whatever it is later renamed to

download · who wrote it · its history

1//! `lint_mutable --root <dir> [--baseline <file>] [--write]`: the mutable-literal gate for any
2//! tree. Exits non-zero when the tree has a literal beyond its baseline, a stale baseline entry, a
3//! thin `// fixed:` marker or an allow entry without a why. `--write` regenerates the baseline from
4//! the tree, keeping its allow list.
5
6use oxedyne_fe2o3_core::prelude::*;
7use oxedyne_fe2o3_jdat::lint;
8use oxedyne_fe2o3_text::lint::mutable;
9
10use std::path::PathBuf;
11
12
13// fixed: the bootstrap name of the baseline at a tree root, overridden by --baseline.
14const BASELINE_NAME: &str = "mutable_literals.jdat";
15
16fn main() {
17 match run() {
18 Ok(true) => {}
19 Ok(false) => std::process::exit(1),
20 Err(e) => {
21 eprintln!("{}", e);
22 std::process::exit(2);
23 }
24 }
25}
26
27fn run() -> Outcome<bool> {
28 let mut root: Option<PathBuf> = None;
29 let mut base_path: Option<PathBuf> = None;
30 let mut write = false;
31 let mut args = std::env::args().skip(1);
32 while let Some(a) = args.next() {
33 match a.as_str() {
34 "--root" => root = args.next().map(PathBuf::from),
35 "--baseline" => base_path = args.next().map(PathBuf::from),
36 "--write" => write = true,
37 _ => return Err(err!(
38 "Unknown argument '{}'; usage: lint_mutable --root <dir> [--baseline <file>] \
39 [--write].", a; Invalid, Input)),
40 }
41 }
42 let root = res!(root.ok_or_else(|| err!("Missing --root <dir>."; Missing, Input)));
43 let base_path = base_path.unwrap_or_else(|| root.join(BASELINE_NAME));
44 let base = res!(lint::load_baseline(&base_path));
45 if write {
46 let (scan, files) = res!(mutable::scan_tree(&root));
47 let next = base.regenerate(&scan.hits);
48 res!(lint::save_baseline(&next, &base_path));
49 println!("Wrote {} entries ({} hits, {} files) to {}.",
50 next.entries.len(), scan.hits.len(), files, base_path.display());
51 return Ok(true);
52 }
53 let rep = res!(mutable::check_tree(&root, &base));
54 println!("{}", rep);
55 Ok(rep.is_clean())
56}