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

Another fix for workspace path joining #8964

Closed
wants to merge 1 commit 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
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ libc = "0.2"
log = "0.4.6"
libgit2-sys = "0.12.14"
memchr = "2.1.3"
normpath = "0.1"
num_cpus = "1.0"
opener = "0.4"
percent-encoding = "2.0"
Expand Down
6 changes: 5 additions & 1 deletion src/cargo/core/workspace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use std::slice;

use glob::glob;
use log::debug;
use normpath::BasePath;
use url::Url;

use crate::core::features::Features;
Expand Down Expand Up @@ -1198,7 +1199,10 @@ impl WorkspaceRootConfig {
let mut expanded_list = Vec::new();

for glob in globs {
let pathbuf = self.root_dir.join(glob);
let pathbuf = BasePath::new(&self.root_dir)
.chain_err(|| "failed to read the current directory")?
.join(glob)
.into_path_buf();
let expanded_paths = Self::expand_member_path(&pathbuf)?;

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

// https://github.com/rust-lang/cargo/pull/8874
#[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();
}