This repository has been archived by the owner on Nov 16, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.rs
52 lines (41 loc) · 1.39 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
use std::{env, fs, path::Path, process::Command};
fn main() {
println!("cargo:rerun-if-changed=build.rs");
println!("cargo:rerun-if-changed=examples");
#[cfg(windows)]
panic!("This program is Linux only.");
if let Some(home_dir) = env::var_os("HOME") {
let config_path = Path::new(&home_dir).join(".config/oxidec/");
if cfg!(feature = "new-examples") {
copy_new_examples(&config_path);
} else {
copy_examples_directory(&config_path);
}
}
}
fn copy_examples_directory(config_path: &Path) {
if !config_path.exists() {
copy_directory("examples", config_path);
}
}
fn copy_new_examples(config_path: &Path) {
let repo_path = Path::new("examples");
for directory in ["templates", "reloaders"] {
let user_directory = config_path.join(directory);
let repo_directory = repo_path.join(directory);
for repo_file in fs::read_dir(repo_directory).unwrap().flatten() {
let file_name = repo_file.file_name();
let user_file = user_directory.join(file_name);
if !user_file.exists() {
fs::copy(repo_file.path(), user_file).unwrap();
}
}
}
}
fn copy_directory(src: &str, dest: &Path) {
let mut command = Command::new("cp");
command.arg("-r");
command.arg(src);
command.arg(dest);
command.output().unwrap();
}