Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

warn newer available version of the x tool #104552

Merged
merged 16 commits into from
Jan 3, 2023
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4805,9 +4805,9 @@ checksum = "1ef965a420fe14fdac7dd018862966a4c14094f900e1650bbc71ddd7d580c8af"

[[package]]
name = "semver"
version = "1.0.12"
version = "1.0.14"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a2333e6df6d6598f2b1974829f853c2b4c5f4a6e503c10af918081aa6f8564e1"
checksum = "e25dfac463d778e353db5be2449d1cce89bd6fd23c9f1ea21310ce6e5a1b29c4"
dependencies = [
"serde",
]
Expand Down Expand Up @@ -5309,6 +5309,7 @@ dependencies = [
"lazy_static",
"miropt-test-tools",
"regex",
"semver",
"termcolor",
"walkdir",
]
Expand Down
3 changes: 1 addition & 2 deletions src/bootstrap/bootstrap.py
Original file line number Diff line number Diff line change
Expand Up @@ -934,8 +934,7 @@ def main():
if len(sys.argv) > 1 and sys.argv[1] == 'help':
sys.argv = [sys.argv[0], '-h'] + sys.argv[2:]

help_triggered = (
'-h' in sys.argv) or ('--help' in sys.argv) or (len(sys.argv) == 1)
help_triggered = len(sys.argv) == 1 or any(x in ["-h", "--help", "--version"] for x in sys.argv)
try:
bootstrap(help_triggered)
if not help_triggered:
Expand Down
1 change: 1 addition & 0 deletions src/tools/tidy/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ miropt-test-tools = { path = "../miropt-test-tools" }
lazy_static = "1"
walkdir = "2"
ignore = "0.4.18"
semver = "1.0.14"
termcolor = "1.1.3"

[[bin]]
Expand Down
1 change: 1 addition & 0 deletions src/tools/tidy/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,3 +69,4 @@ pub mod ui_tests;
pub mod unit_tests;
pub mod unstable_book;
pub mod walk;
pub mod x_version;
4 changes: 3 additions & 1 deletion src/tools/tidy/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ fn main() {

let handle = s.spawn(|| {
let mut flag = false;
$p::check($($args),* , &mut flag);
$p::check($($args, )* &mut flag);
if (flag) {
bad.store(true, Ordering::Relaxed);
}
Expand Down Expand Up @@ -107,6 +107,8 @@ fn main() {
check!(alphabetical, &compiler_path);
check!(alphabetical, &library_path);

check!(x_version);

let collected = {
drain_handles(&mut handles);

Expand Down
54 changes: 54 additions & 0 deletions src/tools/tidy/src/x_version.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
use semver::{BuildMetadata, Prerelease, Version};
use std::io::ErrorKind;
use std::process::{Command, Stdio};

pub fn check(bad: &mut bool) {
let result = Command::new("x").arg("--wrapper-version").stdout(Stdio::piped()).spawn();
// This runs the command inside a temporarily directory.
DebugSteven marked this conversation as resolved.
Show resolved Hide resolved
// This allows us to compare output of result to see if `--wrapper-version` is not a recognized argument to x.
let temp_result = Command::new("x")
.arg("--wrapper-version")
.current_dir(std::env::temp_dir())
.stdout(Stdio::piped())
.spawn();

let (child, temp_child) = match (result, temp_result) {
(Ok(child), Ok(temp_child)) => (child, temp_child),
// what would it mean if the temp cmd error'd?
(Ok(_child), Err(_e)) => todo!(),
(Err(e), _) => match e.kind() {
ErrorKind::NotFound => return,
_ => return tidy_error!(bad, "failed to run `x`: {}", e),
jyn514 marked this conversation as resolved.
Show resolved Hide resolved
},
};

let output = child.wait_with_output().unwrap();
let temp_output = temp_child.wait_with_output().unwrap();

if output != temp_output {
return tidy_error!(
bad,
"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`"
);
}

if output.status.success() {
let version = String::from_utf8_lossy(&output.stdout);
let version = Version::parse(version.trim_end()).unwrap();
jyn514 marked this conversation as resolved.
Show resolved Hide resolved
let expected = Version {
major: 0,
minor: 1,
patch: 0,
pre: Prerelease::new("").unwrap(),
build: BuildMetadata::EMPTY,
};
jyn514 marked this conversation as resolved.
Show resolved Hide resolved
if version < expected {
return tidy_error!(
bad,
"Current version of x is {version} Consider updating to the newer version of x by running `cargo install --path src/tools/x`"
DebugSteven marked this conversation as resolved.
Show resolved Hide resolved
);
}
} else {
return tidy_error!(bad, "failed to check version of `x`: {}", output.status);
}
}
8 changes: 8 additions & 0 deletions src/tools/x/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,14 @@ fn exec_or_status(command: &mut Command) -> io::Result<ExitStatus> {
}

fn main() {
match env::args().skip(1).next().as_deref() {
Some("--wrapper-version") => {
let version = env!("CARGO_PKG_VERSION");
println!("{}", version);
return;
}
_ => {}
}
let current = match env::current_dir() {
Ok(dir) => dir,
Err(err) => {
Expand Down