From d34a0f4e22a7cd3c4bf2d9febe8e3b113805f556 Mon Sep 17 00:00:00 2001 From: Demi Obenour Date: Wed, 13 May 2020 22:55:24 +0000 Subject: [PATCH] Fix escaping of the wasm file path (#6018) * Fix escaping of the wasm file path * Add separate methods for escaped paths --- substrate/utils/wasm-builder/src/lib.rs | 4 ++-- substrate/utils/wasm-builder/src/wasm_project.rs | 15 ++++++++++----- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/substrate/utils/wasm-builder/src/lib.rs b/substrate/utils/wasm-builder/src/lib.rs index 195527a122..8c80181bb8 100644 --- a/substrate/utils/wasm-builder/src/lib.rs +++ b/substrate/utils/wasm-builder/src/lib.rs @@ -166,8 +166,8 @@ pub fn build_project_with_default_rustflags( pub const WASM_BINARY: &[u8] = include_bytes!("{wasm_binary}"); pub const WASM_BINARY_BLOATY: &[u8] = include_bytes!("{wasm_binary_bloaty}"); "#, - wasm_binary = wasm_binary.wasm_binary_path(), - wasm_binary_bloaty = bloaty.wasm_binary_bloaty_path(), + wasm_binary = wasm_binary.wasm_binary_path_escaped(), + wasm_binary_bloaty = bloaty.wasm_binary_bloaty_path_escaped(), ), ); } diff --git a/substrate/utils/wasm-builder/src/wasm_project.rs b/substrate/utils/wasm-builder/src/wasm_project.rs index 6248f81935..41e8694b85 100644 --- a/substrate/utils/wasm-builder/src/wasm_project.rs +++ b/substrate/utils/wasm-builder/src/wasm_project.rs @@ -37,9 +37,9 @@ use itertools::Itertools; pub struct WasmBinaryBloaty(PathBuf); impl WasmBinaryBloaty { - /// Returns the path to the bloaty wasm binary. - pub fn wasm_binary_bloaty_path(&self) -> String { - self.0.display().to_string().replace('\\', "/") + /// Returns the escaped path to the bloaty wasm binary. + pub fn wasm_binary_bloaty_path_escaped(&self) -> String { + self.0.display().to_string().escape_default().to_string() } } @@ -48,8 +48,13 @@ pub struct WasmBinary(PathBuf); impl WasmBinary { /// Returns the path to the wasm binary. - pub fn wasm_binary_path(&self) -> String { - self.0.display().to_string().replace('\\', "/") + pub fn wasm_binary_path(&self) -> &Path { + &self.0 + } + + /// Returns the escaped path to the wasm binary. + pub fn wasm_binary_path_escaped(&self) -> String { + self.0.display().to_string().escape_default().to_string() } }