Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Append workspace paths using components #8874

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion src/cargo/core/workspace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1198,7 +1198,11 @@ impl WorkspaceRootConfig {
let mut expanded_list = Vec::new();

for glob in globs {
let pathbuf = self.root_dir.join(glob);
let pathbuf = self
.root_dir
.components()
.chain((&Path::new(&glob)).components())
.collect::<PathBuf>();
let expanded_paths = Self::expand_member_path(&pathbuf)?;

// If glob does not find any valid paths, then put the original
Expand Down
50 changes: 50 additions & 0 deletions tests/testsuite/workspaces.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2396,3 +2396,53 @@ fn virtual_primary_package_env_var() {
p.cargo("clean").run();
p.cargo("test -p foo").run();
}

#[cargo_test]
#[cfg(windows)]
fn unc_workspace_subfolder() {
let p = project()
.file(
"Cargo.toml",
r#"
[workspace]
# These paths cannot use globs because the glob crate does not support globs in UNC paths
# for unclear reasons
members = ["foo", "crates/bar"]
"#,
)
.file("foo/Cargo.toml", &basic_manifest("foo", "0.1.0"))
.file("foo/src/lib.rs", "")
.file("crates/bar/Cargo.toml", &basic_manifest("bar", "0.1.0"))
.file("crates/bar/src/lib.rs", "");
let p = p.build();
// Check that this project can be built normally
p.cargo("build").run();

let canon = p
.root()
.canonicalize()
.expect("Build dir cannot be canonicalised");

// `std` has this method, but it's private
// canon.components().prefix_verbatim(),
match &canon.components().next() {
Some(std::path::Component::Prefix(it)) if it.kind().is_verbatim() => (),
// If this is because the std implementation has changed, this test should
// be updated to use a different method of getting a UNC path to the build_dir
_ => panic!("canonicalize unexpectedly didn't create a UNC path on windows."),
};
p.cargo("build")
.arg("--manifest-path")
.arg(canon.join("Cargo.toml"))
.run();
p.cargo("clean").run();
p.cargo("build")
.arg("--manifest-path")
.arg(canon.join("Cargo.toml"))
.run();
p.cargo("build")
.arg("--manifest-path")
// This path using a backslash *is* required, because canon is a UNC path
.arg(canon.join("foo\\Cargo.toml"))
.run();
}