Skip to content

Commit 9f9634c

Browse files
authored
Merge pull request drager#830 from 0xd4d/find_correct_pkg
Find the main package if multiple packages have the same name
2 parents 2d0af80 + 2dd1413 commit 9f9634c

File tree

2 files changed

+80
-1
lines changed

2 files changed

+80
-1
lines changed

src/manifest/mod.rs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -424,7 +424,10 @@ impl CrateData {
424424
let current_idx = data
425425
.packages
426426
.iter()
427-
.position(|pkg| pkg.name == manifest.package.name)
427+
.position(|pkg| {
428+
pkg.name == manifest.package.name
429+
&& CrateData::is_same_path(&pkg.manifest_path, &manifest_path)
430+
})
428431
.ok_or_else(|| format_err!("failed to find package in metadata"))?;
429432

430433
Ok(CrateData {
@@ -435,6 +438,15 @@ impl CrateData {
435438
})
436439
}
437440

441+
fn is_same_path(path1: &Path, path2: &Path) -> bool {
442+
if let Ok(path1) = fs::canonicalize(&path1) {
443+
if let Ok(path2) = fs::canonicalize(&path2) {
444+
return path1 == path2;
445+
}
446+
}
447+
path1 == path2
448+
}
449+
438450
/// Read the `manifest_path` file and deserializes it using the toml Deserializer.
439451
/// Returns a Result containing `ManifestAndUnsedKeys` which contains `CargoManifest`
440452
/// and a `BTreeSet<String>` containing the unused keys from the parsed file.

tests/all/build.rs

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -309,3 +309,70 @@ fn build_from_new() {
309309
.assert()
310310
.success();
311311
}
312+
313+
#[test]
314+
fn build_crates_with_same_names() {
315+
let fixture = utils::fixture::Fixture::new();
316+
fixture
317+
.readme()
318+
.file(
319+
"somename1/Cargo.toml",
320+
r#"
321+
[package]
322+
authors = ["The wasm-pack developers"]
323+
description = "so awesome rust+wasm package"
324+
license = "WTFPL"
325+
name = "somename"
326+
repository = "https://github.com/rustwasm/wasm-pack.git"
327+
version = "0.1.0"
328+
329+
[lib]
330+
crate-type = ["cdylib"]
331+
332+
[dependencies]
333+
wasm-bindgen = "0.2"
334+
somenameother = { path = "../somename2", package = "somename" }
335+
"#,
336+
)
337+
.file(
338+
"somename1/src/lib.rs",
339+
r#"
340+
extern crate wasm_bindgen;
341+
use wasm_bindgen::prelude::*;
342+
#[wasm_bindgen]
343+
pub fn method() -> i32 {
344+
somenameother::method()
345+
}
346+
"#,
347+
)
348+
.file(
349+
"somename2/Cargo.toml",
350+
r#"
351+
[package]
352+
authors = ["The wasm-pack developers"]
353+
description = "so awesome rust+wasm package"
354+
license = "WTFPL"
355+
name = "somename"
356+
repository = "https://github.com/rustwasm/wasm-pack.git"
357+
version = "0.1.1"
358+
359+
[lib]
360+
crate-type = ["rlib"]
361+
"#,
362+
)
363+
.file(
364+
"somename2/src/lib.rs",
365+
r#"
366+
pub fn method() -> i32 {
367+
0
368+
}
369+
"#,
370+
);
371+
fixture.install_local_wasm_bindgen();
372+
fixture
373+
.wasm_pack()
374+
.current_dir(fixture.path.join("somename1"))
375+
.arg("build")
376+
.assert()
377+
.success();
378+
}

0 commit comments

Comments
 (0)