diff options
| author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2021-04-24 10:37:42 +0000 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-04-24 10:37:42 +0000 |
| commit | 4d110dd118e42a355ca8db41c7fdbf4371c45105 (patch) | |
| tree | f650e0ecf0aa8a9fad8d205471cf1a37b8efda74 | |
| parent | 43ea1bb9b96138b7967385260a59ea2c02b1a2f6 (diff) | |
| parent | 8d54fd105cbeb159c39fbc803ed45d450f0fe000 (diff) | |
| download | rust-4d110dd118e42a355ca8db41c7fdbf4371c45105.tar.gz rust-4d110dd118e42a355ca8db41c7fdbf4371c45105.zip | |
Merge #8643
8643: fix: correct version string to contain hash, build date and channel r=matklad a=matklad bors r+ 🤖 Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>
| -rw-r--r-- | crates/rust-analyzer/build.rs | 62 | ||||
| -rw-r--r-- | xtask/src/dist.rs | 8 |
2 files changed, 46 insertions, 24 deletions
diff --git a/crates/rust-analyzer/build.rs b/crates/rust-analyzer/build.rs index 13b90389197..25627c7e9b2 100644 --- a/crates/rust-analyzer/build.rs +++ b/crates/rust-analyzer/build.rs @@ -1,13 +1,10 @@ -//! Just embed git-hash to `--version` +//! Construct version in the `commit-hash date chanel` format use std::{env, path::PathBuf, process::Command}; fn main() { set_rerun(); - - let rev = - env::var("RUST_ANALYZER_REV").ok().or_else(rev).unwrap_or_else(|| "???????".to_string()); - println!("cargo:rustc-env=REV={}", rev) + println!("cargo:rustc-env=REV={}", rev()) } fn set_rerun() { @@ -18,29 +15,52 @@ fn set_rerun() { ); while manifest_dir.parent().is_some() { - if manifest_dir.join(".git/HEAD").exists() { - let git_dir = manifest_dir.join(".git"); - - println!("cargo:rerun-if-changed={}", git_dir.join("HEAD").display()); - // current branch ref - if let Ok(output) = - Command::new("git").args(&["rev-parse", "--symbolic-full-name", "HEAD"]).output() - { - if let Ok(ref_link) = String::from_utf8(output.stdout) { - println!("cargo:rerun-if-changed={}", git_dir.join(ref_link).display()); - } - } + let head_ref = manifest_dir.join(".git/HEAD"); + if head_ref.exists() { + println!("cargo:rerun-if-changed={}", head_ref.display()); return; } manifest_dir.pop(); } + println!("cargo:warning=Could not find `.git/HEAD` from manifest dir!"); } -fn rev() -> Option<String> { - let output = - Command::new("git").args(&["describe", "--tags", "--exclude", "nightly"]).output().ok()?; +fn rev() -> String { + if let Ok(rev) = env::var("RUST_ANALYZER_REV") { + return rev; + } + + if let Some(commit_hash) = commit_hash() { + let mut buf = commit_hash; + + if let Some(date) = build_date() { + buf.push(' '); + buf.push_str(&date); + } + + let channel = env::var("RUST_ANALYZER_CHANNEL").unwrap_or_else(|_| "dev".to_string()); + buf.push(' '); + buf.push_str(&channel); + + return buf; + } + + "???????".to_string() +} + +fn commit_hash() -> Option<String> { + output_to_string("git rev-parse --short HEAD") +} + +fn build_date() -> Option<String> { + output_to_string("date --iso --utc") +} + +fn output_to_string(command: &str) -> Option<String> { + let args = command.split_ascii_whitespace().collect::<Vec<_>>(); + let output = Command::new(args[0]).args(&args[1..]).output().ok()?; let stdout = String::from_utf8(output.stdout).ok()?; - Some(stdout) + Some(stdout.trim().to_string()) } diff --git a/xtask/src/dist.rs b/xtask/src/dist.rs index 1e26f2eccf4..d1c00595438 100644 --- a/xtask/src/dist.rs +++ b/xtask/src/dist.rs @@ -7,7 +7,7 @@ use std::{ use anyhow::Result; use flate2::{write::GzEncoder, Compression}; -use xshell::{cmd, cp, mkdir_p, pushd, read_file, rm_rf, write_file}; +use xshell::{cmd, cp, mkdir_p, pushd, pushenv, read_file, rm_rf, write_file}; use crate::{date_iso, project_root}; @@ -26,7 +26,8 @@ impl DistCmd { let release_tag = if self.nightly { "nightly".to_string() } else { date_iso()? }; dist_client(&version, &release_tag)?; } - dist_server()?; + let release_channel = if self.nightly { "nightly" } else { "stable" }; + dist_server(release_channel)?; Ok(()) } } @@ -59,7 +60,8 @@ fn dist_client(version: &str, release_tag: &str) -> Result<()> { Ok(()) } -fn dist_server() -> Result<()> { +fn dist_server(release_channel: &str) -> Result<()> { + let _e = pushenv("RUST_ANALYZER_CHANNEL", release_channel); let target = get_target(); if target.contains("-linux-gnu") || target.contains("-linux-musl") { env::set_var("CC", "clang"); |
