-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbuild.rs
100 lines (74 loc) · 1.89 KB
/
build.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
use std::env;
use std::fs::{File, read_dir};
use std::path::Path;
use std::io::{Write, BufWriter};
use itertools::Itertools;
const ADD_ALL:bool = true;
/// Generate the source code that contains the list of musics
fn main() {
let out_dir = env::var_os("OUT_DIR").unwrap();
let dest_path = Path::new(&out_dir).join("db.rs");
let mut db_code = File::create(dest_path).unwrap();
let mut db_code = BufWriter::new(db_code);
let mut files_data = Vec::new();
let MAX = 10;
let mut i = 0;
for dir in read_dir("BIN").unwrap() {
let dir = dir.unwrap();
for file in read_dir(dir.path()).unwrap() {
let file = file.unwrap();
files_data.push(
(
file.file_name().to_str().unwrap().split('.').next().unwrap().to_owned(),
file.path().to_str().unwrap().replace('\\',"\\\\")
)
);
i+=1;
if i >= MAX && !ADD_ALL{
break;
}
}
if i >= MAX && !ADD_ALL{
break;
}
}
writeln!(&mut db_code, "
use staticfilemap::*;
#[derive(StaticFileMap)]
#[names = \"{}\"]
#[files = \"{}\"]
pub struct StaticMap;
",
files_data.iter().map(|d| d.0.to_owned()).join(";"),
files_data.iter().map(|d| d.1.to_owned()).join(";")
).unwrap();
/*
writeln!(&mut db_code, "
use lazy_static::lazy_static;
use std::collections::HashMap;
lazy_static! {{
static ref CPCMIX_DB: HashMap<&'static str, &'static [u8]> = {{
let mut m = HashMap::<&'static str, &'static [u8]>::new();
").unwrap();
for dir in read_dir("BIN").unwrap() {
let dir = dir.unwrap();
for file in read_dir(dir.path()).unwrap() {
let file = file.unwrap();
writeln!(&mut db_code, "
m.insert(
\"{}\",
include_bytes!(\"../../../../../{}\")
);",
file.file_name().to_str().unwrap().split('.').next().unwrap(),
file.path().to_str().unwrap()
).unwrap();
}
}
writeln!(&mut db_code, "
m
}};
}}
").unwrap();
*/
println!("cargo:rerun-if-changed=build.rs");
}