diff --git a/src/manifest/mod.rs b/src/manifest/mod.rs index 668541ac..80f322c8 100644 --- a/src/manifest/mod.rs +++ b/src/manifest/mod.rs @@ -423,7 +423,10 @@ impl CrateData { let current_idx = data .packages .iter() - .position(|pkg| pkg.name == manifest.package.name) + .position(|pkg| { + pkg.name == manifest.package.name + && CrateData::is_same_path(&pkg.manifest_path, &manifest_path) + }) .ok_or_else(|| format_err!("failed to find package in metadata"))?; Ok(CrateData { @@ -434,6 +437,15 @@ impl CrateData { }) } + fn is_same_path(path1: &Path, path2: &Path) -> bool { + if let Ok(path1) = fs::canonicalize(&path1) { + if let Ok(path2) = fs::canonicalize(&path2) { + return path1 == path2; + } + } + path1 == path2 + } + /// Read the `manifest_path` file and deserializes it using the toml Deserializer. /// Returns a Result containing `ManifestAndUnsedKeys` which contains `CargoManifest` /// and a `BTreeSet` containing the unused keys from the parsed file. diff --git a/tests/all/build.rs b/tests/all/build.rs index dbcdaaeb..82af9fa6 100644 --- a/tests/all/build.rs +++ b/tests/all/build.rs @@ -309,3 +309,70 @@ fn build_from_new() { .assert() .success(); } + +#[test] +fn build_crates_with_same_names() { + let fixture = utils::fixture::Fixture::new(); + fixture + .readme() + .file( + "somename1/Cargo.toml", + r#" + [package] + authors = ["The wasm-pack developers"] + description = "so awesome rust+wasm package" + license = "WTFPL" + name = "somename" + repository = "https://github.com/rustwasm/wasm-pack.git" + version = "0.1.0" + + [lib] + crate-type = ["cdylib"] + + [dependencies] + wasm-bindgen = "0.2" + somenameother = { path = "../somename2", package = "somename" } + "#, + ) + .file( + "somename1/src/lib.rs", + r#" + extern crate wasm_bindgen; + use wasm_bindgen::prelude::*; + #[wasm_bindgen] + pub fn method() -> i32 { + somenameother::method() + } + "#, + ) + .file( + "somename2/Cargo.toml", + r#" + [package] + authors = ["The wasm-pack developers"] + description = "so awesome rust+wasm package" + license = "WTFPL" + name = "somename" + repository = "https://github.com/rustwasm/wasm-pack.git" + version = "0.1.1" + + [lib] + crate-type = ["rlib"] + "#, + ) + .file( + "somename2/src/lib.rs", + r#" + pub fn method() -> i32 { + 0 + } + "#, + ); + fixture.install_local_wasm_bindgen(); + fixture + .wasm_pack() + .current_dir(fixture.path.join("somename1")) + .arg("build") + .assert() + .success(); +}