Skip to content

Commit

Permalink
feat: pop build spec (#257)
Browse files Browse the repository at this point in the history
* feat: pop build spec

* fix: ammend test

* feat: better use of strum

* feat(spec): better ux

* chore(spec): small nits

* chore(spec): silent exit if not supported

* chore(spec): update cargo lock

* feat(spec): simple progress spinner

* fix(spec): outro message if not supported

* fix(spec): amend pop-parachains README

* fix(spec): integration test

* chore: improve pop-parachains/build test coverage

* style: clean code

* fix: integration tests

* remove unnecesary tests

* Update crates/pop-cli/src/commands/build/mod.rs

Co-authored-by: Frank Bell <[email protected]>

* Update crates/pop-cli/tests/parachain.rs

Co-authored-by: Frank Bell <[email protected]>

* Update crates/pop-cli/tests/parachain.rs

Co-authored-by: Frank Bell <[email protected]>

* fix: address feedback

* Update crates/pop-cli/src/commands/build/spec.rs

Co-authored-by: Frank Bell <[email protected]>

* fix: more consistent ui

* style: More concise prompt

* fix: relay chain selection based on chain type

* style: default name for spec

* fix: remove para_id magic num

* Update crates/pop-cli/src/commands/build/spec.rs

Co-authored-by: Frank Bell <[email protected]>

* Update crates/pop-parachains/src/build.rs

Co-authored-by: Frank Bell <[email protected]>

* fix: default_para_id_prompt

* refactor(chain-spec): json replacement

* refactor: fix typos and remove unnecessary formats

* feat: default values from existing chain spec

* fix: merge conflicts

* fix: add missing intro for ux consistency

* refactor: remove unnecessary info

* refactor: improve ux

* docs: remove para_id from generate_plain_chain_spec

* fix: Promt user to check profile

* refactor: handle errors and fix docs (#265)

* docs: update README docs

* refactor: handle errors for replace_para_id

* refactor: handle errors for rest of functions

* test: fix integration test

---------

Co-authored-by: Frank Bell <[email protected]>
Co-authored-by: Frank Bell <[email protected]>
Co-authored-by: Alex Bean <[email protected]>
  • Loading branch information
4 people authored Jul 26, 2024
1 parent 336544d commit 8af198d
Show file tree
Hide file tree
Showing 12 changed files with 905 additions and 140 deletions.
6 changes: 4 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ walkdir = "2.5"
indexmap = "2.2"
toml_edit = { version = "0.22", features = ["serde"] }
symlink = "0.1"
serde_json = "1.0"
serde_json = { version = "1.0", features = ["preserve_order"] }
serde = { version = "1.0", features = ["derive"] }
zombienet-sdk = "0.2.5"
zombienet-support = "0.2.5"
Expand Down
13 changes: 3 additions & 10 deletions crates/pop-cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ clap.workspace = true
cliclack.workspace = true
console.workspace = true
strum.workspace = true
strum_macros.workspace = true

# contracts
pop-contracts = { path = "../pop-contracts", version = "0.2.0", optional = true }
Expand All @@ -51,14 +52,6 @@ predicates.workspace = true

[features]
default = ["contract", "parachain", "telemetry"]
contract = [
"dep:pop-contracts",
"dep:sp-core",
"dep:sp-weights",
"dep:dirs",
]
parachain = [
"dep:pop-parachains",
"dep:dirs",
]
contract = ["dep:pop-contracts", "dep:sp-core", "dep:sp-weights", "dep:dirs"]
parachain = ["dep:pop-parachains", "dep:dirs"]
telemetry = ["dep:pop-telemetry"]
10 changes: 8 additions & 2 deletions crates/pop-cli/src/commands/build/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,16 @@ use clap::{Args, Subcommand};
#[cfg(feature = "contract")]
use contract::BuildContractCommand;
use duct::cmd;
#[cfg(feature = "parachain")]
use parachain::BuildParachainCommand;
use std::path::PathBuf;
#[cfg(feature = "parachain")]
use {parachain::BuildParachainCommand, spec::BuildSpecCommand};

#[cfg(feature = "contract")]
pub(crate) mod contract;
#[cfg(feature = "parachain")]
pub(crate) mod parachain;
#[cfg(feature = "parachain")]
pub(crate) mod spec;

/// Arguments for building a project.
#[derive(Args)]
Expand Down Expand Up @@ -46,6 +48,10 @@ pub(crate) enum Command {
#[cfg(feature = "contract")]
#[clap(alias = "c")]
Contract(BuildContractCommand),
/// Build a chain specification and its genesis artifacts.
#[cfg(feature = "parachain")]
#[clap(alias = "s")]
Spec(BuildSpecCommand),
}

impl Command {
Expand Down
40 changes: 2 additions & 38 deletions crates/pop-cli/src/commands/build/parachain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,11 @@
use crate::{cli, style::style};
use clap::Args;
use pop_common::Profile;
use pop_parachains::{
build_parachain, export_wasm_file, generate_genesis_state_file, generate_plain_chain_spec,
generate_raw_chain_spec,
};
use pop_parachains::build_parachain;
use std::path::PathBuf;
#[cfg(not(test))]
use std::{thread::sleep, time::Duration};

const PLAIN_CHAIN_SPEC_FILE_NAME: &str = "plain-parachain-chainspec.json";
const RAW_CHAIN_SPEC_FILE_NAME: &str = "raw-parachain-chainspec.json";

#[derive(Args)]
pub struct BuildParachainCommand {
/// Directory path for your project [default: current directory].
Expand Down Expand Up @@ -67,37 +61,7 @@ impl BuildParachainCommand {
let binary = build_parachain(&project_path, self.package, &mode, None)?;
cli.info(format!("The {project} was built in {mode} mode."))?;
cli.outro("Build completed successfully!")?;
let mut generated_files = vec![format!("Binary generated at: {}", binary.display())];

// If `para_id` is provided, generate the chain spec
if let Some(para_id) = self.id {
let plain_chain_spec = project_path.join(PLAIN_CHAIN_SPEC_FILE_NAME);
generate_plain_chain_spec(&binary, &plain_chain_spec, para_id)?;
generated_files.push(format!(
"Plain text chain specification file generated at: {}",
plain_chain_spec.display()
));
let raw_chain_spec =
generate_raw_chain_spec(&binary, &plain_chain_spec, RAW_CHAIN_SPEC_FILE_NAME)?;
generated_files.push(format!(
"New raw chain specification file generated at: {}",
raw_chain_spec.display()
));
let wasm_file_name = format!("para-{}-wasm.wasm", para_id);
let wasm_file = export_wasm_file(&binary, &raw_chain_spec, &wasm_file_name)?;
generated_files.push(format!(
"WebAssembly runtime file exported at: {}",
wasm_file.display().to_string()
));
let genesis_file_name = format!("para-{}-genesis-state", para_id);
let genesis_state_file =
generate_genesis_state_file(&binary, &raw_chain_spec, &genesis_file_name)?;
generated_files.push(format!(
"Genesis State exported at {} file",
genesis_state_file.display().to_string()
));
console::Term::stderr().clear_last_lines(5)?;
}
let generated_files = vec![format!("Binary generated at: {}", binary.display())];
let generated_files: Vec<_> = generated_files
.iter()
.map(|s| style(format!("{} {s}", console::Emoji("●", ">"))).dim().to_string())
Expand Down
Loading

0 comments on commit 8af198d

Please sign in to comment.