diff options
author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2020-02-21 10:34:58 +0000 |
---|---|---|
committer | GitHub <[email protected]> | 2020-02-21 10:34:58 +0000 |
commit | db1bbb11fbe85a5230452359e80535a2169d0929 (patch) | |
tree | a6570ab4e6691853804a71598135f5541723f691 /crates | |
parent | 88014fcec04721350abc156efb1e18889fca5255 (diff) | |
parent | 319a09847b47086b73ea7184ee39b3be0b924c60 (diff) |
Merge #3247
3247: Improve RA version display r=matklad a=edwin0cheng
There are 2 problems of current implementation for displaying current version of RA binary:
1. If that binary is coming from built by source, the `REV` may not be updated somehow. (See discussion in [Zuilp](https://rust-lang.zulipchat.com/#narrow/stream/185405-t-compiler.2Fwg-rls-2.2E0/topic/vscode.20version.20in.20console))
2. We must go through the VSCode debugger console to see the output of `console.log`.
This PR implemented a new VSCode command "Show RA Version" to display the version, which fixed the first problem. And added some `rerun-if` flags in `build.rs` to fix the second one.
Co-authored-by: Edwin Cheng <[email protected]>
Diffstat (limited to 'crates')
-rw-r--r-- | crates/rust-analyzer/build.rs | 30 |
1 files changed, 29 insertions, 1 deletions
diff --git a/crates/rust-analyzer/build.rs b/crates/rust-analyzer/build.rs index 05f9772c0..d4b010c04 100644 --- a/crates/rust-analyzer/build.rs +++ b/crates/rust-analyzer/build.rs | |||
@@ -1,12 +1,40 @@ | |||
1 | //! Just embed git-hash to `--version` | 1 | //! Just embed git-hash to `--version` |
2 | 2 | ||
3 | use std::process::Command; | 3 | use std::{env, path::PathBuf, process::Command}; |
4 | 4 | ||
5 | fn main() { | 5 | fn main() { |
6 | set_rerun(); | ||
7 | |||
6 | let rev = rev().unwrap_or_else(|| "???????".to_string()); | 8 | let rev = rev().unwrap_or_else(|| "???????".to_string()); |
7 | println!("cargo:rustc-env=REV={}", rev) | 9 | println!("cargo:rustc-env=REV={}", rev) |
8 | } | 10 | } |
9 | 11 | ||
12 | fn set_rerun() { | ||
13 | let mut manifest_dir = PathBuf::from( | ||
14 | env::var("CARGO_MANIFEST_DIR").expect("`CARGO_MANIFEST_DIR` is always set by cargo."), | ||
15 | ); | ||
16 | |||
17 | while manifest_dir.parent().is_some() { | ||
18 | if manifest_dir.join(".git/HEAD").exists() { | ||
19 | let git_dir = manifest_dir.join(".git"); | ||
20 | |||
21 | println!("cargo:rerun-if-changed={}", git_dir.join("HEAD").display()); | ||
22 | // current branch ref | ||
23 | if let Ok(output) = | ||
24 | Command::new("git").args(&["rev-parse", "--symbolic-full-name", "HEAD"]).output() | ||
25 | { | ||
26 | if let Ok(ref_link) = String::from_utf8(output.stdout) { | ||
27 | println!("cargo:rerun-if-changed={}", git_dir.join(ref_link).display()); | ||
28 | } | ||
29 | } | ||
30 | return; | ||
31 | } | ||
32 | |||
33 | manifest_dir.pop(); | ||
34 | } | ||
35 | println!("cargo:warning=Could not find `.git/HEAD` from manifest dir!"); | ||
36 | } | ||
37 | |||
10 | fn rev() -> Option<String> { | 38 | fn rev() -> Option<String> { |
11 | let output = Command::new("git").args(&["rev-parse", "HEAD"]).output().ok()?; | 39 | let output = Command::new("git").args(&["rev-parse", "HEAD"]).output().ok()?; |
12 | let stdout = String::from_utf8(output.stdout).ok()?; | 40 | let stdout = String::from_utf8(output.stdout).ok()?; |