Repository navigation
Expand file tree
/
Copy pathbuild.rs
More file actions
51 lines (48 loc) · 1.71 KB
/
Copy pathbuild.rs
File metadata and controls
51 lines (48 loc) · 1.71 KB
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
//! Build script: records the git revision, dirty flag, commit date and target triple for `upd`.
use std::process::Command;
fn git(a: &[&str]) -> String {
Command::new("git")
.args(a)
.output()
.ok()
.filter(|o| o.status.success())
.map(|o| String::from_utf8_lossy(&o.stdout).trim().to_string())
.unwrap_or_default()
}
fn main() {
// a crate from crates.io has no .git, only the commit it was packaged from
let vcs = std::path::Path::new(&std::env::var("CARGO_MANIFEST_DIR").unwrap_or_default())
.join(".cargo_vcs_info.json");
let (rev, dirty, date) = if let Ok(j) = std::fs::read_to_string(&vcs) {
if std::env::var("NONAME_CHANNEL").is_err() {
println!("cargo:rustc-env=NONAME_CHANNEL=crates");
}
let sha = j
.split("\"sha1\"")
.nth(1)
.and_then(|r| r.split('"').nth(1))
.unwrap_or_default()
.to_string();
(sha, false, String::new())
} else {
(
git(&["rev-parse", "HEAD"]),
!git(&["status", "--porcelain", "--untracked-files=no"]).is_empty(),
git(&["log", "-1", "--format=%cs"]),
)
};
println!("cargo:rustc-env=NONAME_REV={rev}");
println!(
"cargo:rustc-env=NONAME_DIRTY={}",
if dirty { "1" } else { "" }
);
println!("cargo:rustc-env=NONAME_DATE={date}");
println!(
"cargo:rustc-env=NONAME_TARGET={}",
std::env::var("TARGET").unwrap_or_default()
);
println!("cargo:rerun-if-env-changed=NONAME_CHANNEL");
println!("cargo:rerun-if-changed=.git/HEAD");
println!("cargo:rerun-if-changed=.git/index");
println!("cargo:rerun-if-changed=src");
}