Skip to content
This repository was archived by the owner on Dec 29, 2022. It is now read-only.

Commit 2447786

Browse files
committedSep 22, 2018
use clippy rustc_tools_util to get rls version info and update clippy submodule
1 parent ce1ff4e commit 2447786

File tree

4 files changed

+28
-56
lines changed

4 files changed

+28
-56
lines changed
 

‎Cargo.lock

+10-3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎Cargo.toml

+5-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ build = "build.rs"
1313
[dependencies]
1414
cargo = { git = "https://github.com/rust-lang/cargo", rev = "04cec5fc10a7bbe1dccaad5729eff1823ef2608c" }
1515
cargo_metadata = "0.6"
16-
clippy_lints = { git = "https://github.com/rust-lang-nursery/rust-clippy", rev = "183639b70bacf457920694d78a19cefe3565e1c0", optional = true }
16+
clippy_lints = { git = "https://github.com/rust-lang-nursery/rust-clippy", rev = "125907ad08853b92d35e86aecebcf0f784f348d5", optional = true }
1717
env_logger = "0.5"
1818
failure = "0.1.1"
1919
itertools = "0.7.3"
@@ -31,6 +31,7 @@ rls-data = { version = "0.18", features = ["serialize-serde", "serialize-rustc"]
3131
rls-rustc = "0.5.0"
3232
rls-span = { version = "0.4", features = ["serialize-serde"] }
3333
rls-vfs = "0.4.6"
34+
rustc_tools_util = { git = "https://github.com/rust-lang-nursery/rust-clippy", rev = "125907ad08853b92d35e86aecebcf0f784f348d5" }
3435
rustfmt-nightly = "0.99.4"
3536
rustc-serialize = "0.3"
3637
serde = "1.0"
@@ -47,6 +48,9 @@ crossbeam-channel = "0.2.3"
4748
# for more information.
4849
rustc-workspace-hack = "1.0.0"
4950

51+
[build-dependencies]
52+
rustc_tools_util = { git = "https://github.com/rust-lang-nursery/rust-clippy", rev = "125907ad08853b92d35e86aecebcf0f784f348d5" }
53+
5054
[features]
5155
default = ["clippy"]
5256
clippy = ["clippy_lints"]

‎build.rs

+8-45
Original file line numberDiff line numberDiff line change
@@ -8,53 +8,16 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
use std::env;
12-
use std::fs::File;
13-
use std::io::Write;
14-
use std::path::PathBuf;
15-
use std::process::Command;
16-
1711
fn main() {
1812
println!("cargo:rerun-if-changed=build.rs");
1913
println!("cargo:rerun-if-env-changed=CFG_RELEASE_CHANNEL");
2014

21-
let out_dir = PathBuf::from(env::var_os("OUT_DIR").unwrap());
22-
23-
File::create(out_dir.join("commit-info.txt"))
24-
.unwrap()
25-
.write_all(commit_info().as_bytes())
26-
.unwrap();
27-
}
28-
29-
// Try to get hash and date of the last commit on a best effort basis. If anything goes wrong
30-
// (git not installed or if this is not a git repository) just return an empty string.
31-
fn commit_info() -> String {
32-
match (commit_hash(), commit_date()) {
33-
(Some(hash), Some(date)) => format!("{} ({} {})", channel(), hash.trim_right(), date),
34-
_ => String::new(),
35-
}
36-
}
37-
38-
fn channel() -> String {
39-
if let Ok(channel) = env::var("CFG_RELEASE_CHANNEL") {
40-
channel
41-
} else {
42-
"nightly".to_owned()
43-
}
44-
}
45-
46-
fn commit_hash() -> Option<String> {
47-
Command::new("git")
48-
.args(&["rev-parse", "--short", "HEAD"])
49-
.output()
50-
.ok()
51-
.and_then(|r| String::from_utf8(r.stdout).ok())
52-
}
53-
54-
fn commit_date() -> Option<String> {
55-
Command::new("git")
56-
.args(&["log", "-1", "--date=short", "--pretty=format:%cd"])
57-
.output()
58-
.ok()
59-
.and_then(|r| String::from_utf8(r.stdout).ok())
15+
println!(
16+
"cargo:rustc-env=GIT_HASH={}",
17+
rustc_tools_util::get_commit_hash().unwrap_or_default()
18+
);
19+
println!(
20+
"cargo:rustc-env=COMMIT_DATE={}",
21+
rustc_tools_util::get_commit_date().unwrap_or_default()
22+
);
6023
}

‎src/main.rs

+5-7
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
extern "C" {}
3939

4040
use env_logger;
41+
use rustc_tools_util::*;
4142

4243
use std::env;
4344
use std::sync::Arc;
@@ -83,7 +84,7 @@ fn main_inner() -> i32 {
8384
if let Some(first_arg) = ::std::env::args().nth(1) {
8485
return match first_arg.as_str() {
8586
"--version" | "-V" => {
86-
println!("rls-preview {}", version());
87+
println!("{}", version().replace("rls", "rls-preview"));
8788
0
8889
}
8990
"--help" | "-h" => {
@@ -111,12 +112,9 @@ fn main_inner() -> i32 {
111112
server::run_server(analysis, vfs)
112113
}
113114

114-
fn version() -> &'static str {
115-
concat!(
116-
env!("CARGO_PKG_VERSION"),
117-
"-",
118-
include_str!(concat!(env!("OUT_DIR"), "/commit-info.txt"))
119-
)
115+
fn version() -> String {
116+
let version = rustc_tools_util::get_version_info!();
117+
version.to_string()
120118
}
121119

122120
fn help() -> &'static str {

0 commit comments

Comments
 (0)
This repository has been archived.