]> git.lizzy.rs Git - rust.git/blob - crates/rust-analyzer/build.rs
Move highlight configuration from protocol into the feature
[rust.git] / crates / rust-analyzer / build.rs
1 //! Construct version in the `commit-hash date channel` format
2
3 use std::{env, path::PathBuf, process::Command};
4
5 fn main() {
6     set_rerun();
7     set_commit_info();
8     if option_env!("CFG_RELEASE").is_none() {
9         println!("cargo:rustc-env=POKE_RA_DEVS=1");
10     }
11 }
12
13 fn set_rerun() {
14     println!("cargo:rerun-if-env-changed=CFG_RELEASE");
15
16     let mut manifest_dir = PathBuf::from(
17         env::var("CARGO_MANIFEST_DIR").expect("`CARGO_MANIFEST_DIR` is always set by cargo."),
18     );
19
20     while manifest_dir.parent().is_some() {
21         let head_ref = manifest_dir.join(".git/HEAD");
22         if head_ref.exists() {
23             println!("cargo:rerun-if-changed={}", head_ref.display());
24             return;
25         }
26
27         manifest_dir.pop();
28     }
29
30     println!("cargo:warning=Could not find `.git/HEAD` from manifest dir!");
31 }
32
33 fn set_commit_info() {
34     let output = match Command::new("git")
35         .arg("log")
36         .arg("-1")
37         .arg("--date=short")
38         .arg("--format=%H %h %cd")
39         .output()
40     {
41         Ok(output) if output.status.success() => output,
42         _ => return,
43     };
44     let stdout = String::from_utf8(output.stdout).unwrap();
45     let mut parts = stdout.split_whitespace();
46     let mut next = || parts.next().unwrap();
47     println!("cargo:rustc-env=RA_COMMIT_HASH={}", next());
48     println!("cargo:rustc-env=RA_COMMIT_SHORT_HASH={}", next());
49     println!("cargo:rustc-env=RA_COMMIT_DATE={}", next())
50 }