Skip to content

Commit 91e3293

Browse files
authored
Merge pull request #389 from xmclark/fix-canonical-paths-on-windows
fix canonical paths windows
2 parents b107874 + b3d62e1 commit 91e3293

File tree

3 files changed

+168
-8
lines changed

3 files changed

+168
-8
lines changed

src/command/utils.rs

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,13 @@ use emoji;
44
use failure;
55
use progressbar::Step;
66
use std::fs;
7-
use std::io;
87
use std::path::{Path, PathBuf};
98
use PBAR;
109

1110
/// If an explicit path is given, then use it, otherwise assume the current
1211
/// directory is the crate path.
13-
pub fn set_crate_path(path: Option<PathBuf>) -> io::Result<PathBuf> {
14-
let crate_path = match path {
15-
Some(p) => p,
16-
None => PathBuf::from("."),
17-
};
18-
19-
crate_path.canonicalize()
12+
pub fn set_crate_path(path: Option<PathBuf>) -> Result<PathBuf, failure::Error> {
13+
Ok(path.unwrap_or(PathBuf::from(".")))
2014
}
2115

2216
/// Construct our `pkg` directory in the crate.

tests/all/build.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,3 +125,16 @@ fn renamed_crate_name_works() {
125125
.unwrap();
126126
fixture.run(cli.cmd).unwrap();
127127
}
128+
129+
#[test]
130+
fn it_should_build_nested_project_with_transitive_dependencies() {
131+
let fixture = utils::fixture::transitive_dependencies();
132+
fixture.install_local_wasm_bindgen();
133+
let cli = Cli::from_iter_safe(vec![
134+
"wasm-pack",
135+
"build",
136+
&fixture.path.join("main").display().to_string(),
137+
])
138+
.unwrap();
139+
fixture.run(cli.cmd).unwrap();
140+
}

tests/all/utils/fixture.rs

Lines changed: 153 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -437,3 +437,156 @@ pub fn wbg_test_node() -> Fixture {
437437
);
438438
fixture
439439
}
440+
441+
pub fn transitive_dependencies() -> Fixture {
442+
fn project_main_fixture(fixture: &mut Fixture) {
443+
fixture.file(PathBuf::from("main/README"), "# Main Fixture\n");
444+
fixture.file(
445+
PathBuf::from("main/Cargo.toml"),
446+
r#"
447+
[package]
448+
authors = ["The wasm-pack developers"]
449+
description = "so awesome rust+wasm package"
450+
license = "WTFPL"
451+
name = "main_project"
452+
repository = "https://github.com/rustwasm/wasm-pack.git"
453+
version = "0.1.0"
454+
455+
[lib]
456+
crate-type = ["cdylib"]
457+
458+
[dependencies]
459+
wasm-bindgen = "=0.2.21"
460+
project_a = { path = "../project_a" }
461+
project_b = { path = "../project_b" }
462+
463+
[dev-dependencies]
464+
wasm-bindgen-test = "=0.2.21"
465+
"#,
466+
);
467+
fixture.file(
468+
PathBuf::from("main/src/lib.rs"),
469+
r#"
470+
extern crate wasm_bindgen;
471+
use wasm_bindgen::prelude::*;
472+
473+
// Import the `window.alert` function from the Web.
474+
#[wasm_bindgen]
475+
extern {
476+
fn alert(s: &str);
477+
}
478+
479+
// Export a `greet` function from Rust to JavaScript, that alerts a
480+
// hello message.
481+
#[wasm_bindgen]
482+
pub fn greet(name: &str) {
483+
alert(&format!("Hello, {}!", name));
484+
}
485+
"#,
486+
);
487+
}
488+
489+
fn project_a_fixture(fixture: &mut Fixture) {
490+
fixture.file(
491+
PathBuf::from("project_a/README"),
492+
"# Project Alpha Fixture\n",
493+
);
494+
fixture.file(
495+
PathBuf::from("project_a/Cargo.toml"),
496+
r#"
497+
[package]
498+
authors = ["The wasm-pack developers"]
499+
description = "so awesome rust+wasm package"
500+
license = "WTFPL"
501+
name = "project_a"
502+
repository = "https://github.com/rustwasm/wasm-pack.git"
503+
version = "0.1.0"
504+
505+
[lib]
506+
crate-type = ["cdylib"]
507+
508+
[dependencies]
509+
wasm-bindgen = "=0.2.21"
510+
project_b = { path = "../project_b" }
511+
512+
[dev-dependencies]
513+
wasm-bindgen-test = "=0.2.21"
514+
"#,
515+
);
516+
fixture.file(
517+
PathBuf::from("project_a/src/lib.rs"),
518+
r#"
519+
extern crate wasm_bindgen;
520+
// extern crate project_b;
521+
use wasm_bindgen::prelude::*;
522+
523+
// Import the `window.alert` function from the Web.
524+
#[wasm_bindgen]
525+
extern {
526+
fn alert(s: &str);
527+
}
528+
529+
// Export a `greet` function from Rust to JavaScript, that alerts a
530+
// hello message.
531+
#[wasm_bindgen]
532+
pub fn greet(name: &str) {
533+
alert(&format!("Hello, {}!", name));
534+
}
535+
"#,
536+
);
537+
}
538+
539+
fn project_b_fixture(fixture: &mut Fixture) {
540+
fixture.file(
541+
PathBuf::from("project_b/README"),
542+
"# Project Beta Fixture\n",
543+
);
544+
fixture.file(
545+
PathBuf::from("project_b/Cargo.toml"),
546+
r#"
547+
[package]
548+
authors = ["The wasm-pack developers"]
549+
description = "so awesome rust+wasm package"
550+
license = "WTFPL"
551+
name = "project_b"
552+
repository = "https://github.com/rustwasm/wasm-pack.git"
553+
version = "0.1.0"
554+
555+
[lib]
556+
crate-type = ["cdylib"]
557+
558+
[dependencies]
559+
wasm-bindgen = "=0.2.21"
560+
561+
[dev-dependencies]
562+
wasm-bindgen-test = "=0.2.21"
563+
"#,
564+
);
565+
fixture.file(
566+
PathBuf::from("project_b/src/lib.rs"),
567+
r#"
568+
extern crate wasm_bindgen;
569+
use wasm_bindgen::prelude::*;
570+
571+
// Import the `window.alert` function from the Web.
572+
#[wasm_bindgen]
573+
extern {
574+
fn alert(s: &str);
575+
}
576+
577+
// Export a `greet` function from Rust to JavaScript, that alerts a
578+
// hello message.
579+
#[wasm_bindgen]
580+
pub fn greet(name: &str) {
581+
alert(&format!("Hello, {}!", name));
582+
}
583+
"#,
584+
);
585+
}
586+
587+
let mut fixture = Fixture::new();
588+
project_b_fixture(&mut fixture);
589+
project_a_fixture(&mut fixture);
590+
project_main_fixture(&mut fixture);
591+
fixture
592+
}

0 commit comments

Comments
 (0)