Skip to content

Commit

Permalink
applying code review to make get_sysroot_target_libdir more readable …
Browse files Browse the repository at this point in the history
…+ incorporated changes into corresponding test
  • Loading branch information
jofas committed Feb 6, 2023
1 parent 96366bd commit 4bdface
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 26 deletions.
43 changes: 19 additions & 24 deletions src/cargo/core/compiler/compilation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -381,30 +381,25 @@ fn get_sysroot_target_libdir(
bcx.all_kinds
.iter()
.map(|&kind| {
Ok((
kind,
bcx.target_data
.get_info(kind)
.ok_or_else(|| {
let target = match kind {
CompileKind::Host => "host".to_owned(),
CompileKind::Target(s) => s.short_name().to_owned(),
};

let dependency = bcx
.unit_graph
.iter()
.find_map(|(u, _)| (unit.kind == kind).then_some(unit.pkg.summary().package_id()))
.unwrap();

anyhow::anyhow!(
"could not find specification for target `{target}`.\n \
Dependency `{dependency}` requires to build for target `{target}`."
)
})?
.sysroot_target_libdir
.clone(),
))
let Some(info) = bcx.target_data.get_info(kind) else {
let target = match kind {
CompileKind::Host => "host".to_owned(),
CompileKind::Target(s) => s.short_name().to_owned(),
};

let dependency = bcx
.unit_graph
.iter()
.find_map(|(u, _)| (u.kind == kind).then_some(u.pkg.summary().package_id()))
.unwrap();

anyhow::bail!(
"could not find specification for target `{target}`.\n \
Dependency `{dependency}` requires to build for target `{target}`."
)
};

Ok((kind, info.sysroot_target_libdir.clone()))
})
.collect()
}
Expand Down
4 changes: 2 additions & 2 deletions tests/testsuite/artifact_dep.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2900,8 +2900,8 @@ fn check_transitive_artifact_dependency_with_different_target() {
p.cargo("check -Z bindeps")
.masquerade_as_nightly_cargo(&["bindeps"])
.with_stderr_contains(
"error: could not find specification for target \"custom-target\".\n \
Dependency `baz v0.0.0` requires to build for target \"custom-target\".",
"error: could not find specification for target `custom-target`.\n \
Dependency `baz v0.0.0 [..]` requires to build for target `custom-target`.",
)
.with_status(101)
.run();
Expand Down

0 comments on commit 4bdface

Please sign in to comment.