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

New command: cargo-upgrade #138

Merged
merged 2 commits into from
Jul 19, 2017
Merged

New command: cargo-upgrade #138

merged 2 commits into from
Jul 19, 2017

Conversation

bjgill
Copy link
Collaborator

@bjgill bjgill commented Jul 5, 2017

This adds cargo upgrade as a more fully featured replacement for cargo add --update-only.

Usage:

Upgrade all dependencies in a manifest file to the latest version.

Usage:
    cargo upgrade [--dependency <dep>...] [--manifest-path <path>]
    cargo upgrade (-h | --help)
    cargo upgrade (-V | --version)

Options:
    -d --dependency <dep>       Specific dependency to upgrade. If this option is used, only the
                                specified dependencies will be upgraded.
    --manifest-path <path>      Path to the manifest to upgrade.
    -h --help                   Show this help page.
    -V --version                Show version.

Dev, build, and all target dependencies will also be upgraded. Only dependencies from crates.io are
supported. Git/path dependencies will be ignored.

Resolves #74.

Next steps (beyond this PR; probably not in v0.2) will be:

  • Workspace support
  • interactive 'check mode'
  • Use cargo to parse the manifests

(I'll squash prior to merging)

@bjgill bjgill changed the title Cargo upgrade New command: cargo-upgrade Jul 5, 2017
@bjgill
Copy link
Collaborator Author

bjgill commented Jul 5, 2017

r? @killercup @ordian


Options:
-h, --help Print this message
--dependency -d <dep> Dependency to update
Copy link
Collaborator

Choose a reason for hiding this comment

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

nit: can it be -d, --dependency <dep> for consistency in usage?
Also, -V, --version.
Same in README.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Also it's worth mentioning here that upgrade will update dev, build and all target dependencies as well.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

OK. Though -d --dependency <dep> (etc.) is probably more consistent with cargo add/rm,

Copy link
Collaborator

Choose a reason for hiding this comment

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

Right, lets use -d --dependency <dep> instead.

@ordian
Copy link
Collaborator

ordian commented Jul 5, 2017

Looks good overall.

Do you think we should somehow take into account overriding dependencies (I think we shouldn't)?

README.md Outdated
# Upgrade all dependencies
$ cargo update
# Upgrade libc and serde
$ cargo update -d libc --dependency serde
Copy link
Collaborator

Choose a reason for hiding this comment

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

Should this be cargo upgrade -d libc serde instead?
Also typo: update -> upgrade.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I don't think so - the usage syntax is that you need one of -d/--dependency per dependency to be upgraded. This follows the pattern that cargo update uses.

"foo",
"--manifest-path=tests/fixtures/manifest-invalid/Cargo.toml.sample"] =>
Error 1,
"Command failed due to unhandled error: failed to parse datetime for key `invalid-section.key`")
Copy link
Collaborator

Choose a reason for hiding this comment

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

nit: indentation here seems a bit off.

let manifest_path = manifest_path.as_ref().map(From::from);
let mut manifest = Manifest::open(&manifest_path).unwrap();

// Look for dependencies in all three sections.
Copy link
Collaborator

Choose a reason for hiding this comment

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

src/manifest.rs Outdated
})
.collect::<Vec<_>>();

// ... or in `target.<target name>.(dev-)dependencies`.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Looks like target build-dependencies is also a thing.

@ordian
Copy link
Collaborator

ordian commented Jul 5, 2017

@bjgill Thank you!
💯

@bjgill
Copy link
Collaborator Author

bjgill commented Jul 6, 2017

@killercup - do you want to give this a look? Otherwise, I'll merge on Monday

@killercup
Copy link
Owner

killercup commented Jul 6, 2017 via email

@bjgill
Copy link
Collaborator Author

bjgill commented Jul 17, 2017

I've now added the change to switch cargo-upgrade to using cargo to parse manifest files. This adds a lot of new stuff to Cargo.lock but is otherwise mostly a partial re-write of cargo-upgrade, hence its inclusion in this PR.

Once merged, this will be straightforwardly extensible to add proper workspace support.

@killercup - were you wanting to review this?

@killercup
Copy link
Owner

Sorry, I'm sooo behind on my reviews.

Quick thought: Instead of using cargo as a library (that includes a truckload of dependencies I assume), we can also run cargo metadata and parse its JSON output.

@bjgill
Copy link
Collaborator Author

bjgill commented Jul 18, 2017

Yes. As the AppVeyor CI is showing, the non-Rust dependencies of cargo are quite a pain.

@bjgill
Copy link
Collaborator Author

bjgill commented Jul 18, 2017

In fact, I think the switch to cargo is probably not worth the hassle of getting it into this PR/v0.2.

I've reset to the commit prior to the introduction of cargo. This PR (and v0.2) doesn't need to be delayed any further by me faffing around with the back-end - it should be fine to go in as-is. We can wait to switch back-end and add workspace support in v0.2.1/v0.3.

EDIT: for future reference, the removed commits can be found in bjgill#2

Copy link
Owner

@killercup killercup left a comment

Choose a reason for hiding this comment

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

Alright, I've finally read through this. Very nice! I left a few inline comments, but nothing major. Is there a test for updating a dependency only available in one target?

Feel free to merge this once you think it's good to go!

// Not a version dependency if the `git` or `path` keys are present.
!(table.contains_key("git") || table.contains_key("path"))
})
.unwrap_or(true)
Copy link
Owner

Choose a reason for hiding this comment

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

The comment seems redundant as the code says basically the same thing. I also think I'd nowadays write this as

if let Some(table) = dep.as_table() {
    !table.contains_key("git") && !table.contains_key("path")
} else {
    true
}

})
.filter(|&(_name, old_value)| is_version_dependency(old_value))
.map(|(name, _old_value)| {

Copy link
Owner

Choose a reason for hiding this comment

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

✂️


Ok(())
})
.collect::<Result<Vec<_>, Box<Error>>>()?;
Copy link
Owner

Choose a reason for hiding this comment

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

You are collecting this into a Vec… just to drop it? Seems weird. Better use an inner for-loop with the body of the map (this way the ? will return in the fn scope)

src/manifest.rs Outdated
if let Some(segment) = path.pop_front() {
let value = match *input
.entry(segment.to_owned())
.or_insert_with(|| toml::Value::Table(BTreeMap::new())) {
Copy link
Owner

Choose a reason for hiding this comment

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

This is hard to read. Can you give the thing you are matching over its own binding and keep the match head single-line?

src/manifest.rs Outdated
}
}

descend(&mut self.data, table_path.into_iter().collect())
Copy link
Owner

Choose a reason for hiding this comment

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

Nicely done.

src/manifest.rs Outdated
/// Descend into a manifest until the required table is found.
fn descend<'a>(
input: &'a mut BTreeMap<String, toml::Value>,
mut path: VecDeque<&String>,
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can we avoid allocation?
I think, if we make path: &[String], then
if let Some(segment) = path.pop_front() { can be replaced with if !path.is_empty() { let segment = path[0];
and descend(value, path) with descend(value, &path[1..])

Copy link
Owner

Choose a reason for hiding this comment

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

Interesting, using sub slices is pretty clever :)

(But don't go out your way to optimize stuff like this; this whole project is in no way performance critical code!)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

That is quite nice.

@bjgill
Copy link
Collaborator Author

bjgill commented Jul 19, 2017

@killercup and @ordian - thanks. The Appveyor failures are entirely spurious - it looks as if the revocation server they use is currently down. I'll squash and pass to bors to merge in.

This adds `cargo upgrade` as a more fully featured replacement for
`cargo add --update-only`.

Usage:

```plain
Upgrade all dependencies in a manifest file to the latest version.

Usage:
    cargo upgrade [--dependency <dep>...] [--manifest-path <path>]
    cargo upgrade (-h | --help)
    cargo upgrade (-V | --version)

Options:
    -d --dependency <dep>       Specific dependency to upgrade. If this
option is used, only the
                                specified dependencies will be upgraded.
    --manifest-path <path>      Path to the manifest to upgrade.
    -h --help                   Show this help page.
    -V --version                Show version.

Dev, build, and all target dependencies will also be upgraded. Only
dependencies from crates.io are
supported. Git/path dependencies will be ignored.
```

Resolves killercup#74.
@bjgill
Copy link
Collaborator Author

bjgill commented Jul 19, 2017

bors r+

bors bot added a commit that referenced this pull request Jul 19, 2017
138: New command: cargo-upgrade r=bjgill

This adds `cargo upgrade` as a more fully featured replacement for `cargo add --update-only`. 

Usage:

```plain
Upgrade all dependencies in a manifest file to the latest version.

Usage:
    cargo upgrade [--dependency <dep>...] [--manifest-path <path>]
    cargo upgrade (-h | --help)
    cargo upgrade (-V | --version)

Options:
    -d --dependency <dep>       Specific dependency to upgrade. If this option is used, only the
                                specified dependencies will be upgraded.
    --manifest-path <path>      Path to the manifest to upgrade.
    -h --help                   Show this help page.
    -V --version                Show version.

Dev, build, and all target dependencies will also be upgraded. Only dependencies from crates.io are
supported. Git/path dependencies will be ignored.
```

Resolves #74.

Next steps (beyond this PR; probably not in v0.2) will be:

* Workspace support
* interactive 'check mode'
* Use `cargo` to parse the manifests

(I'll squash prior to merging)
@bors
Copy link
Contributor

bors bot commented Jul 19, 2017

Build failed

@killercup
Copy link
Owner

killercup commented Jul 19, 2017 via email

It's currently too unreliable
@bjgill
Copy link
Collaborator Author

bjgill commented Jul 19, 2017

Ok. I've raised #139 to cover re-instating Appveyor in bors

bors r+

bors bot added a commit that referenced this pull request Jul 19, 2017
138: New command: cargo-upgrade r=bjgill

This adds `cargo upgrade` as a more fully featured replacement for `cargo add --update-only`. 

Usage:

```plain
Upgrade all dependencies in a manifest file to the latest version.

Usage:
    cargo upgrade [--dependency <dep>...] [--manifest-path <path>]
    cargo upgrade (-h | --help)
    cargo upgrade (-V | --version)

Options:
    -d --dependency <dep>       Specific dependency to upgrade. If this option is used, only the
                                specified dependencies will be upgraded.
    --manifest-path <path>      Path to the manifest to upgrade.
    -h --help                   Show this help page.
    -V --version                Show version.

Dev, build, and all target dependencies will also be upgraded. Only dependencies from crates.io are
supported. Git/path dependencies will be ignored.
```

Resolves #74.

Next steps (beyond this PR; probably not in v0.2) will be:

* Workspace support
* interactive 'check mode'
* Use `cargo` to parse the manifests

(I'll squash prior to merging)
@bors
Copy link
Contributor

bors bot commented Jul 19, 2017

Build succeeded

@bors bors bot merged commit c0c4067 into killercup:master Jul 19, 2017
@bjgill bjgill deleted the cargo-upgrade branch July 20, 2017 00:02
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.

None yet

3 participants