Browse Source

Accept missing static_files dir

master
Adrian Heine 5 years ago
parent
commit
9dd2da3cc4
  1. 47
      src/build.rs

47
src/build.rs

@ -1,5 +1,6 @@
use std::env;
use std::fs::{read_dir, File};
use std::io::ErrorKind::NotFound;
use std::io::Read;
use std::io::Write;
use std::path::{Path, PathBuf};
@ -20,24 +21,34 @@ 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 {}: &str = r{1}\"{2}\"{1};\n",
get_const_name(&file_path),
fence,
buffer
)
.as_bytes(),
)
.unwrap();
match read_dir(source_dir) {
Ok(dir_content) => {
for maybe_dir_entry in dir_content {
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 {}: &str = r{1}\"{2}\"{1};\n",
get_const_name(&file_path),
fence,
buffer
)
.as_bytes(),
)
.unwrap();
}
}
Err(err) => {
if err.kind() == NotFound {
} else {
Err(err).unwrap()
}
}
}
}

Loading…
Cancel
Save