Skip to content

Commit

Permalink
Fix issue with base paths and workspaces
Browse files Browse the repository at this point in the history
  • Loading branch information
dpaoliello committed Nov 15, 2023
1 parent 82c7332 commit d522203
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/cargo/util/toml/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1494,7 +1494,11 @@ impl schema::InheritableFields {
};
let mut dep = dep.clone();
if let schema::TomlDependency::Detailed(detailed) = &mut dep {
detailed.resolve_path(name, self.ws_root(), package_root)?;
if detailed.base.is_none() {
// If this is a path dependency without a base, then update the path to be relative
// to the workspace root instead.
detailed.resolve_path(name, self.ws_root(), package_root)?;
}
}
Ok(dep)
}
Expand Down
60 changes: 60 additions & 0 deletions tests/testsuite/path.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ use cargo_test_support::{sleep_ms, t};
use std::fs;

#[cargo_test]
// I have no idea why this is failing spuriously on Windows;
// for more info, see #3466.
#[cfg(not(windows))]
fn cargo_compile_with_nested_deps_shorthand() {
let p = project()
.file(
Expand Down Expand Up @@ -661,6 +664,63 @@ fn path_with_base() {
.run();
}

#[cargo_test]
fn workspace_with_base() {
let bar = project()
.at("dep_with_base")
.file("Cargo.toml", &basic_manifest("dep_with_base", "0.5.0"))
.file("src/lib.rs", "")
.build();

fs::create_dir(&paths::root().join(".cargo")).unwrap();
fs::write(
&paths::root().join(".cargo/config"),
&format!(
"[base_path]\ntest = '{}'",
bar.root().parent().unwrap().display()
),
)
.unwrap();

let p = project()
.file(
"Cargo.toml",
r#"
[package]
name = "parent"
version = "0.1.0"
authors = []
[workspace]
members = ["child"]
[workspace.dependencies.dep_with_base]
path = 'dep_with_base'
base = 'test'
"#,
)
.file("src/main.rs", "fn main() {}")
.file(
"child/Cargo.toml",
r#"
[package]
name = "child"
version = "0.1.0"
authors = []
workspace = ".."
[dependencies.dep_with_base]
workspace = true
"#,
)
.file("child/src/main.rs", "fn main() {}");
let p = p.build();

p.cargo("build -v -Zpath-bases")
.masquerade_as_nightly_cargo(&["path-bases"])
.run();
}

#[cargo_test]
fn unknown_base() {
let p = project()
Expand Down

0 comments on commit d522203

Please sign in to comment.