mirror of
https://github.com/Noratrieb/cargo-minimize.git
synced 2026-01-14 16:35:01 +01:00
things
This commit is contained in:
parent
a9e488f3e3
commit
0f05ef625a
11 changed files with 153 additions and 70 deletions
|
|
@ -1,7 +1,7 @@
|
|||
mod files;
|
||||
mod reaper;
|
||||
|
||||
use std::{ffi::OsStr, path::Path};
|
||||
use std::{collections::HashSet, ffi::OsStr, path::Path};
|
||||
|
||||
use anyhow::{ensure, Context, Result};
|
||||
|
||||
|
|
@ -10,11 +10,19 @@ use crate::{build::Build, processor::files::Changes, Options};
|
|||
use self::files::SourceFile;
|
||||
|
||||
pub trait Processor {
|
||||
fn process_file(&mut self, krate: &mut syn::File, checker: &mut ProcessChecker) -> bool;
|
||||
fn process_file(&mut self, krate: &mut syn::File, checker: &mut ProcessChecker)
|
||||
-> ProcessState;
|
||||
|
||||
fn name(&self) -> &'static str;
|
||||
}
|
||||
|
||||
#[derive(Debug, PartialEq, Eq)]
|
||||
pub enum ProcessState {
|
||||
NoChange,
|
||||
Changed,
|
||||
FileInvalidated,
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct Minimizer {
|
||||
files: Vec<SourceFile>,
|
||||
|
|
@ -61,12 +69,18 @@ impl Minimizer {
|
|||
);
|
||||
}
|
||||
|
||||
let mut invalidated_files = HashSet::new();
|
||||
|
||||
for mut pass in passes {
|
||||
'pass: loop {
|
||||
println!("Starting a round of {}", pass.name());
|
||||
let mut changes = Changes::default();
|
||||
|
||||
for file in &self.files {
|
||||
if invalidated_files.contains(file) {
|
||||
continue;
|
||||
}
|
||||
|
||||
let file_display = file.path.display();
|
||||
|
||||
let mut change = file.try_change(&mut changes)?;
|
||||
|
|
@ -76,22 +90,29 @@ impl Minimizer {
|
|||
|
||||
let has_made_change = pass.process_file(&mut krate, &mut ProcessChecker {});
|
||||
|
||||
if has_made_change {
|
||||
let result = prettyplease::unparse(&krate);
|
||||
match has_made_change {
|
||||
ProcessState::Changed | ProcessState::FileInvalidated => {
|
||||
let result = prettyplease::unparse(&krate);
|
||||
|
||||
change.write(&result)?;
|
||||
change.write(&result)?;
|
||||
|
||||
let after = self.build.build()?;
|
||||
let after = self.build.build()?;
|
||||
|
||||
println!("{file_display}: After {}: {after}", pass.name());
|
||||
println!("{file_display}: After {}: {after}", pass.name());
|
||||
|
||||
if after.reproduces_issue() {
|
||||
change.commit();
|
||||
} else {
|
||||
change.rollback()?;
|
||||
if after.reproduces_issue() {
|
||||
change.commit();
|
||||
} else {
|
||||
change.rollback()?;
|
||||
}
|
||||
|
||||
if has_made_change == ProcessState::FileInvalidated {
|
||||
invalidated_files.insert(file);
|
||||
}
|
||||
}
|
||||
ProcessState::NoChange => {
|
||||
println!("{file_display}: After {}: no change", pass.name());
|
||||
}
|
||||
} else {
|
||||
println!("{file_display}: After {}: no change", pass.name());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue