Skip to content

Commit 8cac5b0

Browse files
ignatzflip1995
authored andcommitted
rustc_tools_util: Change release channel default to stable
Fixes the exposed release channel Bump version to 0.4.1
1 parent 8ae4750 commit 8cac5b0

File tree

5 files changed

+44
-27
lines changed

5 files changed

+44
-27
lines changed

Cargo.toml

+2-2
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ path = "src/driver.rs"
2525
[dependencies]
2626
clippy_config = { path = "clippy_config" }
2727
clippy_lints = { path = "clippy_lints" }
28-
rustc_tools_util = "0.4.0"
28+
rustc_tools_util = { path = "rustc_tools_util", version = "0.4.1" }
2929
tempfile = { version = "3.3", optional = true }
3030
termize = "0.1"
3131
color-print = "0.3.4"
@@ -54,7 +54,7 @@ parking_lot = "0.12"
5454
tokio = { version = "1", features = ["io-util"] }
5555

5656
[build-dependencies]
57-
rustc_tools_util = "0.4.0"
57+
rustc_tools_util = { path = "rustc_tools_util", version = "0.4.1" }
5858

5959
[features]
6060
integration = ["tempfile"]

rustc_tools_util/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "rustc_tools_util"
3-
version = "0.4.0"
3+
version = "0.4.1"
44
description = "small helper to generate version information for git packages"
55
repository = "https://github.com/rust-lang/rust-clippy"
66
readme = "README.md"

rustc_tools_util/README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,10 @@ build = "build.rs"
1313
List rustc_tools_util as regular AND build dependency.
1414
````toml
1515
[dependencies]
16-
rustc_tools_util = "0.4.0"
16+
rustc_tools_util = "0.4.1"
1717

1818
[build-dependencies]
19-
rustc_tools_util = "0.4.0"
19+
rustc_tools_util = "0.4.1"
2020
````
2121

2222
In `build.rs`, generate the data in your `main()`

rustc_tools_util/src/lib.rs

+33-22
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,8 @@ macro_rules! get_version_info {
2828
}};
2929
}
3030

31-
/// This macro can be used in `build.rs` to automatically set the needed
32-
/// environment values, namely `GIT_HASH`, `COMMIT_DATE` and
33-
/// `RUSTC_RELEASE_CHANNEL`
31+
/// This macro can be used in `build.rs` to automatically set the needed environment values, namely
32+
/// `GIT_HASH`, `COMMIT_DATE` and `RUSTC_RELEASE_CHANNEL`
3433
#[macro_export]
3534
macro_rules! setup_version_info {
3635
() => {{
@@ -43,7 +42,11 @@ macro_rules! setup_version_info {
4342
"cargo:rustc-env=COMMIT_DATE={}",
4443
$crate::get_commit_date().unwrap_or_default()
4544
);
46-
println!("cargo:rustc-env=RUSTC_RELEASE_CHANNEL={}", $crate::get_channel());
45+
let compiler_version = $crate::get_compiler_version();
46+
println!(
47+
"cargo:rustc-env=RUSTC_RELEASE_CHANNEL={}",
48+
$crate::get_channel(compiler_version)
49+
);
4750
}};
4851
}
4952

@@ -87,16 +90,17 @@ impl std::fmt::Debug for VersionInfo {
8790
"VersionInfo {{ crate_name: \"{}\", major: {}, minor: {}, patch: {}",
8891
self.crate_name, self.major, self.minor, self.patch,
8992
)?;
90-
if self.commit_hash.is_some() {
91-
write!(
92-
f,
93-
", commit_hash: \"{}\", commit_date: \"{}\" }}",
94-
self.commit_hash.clone().unwrap_or_default().trim(),
95-
self.commit_date.clone().unwrap_or_default().trim()
96-
)?;
97-
} else {
98-
write!(f, " }}")?;
93+
if let Some(ref commit_hash) = self.commit_hash {
94+
write!(f, ", commit_hash: \"{}\"", commit_hash.trim(),)?;
95+
}
96+
if let Some(ref commit_date) = self.commit_date {
97+
write!(f, ", commit_date: \"{}\"", commit_date.trim())?;
9998
}
99+
if let Some(ref host_compiler) = self.host_compiler {
100+
write!(f, ", host_compiler: \"{}\"", host_compiler.trim())?;
101+
}
102+
103+
write!(f, " }}")?;
100104

101105
Ok(())
102106
}
@@ -152,22 +156,27 @@ pub fn get_commit_date() -> Option<String> {
152156
}
153157

154158
#[must_use]
155-
pub fn get_channel() -> String {
159+
pub fn get_compiler_version() -> Option<String> {
160+
get_output("rustc", &["-V"])
161+
}
162+
163+
#[must_use]
164+
pub fn get_channel(compiler_version: Option<String>) -> String {
156165
if let Ok(channel) = std::env::var("CFG_RELEASE_CHANNEL") {
157166
return channel;
158167
}
159168

160169
// if that failed, try to ask rustc -V, do some parsing and find out
161-
if let Some(rustc_output) = get_output("rustc", &["-V"]) {
170+
if let Some(rustc_output) = compiler_version {
162171
if rustc_output.contains("beta") {
163172
return String::from("beta");
164-
} else if rustc_output.contains("stable") {
165-
return String::from("stable");
173+
} else if rustc_output.contains("nightly") {
174+
return String::from("nightly");
166175
}
167176
}
168177

169-
// default to nightly
170-
String::from("nightly")
178+
// default to stable
179+
String::from("stable")
171180
}
172181

173182
#[cfg(test)]
@@ -179,17 +188,19 @@ mod test {
179188
let vi = get_version_info!();
180189
assert_eq!(vi.major, 0);
181190
assert_eq!(vi.minor, 4);
182-
assert_eq!(vi.patch, 0);
191+
assert_eq!(vi.patch, 1);
183192
assert_eq!(vi.crate_name, "rustc_tools_util");
184193
// hard to make positive tests for these since they will always change
185194
assert!(vi.commit_hash.is_none());
186195
assert!(vi.commit_date.is_none());
196+
197+
assert!(vi.host_compiler.is_none());
187198
}
188199

189200
#[test]
190201
fn test_display_local() {
191202
let vi = get_version_info!();
192-
assert_eq!(vi.to_string(), "rustc_tools_util 0.4.0");
203+
assert_eq!(vi.to_string(), "rustc_tools_util 0.4.1");
193204
}
194205

195206
#[test]
@@ -198,7 +209,7 @@ mod test {
198209
let s = format!("{vi:?}");
199210
assert_eq!(
200211
s,
201-
"VersionInfo { crate_name: \"rustc_tools_util\", major: 0, minor: 4, patch: 0 }"
212+
"VersionInfo { crate_name: \"rustc_tools_util\", major: 0, minor: 4, patch: 1 }"
202213
);
203214
}
204215
}

tests/versioncheck.rs

+6
Original file line numberDiff line numberDiff line change
@@ -90,3 +90,9 @@ fn check_that_clippy_has_the_same_major_version_as_rustc() {
9090
},
9191
}
9292
}
93+
94+
#[test]
95+
fn check_host_compiler() {
96+
let version = rustc_tools_util::get_version_info!();
97+
assert_eq!(version.host_compiler, Some("nightly".to_string()));
98+
}

0 commit comments

Comments
 (0)