-
Notifications
You must be signed in to change notification settings - Fork 29
/
build.rs
60 lines (52 loc) · 1.79 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
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
use std::env;
use std::fs;
use std::path::Path;
extern crate pkg_config;
fn update_local_git_hook() {
let p = env::current_dir().unwrap();
let origin_path = Path::new(&p).join("./tools/pre-commit");
let dest_path = Path::new(&p).join(".git/hooks/pre-commit");
fs::copy(&origin_path, &dest_path).unwrap();
}
fn cp_r(origin: &Path, dest: &Path) {
let dir = fs::read_dir(origin).unwrap();
for file in dir {
let file = file.unwrap();
let origin_buf = origin.join(file.file_name());
let origin = origin_buf.as_path();
let dest_buf = dest.join(file.file_name());
let dest = dest_buf.as_path();
if file.file_type().unwrap().is_dir() {
let dest_str = dest.to_str().unwrap();
if let Err(_) = fs::metadata(&dest_str) {
fs::create_dir(dest_str).unwrap();
}
cp_r(origin, dest);
} else {
fs::copy(origin, dest).unwrap();
}
}
}
fn copy_shared_static_files() {
let current = env::current_dir().unwrap();
let shared = Path::new(¤t).join("./static/shared");
for dest in vec!["./static/setup/shared", "./static/main/shared"] {
let dest = Path::new(¤t).join(dest);
let dest_str = dest.to_str().unwrap();
if let Err(_) = fs::metadata(&dest_str) {
fs::create_dir(dest_str).unwrap();
}
cp_r(&shared, &dest);
}
}
fn link_external_libs() {
pkg_config::probe_library("libupnp").unwrap();
}
fn main() {
update_local_git_hook();
link_external_libs();
copy_shared_static_files();
}