Skip to content

Commit

Permalink
Prefer workspace for root_module path
Browse files Browse the repository at this point in the history
  • Loading branch information
martingms committed Dec 18, 2024
1 parent 367aa40 commit 284f5a2
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,9 @@ mod tests {
.find(|c| &c.display_name == "generated_srcs")
.unwrap();
assert!(gen.root_module.starts_with("/"));
assert!(gen.root_module.ends_with("/lib.rs"));
assert!(gen
.root_module
.ends_with("rules_rust_test_rust_analyzer/lib.rs"));

let include_dirs = &gen.source.as_ref().unwrap().include_dirs;
assert!(include_dirs.len() == 1);
Expand Down
9 changes: 9 additions & 0 deletions tools/rust_analyzer/aquery.rs
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,15 @@ fn consolidate_crate_specs(crate_specs: Vec<CrateSpec>) -> anyhow::Result<BTreeS
existing.proc_macro_dylib_path.replace(dylib_path.clone());
}
}

// Prefer using workspace for root_module path if possible.
// A test crate might get an __EXEC_ROOT__-based root_module when depending
// on a library crate with mixed generated sources, for example.
if existing.root_module.starts_with("__EXEC_ROOT__")
&& spec.root_module.starts_with("__WORKSPACE__")
{
existing.root_module = spec.root_module;
}
} else {
consolidated_specs.insert(spec.crate_id.clone(), spec);
}
Expand Down

0 comments on commit 284f5a2

Please sign in to comment.