4937: Allow overriding rust-analyzer display version r=matklad a=oxalica

The build script invokes `git` for version information which is displayed when rust-analyzer is called with `--version`. But in build environment without `git` or when the source code is not a git repo, there's no way to manually specify the version information.

This patch respects environment variable ~`REV`~ `RUST_ANALYZER_REV` in compile time for overriding.

Related: https://github.com/NixOS/nixpkgs/pull/90976

Co-authored-by: oxalica <oxalicc@pm.me>
This commit is contained in:
bors[bot] 2020-06-19 13:43:42 +00:00 committed by GitHub
commit ec6df5d3e8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -5,11 +5,14 @@ use std::{env, path::PathBuf, process::Command};
fn main() {
set_rerun();
let rev = rev().unwrap_or_else(|| "???????".to_string());
let rev =
env::var("RUST_ANALYZER_REV").ok().or_else(rev).unwrap_or_else(|| "???????".to_string());
println!("cargo:rustc-env=REV={}", rev)
}
fn set_rerun() {
println!("cargo:rerun-if-env-changed=RUST_ANALYZER_REV");
let mut manifest_dir = PathBuf::from(
env::var("CARGO_MANIFEST_DIR").expect("`CARGO_MANIFEST_DIR` is always set by cargo."),
);