Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Specify optional --manifest-path for build and generate-metadata #93

Merged
merged 4 commits into from
Oct 29, 2020
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/cmd/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
3 changes: 1 addition & 2 deletions src/cmd/metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::*;
Expand Down
2 changes: 1 addition & 1 deletion src/crate_metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
// You should have received a copy of the GNU General Public License
// along with cargo-contract. If not, see <http://www.gnu.org/licenses/>.

use crate::workspace::ManifestPath;
use crate::ManifestPath;
use anyhow::{Context, Result};
use cargo_metadata::{Metadata as CargoMetadata, MetadataCommand, Package};
use semver::Version;
Expand Down
15 changes: 13 additions & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::{
Expand Down Expand Up @@ -163,6 +165,9 @@ enum Command {
/// Compiles the smart contract
#[structopt(name = "build")]
Build {
/// Path to the Cargo.toml of the contract to build.
ascjones marked this conversation as resolved.
Show resolved Hide resolved
#[structopt(long, parse(from_os_str))]
manifest_path: Option<PathBuf>,
#[structopt(flatten)]
verbosity: VerbosityFlags,
#[structopt(flatten)]
Expand All @@ -171,6 +176,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(long, parse(from_os_str))]
manifest_path: Option<PathBuf>,
#[structopt(flatten)]
verbosity: VerbosityFlags,
#[structopt(flatten)]
Expand Down Expand Up @@ -239,10 +247,11 @@ fn exec(cmd: Command) -> Result<String> {
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()?,
Expand All @@ -254,11 +263,13 @@ fn exec(cmd: Command) -> Result<String> {
))
}
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()?,
)?;
Expand Down
11 changes: 11 additions & 0 deletions src/workspace/manifest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,17 @@ impl TryFrom<&PathBuf> for ManifestPath {
}
}

impl<P> TryFrom<Option<P>> for ManifestPath
where
P: AsRef<Path>,
{
type Error = anyhow::Error;

fn try_from(value: Option<P>) -> Result<Self, Self::Error> {
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")
Expand Down