Skip to content

Commit

Permalink
fix(subplanners): Match aliased dependencies by name and semver (#346)
Browse files Browse the repository at this point in the history
* fix(subplanners): Match aliased dependencies by name and semver

* Simplify the aliased dependency test
  • Loading branch information
Arm1stice committed Jan 19, 2021
1 parent 32e5c27 commit 0cb6178
Show file tree
Hide file tree
Showing 3 changed files with 433 additions and 35,028 deletions.
35 changes: 20 additions & 15 deletions impl/src/planning.rs
Original file line number Diff line number Diff line change
Expand Up @@ -222,36 +222,41 @@ mod tests {
Vec::new(), /* attrs */
)));

// Retrieve the crates that have aliased dependencies from the planned build
let crates_with_aliased_deps: Vec<CrateContext> = planned_build_res
.unwrap()
.crate_contexts
.into_iter()
.filter(|krate| krate.default_deps.aliased_dependencies.len() != 0)
.collect();

// Vec length shouldn't be 0
assert!(
crates_with_aliased_deps.len() != 0,
"Crates with aliased dependencies is 0"
// Vec length should be 1 as only cargo-raze-alias-test should have aliased dependencies
assert_eq!(
crates_with_aliased_deps.len(),
1,
"Crates with aliased dependencies is not 1"
);

// Find the actix-web crate
let actix_web_position = crates_with_aliased_deps
// Find and verify that the cargo-raze-alias-test crate is in the Vec
let krate_position = crates_with_aliased_deps
.iter()
.position(|krate| krate.pkg_name == "actix-http");
assert!(actix_web_position.is_some());
.position(|krate| krate.pkg_name == "cargo-raze-alias-test");
assert!(krate_position.is_some());

// Get crate context using computed position
let actix_http_context = crates_with_aliased_deps[actix_web_position.unwrap()].clone();
let krate_context = crates_with_aliased_deps[krate_position.unwrap()].clone();

assert!(actix_http_context.default_deps.aliased_dependencies.len() == 1);
assert!(
actix_http_context.default_deps.aliased_dependencies[0].target
== "@raze_test__failure__0_1_8//:failure"
// There are two default dependencies for cargo-raze-alias-test, log^0.4 and log^0.3
// However, log^0.3 is aliased to old_log while log^0.4 isn't aliased. Therefore, we
// should only see one aliased dependency (log^0.3 -> old_log) which shows that the
// name and semver matching for aliased dependencies is working correctly
assert!(krate_context.default_deps.aliased_dependencies.len() == 1);
assert_eq!(
krate_context.default_deps.aliased_dependencies[0].target,
"@raze_test__log__0_3_9//:log"
);
assert!(actix_http_context.default_deps.aliased_dependencies[0].alias == "fail_ure");
assert_eq!(krate_context.default_deps.aliased_dependencies[0].alias, "old_log");
}

#[test]
fn test_plan_build_produces_proc_macro_dependencies() {
let mut settings = dummy_raze_settings();
Expand Down
18 changes: 11 additions & 7 deletions impl/src/planning/subplanners.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ struct DependencyNames {
// Dependencies that are required for tests
dev_dep_names: Vec<String>,
// Dependencies that have been renamed and need to be aliased in the build rule
aliased_dep_names: HashMap<String, String>,
aliased_dep_names: HashMap<String, (semver::VersionReq, String)>,
}

// TODO(acmcarther): Remove this struct -- move it into CrateContext.
Expand Down Expand Up @@ -525,11 +525,15 @@ impl<'planner> CrateSubplanner<'planner> {
dep_set.normal_deps.push(buildable_dependency);
}
// Only add aliased normal deps to the Vec
if let Some(alias) = aliased_dep_names.get(&dep_package.name) {
dep_set.aliased_deps.push(DependencyAlias {
target: buildable_target.clone(),
alias: util::sanitize_ident(alias),
})
if let Some(alias_pair) = aliased_dep_names.get(&dep_package.name) {
// Check whether the package's version matches the semver requirement
// of the package that had an alias
if alias_pair.0.matches(&dep_package.version) {
dep_set.aliased_deps.push(DependencyAlias {
target: buildable_target.clone(),
alias: util::sanitize_ident(&alias_pair.1),
})
}
}
}
}
Expand Down Expand Up @@ -644,7 +648,7 @@ impl<'planner> CrateSubplanner<'planner> {
if let Some(alias) = dep.rename.as_ref() {
dep_names
.aliased_dep_names
.insert(dep.name.clone(), alias.clone());
.insert(dep.name.clone(), (dep.req.clone(), alias.clone()));
}
}

Expand Down
Loading

0 comments on commit 0cb6178

Please sign in to comment.