Skip to content

Commit

Permalink
Clean bench-report.xml from all the repo tree.
Browse files Browse the repository at this point in the history
  • Loading branch information
mwu-tow committed Jan 16, 2024
1 parent 5b91f16 commit 4acda8d
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 1 deletion.
6 changes: 5 additions & 1 deletion build/build/src/engine/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,11 @@ impl RunContext {

// Remove the benchmark reports. They are not meant currently to be incrementally
// updated.
ide_ci::fs::remove_if_exists(&self.paths.repo_root.engine.runtime.bench_report_xml)?;

// We remove all "bench-report.xml" files across the repo, as they confuse the
// benchmark reporter. See the request: https://github.com/enso-org/enso/pull/8707#issuecomment-1882512361
let bench_report_xml = "**/bench-report.xml";
ide_ci::fs::remove_glob(bench_report_xml)?;
}


Expand Down
49 changes: 49 additions & 0 deletions build/ci_utils/src/fs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -158,3 +158,52 @@ pub fn handle_fs_extra_error(error: fs_extra::error::Error) -> anyhow::Error {
}
.context(message)
}

/// Remove files using [glob patterns](https://docs.rs/glob/latest/glob/struct.Pattern.html).
#[tracing::instrument(skip_all, fields(pattern = %glob_pattern), err)]
#[context("Failed to remove files using glob pattern `{}`.", glob_pattern)]
pub fn remove_glob(glob_pattern: &str) -> Result {
for entry in glob::glob(glob_pattern)? {
let path = entry?;
remove_if_exists(&path)?;
}
Ok(())
}


#[cfg(test)]
mod tests {
use super::*;

#[test]
fn remove_glob_test() -> Result {
let temp = tempfile::tempdir()?;
crate::env::set_current_dir(&temp)?;

let pattern_to_remove = "**/file1.txt";
write("file1.txt", "file1")?;
write("file2.txt", "file2")?;
write("dir1/file1.txt", "file1")?;
write("dir1/file2.txt", "file2")?;

remove_glob(pattern_to_remove)?;
assert!(!Path::new("file1.txt").exists());
assert!(Path::new("file2.txt").exists());
assert!(!Path::new("dir1/file1.txt").exists());
assert!(Path::new("dir1/file2.txt").exists());
Ok(())
}

#[test]
fn remove_glob_test2() -> Result {
// Make sure that `**` can expand to nothing outside the current directory.
let temp = tempfile::tempdir()?;
let pattern_to_remove = "**/file1.txt";
let file1 = temp.path().join("file1.txt");

write(&file1, "file1")?;
remove_glob(temp.path().join(pattern_to_remove).as_str())?;
assert!(!file1.exists());
Ok(())
}
}

0 comments on commit 4acda8d

Please sign in to comment.