-
Notifications
You must be signed in to change notification settings - Fork 12.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rollup merge of #107048 - DebugSteven:newer-x-check-cargo, r=albertla…
…rsan68 check for x version updates 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 checks the installed version of `x` by parsing the output of `cargo install --list` (as an option proposed in this [issue](#106469)). It does not warn if `x` has not yet been installed, on the assumption that the user isn't interested in using it.
- Loading branch information
Showing
5 changed files
with
73 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -70,3 +70,4 @@ pub mod ui_tests; | |
pub mod unit_tests; | ||
pub mod unstable_book; | ||
pub mod walk; | ||
pub mod x_version; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
use semver::Version; | ||
use std::path::Path; | ||
use std::process::{Command, Stdio}; | ||
|
||
pub fn check(root: &Path, cargo: &Path, bad: &mut bool) { | ||
let cargo_list = Command::new(cargo).args(["install", "--list"]).stdout(Stdio::piped()).spawn(); | ||
|
||
let child = match cargo_list { | ||
Ok(child) => child, | ||
Err(e) => return tidy_error!(bad, "failed to run `cargo`: {}", e), | ||
}; | ||
|
||
let cargo_list = child.wait_with_output().unwrap(); | ||
|
||
if cargo_list.status.success() { | ||
let exe_list = String::from_utf8_lossy(&cargo_list.stdout); | ||
let exe_list = exe_list.lines(); | ||
|
||
let mut installed: Option<Version> = None; | ||
|
||
for line in exe_list { | ||
let mut iter = line.split_whitespace(); | ||
if iter.next() == Some("x") { | ||
if let Some(version) = iter.next() { | ||
// Check this is the rust-lang/rust x tool installation since it should be | ||
// installed at a path containing `src/tools/x`. | ||
if let Some(path) = iter.next() { | ||
if path.contains(&"src/tools/x") { | ||
let version = version.strip_prefix("v").unwrap(); | ||
installed = Some(Version::parse(version).unwrap()); | ||
break; | ||
} | ||
}; | ||
} | ||
} else { | ||
continue; | ||
} | ||
} | ||
// Unwrap the some if x is installed, otherwise return because it's fine if x isn't installed. | ||
let installed = if let Some(i) = installed { i } else { return }; | ||
|
||
if let Some(expected) = get_x_wrapper_version(root, cargo) { | ||
if installed < expected { | ||
return println!( | ||
"Current version of x is {installed}, but the latest version is {expected}\nConsider updating to the newer version of x by running `cargo install --path src/tools/x`" | ||
); | ||
} | ||
} else { | ||
return tidy_error!( | ||
bad, | ||
"Unable to parse the latest version of `x` at `src/tools/x/Cargo.toml`" | ||
); | ||
} | ||
} else { | ||
return tidy_error!(bad, "failed to check version of `x`: {}", cargo_list.status); | ||
} | ||
} | ||
|
||
// Parse latest version out of `x` Cargo.toml | ||
fn get_x_wrapper_version(root: &Path, cargo: &Path) -> Option<Version> { | ||
let mut cmd = cargo_metadata::MetadataCommand::new(); | ||
cmd.cargo_path(cargo) | ||
.manifest_path(root.join("src/tools/x/Cargo.toml")) | ||
.no_deps() | ||
.features(cargo_metadata::CargoOpt::AllFeatures); | ||
let mut metadata = t!(cmd.exec()); | ||
metadata.packages.pop().map(|x| x.version) | ||
} |