build(xtask): scoped lint fits bin-only and lib-only packages; smith-alloc::measure replaces duplicated delta logic
8398eaec934217ff3e69c09ddff224dacdd0a54e
Oliver Jan Krylow <oliver@bugabinga.net> ·
unsigned
- Parent 1: 513dc51f4e6d
There are many coding harnesses - but this one is fast
8398eaec934217ff3e69c09ddff224dacdd0a54e
Oliver Jan Krylow <oliver@bugabinga.net> ·
unsigned
+54 / −24 text lines
+22 / −0 text lines
/// Run `work` charged to `scope` and report what it cost: `allocations`/// and `bytes` are the deltas across the run, `live` and `peak` the scope's/// values right after it.////// Counters are process-wide; concurrent measurements of one scope mix.pub fn measure<T>(scope: Scope, work: impl FnOnce() -> T) -> (T, Stats) { let before = snapshot(scope); let guard = enter(scope); let out = work(); drop(guard); let after = snapshot(scope); ( out, Stats { allocations: after.allocations - before.allocations, bytes: after.bytes - before.bytes, live: after.live, peak: after.peak, }, )}+3 / −13 text lines
use smith_alloc::{Counting, Scope, Stats, enter, snapshot};use smith_alloc::{Counting, Scope, measure};+3 / −10 text lines
+26 / −1 text lines
clippy_phase(&["--lib", "--bins"], &[], extra) clippy_phase(&prod_targets(extra), &[], extra)}/// `--lib` and `--bins` as the scoped package actually has them; cargo/// rejects a target flag the package cannot satisfy.fn prod_targets(extra: &[OsString]) -> Vec<&'static str> { let package = extra .iter() .position(|arg| arg == "-p" || arg == "--package") .and_then(|at| extra.get(at + 1)) .map(|name| name.to_string_lossy().into_owned()); let Some(package) = package else { return vec!["--lib", "--bins"]; }; let src = Path::new(&package).join("src"); let mut targets = Vec::new(); if src.join("lib.rs").is_file() { targets.push("--lib"); } if src.join("main.rs").is_file() || Path::new(&package).join("src/bin").is_dir() { targets.push("--bins"); } if targets.is_empty() { targets = vec!["--lib", "--bins"]; } targets