Skip to content

Commit

Permalink
Change iter_dts_files to first check for a DTS_DIR enviroment variable
Browse files Browse the repository at this point in the history
Allows for running in cases where CARGO_MANIFEST_DIR is unset or in an unusual
location. Also just exit if the dir cannot be found instead panicing.
  • Loading branch information
yodaldevoid committed Jul 8, 2017
1 parent 1cf35d1 commit feaa7be
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions device_tree_source/tests/iter_dts_files.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,22 @@ use device_tree_source::include::{IncludeError, include_files};
fn main() {
let args: Vec<_> = args().collect();

let new_dir = PathBuf::from(::std::env::var("CARGO_MANIFEST_DIR").unwrap())
.join("tests/dts");
::std::env::set_current_dir(&new_dir)
.expect("Could not change current directory. Does tests/dts exist?");
let new_dir = ::std::env::var("DTS_DIR")
.map(|env| PathBuf::from(env))
.or_else(|_| ::std::env::var("CARGO_MANIFEST_DIR")
.map(|env| PathBuf::from(env).join("tests/dts")));
match new_dir {
Ok(new_dir) => {
if let Err(_) = ::std::env::set_current_dir(&new_dir) {
println!("\nCould not change current directory. Does tests/dts exist?\n");
return
}
}
Err(_) => {
println!("Both DTS_DIR and CARGO_MANIFEST_DIR unset!");
return
}
}

let tests = WalkDir::new(".")
.follow_links(true)
Expand Down

0 comments on commit feaa7be

Please sign in to comment.