forked from Electron100/butane
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Clean butane/.butane only during cargo test (Electron100#215)
Fixes Electron100#56 Also only re-run build.rs if the tests/ change.
- Loading branch information
Showing
1 changed file
with
9 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,21 @@ | ||
fn main() { | ||
// This build.rs is only needed to help the tests | ||
if std::env::var("CARGO_CFG_TEST").is_err() { | ||
return; | ||
} | ||
println!("cargo:rerun-if-changed=tests"); | ||
|
||
// This cleans the .butane/ directory which is generated when compiling the tests so that | ||
// the tests do not encounter side effects from previous test runs. | ||
// Currently the only way to remove stale items from the generated .butane/ directory is to | ||
// delete it before the code is compiled. | ||
// This means we can not rely on `butane clean` or the code behind it, because it hasnt | ||
// been compiled yet. | ||
let dir = ".butane/"; | ||
println!("cargo:rerun-if-changed={dir}"); | ||
if std::path::Path::new(&dir).is_dir() { | ||
match std::fs::remove_dir_all(dir) { | ||
Ok(_) => { | ||
// Re-create the directory. Only tests populate it and if it is left non-existent | ||
// Cargo will detect it as changed and a no-op build will not in fact no-op | ||
std::fs::create_dir(dir).unwrap(); | ||
} | ||
Err(_) => eprintln!("Cannot delete .butane dir"), | ||
println!("cargo:warning=Deleting .butane directory"); | ||
if std::fs::remove_dir_all(dir).is_err() { | ||
println!("cargo:warning=Cannot delete .butane directory"); | ||
} | ||
} | ||
} |