Accept missing static_files dir
This commit is contained in:
parent
907a4962c5
commit
9dd2da3cc4
1 changed files with 29 additions and 18 deletions
47
src/build.rs
47
src/build.rs
|
|
@ -1,5 +1,6 @@
|
||||||
use std::env;
|
use std::env;
|
||||||
use std::fs::{read_dir, File};
|
use std::fs::{read_dir, File};
|
||||||
|
use std::io::ErrorKind::NotFound;
|
||||||
use std::io::Read;
|
use std::io::Read;
|
||||||
use std::io::Write;
|
use std::io::Write;
|
||||||
use std::path::{Path, PathBuf};
|
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 out_dir = env::var("OUT_DIR").unwrap();
|
||||||
let dest_path = Path::new(&out_dir).join("static_files.rs");
|
let dest_path = Path::new(&out_dir).join("static_files.rs");
|
||||||
let mut f = File::create(&dest_path).unwrap();
|
let mut f = File::create(&dest_path).unwrap();
|
||||||
for maybe_dir_entry in read_dir(source_dir).unwrap() {
|
match read_dir(source_dir) {
|
||||||
let file_path = maybe_dir_entry.unwrap().path();
|
Ok(dir_content) => {
|
||||||
let mut buffer = String::new();
|
for maybe_dir_entry in dir_content {
|
||||||
File::open(file_path.clone())
|
let file_path = maybe_dir_entry.unwrap().path();
|
||||||
.unwrap()
|
let mut buffer = String::new();
|
||||||
.read_to_string(&mut buffer)
|
File::open(file_path.clone())
|
||||||
.unwrap();
|
.unwrap()
|
||||||
let fence = buffer.chars().filter(|c| *c == '#').collect::<String>() + "#";
|
.read_to_string(&mut buffer)
|
||||||
f.write_all(
|
.unwrap();
|
||||||
format!(
|
let fence = buffer.chars().filter(|c| *c == '#').collect::<String>() + "#";
|
||||||
"pub const {}: &str = r{1}\"{2}\"{1};\n",
|
f.write_all(
|
||||||
get_const_name(&file_path),
|
format!(
|
||||||
fence,
|
"pub const {}: &str = r{1}\"{2}\"{1};\n",
|
||||||
buffer
|
get_const_name(&file_path),
|
||||||
)
|
fence,
|
||||||
.as_bytes(),
|
buffer
|
||||||
)
|
)
|
||||||
.unwrap();
|
.as_bytes(),
|
||||||
|
)
|
||||||
|
.unwrap();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Err(err) => {
|
||||||
|
if err.kind() == NotFound {
|
||||||
|
} else {
|
||||||
|
Err(err).unwrap()
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue