Skip to content

Allow getting version info for a specified command #4

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

Merged
merged 4 commits into from
Mar 5, 2017

Conversation

kamalmarhubi
Copy link
Contributor

These commits add support for getting version info for a specified command. Along the way, functions are changed to return an error instead of panicking, making them more flexible for downstream users.

@kamalmarhubi
Copy link
Contributor Author

The failure is from bumping semver to include dtolnay/semver@0faefa8, which changes how pre-release tags are handled with requirements. I'll take a closer look tomorrow.

SemVerError(semver::SemVerError),
/// The pre-release tag is unknown.
UnknownPreReleaseTag(Identifier),
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

I'm not opposed to add this as is, but I feel like half of these error scenarios could reasonably be declared unexpected failures that don't need to appear in the Result. :)

Eg, rustc changing to non-utf8 output or not using semver compatible version numbers is unlikely to be an error, ever.

Though I guess since a) there are already many error variants in that enum and b) RUSTC might be a wrapper or alternate compiler, just covering everything is probably for the best anyway.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I just translated the panics directly to variants. If you prefer, all but CouldNotExecuteCommand could be some kind of catch all parse error that wraps the cause as Option<Box<Error>>. I'm happy either way: all I want is a way not to panic! :-)

@Kimundi
Copy link
Collaborator

Kimundi commented Feb 19, 2016

Seems like the dtolnay/semver#54 change makes it no longer possible to use semver version requirements to sort rustc versions while ignoring prerelease tags, that is it appears that 1.4.0-nightly <= 1.5.0 no longer holds.

Which is kinda annoying because that kind of usage was the main motivation for exposing semver in this crate. :)

I wonder if I should add rustc-release-train-specific functions that ignore the prelrease tags, or specify this crate as doing this automatically... (the latter is probably a bad idea though)

@kamalmarhubi
Copy link
Contributor Author

it appears that 1.4.0-nightly <= 1.5.0 no longer holds.

I think it's the other way around: 1.4.0 <= 1.5.0-nightly no longer holds. From my reading of the NPM spec, this is to prevent very alpha prereleases being used in place of an earlier stable release. It makes sense in terms of package management, but not here.

I wonder if I should add rustc-release-train-specific functions that ignore the prelrease tags, or specify this crate as doing this automatically... (the latter is probably a bad idea though)

Former makes more sense to me. Arguably, the new behavior is fixing a bug. To get the behavior that makes sense for release trains, we could just use the Ord impl on Version. Eg, this works:

let v1 = Version::parse("1.4.0").unwrap();
let v2 = Version::parse("1.7.0-beta.3").unwrap();

assert!(v1 <= v2);

even though this does not:

let req = VersionReq::parse(">= 1.4.0").unwrap();
let ver = Version::parse("1.7.0-beta.3").unwrap();

assert!(req.matches(&ver));

@Kimundi
Copy link
Collaborator

Kimundi commented Feb 20, 2016

Ah, interesting. I had assumed that the Ord impl on Version follows the same scheme as version requirments, but if it doesn't then thats a fine replacement, yeah.

Still have to change the example code and maybe deprecate version_matches though, hm...

@kamalmarhubi
Copy link
Contributor Author

Still have to change the example code and maybe deprecate version_matches though, hm...

Here are some of approaches:

  1. mark it as deprecated, and if version_matches() returns false and there is a prerelease identifier in the version but not the req, panic with a message explaining the replacement of using the Ord impl
  2. mark it as deprecated, and emulate existing behavior for Rust prerelease identifiers, panicking if the VersionReq wasn't of a very simple form (minimum version only)
  3. mark it as deprecated, and attempt to fully emulate existing behavior
  4. remove it entirely, and clearly state in the release notes what the replacement is

I kind of lean towards 4. Changing panics to Result is already a breaking change and people will likely need to revisit things a little. The changes that result are all very minor.

@Kimundi
Copy link
Collaborator

Kimundi commented Feb 21, 2016

Yeah, will probably just remove it.

semver 0.2 was the first to include a fix to how `VersionReq`
comparisons work with pre-release identifiers. The fix results in, eg,

    version_matches(">= 1.4.0")

not matching for a compiler version `1.8.0-nightly`. For more details,
see dtolnay/semver#54.

This makes `version_matches()` far less useful, and so it is removed.
It's still possible to get the original intent by using the `Ord` impl
on `semver::Version`. To make this more convenient, `semver::Version` is
exported from this crate.

This is a breaking change.
This gives the choice of how to handle the error to the downstream user,
making it easier to use rustc_version as a library in non-build-script
contexts.

This is a breaking change.
This allows controlling what command to use without needing to set the
`RUSTC` environment variable.
@kamalmarhubi
Copy link
Contributor Author

I just opened #5 for that change and rebased this PR on top of that one.

@kamalmarhubi
Copy link
Contributor Author

@Kimundi ping for your thoughts on on this and #5 :-)

@Kimundi Kimundi merged commit 198ee85 into djc:master Mar 5, 2017
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