Skip to content

Commit

Permalink
Merge pull request #830 from 0xd4d/find_correct_pkg
Browse files Browse the repository at this point in the history
Find the main package if multiple packages have the same name
  • Loading branch information
Pauan authored Jun 4, 2020
2 parents 2d0af80 + 2dd1413 commit 9f9634c
Show file tree
Hide file tree
Showing 2 changed files with 80 additions and 1 deletion.
14 changes: 13 additions & 1 deletion src/manifest/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -424,7 +424,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 {
Expand All @@ -435,6 +438,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<String>` containing the unused keys from the parsed file.
Expand Down
67 changes: 67 additions & 0 deletions tests/all/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

0 comments on commit 9f9634c

Please sign in to comment.