Skip to content

Commit

Permalink
Merge pull request killercup#755 from epage/fixes
Browse files Browse the repository at this point in the history
fix(upgrade): Resolve problems found in killercup#754
  • Loading branch information
epage authored Jul 27, 2022
2 parents be0ef22 + fb633e4 commit 36dbb19
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 11 deletions.
21 changes: 12 additions & 9 deletions src/bin/upgrade/upgrade.rs
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ fn exec(args: UpgradeArgs) -> CargoResult<()> {
let manifests = args.resolve_targets()?;
let locked = args
.to_lockfile
.then(|| load_lockfile(&manifests))
.then(|| load_lockfile(&manifests, args.offline))
.transpose()?
.unwrap_or_default();

Expand Down Expand Up @@ -186,7 +186,7 @@ fn exec(args: UpgradeArgs) -> CargoResult<()> {
let dependency = match Dependency::from_toml(&manifest_path, dep_key, dep_item) {
Ok(dependency) => dependency,
Err(err) => {
shell_warn(&format!("ignoring {}, invalid entry: {}", dep_key, err))?;
shell_warn(&format!("ignoring {}, unsupported entry: {}", dep_key, err))?;
continue;
}
};
Expand Down Expand Up @@ -390,7 +390,10 @@ fn exec(args: UpgradeArgs) -> CargoResult<()> {
Ok(())
}

fn load_lockfile(targets: &[cargo_metadata::Package]) -> CargoResult<Vec<cargo_metadata::Package>> {
fn load_lockfile(
targets: &[cargo_metadata::Package],
offline: bool,
) -> CargoResult<Vec<cargo_metadata::Package>> {
// Get locked dependencies. For workspaces with multiple Cargo.toml
// files, there is only a single lockfile, so it suffices to get
// metadata for any one of Cargo.toml files.
Expand All @@ -400,15 +403,15 @@ fn load_lockfile(targets: &[cargo_metadata::Package]) -> CargoResult<Vec<cargo_m
let mut cmd = cargo_metadata::MetadataCommand::new();
cmd.manifest_path(package.manifest_path.clone());
cmd.features(cargo_metadata::CargoOpt::AllFeatures);
cmd.other_options(vec!["--locked".to_string()]);
let mut other = vec!["--locked".to_owned()];
if offline {
other.push("--offline".to_owned());
}
cmd.other_options(other);

let result = cmd.exec()?;

let locked = result
.packages
.into_iter()
.filter(|p| p.source.is_some()) // Source is none for local packages
.collect::<Vec<_>>();
let locked = result.packages;

Ok(locked)
}
Expand Down
2 changes: 1 addition & 1 deletion tests/cargo-upgrade/to_lockfile/out/one/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ path = "../dummy.rs"

[dependencies]
my-package = "0.2.3"
three = { path = "../implicit/three", version = "0.1.0" }
three = { path = "../implicit/three", version = "0.1.5" }
2 changes: 1 addition & 1 deletion tests/cargo-upgrade/to_lockfile/stderr.log
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Checking one's dependencies
Upgrading my-package: v0.2.0 -> v0.2.3
warning: ignoring three, could not find package: not in lock file
Upgrading three: v0.1.0 -> v0.1.5
Checking three's dependencies
Upgrading my-package: v0.2.0 -> v0.2.3
Checking two's dependencies
Expand Down

0 comments on commit 36dbb19

Please sign in to comment.