Skip to content

Commit 258a0fb

Browse files
authored
Rollup merge of #104552 - DebugSteven:warn-newer-x, r=jyn514
warn newer available version of the x tool This PR adds a check to `tidy` to assert that the installed version of `x` is equal to the version in `src/tools/x/Cargo.toml`. It adds a `--wrapper-version` argument to `x` to determine the version at runtime, . It does not warn if `x` has not yet been installed, on the assumption that the user isn't interested in using it.
2 parents b435960 + 85f649f commit 258a0fb

File tree

7 files changed

+90
-13
lines changed

7 files changed

+90
-13
lines changed

Cargo.lock

+11-10
Original file line numberDiff line numberDiff line change
@@ -4805,18 +4805,18 @@ checksum = "1ef965a420fe14fdac7dd018862966a4c14094f900e1650bbc71ddd7d580c8af"
48054805

48064806
[[package]]
48074807
name = "semver"
4808-
version = "1.0.12"
4808+
version = "1.0.14"
48094809
source = "registry+https://github.com/rust-lang/crates.io-index"
4810-
checksum = "a2333e6df6d6598f2b1974829f853c2b4c5f4a6e503c10af918081aa6f8564e1"
4810+
checksum = "e25dfac463d778e353db5be2449d1cce89bd6fd23c9f1ea21310ce6e5a1b29c4"
48114811
dependencies = [
48124812
"serde",
48134813
]
48144814

48154815
[[package]]
48164816
name = "serde"
4817-
version = "1.0.147"
4817+
version = "1.0.152"
48184818
source = "registry+https://github.com/rust-lang/crates.io-index"
4819-
checksum = "d193d69bae983fc11a79df82342761dfbf28a99fc8d203dca4c3c1b590948965"
4819+
checksum = "bb7d1f0d3021d347a83e556fc4683dea2ea09d87bccdf88ff5c12545d89d5efb"
48204820
dependencies = [
48214821
"serde_derive",
48224822
]
@@ -4833,9 +4833,9 @@ dependencies = [
48334833

48344834
[[package]]
48354835
name = "serde_derive"
4836-
version = "1.0.147"
4836+
version = "1.0.152"
48374837
source = "registry+https://github.com/rust-lang/crates.io-index"
4838-
checksum = "4f1d362ca8fc9c3e3a7484440752472d68a6caa98f1ab81d99b5dfe517cec852"
4838+
checksum = "af487d118eecd09402d70a5d72551860e788df87b464af30e5ea6a38c75c541e"
48394839
dependencies = [
48404840
"proc-macro2",
48414841
"quote",
@@ -4853,9 +4853,9 @@ dependencies = [
48534853

48544854
[[package]]
48554855
name = "serde_json"
4856-
version = "1.0.85"
4856+
version = "1.0.91"
48574857
source = "registry+https://github.com/rust-lang/crates.io-index"
4858-
checksum = "e55a28e3aaef9d5ce0506d0a14dbba8054ddc7e499ef522dd8b26859ec9d4a44"
4858+
checksum = "877c235533714907a8c2464236f5c4b2a17262ef1bd71f38f35ea592c8da6883"
48594859
dependencies = [
48604860
"indexmap",
48614861
"itoa",
@@ -5133,9 +5133,9 @@ dependencies = [
51335133

51345134
[[package]]
51355135
name = "syn"
5136-
version = "1.0.102"
5136+
version = "1.0.107"
51375137
source = "registry+https://github.com/rust-lang/crates.io-index"
5138-
checksum = "3fcd952facd492f9be3ef0d0b7032a6e442ee9b361d4acc2b1d0c4aaa5f613a1"
5138+
checksum = "1f4064b5b16e03ae50984a5a8ed5d4f8803e6bc1fd170a3cda91a1be4b18e3f5"
51395139
dependencies = [
51405140
"proc-macro2",
51415141
"quote",
@@ -5309,6 +5309,7 @@ dependencies = [
53095309
"lazy_static",
53105310
"miropt-test-tools",
53115311
"regex",
5312+
"semver",
53125313
"termcolor",
53135314
"walkdir",
53145315
]

src/bootstrap/bootstrap.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -934,8 +934,7 @@ def main():
934934
if len(sys.argv) > 1 and sys.argv[1] == 'help':
935935
sys.argv = [sys.argv[0], '-h'] + sys.argv[2:]
936936

937-
help_triggered = (
938-
'-h' in sys.argv) or ('--help' in sys.argv) or (len(sys.argv) == 1)
937+
help_triggered = len(sys.argv) == 1 or any(x in ["-h", "--help", "--version"] for x in sys.argv)
939938
try:
940939
bootstrap(help_triggered)
941940
if not help_triggered:

src/tools/tidy/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ miropt-test-tools = { path = "../miropt-test-tools" }
1111
lazy_static = "1"
1212
walkdir = "2"
1313
ignore = "0.4.18"
14+
semver = "1.0.14"
1415
termcolor = "1.1.3"
1516

1617
[[bin]]

src/tools/tidy/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -69,3 +69,4 @@ pub mod ui_tests;
6969
pub mod unit_tests;
7070
pub mod unstable_book;
7171
pub mod walk;
72+
pub mod x_version;

src/tools/tidy/src/main.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ fn main() {
5858

5959
let handle = s.spawn(|| {
6060
let mut flag = false;
61-
$p::check($($args),* , &mut flag);
61+
$p::check($($args, )* &mut flag);
6262
if (flag) {
6363
bad.store(true, Ordering::Relaxed);
6464
}
@@ -107,6 +107,8 @@ fn main() {
107107
check!(alphabetical, &compiler_path);
108108
check!(alphabetical, &library_path);
109109

110+
check!(x_version, &root_path, &cargo);
111+
110112
let collected = {
111113
drain_handles(&mut handles);
112114

src/tools/tidy/src/x_version.rs

+65
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
use semver::Version;
2+
use std::io::ErrorKind;
3+
use std::path::Path;
4+
use std::process::{Command, Stdio};
5+
6+
pub fn check(root: &Path, cargo: &Path, bad: &mut bool) {
7+
let result = Command::new("x").arg("--wrapper-version").stdout(Stdio::piped()).spawn();
8+
// This runs the command inside a temporary directory.
9+
// This allows us to compare output of result to see if `--wrapper-version` is not a recognized argument to x.
10+
let temp_result = Command::new("x")
11+
.arg("--wrapper-version")
12+
.current_dir(std::env::temp_dir())
13+
.stdout(Stdio::piped())
14+
.spawn();
15+
16+
let (child, temp_child) = match (result, temp_result) {
17+
(Ok(child), Ok(temp_child)) => (child, temp_child),
18+
(Err(e), _) | (_, Err(e)) => match e.kind() {
19+
ErrorKind::NotFound => return,
20+
_ => return tidy_error!(bad, "failed to run `x`: {}", e),
21+
},
22+
};
23+
24+
let output = child.wait_with_output().unwrap();
25+
let temp_output = temp_child.wait_with_output().unwrap();
26+
27+
if output != temp_output {
28+
return tidy_error!(
29+
bad,
30+
"Current version of x does not support the `--wrapper-version` argument\nConsider updating to the newer version of x by running `cargo install --path src/tools/x`"
31+
);
32+
}
33+
34+
if output.status.success() {
35+
let version = String::from_utf8_lossy(&output.stdout);
36+
let version = Version::parse(version.trim_end()).unwrap();
37+
38+
if let Some(expected) = get_x_wrapper_version(root, cargo) {
39+
if version < expected {
40+
return tidy_error!(
41+
bad,
42+
"Current version of x is {version}, but the latest version is {expected}\nConsider updating to the newer version of x by running `cargo install --path src/tools/x`"
43+
);
44+
}
45+
} else {
46+
return tidy_error!(
47+
bad,
48+
"Unable to parse the latest version of `x` at `src/tools/x/Cargo.toml`"
49+
);
50+
}
51+
} else {
52+
return tidy_error!(bad, "failed to check version of `x`: {}", output.status);
53+
}
54+
}
55+
56+
// Parse latest version out of `x` Cargo.toml
57+
fn get_x_wrapper_version(root: &Path, cargo: &Path) -> Option<Version> {
58+
let mut cmd = cargo_metadata::MetadataCommand::new();
59+
cmd.cargo_path(cargo)
60+
.manifest_path(root.join("src/tools/x/Cargo.toml"))
61+
.no_deps()
62+
.features(cargo_metadata::CargoOpt::AllFeatures);
63+
let mut metadata = t!(cmd.exec());
64+
metadata.packages.pop().map(|x| x.version)
65+
}

src/tools/x/src/main.rs

+8
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,14 @@ fn exec_or_status(command: &mut Command) -> io::Result<ExitStatus> {
5252
}
5353

5454
fn main() {
55+
match env::args().skip(1).next().as_deref() {
56+
Some("--wrapper-version") => {
57+
let version = env!("CARGO_PKG_VERSION");
58+
println!("{}", version);
59+
return;
60+
}
61+
_ => {}
62+
}
5563
let current = match env::current_dir() {
5664
Ok(dir) => dir,
5765
Err(err) => {

0 commit comments

Comments
 (0)