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>
This commit is contained in:
commit
4d110dd118
@ -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()?;
|
||||
let stdout = String::from_utf8(output.stdout).ok()?;
|
||||
Some(stdout)
|
||||
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.trim().to_string())
|
||||
}
|
||||
|
@ -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");
|
||||
|
Loading…
x
Reference in New Issue
Block a user