aboutsummaryrefslogtreecommitdiff
path: root/crates
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2021-04-24 11:36:45 +0100
committerAleksey Kladov <[email protected]>2021-04-24 11:36:45 +0100
commit8d54fd105cbeb159c39fbc803ed45d450f0fe000 (patch)
treef650e0ecf0aa8a9fad8d205471cf1a37b8efda74 /crates
parent43ea1bb9b96138b7967385260a59ea2c02b1a2f6 (diff)
fix: correct version string to contain hash, build date and channel
Diffstat (limited to 'crates')
-rw-r--r--crates/rust-analyzer/build.rs62
1 files changed, 41 insertions, 21 deletions
diff --git a/crates/rust-analyzer/build.rs b/crates/rust-analyzer/build.rs
index 13b903891..25627c7e9 100644
--- a/crates/rust-analyzer/build.rs
+++ b/crates/rust-analyzer/build.rs
@@ -1,13 +1,10 @@
1//! Just embed git-hash to `--version` 1//! Construct version in the `commit-hash date chanel` format
2 2
3use std::{env, path::PathBuf, process::Command}; 3use std::{env, path::PathBuf, process::Command};
4 4
5fn main() { 5fn main() {
6 set_rerun(); 6 set_rerun();
7 7 println!("cargo:rustc-env=REV={}", rev())
8 let rev =
9 env::var("RUST_ANALYZER_REV").ok().or_else(rev).unwrap_or_else(|| "???????".to_string());
10 println!("cargo:rustc-env=REV={}", rev)
11} 8}
12 9
13fn set_rerun() { 10fn set_rerun() {
@@ -18,29 +15,52 @@ fn set_rerun() {
18 ); 15 );
19 16
20 while manifest_dir.parent().is_some() { 17 while manifest_dir.parent().is_some() {
21 if manifest_dir.join(".git/HEAD").exists() { 18 let head_ref = manifest_dir.join(".git/HEAD");
22 let git_dir = manifest_dir.join(".git"); 19 if head_ref.exists() {
23 20 println!("cargo:rerun-if-changed={}", head_ref.display());
24 println!("cargo:rerun-if-changed={}", git_dir.join("HEAD").display());
25 // current branch ref
26 if let Ok(output) =
27 Command::new("git").args(&["rev-parse", "--symbolic-full-name", "HEAD"]).output()
28 {
29 if let Ok(ref_link) = String::from_utf8(output.stdout) {
30 println!("cargo:rerun-if-changed={}", git_dir.join(ref_link).display());
31 }
32 }
33 return; 21 return;
34 } 22 }
35 23
36 manifest_dir.pop(); 24 manifest_dir.pop();
37 } 25 }
26
38 println!("cargo:warning=Could not find `.git/HEAD` from manifest dir!"); 27 println!("cargo:warning=Could not find `.git/HEAD` from manifest dir!");
39} 28}
40 29
41fn rev() -> Option<String> { 30fn rev() -> String {
42 let output = 31 if let Ok(rev) = env::var("RUST_ANALYZER_REV") {
43 Command::new("git").args(&["describe", "--tags", "--exclude", "nightly"]).output().ok()?; 32 return rev;
33 }
34
35 if let Some(commit_hash) = commit_hash() {
36 let mut buf = commit_hash;
37
38 if let Some(date) = build_date() {
39 buf.push(' ');
40 buf.push_str(&date);
41 }
42
43 let channel = env::var("RUST_ANALYZER_CHANNEL").unwrap_or_else(|_| "dev".to_string());
44 buf.push(' ');
45 buf.push_str(&channel);
46
47 return buf;
48 }
49
50 "???????".to_string()
51}
52
53fn commit_hash() -> Option<String> {
54 output_to_string("git rev-parse --short HEAD")
55}
56
57fn build_date() -> Option<String> {
58 output_to_string("date --iso --utc")
59}
60
61fn output_to_string(command: &str) -> Option<String> {
62 let args = command.split_ascii_whitespace().collect::<Vec<_>>();
63 let output = Command::new(args[0]).args(&args[1..]).output().ok()?;
44 let stdout = String::from_utf8(output.stdout).ok()?; 64 let stdout = String::from_utf8(output.stdout).ok()?;
45 Some(stdout) 65 Some(stdout.trim().to_string())
46} 66}