mirror of https://github.com/m-labs/artiq.git
firmware: don't bail out if building not from a git checkout (#783).
This commit is contained in:
parent
0253db0421
commit
d06d53b00d
|
@ -3,44 +3,50 @@ extern crate walkdir;
|
||||||
use std::env;
|
use std::env;
|
||||||
use std::fs::File;
|
use std::fs::File;
|
||||||
use std::io::{Write, BufRead, BufReader};
|
use std::io::{Write, BufRead, BufReader};
|
||||||
use std::path::Path;
|
use std::path::{Path, PathBuf};
|
||||||
use std::process::Command;
|
use std::process::Command;
|
||||||
|
|
||||||
use walkdir::WalkDir;
|
use walkdir::WalkDir;
|
||||||
|
|
||||||
pub fn git_describe() {
|
pub fn git_describe() {
|
||||||
let id =
|
let git_dir = Path::new("../../../.git");
|
||||||
Command::new("git")
|
|
||||||
.arg("describe")
|
|
||||||
.arg("--tags")
|
|
||||||
.arg("--dirty")
|
|
||||||
.arg("--always")
|
|
||||||
.arg("--long")
|
|
||||||
.arg("--abbrev=8")
|
|
||||||
.output()
|
|
||||||
.ok()
|
|
||||||
.and_then(|o| String::from_utf8(o.stdout).ok())
|
|
||||||
.map(|mut s| {
|
|
||||||
let len = s.trim_right().len();
|
|
||||||
s.truncate(len);
|
|
||||||
s
|
|
||||||
})
|
|
||||||
.unwrap();
|
|
||||||
let id = id.split("-").collect::<Vec<_>>();
|
|
||||||
let id = format!("{}+{}.{}", id[0], id[1], id[2]);
|
|
||||||
|
|
||||||
let out_dir = env::var("OUT_DIR").unwrap();
|
println!("cargo:rerun-if-changed={}", git_dir.join("HEAD").display());
|
||||||
let dest_path = Path::new(&out_dir).join("git-describe");
|
for entry in WalkDir::new(git_dir.join("refs")) {
|
||||||
let mut f = File::create(&dest_path).unwrap();
|
|
||||||
f.write(id.as_bytes()).unwrap();
|
|
||||||
|
|
||||||
println!("cargo:rust-cfg=git_describe={:?}", id);
|
|
||||||
|
|
||||||
println!("cargo:rerun-if-changed=../../../.git/HEAD");
|
|
||||||
for entry in WalkDir::new("../../../.git/refs") {
|
|
||||||
let entry = entry.unwrap();
|
let entry = entry.unwrap();
|
||||||
println!("cargo:rerun-if-changed={}", entry.path().display());
|
println!("cargo:rerun-if-changed={}", entry.path().display());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let version;
|
||||||
|
if git_dir.exists() {
|
||||||
|
let git_describe =
|
||||||
|
Command::new("git")
|
||||||
|
.arg("describe")
|
||||||
|
.arg("--tags")
|
||||||
|
.arg("--dirty")
|
||||||
|
.arg("--always")
|
||||||
|
.arg("--long")
|
||||||
|
.arg("--abbrev=8")
|
||||||
|
.output()
|
||||||
|
.ok()
|
||||||
|
.and_then(|o| String::from_utf8(o.stdout).ok())
|
||||||
|
.map(|mut s| {
|
||||||
|
let len = s.trim_right().len();
|
||||||
|
s.truncate(len);
|
||||||
|
s
|
||||||
|
})
|
||||||
|
.unwrap();
|
||||||
|
let parts = git_describe.split("-").collect::<Vec<_>>();
|
||||||
|
version = format!("{}+{}.{}", parts[0], parts[1], parts[2]);
|
||||||
|
} else {
|
||||||
|
version = "unknown".to_owned();
|
||||||
|
}
|
||||||
|
|
||||||
|
let out_dir = PathBuf::from(env::var("OUT_DIR").unwrap());
|
||||||
|
let mut f = File::create(out_dir.join("git-describe")).unwrap();
|
||||||
|
write!(f, "{}", version).unwrap();
|
||||||
|
|
||||||
|
println!("cargo:rust-cfg=git_describe={:?}", version);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn misoc_cfg() {
|
pub fn misoc_cfg() {
|
||||||
|
|
Loading…
Reference in New Issue