mirror of
https://github.com/denoland/deno.git
synced 2025-02-01 12:16:11 -05:00
34 lines
837 B
Rust
34 lines
837 B
Rust
|
// Copyright 2018-2025 the Deno authors. MIT license.
|
||
|
|
||
|
fn main() {
|
||
|
let commit_hash = git_commit_hash();
|
||
|
println!("cargo:rustc-env=GIT_COMMIT_HASH={}", commit_hash);
|
||
|
println!("cargo:rerun-if-env-changed=GIT_COMMIT_HASH");
|
||
|
println!(
|
||
|
"cargo:rustc-env=GIT_COMMIT_HASH_SHORT={}",
|
||
|
&commit_hash[..7]
|
||
|
);
|
||
|
}
|
||
|
|
||
|
fn git_commit_hash() -> String {
|
||
|
if let Ok(output) = std::process::Command::new("git")
|
||
|
.arg("rev-list")
|
||
|
.arg("-1")
|
||
|
.arg("HEAD")
|
||
|
.output()
|
||
|
{
|
||
|
if output.status.success() {
|
||
|
std::str::from_utf8(&output.stdout[..40])
|
||
|
.unwrap()
|
||
|
.to_string()
|
||
|
} else {
|
||
|
// When not in git repository
|
||
|
// (e.g. when the user install by `cargo install deno`)
|
||
|
"UNKNOWN".to_string()
|
||
|
}
|
||
|
} else {
|
||
|
// When there is no git command for some reason
|
||
|
"UNKNOWN".to_string()
|
||
|
}
|
||
|
}
|