-
Notifications
You must be signed in to change notification settings - Fork 43
/
build.rs
60 lines (51 loc) · 1.5 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
//! lovingly stolen from https://github.com/rust-lang-nursery/rustup.rs/blob/master/build.rs
use std::env;
use std::error::Error;
use std::fs::File;
use std::io::Write;
use std::path::PathBuf;
use std::process::{self, Command};
struct Ignore;
impl<E> From<E> for Ignore
where
E: Error,
{
fn from(_: E) -> Ignore {
Ignore
}
}
fn main() {
if let Err(_) = Command::new("sass").status() {
eprintln!(
"build error: sass compiler not installed.\n\
please follow the instructions at https://sass-lang.com/install, \
making sure the `sass` executable is in your $PATH."
);
process::exit(1);
}
let out_dir = PathBuf::from(env::var_os("OUT_DIR").unwrap());
File::create(out_dir.join("commit-info.txt"))
.unwrap()
.write_all(commit_info().as_bytes())
.unwrap();
Command::new("sass")
.args(&["style/style.scss", "static/style.css"])
.status()
.unwrap();
}
// Try to get hash and date of the last commit on a best effort basis. If anything goes wrong
// (git not installed or if this is not a git repository) just return an empty string.
fn commit_info() -> String {
match commit_hash() {
Ok(hash) => hash.trim_end().to_owned(),
_ => String::new(),
}
}
fn commit_hash() -> Result<String, Ignore> {
Ok(String::from_utf8(
Command::new("git")
.args(&["rev-parse", "--short=9", "HEAD"])
.output()?
.stdout,
)?)
}