From: Aleksey Kladov Date: Tue, 14 Feb 2017 20:04:24 +0000 (+0300) Subject: Normalize ws root path X-Git-Tag: archive/raspbian/0.35.0-2+rpi1~3^2^2^2^2^2^2^2~22^2~9^2~151^2 X-Git-Url: https://dgit.raspbian.org/?a=commitdiff_plain;h=0a3db8b7090247e51d282052ff1bf0efa1f48cd2;p=cargo.git Normalize ws root path closes #3586 --- diff --git a/src/cargo/util/important_paths.rs b/src/cargo/util/important_paths.rs index 5ee44cf20..97e7eed1c 100644 --- a/src/cargo/util/important_paths.rs +++ b/src/cargo/util/important_paths.rs @@ -1,6 +1,7 @@ use std::fs; use std::path::{Path, PathBuf}; use util::{CargoResult, human}; +use util::paths; /// Iteratively search for `file` in `pwd` and its parents, returning /// the path of the directory. @@ -38,7 +39,7 @@ pub fn find_root_manifest_for_wd(manifest_path: Option, cwd: &Path) -> CargoResult { match manifest_path { Some(path) => { - let absolute_path = cwd.join(&path); + let absolute_path = paths::normalize_path(&cwd.join(&path)); if !absolute_path.ends_with("Cargo.toml") { bail!("the manifest-path must be a path to a Cargo.toml file") } diff --git a/tests/workspaces.rs b/tests/workspaces.rs index dc3860f27..0ae7a609a 100644 --- a/tests/workspaces.rs +++ b/tests/workspaces.rs @@ -1102,6 +1102,39 @@ fn relative_path_for_member_works() { assert_that(p.cargo("build").cwd(p.root().join("bar")), execs().with_status(0)); } +#[test] +fn relative_path_for_root_works() { + let p = project("foo") + .file("Cargo.toml", r#" + [project] + name = "foo" + version = "0.1.0" + authors = [] + + [workspace] + + [dependencies] + subproj = { path = "./subproj" } + "#) + .file("src/main.rs", "fn main() {}") + .file("subproj/Cargo.toml", r#" + [project] + name = "subproj" + version = "0.1.0" + authors = [] + "#) + .file("subproj/src/main.rs", "fn main() {}"); + p.build(); + + assert_that(p.cargo("build").cwd(p.root()) + .arg("--manifest-path").arg("./Cargo.toml"), + execs().with_status(0)); + + assert_that(p.cargo("build").cwd(p.root().join("subproj")) + .arg("--manifest-path").arg("../Cargo.toml"), + execs().with_status(0)); +} + #[test] fn path_dep_outside_workspace_is_not_member() { let p = project("foo")