mirror of
https://github.com/Noratrieb/cargo-minimize.git
synced 2026-01-14 08:25:01 +01:00
Dont use script
This commit is contained in:
parent
6eaf188597
commit
250f0cd557
2 changed files with 58 additions and 25 deletions
|
|
@ -1,9 +1,18 @@
|
|||
fn main() -> anyhow::Result<()> {
|
||||
if std::env::var("MINIMIZE_LINTS").as_deref() == Ok("1") {
|
||||
std::process::Command::new("cargo")
|
||||
.arg("check")
|
||||
.spawn()
|
||||
.unwrap()
|
||||
.wait()
|
||||
.unwrap();
|
||||
}
|
||||
|
||||
let root_var =
|
||||
std::env::var("MINIMIZE_RUNTEST_ROOTS").expect("MINIMIZE_RUNTEST_ROOTS env var not found");
|
||||
let roots = root_var.split(",").collect::<Vec<_>>();
|
||||
|
||||
let proj_dir = std::env::current_dir().expect("current dir not found");
|
||||
|
||||
testsuite::ensure_correct_minimization(&proj_dir, roots)
|
||||
testsuite::ensure_roots_kept(&proj_dir, roots)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@ use rayon::prelude::{IntoParallelIterator, ParallelIterator};
|
|||
use regex::Regex;
|
||||
use std::collections::hash_map::RandomState;
|
||||
use std::collections::HashSet;
|
||||
use std::ffi::OsString;
|
||||
use std::fs::Permissions;
|
||||
use std::io::BufWriter;
|
||||
#[cfg(unix)]
|
||||
|
|
@ -18,17 +19,10 @@ use std::{
|
|||
use tempfile::TempDir;
|
||||
|
||||
/// This is called by the regression_checked binary during minimization and by the test runner at the end.
|
||||
pub fn ensure_correct_minimization(
|
||||
pub fn ensure_roots_kept(
|
||||
proj_dir: &Path,
|
||||
start_roots: impl IntoIterator<Item = impl AsRef<str>>,
|
||||
) -> Result<()> {
|
||||
let required_deleted = get_required_deleted(&proj_dir).context("get REQUIRED-DELETED")?;
|
||||
|
||||
ensure!(
|
||||
required_deleted.is_empty(),
|
||||
"Some REQUIRE-DELETED have not been deleted: {required_deleted:?}"
|
||||
);
|
||||
|
||||
let end_roots = HashSet::<_, RandomState>::from_iter(
|
||||
get_roots(proj_dir).context("getting final MINIMIZE-ROOTs")?,
|
||||
);
|
||||
|
|
@ -72,17 +66,31 @@ pub fn full_tests() -> Result<()> {
|
|||
]))
|
||||
.context("running cargo build")?;
|
||||
|
||||
let path = Path::new(file!())
|
||||
.canonicalize()?
|
||||
.parent()
|
||||
.unwrap()
|
||||
.parent()
|
||||
.unwrap()
|
||||
.parent()
|
||||
.unwrap()
|
||||
.join("full-tests");
|
||||
let this_file = Path::new(file!())
|
||||
.canonicalize()
|
||||
.with_context(|| format!("failed to find current file: {}", file!()))?;
|
||||
|
||||
let children = fs::read_dir(&path).with_context(|| format!("reading {}", path.display()))?;
|
||||
let root_dir = this_file
|
||||
.parent()
|
||||
.unwrap()
|
||||
.parent()
|
||||
.unwrap()
|
||||
.parent()
|
||||
.unwrap();
|
||||
|
||||
let full_tests_path = root_dir.join("full-tests");
|
||||
|
||||
let mut regression_checker_path = root_dir
|
||||
.join("target")
|
||||
.join("debug")
|
||||
.join("regression_checker");
|
||||
|
||||
if cfg!(windows) {
|
||||
regression_checker_path.set_extension("exe");
|
||||
}
|
||||
|
||||
let children = fs::read_dir(&full_tests_path)
|
||||
.with_context(|| format!("reading {}", full_tests_path.display()))?;
|
||||
|
||||
let children = children
|
||||
.map(|e| e.map_err(Into::into))
|
||||
|
|
@ -94,14 +102,16 @@ pub fn full_tests() -> Result<()> {
|
|||
.map(|child| {
|
||||
let path = child.path();
|
||||
|
||||
build(&path).with_context(|| format!("building {:?}", path.file_name().unwrap()))
|
||||
build(&path, ®ression_checker_path)
|
||||
.with_context(|| format!("building {:?}", path.file_name().unwrap()))
|
||||
})
|
||||
.collect::<Result<Vec<_>>>()?;
|
||||
} else {
|
||||
for child in children {
|
||||
let path = child.path();
|
||||
|
||||
build(&path).with_context(|| format!("building {:?}", path.file_name().unwrap()))?;
|
||||
build(&path, ®ression_checker_path)
|
||||
.with_context(|| format!("building {:?}", path.file_name().unwrap()))?;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -206,7 +216,7 @@ cargo check
|
|||
Ok(())
|
||||
}
|
||||
|
||||
fn build(path: &Path) -> Result<()> {
|
||||
fn build(path: &Path, regression_checker_path: &Path) -> Result<()> {
|
||||
let (_tempdir, proj_dir) = setup_dir(path).context("setting up tempdir")?;
|
||||
let mut cargo_minimize_path = PathBuf::from("target/debug/cargo-minimize");
|
||||
if cfg!(windows) {
|
||||
|
|
@ -224,8 +234,15 @@ fn build(path: &Path) -> Result<()> {
|
|||
cmd.current_dir(&proj_dir);
|
||||
|
||||
cmd.arg("minimize");
|
||||
cmd.arg("--script-path=./check.sh");
|
||||
cmd.arg("--script-path-lints=./lint.sh");
|
||||
cmd.arg({
|
||||
let mut flag = OsString::from("--script-path=");
|
||||
flag.push(regression_checker_path);
|
||||
flag
|
||||
});
|
||||
|
||||
let minimize_roots = start_roots.join(",");
|
||||
|
||||
cmd.env("MINIMIZE_RUNTEST_ROOTS", &minimize_roots);
|
||||
|
||||
let out = cmd.output().context("spawning cargo-minimize")?;
|
||||
let stderr = String::from_utf8(out.stderr).unwrap();
|
||||
|
|
@ -236,7 +253,14 @@ fn build(path: &Path) -> Result<()> {
|
|||
"Command failed:\n--- stderr:\n{stderr}\n--- stdout:\n{stdout}"
|
||||
);
|
||||
|
||||
ensure_correct_minimization(&proj_dir, &start_roots)?;
|
||||
let required_deleted = get_required_deleted(&proj_dir).context("get REQUIRED-DELETED")?;
|
||||
|
||||
ensure!(
|
||||
required_deleted.is_empty(),
|
||||
"Some REQUIRE-DELETED have not been deleted: {required_deleted:?}"
|
||||
);
|
||||
|
||||
ensure_roots_kept(&proj_dir, &start_roots)?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue