-
Notifications
You must be signed in to change notification settings - Fork 52
/
build.rs
60 lines (57 loc) · 2.27 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
use hit::repo::Repo;
use std::path::{Path, PathBuf};
fn main() {
let pkg_name = std::env::var("CARGO_PKG_NAME").unwrap();
let manifest_dir = PathBuf::from(std::env::var("CARGO_MANIFEST_DIR").unwrap());
let install_dir = home::home_dir()
.expect("failed to get user's home dir")
.join(format!(".{}", pkg_name));
std::fs::create_dir_all(&install_dir).expect("failed to create install dir");
// Copy version info
match Repo::from_path(&manifest_dir).latest_subject() {
Ok(msg) => {
if let Err(err) = std::fs::write(install_dir.join("commit"), msg) {
println!(
"cargo:warning=failed to write current commit message: {}",
err
)
}
}
Err(err) => println!(
"cargo:warning=failed to get current commit message: {}",
err
),
}
// Copy templates
let bike = bicycle::Bicycle::default();
for rel in ["platforms", "apps"]
.iter()
.map(|prefix| Path::new("templates").join(prefix))
{
let src = manifest_dir.join(&rel);
println!("cargo:rerun-if-changed={}", src.display());
let dest = install_dir.join(rel);
let actions = bicycle::traverse(&src, &dest, bicycle::no_transform, None)
.expect("failed to traverse src templates dir");
if dest.is_dir() {
std::fs::remove_dir_all(&dest).expect("failed to delete old templates");
}
// bicycle creates directories for us, so we don't need to worry about
// using `create_dir_all` or anything.
bike.process_actions(
actions.iter().inspect(|action| match action {
bicycle::Action::CreateDirectory { dest: in_dest } => {
// This is sorta gross, but not really *that* gross, so...
let src = src.join(in_dest.strip_prefix(&dest).unwrap());
println!("cargo:rerun-if-changed={}", src.display());
}
bicycle::Action::CopyFile { src, .. } => {
println!("cargo:rerun-if-changed={}", src.display());
}
_ => (),
}),
|_| (),
)
.expect("failed to process actions");
}
}