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

Use canonical paths for checking equality #3489

Merged
merged 1 commit into from
Jan 10, 2017
Merged
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
Normalize paths before checking for equality
  • Loading branch information
matklad committed Jan 7, 2017
commit 083da1417774fdadbc15cbae2175bd617339c05d
7 changes: 4 additions & 3 deletions src/cargo/core/workspace.rs
Original file line number Diff line number Diff line change
@@ -304,15 +304,16 @@ impl<'cfg> Workspace<'cfg> {
}

fn find_path_deps(&mut self, manifest_path: &Path) -> CargoResult<()> {
if self.members.iter().any(|p| p == manifest_path) {
let manifest_path = paths::normalize_path(manifest_path);
if self.members.iter().any(|p| p == &manifest_path) {
return Ok(())
}

debug!("find_members - {}", manifest_path.display());
self.members.push(manifest_path.to_path_buf());
self.members.push(manifest_path.clone());

let candidates = {
let pkg = match *self.packages.load(manifest_path)? {
let pkg = match *self.packages.load(&manifest_path)? {
MaybePackage::Package(ref p) => p,
MaybePackage::Virtual(_) => return Ok(()),
};
27 changes: 27 additions & 0 deletions tests/workspaces.rs
Original file line number Diff line number Diff line change
@@ -1074,3 +1074,30 @@ fn error_if_parent_cargo_toml_is_invalid() {
.with_stderr_contains("\
[ERROR] failed to parse manifest at `[..]`"));
}

#[test]
fn relative_path_for_member_works() {
let p = project("foo")
.file("foo/Cargo.toml", r#"
[project]
name = "foo"
version = "0.1.0"
authors = []

[workspace]
members = ["../bar"]
"#)
.file("foo/src/main.rs", "fn main() {}")
.file("bar/Cargo.toml", r#"
[project]
name = "bar"
version = "0.1.0"
authors = []
workspace = "../foo"
"#)
.file("bar/src/main.rs", "fn main() {}");
p.build();

assert_that(p.cargo("build").cwd(p.root().join("foo")), execs().with_status(0));
assert_that(p.cargo("build").cwd(p.root().join("bar")), execs().with_status(0));
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With current cargo, this invocation will fail with bar believes it is in workspace foo, but foo does not think so. This happens because paths are compared, and they look like foo/Cargo.toml and bar/../foo/Cargo.toml.

}