aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--crates/rust-analyzer/build.rs62
-rw-r--r--xtask/src/dist.rs8
2 files changed, 46 insertions, 24 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}
diff --git a/xtask/src/dist.rs b/xtask/src/dist.rs
index 1e26f2ecc..d1c005954 100644
--- a/xtask/src/dist.rs
+++ b/xtask/src/dist.rs
@@ -7,7 +7,7 @@ use std::{
7 7
8use anyhow::Result; 8use anyhow::Result;
9use flate2::{write::GzEncoder, Compression}; 9use flate2::{write::GzEncoder, Compression};
10use xshell::{cmd, cp, mkdir_p, pushd, read_file, rm_rf, write_file}; 10use xshell::{cmd, cp, mkdir_p, pushd, pushenv, read_file, rm_rf, write_file};
11 11
12use crate::{date_iso, project_root}; 12use crate::{date_iso, project_root};
13 13
@@ -26,7 +26,8 @@ impl DistCmd {
26 let release_tag = if self.nightly { "nightly".to_string() } else { date_iso()? }; 26 let release_tag = if self.nightly { "nightly".to_string() } else { date_iso()? };
27 dist_client(&version, &release_tag)?; 27 dist_client(&version, &release_tag)?;
28 } 28 }
29 dist_server()?; 29 let release_channel = if self.nightly { "nightly" } else { "stable" };
30 dist_server(release_channel)?;
30 Ok(()) 31 Ok(())
31 } 32 }
32} 33}
@@ -59,7 +60,8 @@ fn dist_client(version: &str, release_tag: &str) -> Result<()> {
59 Ok(()) 60 Ok(())
60} 61}
61 62
62fn dist_server() -> Result<()> { 63fn dist_server(release_channel: &str) -> Result<()> {
64 let _e = pushenv("RUST_ANALYZER_CHANNEL", release_channel);
63 let target = get_target(); 65 let target = get_target();
64 if target.contains("-linux-gnu") || target.contains("-linux-musl") { 66 if target.contains("-linux-gnu") || target.contains("-linux-musl") {
65 env::set_var("CC", "clang"); 67 env::set_var("CC", "clang");