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

Conversation

kt3k
Copy link
Member

@kt3k kt3k commented Oct 26, 2020

This PR adds the git commit hash and build target to long version output (--version) as suggested in #6037. The output now looks like the below:

$ ./target/debug/deno --version
deno 1.4.6 (0dcdc5e)
target x86_64-apple-darwin
v8 8.7.220.3
typescript 4.0.3

fixes #6037

cli/version.rs Outdated
@@ -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 BUILD: &str = env!("GIT_COMMIT_HASH");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just "GIT_COMMIT_HASH" instead of "BUILD" would be more descriptive.

cli/flags.rs Show resolved Hide resolved
cli/build.rs Outdated
Comment on lines 107 to 121
fn git_commit_hash() -> String {
let output = std::process::Command::new("git")
.arg("rev-list")
.arg("-1")
.arg("HEAD")
.output()
.expect("failed to execute process");
std::str::from_utf8(&output.stdout[..7])
.unwrap()
.to_string()
}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this going to work when doing cargo install deno?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's a good point. I think it will break "cargo install deno".

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see. It won't work with cargo install...

We need a different strategy here.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems sha1 is stored in the file called .cargo_vcs_info.json in crates.io. (ref: rust-lang/cargo#5629 ) Maybe we can use it.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe just return "crates.io" if anything in git_commit_hash fails?

@kt3k
Copy link
Member Author

kt3k commented Oct 26, 2020

Closing for the moment. I'll reopen it when I find a way to handle cargo install deno case correctly.

@kt3k kt3k closed this Oct 26, 2020
@bartlomieju
Copy link
Member

@kt3k I think this is a valid approach. As @lucacasonato suggested we can fallback to some constant value eg. empty string. For reference vergen returns UNKNOWN if git command fails (https://github.com/rustyhorde/vergen/blob/8d522db8c8e16e26c0fc9ea8e6b0247cbf5cca84/src/output/mod.rs#L88-L95).

@bartlomieju bartlomieju reopened this Oct 31, 2020
@kt3k
Copy link
Member Author

kt3k commented Oct 31, 2020

OK. I'll update the change!

@kt3k
Copy link
Member Author

kt3k commented Oct 31, 2020

I updated the change. Now the commit hash becomes UNKNOWN when not in git repository. The output looks like the below (I also added PROFILE):

$ ./target/debug/deno --version
deno 1.5.0 (UNKNOWN, debug, x86_64-apple-darwin)
v8 8.7.220.3
typescript 4.0.3

Checked on windows as well just in case.
スクリーンショット 2020-10-31 21 20 15

@bartlomieju
Copy link
Member

The solution looks satisfactory to me. Waiting on @ry to double check before landing.

@bartlomieju bartlomieju requested a review from ry November 2, 2020 17:07
Copy link
Member

@ry ry left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM - thank you @kt3k !

@ry ry merged commit 0e5c8c0 into denoland:master Nov 2, 2020
@bartlomieju bartlomieju mentioned this pull request Nov 2, 2020
@kt3k kt3k deleted the feat/build-hash branch November 3, 2020 04:20
maximousblk added a commit to maximousblk/deno_nightly that referenced this pull request Nov 3, 2020
jannes pushed a commit to jannes/deno that referenced this pull request Dec 1, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Display commit in deno version.
4 participants