A library for writing host-specific, single-binary configuration management and deployment tools
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

24 lines
1.0 KiB

use std::env;
use std::fs::{read_dir, File};
use std::io::Read;
use std::io::Write;
use std::path::{Path, PathBuf};
fn get_const_name<P: Clone + Into<PathBuf>>(p: &P) -> String {
let mut file_name_without_extension = p.clone().into();
file_name_without_extension.set_extension("");
String::from(file_name_without_extension.file_name().unwrap().to_string_lossy()).to_uppercase()
}
pub fn create_static_output_files(source_dir: &str) {
let out_dir = env::var("OUT_DIR").unwrap();
let dest_path = Path::new(&out_dir).join("static_files.rs");
let mut f = File::create(&dest_path).unwrap();
for maybe_dir_entry in read_dir(source_dir).unwrap() {
let file_path = maybe_dir_entry.unwrap().path();
let mut buffer = String::new();
File::open(file_path.clone()).unwrap().read_to_string(&mut buffer).unwrap();
let fence = buffer.chars().filter(|c| *c == '#').collect::<String>() + "#";
f.write_all(format!("pub const {}: &'static str = r{1}\"{2}\"{1};\n", get_const_name(&file_path), fence, buffer).as_bytes()).unwrap();
}
}