9353: Include extra targets when the pkg_root is not the same as the target root. r=matklad a=rezural

Fixes #7715 

For example, if a sub-crate includes sets the path='../somewhere-else/lib.rs', the files will not be in pkg_root , but in the target root's parent.

It may actually be in root.parent().parent(), I'm not sure about that.

At the moment it is just a fix, are there any relevant tests that this could go in? I've got about 1 brain cell left... but im happy to add tests where appropriate.


Co-authored-by: rezural <rezural@protonmail.com>
This commit is contained in:
bors[bot] 2021-06-23 21:33:30 +00:00 committed by GitHub
commit 85a59de39f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -234,6 +234,23 @@ impl ProjectWorkspace {
.and_then(|it| it.out_dir.clone()),
);
// In case target's path is manually set in Cargo.toml to be
// outside the package root, add its parent as an extra include.
// An example of this situation would look like this:
//
// ```toml
// [lib]
// path = "../../src/lib.rs"
// ```
let extra_targets = cargo[pkg]
.targets
.iter()
.filter(|&&tgt| cargo[tgt].kind == TargetKind::Lib)
.filter_map(|&tgt| cargo[tgt].root.parent())
.map(|tgt| tgt.normalize().to_path_buf())
.filter(|path| !path.starts_with(pkg_root.clone()));
include.extend(extra_targets);
let mut exclude = vec![pkg_root.join(".git")];
if is_member {
exclude.push(pkg_root.join("target"));