-
Notifications
You must be signed in to change notification settings - Fork 8
/
build.rs
58 lines (51 loc) · 1.57 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
use failure::{format_err, Error};
use std::env;
use std::io::{BufRead, BufReader, Read};
use std::path::PathBuf;
use std::process::{Command, Stdio};
trait RunIt {
fn run_it(&mut self, err: &str) -> Result<(), Error>;
}
impl RunIt for Command {
fn run_it(&mut self, err: &str) -> Result<(), Error> {
self.stderr(Stdio::piped());
let mut child = self.spawn()?;
if let Some(out) = child.stdout.take() {
let buf = BufReader::new(out);
for line in buf.lines() {
eprint!("{}", line?);
}
}
if !child.wait()?.success() {
if let Some(mut err) = child.stderr.take() {
let mut out = String::new();
err.read_to_string(&mut out)?;
eprintln!("{}", out);
}
Err(format_err!("{}", err))
} else {
Ok(())
}
}
}
fn main() -> Result<(), Error> {
Command::new("cargo")
.args(&["web", "deploy"])
.current_dir("ui")
.run_it("Can't compile UI")?;
let out_path = PathBuf::from(env::var("OUT_DIR")?);
let tar_path = out_path.join("ui.tar.gz");
let tar_path = tar_path
.to_str()
.ok_or_else(|| format_err!("can't create path to archive"))?;
Command::new("tar")
.args(&["-cvzf", tar_path, "-C", "target/deploy", "."])
.current_dir("ui")
.run_it("Can't pack UI")?;
if cfg!(feature = "refresh") {
Command::new("touch")
.args(&["build.rs"])
.run_it("Can't touch the build file")?;
}
Ok(())
}