From 9aef891880a027d1593ab2badfdd8d2e7b10a983 Mon Sep 17 00:00:00 2001 From: Andrew Jones Date: Thu, 29 Oct 2020 15:48:15 +0000 Subject: [PATCH 1/4] Add --manifest-path to build and generate-metadata --- src/main.rs | 14 ++++++++++++-- src/workspace/manifest.rs | 11 +++++++++++ 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/src/main.rs b/src/main.rs index 1e721a4b..09bab3ba 100644 --- a/src/main.rs +++ b/src/main.rs @@ -31,6 +31,7 @@ use subxt::PairSigner; use anyhow::{Error, Result}; use colored::Colorize; use structopt::{clap, StructOpt}; +use crate::workspace::ManifestPath; #[derive(Debug, StructOpt)] #[structopt(bin_name = "cargo")] @@ -163,6 +164,9 @@ enum Command { /// Compiles the smart contract #[structopt(name = "build")] Build { + /// Path to the Cargo.toml of the contract to build. + #[structopt(parse(from_os_str))] + manifest_path: Option, #[structopt(flatten)] verbosity: VerbosityFlags, #[structopt(flatten)] @@ -171,6 +175,9 @@ enum Command { /// Generate contract metadata artifacts #[structopt(name = "generate-metadata")] GenerateMetadata { + /// Path to the Cargo.toml of the contract for which to generate metadata + #[structopt(parse(from_os_str))] + manifest_path: Option, #[structopt(flatten)] verbosity: VerbosityFlags, #[structopt(flatten)] @@ -239,10 +246,11 @@ fn exec(cmd: Command) -> Result { match &cmd { Command::New { name, target_dir } => cmd::new::execute(name, target_dir.as_ref()), Command::Build { + manifest_path, verbosity, unstable_options, } => { - let manifest_path = Default::default(); + let manifest_path = ManifestPath::try_from(manifest_path.as_ref())?; let dest_wasm = cmd::build::execute( &manifest_path, verbosity.try_into()?, @@ -254,11 +262,13 @@ fn exec(cmd: Command) -> Result { )) } Command::GenerateMetadata { + manifest_path, verbosity, unstable_options, } => { + let manifest_path = ManifestPath::try_from(manifest_path.as_ref())?; let metadata_file = cmd::metadata::execute( - Default::default(), + manifest_path, verbosity.try_into()?, unstable_options.try_into()?, )?; diff --git a/src/workspace/manifest.rs b/src/workspace/manifest.rs index bf41a8e9..6d33d984 100644 --- a/src/workspace/manifest.rs +++ b/src/workspace/manifest.rs @@ -76,6 +76,17 @@ impl TryFrom<&PathBuf> for ManifestPath { } } +impl

TryFrom> for ManifestPath +where + P: AsRef +{ + type Error = anyhow::Error; + + fn try_from(value: Option

) -> Result { + value.map_or(Ok(Default::default()), ManifestPath::new) + } +} + impl Default for ManifestPath { fn default() -> ManifestPath { ManifestPath::new(MANIFEST_FILE).expect("it's a valid manifest file") -- GitLab From ca30c83ffccc3577cbb23509f9c7fe5b7342fc9f Mon Sep 17 00:00:00 2001 From: Andrew Jones Date: Thu, 29 Oct 2020 15:52:12 +0000 Subject: [PATCH 2/4] Fix up manifest path options --- src/main.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main.rs b/src/main.rs index 09bab3ba..1b10516b 100644 --- a/src/main.rs +++ b/src/main.rs @@ -165,7 +165,7 @@ enum Command { #[structopt(name = "build")] Build { /// Path to the Cargo.toml of the contract to build. - #[structopt(parse(from_os_str))] + #[structopt(long, parse(from_os_str))] manifest_path: Option, #[structopt(flatten)] verbosity: VerbosityFlags, @@ -176,7 +176,7 @@ enum Command { #[structopt(name = "generate-metadata")] GenerateMetadata { /// Path to the Cargo.toml of the contract for which to generate metadata - #[structopt(parse(from_os_str))] + #[structopt(long, parse(from_os_str))] manifest_path: Option, #[structopt(flatten)] verbosity: VerbosityFlags, -- GitLab From 8936b88701034e09379a6fea007991ae1a0ebfeb Mon Sep 17 00:00:00 2001 From: Andrew Jones Date: Thu, 29 Oct 2020 16:06:28 +0000 Subject: [PATCH 3/4] Fmt and use ManifestPath --- src/cmd/build.rs | 2 +- src/cmd/metadata.rs | 3 +-- src/crate_metadata.rs | 2 +- src/main.rs | 3 ++- src/workspace/manifest.rs | 2 +- 5 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/cmd/build.rs b/src/cmd/build.rs index 7848b301..4fa2011b 100644 --- a/src/cmd/build.rs +++ b/src/cmd/build.rs @@ -291,7 +291,7 @@ pub(crate) fn execute_with_metadata( #[cfg(feature = "test-ci-only")] #[cfg(test)] mod tests { - use crate::{cmd, util::tests::with_tmp_dir, workspace::ManifestPath, UnstableFlags}; + use crate::{cmd, util::tests::with_tmp_dir, ManifestPath, UnstableFlags}; #[test] fn build_template() { diff --git a/src/cmd/metadata.rs b/src/cmd/metadata.rs index 8b658d3f..15393910 100644 --- a/src/cmd/metadata.rs +++ b/src/cmd/metadata.rs @@ -192,8 +192,7 @@ pub(crate) fn execute( #[cfg(test)] mod tests { use crate::{ - cmd, crate_metadata::CrateMetadata, util::tests::with_tmp_dir, workspace::ManifestPath, - UnstableFlags, + cmd, crate_metadata::CrateMetadata, util::tests::with_tmp_dir, ManifestPath, UnstableFlags, }; use blake2::digest::{Update as _, VariableOutput as _}; use contract_metadata::*; diff --git a/src/crate_metadata.rs b/src/crate_metadata.rs index 82469dfc..60837b73 100644 --- a/src/crate_metadata.rs +++ b/src/crate_metadata.rs @@ -14,7 +14,7 @@ // You should have received a copy of the GNU General Public License // along with cargo-contract. If not, see . -use crate::workspace::ManifestPath; +use crate::ManifestPath; use anyhow::{Context, Result}; use cargo_metadata::{Metadata as CargoMetadata, MetadataCommand, Package}; use semver::Version; diff --git a/src/main.rs b/src/main.rs index 1b10516b..0db5993d 100644 --- a/src/main.rs +++ b/src/main.rs @@ -19,6 +19,8 @@ mod crate_metadata; mod util; mod workspace; +use self::workspace::ManifestPath; + #[cfg(feature = "extrinsics")] use sp_core::{crypto::Pair, sr25519, H256}; use std::{ @@ -31,7 +33,6 @@ use subxt::PairSigner; use anyhow::{Error, Result}; use colored::Colorize; use structopt::{clap, StructOpt}; -use crate::workspace::ManifestPath; #[derive(Debug, StructOpt)] #[structopt(bin_name = "cargo")] diff --git a/src/workspace/manifest.rs b/src/workspace/manifest.rs index 6d33d984..3cc851b9 100644 --- a/src/workspace/manifest.rs +++ b/src/workspace/manifest.rs @@ -78,7 +78,7 @@ impl TryFrom<&PathBuf> for ManifestPath { impl

TryFrom> for ManifestPath where - P: AsRef + P: AsRef, { type Error = anyhow::Error; -- GitLab From 35ff6e6ac0309d7e4600e480208b66fa458dba04 Mon Sep 17 00:00:00 2001 From: Andrew Jones Date: Thu, 29 Oct 2020 20:17:26 +0000 Subject: [PATCH 4/4] Update src/main.rs MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Michael Müller --- src/main.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main.rs b/src/main.rs index 0db5993d..d6698c2b 100644 --- a/src/main.rs +++ b/src/main.rs @@ -165,7 +165,7 @@ enum Command { /// Compiles the smart contract #[structopt(name = "build")] Build { - /// Path to the Cargo.toml of the contract to build. + /// Path to the Cargo.toml of the contract to build #[structopt(long, parse(from_os_str))] manifest_path: Option, #[structopt(flatten)] -- GitLab