Browse Source

Migrate run.rs script of cmake dataflow example to xshell

xshell
Philipp Oppermann 1 year ago
parent
commit
46433bb8c5
Failed to extract signature
1 changed files with 43 additions and 47 deletions
  1. +43
    -47
      examples/cmake-dataflow/run.rs

+ 43
- 47
examples/cmake-dataflow/run.rs View File

@@ -1,6 +1,7 @@
use dora_tracing::set_up_tracing;
use eyre::{bail, Context};
use std::path::Path;
use eyre::{Context, ContextCompat};
use std::path::{Path, PathBuf};
use xshell::{cmd, Shell};

#[tokio::main]
async fn main() -> eyre::Result<()> {
@@ -13,60 +14,55 @@ async fn main() -> eyre::Result<()> {
return Ok(());
}

// create a new shell in this folder
let sh = prepare_shell()?;

// build C++ source code using cmake
let root = Path::new(env!("CARGO_MANIFEST_DIR"));
std::env::set_current_dir(root.join(file!()).parent().unwrap())
.wrap_err("failed to set working dir")?;
cmd!(sh, "cmake -DDORA_ROOT_DIR={root} -B build .").run()?;
cmd!(sh, "cmake --build build").run()?;
cmd!(sh, "cmake --install build").run()?;

tokio::fs::create_dir_all("build").await?;
let mut cmd = tokio::process::Command::new("cmake");
cmd.arg(format!("-DDORA_ROOT_DIR={}", root.display()));
cmd.arg("-B").arg("build");
cmd.arg(".");
if !cmd.status().await?.success() {
bail!("failed to generating make file");
}
// build the `dora` binary (you can skip this if you use `cargo install dora-cli`)
let dora = prepare_dora(&sh)?;

let mut cmd = tokio::process::Command::new("cmake");
cmd.arg("--build").arg("build");
if !cmd.status().await?.success() {
bail!("failed to build a cmake-generated project binary tree");
}
// start up the dora daemon and coordinator
cmd!(sh, "{dora} up").run()?;

let mut cmd = tokio::process::Command::new("cmake");
cmd.arg("--install").arg("build");
if !cmd.status().await?.success() {
bail!("failed to build a cmake-generated project binary tree");
}
// start running the dataflow.yml -> outputs the UUID assigned to the dataflow
let output = cmd!(sh, "{dora} start dataflow.yml --attach").read_stderr()?;
let uuid = output.lines().next().context("no output")?;

// stop the dora daemon and coordinator again
cmd!(sh, "{dora} destroy").run()?;

let dataflow = Path::new("dataflow.yml").to_owned();
build_package("dora-runtime").await?;
run_dataflow(&dataflow).await?;
// verify that the node output was written to `out`
sh.change_dir("out");
sh.change_dir(uuid);
let sink_output = sh.read_file("log_runtime-node-2.txt")?;
if sink_output.lines().count() < 20 {
eyre::bail!("sink did not receive the expected number of messages")
}

Ok(())
}

async fn build_package(package: &str) -> eyre::Result<()> {
let cargo = std::env::var("CARGO").unwrap();
let mut cmd = tokio::process::Command::new(&cargo);
cmd.arg("build");
cmd.arg("--package").arg(package);
if !cmd.status().await?.success() {
bail!("failed to build {package}");
}
Ok(())
/// Prepares a shell and set the working directory to the parent folder of this file.
///
/// You can use your system shell instead (e.g. `bash`);
fn prepare_shell() -> Result<Shell, eyre::Error> {
let sh = Shell::new()?;
let root = Path::new(env!("CARGO_MANIFEST_DIR"));
sh.change_dir(root.join(file!()).parent().unwrap());
Ok(sh)
}

async fn run_dataflow(dataflow: &Path) -> eyre::Result<()> {
let cargo = std::env::var("CARGO").unwrap();
let mut cmd = tokio::process::Command::new(&cargo);
cmd.arg("run");
cmd.arg("--package").arg("dora-cli");
cmd.arg("--")
.arg("daemon")
.arg("--run-dataflow")
.arg(dataflow);
if !cmd.status().await?.success() {
bail!("failed to run dataflow");
};
Ok(())
/// Build the `dora` command-line executable from this repo.
///
/// You can skip this step and run `cargo install dora-cli --locked` instead.
fn prepare_dora(sh: &Shell) -> eyre::Result<PathBuf> {
cmd!(sh, "cargo build --package dora-cli").run()?;
let root = Path::new(env!("CARGO_MANIFEST_DIR"));
let dora = root.join("target").join("debug").join("dora");
Ok(dora)
}

Loading…
Cancel
Save