Skip to content

Commit

Permalink
Auto merge of #11839 - djc:downgrading-status, r=weihanglo
Browse files Browse the repository at this point in the history
Accurately show status when downgrading dependencies

### What does this PR try to resolve?

A few times now I've ran into issues where Cargo ends up downgrading a dependency in order to satisfy a pinned dependency somewhere in the dependency graph. Unfortunately this is not clear in the output of `cargo update`, which just shows all the changed dependencies as `Updating`.

References:

* #5702
* [Finding a pinned dependency edge](https://users.rust-lang.org/t/finding-a-pinned-dependency-edge/81157)
* tokio-rs/axum#1814

### How should we test and review this PR?

This is a small change that tries to make dependency downgrades stand out more in the output of `cargo update`. I have not added any new tests since the existing tests seem to cover this functionality.

Some tests still fail, these refer to Git dependencies. I'm honestly not sure how to handle these, so I'd like to get some feedback on this before I fix those tests up. Git commits form a DAG, so one option is to see if the new commit is an ancestor of the old one (mark as "updating"), if the old commit is an ancestor of the new one (mark as "downgrading"), or neither (could be from parallel branches) we could compare based on timestamp in that case.

### To do

* Fix up tests for Git dependency updates
  • Loading branch information
bors committed Mar 14, 2023
2 parents 71ea049 + 20a5d2b commit 4e11cae
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 5 deletions.
1 change: 1 addition & 0 deletions crates/cargo-test-support/src/compare.rs
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,7 @@ fn substitute_macros(input: &str) -> String {
("[CHECKING]", " Checking"),
("[COMPLETED]", " Completed"),
("[CREATED]", " Created"),
("[DOWNGRADING]", " Downgrading"),
("[FINISHED]", " Finished"),
("[ERROR]", "error:"),
("[WARNING]", "warning:"),
Expand Down
9 changes: 7 additions & 2 deletions src/cargo/ops/cargo_generate_lockfile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use crate::util::CargoResult;
use anyhow::Context;
use log::debug;
use std::collections::{BTreeMap, HashSet};
use termcolor::Color::{self, Cyan, Green, Red};
use termcolor::Color::{self, Cyan, Green, Red, Yellow};

pub struct UpdateOptions<'a> {
pub config: &'a Config,
Expand Down Expand Up @@ -142,7 +142,12 @@ pub fn update_lockfile(ws: &Workspace<'_>, opts: &UpdateOptions<'_>) -> CargoRes
} else {
format!("{} -> v{}", removed[0], added[0].version())
};
print_change("Updating", msg, Green)?;

if removed[0].version() > added[0].version() {
print_change("Downgrading", msg, Yellow)?;
} else {
print_change("Updating", msg, Green)?;
}
} else {
for package in removed.iter() {
print_change("Removing", format!("{}", package), Red)?;
Expand Down
2 changes: 1 addition & 1 deletion tests/testsuite/offline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -657,7 +657,7 @@ fn main(){
.with_status(0)
.with_stderr(
"\
[UPDATING] present_dep v1.2.9 -> v1.2.3
[DOWNGRADING] present_dep v1.2.9 -> v1.2.3
",
)
.run();
Expand Down
4 changes: 2 additions & 2 deletions tests/testsuite/update.rs
Original file line number Diff line number Diff line change
Expand Up @@ -385,7 +385,7 @@ fn update_precise() {
.with_stderr(
"\
[UPDATING] `[..]` index
[UPDATING] serde v0.2.1 -> v0.2.0
[DOWNGRADING] serde v0.2.1 -> v0.2.0
",
)
.run();
Expand Down Expand Up @@ -492,7 +492,7 @@ fn update_precise_first_run() {
.with_stderr(
"\
[UPDATING] `[..]` index
[UPDATING] serde v0.2.1 -> v0.2.0
[DOWNGRADING] serde v0.2.1 -> v0.2.0
",
)
.run();
Expand Down

0 comments on commit 4e11cae

Please sign in to comment.