mirror of
https://github.com/rust-lang/rust-clippy
synced 2024-11-10 07:04:18 +00:00
Cleanup rustc_tool_util
and add a convenient macro for build.rs
This commit is contained in:
parent
73efce9ee6
commit
aa66212e29
7 changed files with 45 additions and 47 deletions
|
@ -23,7 +23,7 @@ path = "src/driver.rs"
|
||||||
[dependencies]
|
[dependencies]
|
||||||
clippy_lints = { path = "clippy_lints" }
|
clippy_lints = { path = "clippy_lints" }
|
||||||
semver = "1.0"
|
semver = "1.0"
|
||||||
rustc_tools_util = "0.2.1"
|
rustc_tools_util = {version = "0.2.1", path = "./rustc_tools_util"}
|
||||||
tempfile = { version = "3.2", optional = true }
|
tempfile = { version = "3.2", optional = true }
|
||||||
termize = "0.1"
|
termize = "0.1"
|
||||||
|
|
||||||
|
@ -56,7 +56,7 @@ tokio = { version = "1", features = ["io-util"] }
|
||||||
rustc-semver = "1.1"
|
rustc-semver = "1.1"
|
||||||
|
|
||||||
[build-dependencies]
|
[build-dependencies]
|
||||||
rustc_tools_util = "0.2.1"
|
rustc_tools_util = {version = "0.2.1", path = "./rustc_tools_util"}
|
||||||
|
|
||||||
[features]
|
[features]
|
||||||
deny-warnings = ["clippy_lints/deny-warnings"]
|
deny-warnings = ["clippy_lints/deny-warnings"]
|
||||||
|
|
14
build.rs
14
build.rs
|
@ -3,17 +3,5 @@ fn main() {
|
||||||
println!("cargo:rustc-env=PROFILE={}", std::env::var("PROFILE").unwrap());
|
println!("cargo:rustc-env=PROFILE={}", std::env::var("PROFILE").unwrap());
|
||||||
// Don't rebuild even if nothing changed
|
// Don't rebuild even if nothing changed
|
||||||
println!("cargo:rerun-if-changed=build.rs");
|
println!("cargo:rerun-if-changed=build.rs");
|
||||||
// forward git repo hashes we build at
|
rustc_tools_util::setup_version_info!();
|
||||||
println!(
|
|
||||||
"cargo:rustc-env=GIT_HASH={}",
|
|
||||||
rustc_tools_util::get_commit_hash().unwrap_or_default()
|
|
||||||
);
|
|
||||||
println!(
|
|
||||||
"cargo:rustc-env=COMMIT_DATE={}",
|
|
||||||
rustc_tools_util::get_commit_date().unwrap_or_default()
|
|
||||||
);
|
|
||||||
println!(
|
|
||||||
"cargo:rustc-env=RUSTC_RELEASE_CHANNEL={}",
|
|
||||||
rustc_tools_util::get_channel()
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,36 +20,29 @@ rustc_tools_util = "0.2.1"
|
||||||
````
|
````
|
||||||
|
|
||||||
In `build.rs`, generate the data in your `main()`
|
In `build.rs`, generate the data in your `main()`
|
||||||
````rust
|
|
||||||
fn main() {
|
|
||||||
println!(
|
|
||||||
"cargo:rustc-env=GIT_HASH={}",
|
|
||||||
rustc_tools_util::get_commit_hash().unwrap_or_default()
|
|
||||||
);
|
|
||||||
println!(
|
|
||||||
"cargo:rustc-env=COMMIT_DATE={}",
|
|
||||||
rustc_tools_util::get_commit_date().unwrap_or_default()
|
|
||||||
);
|
|
||||||
println!(
|
|
||||||
"cargo:rustc-env=RUSTC_RELEASE_CHANNEL={}",
|
|
||||||
rustc_tools_util::get_channel().unwrap_or_default()
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
````
|
```rust
|
||||||
|
fn main() {
|
||||||
|
rustc_tools_util::setup_version_info!();
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
Use the version information in your main.rs
|
Use the version information in your main.rs
|
||||||
````rust
|
|
||||||
use rustc_tools_util::*;
|
|
||||||
|
|
||||||
|
```rust
|
||||||
fn show_version() {
|
fn show_version() {
|
||||||
let version_info = rustc_tools_util::get_version_info!();
|
let version_info = rustc_tools_util::get_version_info!();
|
||||||
println!("{}", version_info);
|
println!("{}", version_info);
|
||||||
}
|
}
|
||||||
````
|
```
|
||||||
This gives the following output in clippy:
|
|
||||||
`clippy 0.0.212 (a416c5e 2018-12-14)`
|
|
||||||
|
|
||||||
|
This gives the following output in clippy:
|
||||||
|
`clippy 0.1.66 (a28f3c8 2022-11-20)`
|
||||||
|
|
||||||
|
## Repository
|
||||||
|
|
||||||
|
This project is part of the rust-lang/rust-clippy repository. The source code
|
||||||
|
can be found under `./rustc_tools_util/`.
|
||||||
|
|
||||||
## License
|
## License
|
||||||
|
|
||||||
|
|
|
@ -2,19 +2,21 @@
|
||||||
|
|
||||||
use std::env;
|
use std::env;
|
||||||
|
|
||||||
|
/// This macro creates the version string during compilation from the
|
||||||
|
/// current environment
|
||||||
#[macro_export]
|
#[macro_export]
|
||||||
macro_rules! get_version_info {
|
macro_rules! get_version_info {
|
||||||
() => {{
|
() => {{
|
||||||
let major = env!("CARGO_PKG_VERSION_MAJOR").parse::<u8>().unwrap();
|
let major = std::env!("CARGO_PKG_VERSION_MAJOR").parse::<u8>().unwrap();
|
||||||
let minor = env!("CARGO_PKG_VERSION_MINOR").parse::<u8>().unwrap();
|
let minor = std::env!("CARGO_PKG_VERSION_MINOR").parse::<u8>().unwrap();
|
||||||
let patch = env!("CARGO_PKG_VERSION_PATCH").parse::<u16>().unwrap();
|
let patch = std::env!("CARGO_PKG_VERSION_PATCH").parse::<u16>().unwrap();
|
||||||
let crate_name = String::from(env!("CARGO_PKG_NAME"));
|
let crate_name = String::from(std::env!("CARGO_PKG_NAME"));
|
||||||
|
|
||||||
let host_compiler = option_env!("RUSTC_RELEASE_CHANNEL").map(str::to_string);
|
let host_compiler = std::option_env!("RUSTC_RELEASE_CHANNEL").map(str::to_string);
|
||||||
let commit_hash = option_env!("GIT_HASH").map(str::to_string);
|
let commit_hash = std::option_env!("GIT_HASH").map(str::to_string);
|
||||||
let commit_date = option_env!("COMMIT_DATE").map(str::to_string);
|
let commit_date = std::option_env!("COMMIT_DATE").map(str::to_string);
|
||||||
|
|
||||||
VersionInfo {
|
$crate::VersionInfo {
|
||||||
major,
|
major,
|
||||||
minor,
|
minor,
|
||||||
patch,
|
patch,
|
||||||
|
@ -26,6 +28,24 @@ macro_rules! get_version_info {
|
||||||
}};
|
}};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// This macro can be used in `build.rs` to automatically set the needed
|
||||||
|
/// environment values, namely `GIT_HASH`, `COMMIT_DATE` and
|
||||||
|
/// `RUSTC_RELEASE_CHANNEL`
|
||||||
|
#[macro_export]
|
||||||
|
macro_rules! setup_version_info {
|
||||||
|
() => {{
|
||||||
|
println!(
|
||||||
|
"cargo:rustc-env=GIT_HASH={}",
|
||||||
|
$crate::get_commit_hash().unwrap_or_default()
|
||||||
|
);
|
||||||
|
println!(
|
||||||
|
"cargo:rustc-env=COMMIT_DATE={}",
|
||||||
|
$crate::get_commit_date().unwrap_or_default()
|
||||||
|
);
|
||||||
|
println!("cargo:rustc-env=RUSTC_RELEASE_CHANNEL={}", $crate::get_channel());
|
||||||
|
}};
|
||||||
|
}
|
||||||
|
|
||||||
// some code taken and adapted from RLS and cargo
|
// some code taken and adapted from RLS and cargo
|
||||||
pub struct VersionInfo {
|
pub struct VersionInfo {
|
||||||
pub major: u8,
|
pub major: u8,
|
||||||
|
|
|
@ -18,7 +18,6 @@ extern crate rustc_span;
|
||||||
use rustc_interface::interface;
|
use rustc_interface::interface;
|
||||||
use rustc_session::parse::ParseSess;
|
use rustc_session::parse::ParseSess;
|
||||||
use rustc_span::symbol::Symbol;
|
use rustc_span::symbol::Symbol;
|
||||||
use rustc_tools_util::VersionInfo;
|
|
||||||
|
|
||||||
use std::borrow::Cow;
|
use std::borrow::Cow;
|
||||||
use std::env;
|
use std::env;
|
||||||
|
|
|
@ -2,7 +2,6 @@
|
||||||
// warn on lints, that are included in `rust-lang/rust`s bootstrap
|
// warn on lints, that are included in `rust-lang/rust`s bootstrap
|
||||||
#![warn(rust_2018_idioms, unused_lifetimes)]
|
#![warn(rust_2018_idioms, unused_lifetimes)]
|
||||||
|
|
||||||
use rustc_tools_util::VersionInfo;
|
|
||||||
use std::env;
|
use std::env;
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
use std::process::{self, Command};
|
use std::process::{self, Command};
|
||||||
|
|
|
@ -2,7 +2,6 @@
|
||||||
#![warn(rust_2018_idioms, unused_lifetimes)]
|
#![warn(rust_2018_idioms, unused_lifetimes)]
|
||||||
#![allow(clippy::single_match_else)]
|
#![allow(clippy::single_match_else)]
|
||||||
|
|
||||||
use rustc_tools_util::VersionInfo;
|
|
||||||
use std::fs;
|
use std::fs;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
|
Loading…
Reference in a new issue