Skip to content

Commit

Permalink
Find the main package if multiple packages have the same name
Browse files Browse the repository at this point in the history
  • Loading branch information
wtfsck committed Apr 15, 2020
1 parent 9209df9 commit 6c0c144
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
Expand Up @@ -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 {
Expand All @@ -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<String>` containing the unused keys from the parsed file.
Expand Down
67 changes: 67 additions & 0 deletions tests/all/build.rs
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 6c0c144

Please sign in to comment.