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

Print rustup version after update #614

Merged
merged 1 commit into from
Aug 1, 2016

Conversation

julienXX
Copy link
Contributor

@julienXX julienXX commented Jul 25, 2016

Fixes #542

@@ -1069,7 +1071,7 @@ pub fn update() -> Result<()> {
}
let setup_path = try!(prepare_update());
if let Some(ref p) = setup_path {
info!("rustup updated successfully");
info!("rustup updated successfully to {}", VERSION);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

By printing CARGO_PKG_VERSION here rustup will be printing the version of the currently running version of rustup. Instead, what we want is to print the version we just downloaded (here represented by setup_path). So this is instead going to need to run the executable at setup_path with --version and parse out the new version number.

@brson
Copy link
Contributor

brson commented Jul 25, 2016

Thanks @julienXX !

@julienXX julienXX force-pushed the print-new-version-after-update branch from b35bb04 to a23c403 Compare July 26, 2016 09:18
@julienXX
Copy link
Contributor Author

@brson Oh okay, I should have thought about that. Thanks!
I updated the PR with getting the version of the downloaded rustup.
Do you have any advice on how I should test this? The current test pass but I don't think it's really adequate.

let re = Regex::new(r"\d+.\d+.\d+").unwrap();
let capture = re.captures(&string_version).unwrap().at(0).unwrap();
Ok(String::from(capture))
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since this code is on the super-important upgrade path, let's be a little more defensive. What happens if the new executable doesn't run? Seems like it could happen. What happens if it fails? What happens if the output of --version changes? Seems like we might want to do that (for example returning a version like "2.0.0-rc1"). Instead of unwraps here can they return errors instead? Then have the caller convert those errors to a placeholder string like "(unknown)".

An aside, if the executable fails to run that would be a bad sign - it might be worth thinking about turning that into a hard error and failing the upgrade. But that can be a different PR.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes absolutely! I'll update the code to be more defensive. Do you feel like regexp is the way to go or could a string split be sufficient?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Regexp is good!

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for the slow response.

@brson
Copy link
Contributor

brson commented Jul 26, 2016

The test is good enough I think. Yeah, it could be better by having a different version number, but the effort to make that happen isn't worth it.

@julienXX julienXX force-pushed the print-new-version-after-update branch from a23c403 to 5ea4473 Compare August 1, 2016 13:19
@julienXX
Copy link
Contributor Author

julienXX commented Aug 1, 2016

@brson I updated the code to be more defensive. Also it now exit the process if the executable fails to run.

@brson brson merged commit a181b2b into rust-lang:master Aug 1, 2016
@brson
Copy link
Contributor

brson commented Aug 1, 2016

Looks great. Thanks @julienXX !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants