Skip to content

Commit

Permalink
Auto merge of #5083 - matklad:Cargo-the-tool-1.0, r=alexcrichton
Browse files Browse the repository at this point in the history
Make cargo-the-binary version the same as the Rust version

Closes #4211 which seems stuck :-)

Soooo, this is the simplest possible fix to this problem:

```
~/projects/cargo Cargo-the-tool-1.0
λ rustc --version
rustc 1.24.0 (4d90ac38c 2018-02-12)

~/projects/cargo Cargo-the-tool-1.0
λ cargo --version
cargo 0.25.0 (8c93e08 2018-02-01)
```

It makes `cargo --version` to print the corresponding Rust version (with possibly cargo-specific patch number), while keeping the library version the same as today.

On the one hand, this is horrible. On the other hand, it seems to do the job? In the long term, it would be cool skip one version bump for the library, so that `0.x` corresponds to `1.x`.

cc @rust-lang/cargo

I am not sure that this is good idea, the implementation certainly feels horrible :)
  • Loading branch information
bors committed Feb 26, 2018
2 parents ce87cfa + cc971ee commit cd2ae96
Showing 1 changed file with 28 additions and 12 deletions.
40 changes: 28 additions & 12 deletions src/cargo/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,9 @@ pub struct CfgInfo {
}

pub struct VersionInfo {
pub major: String,
pub minor: String,
pub patch: String,
pub major: u8,
pub minor: u8,
pub patch: u8,
pub pre_release: Option<String>,
// Information that's only available when we were built with
// configure/make, rather than cargo itself.
Expand Down Expand Up @@ -192,12 +192,28 @@ fn handle_cause(cargo_err: &Error, shell: &mut Shell) -> bool {
}

pub fn version() -> VersionInfo {
macro_rules! env_str {
($name:expr) => { env!($name).to_string() }
}
macro_rules! option_env_str {
($name:expr) => { option_env!($name).map(|s| s.to_string()) }
}

// So this is pretty horrible...
// There are two versions at play here:
// - version of cargo-the-binary, which you see when you type `cargo --version`
// - version of cargo-the-library, which you download from crates.io for use
// in your projects.
//
// We want to make the `binary` version the same as the corresponding Rust/rustc release.
// At the same time, we want to keep the library version at `0.x`, because Cargo as
// a library is (and probably will always be) unstable.
//
// Historically, Cargo used the same version number for both the binary and the library.
// Specifically, rustc 1.x.z was paired with cargo 0.x+1.w.
// We continue to use this scheme for the library, but transform it to 1.x.w for the purposes
// of `cargo --version`.
let major = 1;
let minor = env!("CARGO_PKG_VERSION_MINOR").parse::<u8>().unwrap() - 1;
let patch = env!("CARGO_PKG_VERSION_PATCH").parse::<u8>().unwrap();

match option_env!("CFG_RELEASE_CHANNEL") {
// We have environment variables set up from configure/make.
Some(_) => {
Expand All @@ -210,9 +226,9 @@ pub fn version() -> VersionInfo {
}
});
VersionInfo {
major: env_str!("CARGO_PKG_VERSION_MAJOR"),
minor: env_str!("CARGO_PKG_VERSION_MINOR"),
patch: env_str!("CARGO_PKG_VERSION_PATCH"),
major,
minor,
patch,
pre_release: option_env_str!("CARGO_PKG_VERSION_PRE"),
cfg_info: Some(CfgInfo {
release_channel: option_env_str!("CFG_RELEASE_CHANNEL").unwrap(),
Expand All @@ -223,9 +239,9 @@ pub fn version() -> VersionInfo {
// We are being compiled by Cargo itself.
None => {
VersionInfo {
major: env_str!("CARGO_PKG_VERSION_MAJOR"),
minor: env_str!("CARGO_PKG_VERSION_MINOR"),
patch: env_str!("CARGO_PKG_VERSION_PATCH"),
major,
minor,
patch,
pre_release: option_env_str!("CARGO_PKG_VERSION_PRE"),
cfg_info: None,
}
Expand Down

0 comments on commit cd2ae96

Please sign in to comment.