40 lines
1.3 KiB
Rust
40 lines
1.3 KiB
Rust
use std::{env, fs, path::Path};
|
|
fn main() {
|
|
println!("cargo:rerun-if-env-changed=CSR_BUILD_ID");
|
|
println!("cargo:rerun-if-changed=src");
|
|
println!("cargo:rerun-if-changed=../scripts/inventory-sync.py");
|
|
println!("cargo:rerun-if-changed=Cargo.lock");
|
|
fn hash_dir(path: &Path, hash: &mut u64) {
|
|
let mut files: Vec<_> = fs::read_dir(path)
|
|
.unwrap()
|
|
.flatten()
|
|
.map(|e| e.path())
|
|
.collect();
|
|
files.sort();
|
|
for p in files {
|
|
if p.is_dir() {
|
|
hash_dir(&p, hash);
|
|
} else {
|
|
for b in fs::read(p).unwrap() {
|
|
*hash = (*hash ^ b as u64).wrapping_mul(1099511628211);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
let mut hash = 14695981039346656037u64;
|
|
hash_dir(Path::new("src"), &mut hash);
|
|
for file in [
|
|
"../scripts/inventory-sync.py",
|
|
"Cargo.toml",
|
|
"Cargo.lock",
|
|
"build.rs",
|
|
] {
|
|
for b in fs::read(file).unwrap() {
|
|
hash = (hash ^ b as u64).wrapping_mul(1099511628211);
|
|
}
|
|
}
|
|
let id = env::var("CSR_BUILD_ID")
|
|
.unwrap_or_else(|_| format!("{}-{hash:016x}", env::var("CARGO_PKG_VERSION").unwrap()));
|
|
println!("cargo:rustc-env=CSR_BUILD_ID={id}");
|
|
}
|