Skip to content

Commit ae356a8

Browse files
committed
xtask: utility to launch zombienet
1 parent 73ad15d commit ae356a8

File tree

7 files changed

+122
-54
lines changed

7 files changed

+122
-54
lines changed

Cargo.lock

Lines changed: 23 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,3 +182,4 @@ pallet-ikura-length-fee-adjustment = { path = "ikura/chain/pallets/length-fee-ad
182182

183183
# xtask
184184
duct = { version = "0.13.7" }
185+
ctrlc = { version = "3.4.2" }

xtask/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,4 @@ clap = { workspace = true, features = ["derive"] }
1515
anyhow = { workspace = true }
1616
tracing = { workspace = true }
1717
tracing-subscriber = { workspace = true, features = ["env-filter"] }
18+
ctrlc = { workspace = true }

xtask/src/build.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use crate::{cli::test::BuildParams, logging::create_with_logs};
1+
use crate::{cli::BuildParams, logging::create_with_logs};
22
use duct::cmd;
33

44
// TODO: https://github.com/thrumdev/blobs/issues/225

xtask/src/cli.rs

Lines changed: 57 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,51 @@ pub struct Cli {
1010
#[derive(Subcommand, Debug)]
1111
pub enum Commands {
1212
Test(test::Params),
13+
Zombienet(zombienet::Params),
14+
}
15+
16+
#[derive(clap::Args, Debug, Clone)]
17+
pub struct ZombienetParams {
18+
/// Zombienet process stdout and stderr are redirected into this file
19+
///
20+
/// Relative paths will be treated as relative to the root project directory
21+
/// and not relative to where it is called
22+
#[arg(
23+
long = "zombienet-log-path",
24+
value_name = "log-path",
25+
id = "zombienet.log-path"
26+
)]
27+
#[clap(default_value = "test_log/zombienet.log")]
28+
pub log_path: String,
29+
}
30+
31+
#[derive(clap::Args, Debug, Clone)]
32+
pub struct BuildParams {
33+
/// Skip building required binaries
34+
/// (ikura-node, ikura-shim, sov-demo-rollup and sov-cli)
35+
#[clap(default_value = "false")]
36+
#[arg(long = "skip-build", value_name = "skip", id = "build.skip")]
37+
pub skip: bool,
38+
39+
/// Build process stdout and stderr are redirected into this file
40+
///
41+
/// Relative paths will be treated as relative to the root project directory
42+
/// and not relative to where it is called
43+
#[arg(
44+
long = "build-log-path",
45+
value_name = "log-path",
46+
id = "build.log-path"
47+
)]
48+
#[clap(default_value = "test_log/build.log")]
49+
pub log_path: String,
1350
}
1451

1552
pub mod test {
53+
use super::{BuildParams, ZombienetParams};
1654

1755
// TODO: https://github.com/thrumdev/blobs/issues/224
1856
use clap::Args;
57+
1958
#[derive(Debug, Args)]
2059
pub struct Params {
2160
/// If the test is executed in CI
@@ -35,27 +74,6 @@ pub mod test {
3574
pub sovereign: SovereignParams,
3675
}
3776

38-
#[derive(clap::Args, Debug, Clone)]
39-
pub struct BuildParams {
40-
/// Skip building required binaries
41-
/// (ikura-node, ikura-shim, sov-demo-rollup and sov-cli)
42-
#[clap(default_value = "false")]
43-
#[arg(long = "skip-build", value_name = "skip", id = "build.skip")]
44-
pub skip: bool,
45-
46-
/// Build process stdout and stderr are redirected into this file
47-
///
48-
/// Relative paths will be treated as relative to the root project directory
49-
/// and not relative to where it is called
50-
#[arg(
51-
long = "build-log-path",
52-
value_name = "log-path",
53-
id = "build.log-path"
54-
)]
55-
#[clap(default_value = "test_log/build.log")]
56-
pub log_path: String,
57-
}
58-
5977
#[derive(clap::Args, Debug, Clone)]
6078
pub struct ShimParams {
6179
/// Shim process stdout and stderr are redirected into this file
@@ -67,21 +85,6 @@ pub mod test {
6785
pub log_path: String,
6886
}
6987

70-
#[derive(clap::Args, Debug, Clone)]
71-
pub struct ZombienetParams {
72-
/// Zombienet process stdout and stderr are redirected into this file
73-
///
74-
/// Relative paths will be treated as relative to the root project directory
75-
/// and not relative to where it is called
76-
#[arg(
77-
long = "zombienet-log-path",
78-
value_name = "log-path",
79-
id = "zombienet.log-path"
80-
)]
81-
#[clap(default_value = "test_log/zombienet.log")]
82-
pub log_path: String,
83-
}
84-
8588
#[derive(clap::Args, Debug, Clone)]
8689
pub struct SovereignParams {
8790
/// Sovereign rollup process stdout and stderr are redirected into this file
@@ -97,3 +100,21 @@ pub mod test {
97100
pub log_path: String,
98101
}
99102
}
103+
104+
pub mod zombienet {
105+
use super::{BuildParams, ZombienetParams};
106+
use clap::Args;
107+
108+
#[derive(Debug, Args)]
109+
pub struct Params {
110+
/// If the test is executed in CI
111+
#[clap(long, default_value = "false")]
112+
pub ci: bool,
113+
114+
#[clap(flatten)]
115+
pub build: BuildParams,
116+
117+
#[clap(flatten)]
118+
pub zombienet: ZombienetParams,
119+
}
120+
}

xtask/src/main.rs

Lines changed: 38 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -7,41 +7,34 @@ mod zombienet;
77

88
use clap::Parser;
99
use cli::{test, Cli, Commands};
10-
use std::path::Path;
10+
use std::{
11+
path::{Path, PathBuf},
12+
str,
13+
};
1114

1215
fn main() -> anyhow::Result<()> {
1316
init_logging()?;
1417
let cli = Cli::parse();
1518

1619
match cli.command {
1720
Commands::Test(params) => test(params)?,
21+
Commands::Zombienet(params) => zombienet(params)?,
1822
}
1923

2024
Ok(())
2125
}
2226

2327
fn test(params: test::Params) -> anyhow::Result<()> {
24-
// extract project path
25-
#[rustfmt::skip]
26-
let project_path = duct::cmd!(
27-
"sh", "-c",
28-
"cargo metadata --format-version 1 | jq -r '.workspace_root'"
29-
)
30-
.stdout_capture()
31-
.run()?;
32-
33-
let project_path = Path::new(std::str::from_utf8(&project_path.stdout)?.trim());
28+
let project_path = obtain_project_path()?;
3429

3530
init_env(&project_path, params.ci)?;
3631

3732
build::build(&project_path, params.build)?;
3833

3934
// the variables must be kept alive and not dropped
4035
// otherwise the child process will be killed
41-
#[allow(unused)]
42-
let zombienet = zombienet::Zombienet::try_new(&project_path, params.zombienet)?;
43-
#[allow(unused)]
44-
let shim = shim::Shim::try_new(&project_path, params.shim)?;
36+
let _zombienet = zombienet::Zombienet::try_new(&project_path, params.zombienet)?;
37+
let _shim = shim::Shim::try_new(&project_path, params.shim)?;
4538
let sovereign = sovereign::Sovereign::try_new(&project_path, params.sovereign)?;
4639

4740
// TODO: https://github.com/thrumdev/blobs/issues/226
@@ -53,6 +46,36 @@ fn test(params: test::Params) -> anyhow::Result<()> {
5346
Ok(())
5447
}
5548

49+
fn zombienet(params: crate::cli::zombienet::Params) -> anyhow::Result<()> {
50+
let project_path = obtain_project_path()?;
51+
build::build(&project_path, params.build)?;
52+
let _zombienet = zombienet::Zombienet::try_new(&project_path, params.zombienet)?;
53+
wait_interrupt();
54+
Ok(())
55+
}
56+
57+
fn obtain_project_path() -> anyhow::Result<PathBuf> {
58+
#[rustfmt::skip]
59+
let project_path = duct::cmd!(
60+
"sh", "-c",
61+
"cargo metadata --format-version 1 | jq -r '.workspace_root'"
62+
)
63+
.stdout_capture()
64+
.run()?;
65+
Ok(PathBuf::from(str::from_utf8(&project_path.stdout)?.trim()))
66+
}
67+
68+
/// Blocks until ^C signal is delivered to this process. Uses global resource, don't proliferate.
69+
fn wait_interrupt() {
70+
use std::sync::mpsc;
71+
let (tx, rx) = mpsc::channel();
72+
ctrlc::set_handler(move || {
73+
let _ = tx.send(());
74+
})
75+
.unwrap();
76+
let _ = rx.recv();
77+
}
78+
5679
// Set up environment variables needed by the compilation and testing process.
5780
//
5881
// If ci flag is specified, all binaries are added to PATH env variable

xtask/src/zombienet.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use crate::{check_binary, cli::test::ZombienetParams, logging::create_with_logs};
1+
use crate::{check_binary, cli::ZombienetParams, logging::create_with_logs};
22
use duct::cmd;
33
use std::path::Path;
44
use tracing::info;

0 commit comments

Comments
 (0)