Skip to content

Commit

Permalink
Lookup translated names in workspace deps
Browse files Browse the repository at this point in the history
  • Loading branch information
dohse committed Apr 17, 2024
1 parent 39c1d77 commit 1f04812
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 18 deletions.
45 changes: 29 additions & 16 deletions src/cargo/ops/cargo_add/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -364,24 +364,28 @@ fn resolve_dependency(
};
selected_dep = populate_dependency(selected_dep, arg);

let old_dep = get_existing_dependency(manifest, selected_dep.toml_key(), section)?;
let mut dependency = if let Some(mut old_dep) = old_dep.clone() {
if old_dep.name != selected_dep.name {
// Assuming most existing keys are not relevant when the package changes
if selected_dep.optional.is_none() {
selected_dep.optional = old_dep.optional;
let get_dependency = |mut selected_dep: Dependency| {
let old_dep = get_existing_dependency(manifest, selected_dep.toml_key(), section)?;
let dependency = if let Some(mut old_dep) = old_dep.clone() {
if old_dep.name != selected_dep.name {
// Assuming most existing keys are not relevant when the package changes
if selected_dep.optional.is_none() {
selected_dep.optional = old_dep.optional;
}
selected_dep
} else {
if selected_dep.source().is_some() {
// Overwrite with `crate_spec`
old_dep.source = selected_dep.source;
}
populate_dependency(old_dep, arg)
}
selected_dep
} else {
if selected_dep.source().is_some() {
// Overwrite with `crate_spec`
old_dep.source = selected_dep.source;
}
populate_dependency(old_dep, arg)
}
} else {
selected_dep
selected_dep
};
anyhow::Ok((old_dep, dependency))
};
let (mut old_dep, mut dependency) = get_dependency(selected_dep)?;

if dependency.source().is_none() {
// Checking for a workspace dependency happens first since a member could be specified
Expand All @@ -403,14 +407,23 @@ fn resolve_dependency(
let latest =
get_latest_dependency(spec, &dependency, honor_rust_version, gctx, registry)?;

dependency = dependency.set_source(latest.source.expect("latest always has a source"));

if dependency.name != latest.name {
gctx.shell().warn(format!(
"translating `{}` to `{}`",
dependency.name, latest.name,
))?;
dependency.name = latest.name; // Normalize the name
let (norm_old_dep, norm_dep) = get_dependency(dependency.clone())?;

// Re-check workspace dependencies table with normalized name
if let Some(_dep) = find_workspace_dep(norm_dep.toml_key(), ws.root_manifest()).ok()
{
old_dep = norm_old_dep;
dependency = norm_dep.set_source(WorkspaceSource::new());
}
}
dependency = dependency.set_source(latest.source.expect("latest always has a source"));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ use cargo_test_support::str;
use cargo_test_support::Project;

#[cargo_test]
#[ignore]
fn case() {
cargo_test_support::registry::init();

Expand Down
1 change: 0 additions & 1 deletion tests/testsuite/cargo_add/features_fuzzy/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ use cargo_test_support::str;
use cargo_test_support::Project;

#[cargo_test]
#[ignore]
fn case() {
cargo_test_support::registry::init();
cargo_test_support::registry::Package::new("your_face", "99999.0.0+my-package")
Expand Down

0 comments on commit 1f04812

Please sign in to comment.