From dca438936cb985531dff219f349ee89ac1c3a9d0 Mon Sep 17 00:00:00 2001 From: koushiro Date: Wed, 27 Nov 2019 15:13:05 +0800 Subject: [PATCH 1/2] Add feature deploy Signed-off-by: koushiro --- Cargo.toml | 12 +++++++----- src/cmd/build.rs | 9 +-------- src/cmd/deploy.rs | 2 +- src/cmd/mod.rs | 6 ++++-- src/main.rs | 2 ++ 5 files changed, 15 insertions(+), 16 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index aed55917..5fc193ed 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -24,11 +24,12 @@ zip = { version = "0.5", default-features = false } pwasm-utils = "0.12" parity-wasm = "0.41" cargo_metadata = "0.9" -substrate-primitives = { git = "https://github.com/paritytech/substrate/", package = "substrate-primitives" } -subxt = { git = "https://github.com/paritytech/substrate-subxt/", branch = "v0.3", package = "substrate-subxt" } -tokio = "0.1" -futures = "0.1" -url = "1.7" + +substrate-primitives = { git = "https://github.com/paritytech/substrate/", package = "substrate-primitives", optional = true } +subxt = { git = "https://github.com/paritytech/substrate-subxt/", branch = "v0.3", package = "substrate-subxt", optional = true } +tokio = { version = "0.1", optional = true } +futures = { version = "0.1", optional = true } +url = { version = "1.7", optional = true } [build-dependencies] anyhow = "1.0" @@ -42,4 +43,5 @@ wabt = "0.9" [features] default = [] +deploy = ["substrate-primitives", "subxt", "tokio", "futures", "url"] test-ci-only = [] diff --git a/src/cmd/build.rs b/src/cmd/build.rs index 7687c7e6..da1da85b 100644 --- a/src/cmd/build.rs +++ b/src/cmd/build.rs @@ -26,14 +26,7 @@ const MAX_MEMORY_PAGES: u32 = 16; /// Relevant metadata obtained from Cargo.toml. pub struct CrateMetadata { original_wasm: PathBuf, - dest_wasm: PathBuf, -} - -impl CrateMetadata { - /// Get the path of the wasm destination file - pub fn dest_wasm(self) -> PathBuf { - self.dest_wasm - } + pub dest_wasm: PathBuf, } /// Parses the contract manifest and returns relevant metadata. diff --git a/src/cmd/deploy.rs b/src/cmd/deploy.rs index cd9b8d85..245d79b2 100644 --- a/src/cmd/deploy.rs +++ b/src/cmd/deploy.rs @@ -27,7 +27,7 @@ use crate::cmd::build::{self, CrateMetadata}; /// /// Defaults to the target contract wasm in the current project, inferred via the crate metadata. fn load_contract_code(path: Option<&PathBuf>) -> Result> { - let default_wasm_path = build::collect_crate_metadata(path).map(CrateMetadata::dest_wasm)?; + let default_wasm_path = build::collect_crate_metadata(path)?.dest_wasm; let contract_wasm_path = path.unwrap_or(&default_wasm_path); let mut data = Vec::new(); diff --git a/src/cmd/mod.rs b/src/cmd/mod.rs index b9fd558e..64a93ec5 100644 --- a/src/cmd/mod.rs +++ b/src/cmd/mod.rs @@ -23,13 +23,15 @@ use std::{ use anyhow::Result; mod build; +#[cfg(feature = "deploy")] mod deploy; mod metadata; mod new; +#[cfg(feature = "deploy")] +pub(crate) use self::deploy::execute_deploy; pub(crate) use self::{ - build::execute_build, deploy::execute_deploy, metadata::execute_generate_metadata, - new::execute_new, + build::execute_build, metadata::execute_generate_metadata, new::execute_new, }; fn exec_cargo(command: &str, args: &[&'static str], working_dir: Option<&PathBuf>) -> Result<()> { diff --git a/src/main.rs b/src/main.rs index 1ada966a..5f3e529d 100644 --- a/src/main.rs +++ b/src/main.rs @@ -91,6 +91,7 @@ enum Command { #[structopt(name = "test")] Test {}, /// Deploy the smart contract on-chain. (Also for testing purposes.) + #[cfg(feature = "deploy")] #[structopt(name = "deploy")] Deploy { /// Websockets url of a substrate node @@ -136,6 +137,7 @@ fn exec(cmd: Command) -> Result { Command::Build {} => cmd::execute_build(None), Command::GenerateMetadata {} => cmd::execute_generate_metadata(None), Command::Test {} => Err(anyhow::anyhow!("Command unimplemented")), + #[cfg(feature = "deploy")] Command::Deploy { url, suri, -- GitLab From 2594ebe74e236b4d8a1ae80ac4389389ac2081f8 Mon Sep 17 00:00:00 2001 From: koushiro Date: Thu, 28 Nov 2019 11:50:25 +0800 Subject: [PATCH 2/2] Update README about the deploy feature Signed-off-by: koushiro --- README.md | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/README.md b/README.md index f21c2ae4..f7781b59 100644 --- a/README.md +++ b/README.md @@ -32,6 +32,14 @@ SUBCOMMANDS: help Prints this message or the help of the given subcommand(s) ``` +## Feature + +The `deploy` subcommand is **disabled by default**, since it's not working properly at the moment and increases the build time. + +If you want to try it, you need to enable the `deploy` feature. + +Once it is working properly and the compilation time is acceptable, we will consider removing the `deploy` feature. + ## License The entire code within this repository is licensed under the [GPLv3](LICENSE). Please [contact us](https://www.parity.io/contact/) if you have questions about the licensing of our products. -- GitLab