]> git.lizzy.rs Git - rust.git/commitdiff
add extra include paths, if target's path is manually set in Cargo.toml to be
authorrezural <rezural@protonmail.com>
Mon, 21 Jun 2021 22:59:57 +0000 (08:59 +1000)
committerrezural <rezural@protonmail.com>
Mon, 21 Jun 2021 22:59:57 +0000 (08:59 +1000)
crates/project_model/src/workspace.rs

index e67ba2bd92849e40ae290f90062b45368c2bb637..5c178785d808f3ab5acd4877a8343c567d68a41c 100644 (file)
@@ -234,6 +234,23 @@ pub fn to_roots(&self, build_data: Option<&BuildDataResult>) -> Vec<PackageRoot>
                                 .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"));