From d90db967bcc46ef4ae3d8d25755655da5b578073 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Edvard=20Th=C3=B6rnros?= Date: Mon, 1 Mar 2021 19:57:59 +0100 Subject: reading all scripts into a variable --- build.rs | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 build.rs diff --git a/build.rs b/build.rs new file mode 100644 index 0000000..92b63ab --- /dev/null +++ b/build.rs @@ -0,0 +1,28 @@ +use std::path::{Path, PathBuf}; + +fn find_tests(directory: &Path) -> Vec { + let mut tests = Vec::new(); + + for entry in std::fs::read_dir(directory).unwrap() { + let path = entry.unwrap().path(); + + if path.file_name().unwrap().to_str().unwrap().starts_with("_") { + continue; + } + + if path.is_dir() { + tests.append(&mut find_tests(&path)); + } else { + assert!(!path.to_str().unwrap().contains(","), "You should be ashamed."); + tests.push(path); + } + } + + tests +} + +fn main() { + let tests = find_tests(Path::new("progs/")); + let files = tests.iter().fold(String::new(), |a, b| format!("{},{}", a, b.display())); + println!("cargo:rustc-env=SCRIPTS={}", &files[1..]); +} -- cgit v1.2.1