Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(cli): add commit hash and target to long_version output #8133

Merged
merged 4 commits into from
Nov 2, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 25 additions & 4 deletions cli/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,28 @@ fn ts_version() -> String {
.collect::<String>()
}

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[..7])
.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()
}
}

fn main() {
// Don't build V8 if "cargo doc" is being run. This is to support docs.rs.
if env::var_os("RUSTDOCFLAGS").is_some() {
Expand All @@ -114,6 +136,7 @@ fn main() {
// op_fetch_asset::trace_serializer();

println!("cargo:rustc-env=TS_VERSION={}", ts_version());
println!("cargo:rustc-env=GIT_COMMIT_HASH={}", git_commit_hash());
println!(
"cargo:rustc-env=DENO_WEB_LIB_PATH={}",
deno_web::get_declaration().display()
Expand All @@ -123,10 +146,8 @@ fn main() {
deno_fetch::get_declaration().display()
);

println!(
"cargo:rustc-env=TARGET={}",
std::env::var("TARGET").unwrap()
);
println!("cargo:rustc-env=TARGET={}", env::var("TARGET").unwrap());
println!("cargo:rustc-env=PROFILE={}", env::var("PROFILE").unwrap());

let c = PathBuf::from(env::var_os("CARGO_MANIFEST_DIR").unwrap());
let o = PathBuf::from(env::var_os("OUT_DIR").unwrap());
Expand Down
5 changes: 4 additions & 1 deletion cli/flags.rs
Original file line number Diff line number Diff line change
Expand Up @@ -221,8 +221,11 @@ To evaluate code in the shell:

lazy_static! {
static ref LONG_VERSION: String = format!(
"{}\nv8 {}\ntypescript {}",
"{} ({}, {}, {})\nv8 {}\ntypescript {}",
crate::version::DENO,
crate::version::GIT_COMMIT_HASH,
env!("PROFILE"),
env!("TARGET"),
ry marked this conversation as resolved.
Show resolved Hide resolved
crate::version::v8(),
crate::version::TYPESCRIPT
);
Expand Down
1 change: 1 addition & 0 deletions cli/version.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.

pub const DENO: &str = env!("CARGO_PKG_VERSION");
pub const GIT_COMMIT_HASH: &str = env!("GIT_COMMIT_HASH");
pub const TYPESCRIPT: &str = crate::js::TS_VERSION;

pub fn v8() -> &'static str {
Expand Down