Skip to content

Commit d522203

Browse files
committed
Fix issue with base paths and workspaces
1 parent 82c7332 commit d522203

File tree

2 files changed

+65
-1
lines changed

2 files changed

+65
-1
lines changed

src/cargo/util/toml/mod.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1494,7 +1494,11 @@ impl schema::InheritableFields {
14941494
};
14951495
let mut dep = dep.clone();
14961496
if let schema::TomlDependency::Detailed(detailed) = &mut dep {
1497-
detailed.resolve_path(name, self.ws_root(), package_root)?;
1497+
if detailed.base.is_none() {
1498+
// If this is a path dependency without a base, then update the path to be relative
1499+
// to the workspace root instead.
1500+
detailed.resolve_path(name, self.ws_root(), package_root)?;
1501+
}
14981502
}
14991503
Ok(dep)
15001504
}

tests/testsuite/path.rs

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ use cargo_test_support::{sleep_ms, t};
77
use std::fs;
88

99
#[cargo_test]
10+
// I have no idea why this is failing spuriously on Windows;
11+
// for more info, see #3466.
12+
#[cfg(not(windows))]
1013
fn cargo_compile_with_nested_deps_shorthand() {
1114
let p = project()
1215
.file(
@@ -661,6 +664,63 @@ fn path_with_base() {
661664
.run();
662665
}
663666

667+
#[cargo_test]
668+
fn workspace_with_base() {
669+
let bar = project()
670+
.at("dep_with_base")
671+
.file("Cargo.toml", &basic_manifest("dep_with_base", "0.5.0"))
672+
.file("src/lib.rs", "")
673+
.build();
674+
675+
fs::create_dir(&paths::root().join(".cargo")).unwrap();
676+
fs::write(
677+
&paths::root().join(".cargo/config"),
678+
&format!(
679+
"[base_path]\ntest = '{}'",
680+
bar.root().parent().unwrap().display()
681+
),
682+
)
683+
.unwrap();
684+
685+
let p = project()
686+
.file(
687+
"Cargo.toml",
688+
r#"
689+
[package]
690+
name = "parent"
691+
version = "0.1.0"
692+
authors = []
693+
694+
[workspace]
695+
members = ["child"]
696+
697+
[workspace.dependencies.dep_with_base]
698+
path = 'dep_with_base'
699+
base = 'test'
700+
"#,
701+
)
702+
.file("src/main.rs", "fn main() {}")
703+
.file(
704+
"child/Cargo.toml",
705+
r#"
706+
[package]
707+
name = "child"
708+
version = "0.1.0"
709+
authors = []
710+
workspace = ".."
711+
712+
[dependencies.dep_with_base]
713+
workspace = true
714+
"#,
715+
)
716+
.file("child/src/main.rs", "fn main() {}");
717+
let p = p.build();
718+
719+
p.cargo("build -v -Zpath-bases")
720+
.masquerade_as_nightly_cargo(&["path-bases"])
721+
.run();
722+
}
723+
664724
#[cargo_test]
665725
fn unknown_base() {
666726
let p = project()

0 commit comments

Comments
 (0)