Skip to content

Commit

Permalink
Merge pull request #212 from dora-rs/dont-require-tag
Browse files Browse the repository at this point in the history
Add an internal cli argument to create template with path dependencies
  • Loading branch information
phil-opp authored Mar 14, 2023
2 parents 2dc965e + 7ede910 commit 6e4a651
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 19 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,9 @@ jobs:
run: |
dora-cli up
dora-cli list
dora-cli new test_project
dora-cli new test_project --internal-create-with-path-dependencies
cd test_project
cargo build --all --config "patch.'https://github.com/dora-rs/dora.git'.dora-node-api.path=\"../apis/rust/node\"" --config "patch.'https://github.com/dora-rs/dora.git'.dora-operator-api.path=\"../apis/rust/operator\""
cargo build --all
UUID=$(dora-cli start dataflow.yml)
sleep 10
dora-cli stop $UUID
Expand Down
7 changes: 6 additions & 1 deletion binaries/cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ enum Command {
New {
#[clap(flatten)]
args: CommandNew,
#[clap(hide = true, long)]
internal_create_with_path_dependencies: bool,
},
Up {
#[clap(long)]
Expand Down Expand Up @@ -120,7 +122,10 @@ fn main() -> eyre::Result<()> {
Command::Build { dataflow } => {
build::build(&dataflow)?;
}
Command::New { args } => template::create(args)?,
Command::New {
args,
internal_create_with_path_dependencies,
} => template::create(args, internal_create_with_path_dependencies)?,
Command::Up {
config,
coordinator_path,
Expand Down
4 changes: 2 additions & 2 deletions binaries/cli/src/template/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ mod cxx;
mod python;
mod rust;

pub fn create(args: crate::CommandNew) -> eyre::Result<()> {
pub fn create(args: crate::CommandNew, use_path_deps: bool) -> eyre::Result<()> {
match args.lang {
crate::Lang::Rust => rust::create(args),
crate::Lang::Rust => rust::create(args, use_path_deps),
crate::Lang::Python => python::create(args),
crate::Lang::C => c::create(args),
crate::Lang::Cxx => cxx::create(args),
Expand Down
51 changes: 39 additions & 12 deletions binaries/cli/src/template/rust/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use std::{
};

const VERSION: &str = env!("CARGO_PKG_VERSION");
pub fn create(args: crate::CommandNew) -> eyre::Result<()> {
pub fn create(args: crate::CommandNew, use_path_deps: bool) -> eyre::Result<()> {
let crate::CommandNew {
kind,
lang: _,
Expand All @@ -14,13 +14,17 @@ pub fn create(args: crate::CommandNew) -> eyre::Result<()> {
} = args;

match kind {
crate::Kind::Operator => create_operator(name, path),
crate::Kind::CustomNode => create_custom_node(name, path),
crate::Kind::Dataflow => create_dataflow(name, path),
crate::Kind::Operator => create_operator(name, path, use_path_deps),
crate::Kind::CustomNode => create_custom_node(name, path, use_path_deps),
crate::Kind::Dataflow => create_dataflow(name, path, use_path_deps),
}
}

fn create_dataflow(name: String, path: Option<PathBuf>) -> Result<(), eyre::ErrReport> {
fn create_dataflow(
name: String,
path: Option<PathBuf>,
use_path_deps: bool,
) -> Result<(), eyre::ErrReport> {
const DATAFLOW_YML: &str = include_str!("dataflow-template.yml");
const WORKSPACE_CARGO_TOML: &str = include_str!("Cargo-template.toml");

Expand All @@ -45,9 +49,9 @@ fn create_dataflow(name: String, path: Option<PathBuf>) -> Result<(), eyre::ErrR
fs::write(&cargo_toml_path, &cargo_toml)
.with_context(|| format!("failed to write `{}`", cargo_toml_path.display()))?;

create_operator("op_1".into(), Some(root.join("op_1")))?;
create_operator("op_2".into(), Some(root.join("op_2")))?;
create_custom_node("node_1".into(), Some(root.join("node_1")))?;
create_operator("op_1".into(), Some(root.join("op_1")), use_path_deps)?;
create_operator("op_2".into(), Some(root.join("op_2")), use_path_deps)?;
create_custom_node("node_1".into(), Some(root.join("node_1")), use_path_deps)?;

println!(
"Created new Rust dataflow at `{name}` at {}",
Expand All @@ -57,7 +61,11 @@ fn create_dataflow(name: String, path: Option<PathBuf>) -> Result<(), eyre::ErrR
Ok(())
}

fn create_operator(name: String, path: Option<PathBuf>) -> Result<(), eyre::ErrReport> {
fn create_operator(
name: String,
path: Option<PathBuf>,
use_path_deps: bool,
) -> Result<(), eyre::ErrReport> {
const CARGO_TOML: &str = include_str!("operator/Cargo-template.toml");
const LIB_RS: &str = include_str!("operator/lib-template.rs");

Expand All @@ -82,9 +90,17 @@ fn create_operator(name: String, path: Option<PathBuf>) -> Result<(), eyre::ErrR
fs::create_dir(&src)
.with_context(|| format!("failed to create directory `{}`", src.display()))?;

let dep = if use_path_deps {
r#"dora-operator-api = { path = "../../apis/rust/operator" }"#.to_string()
} else {
format!(
r#"dora-operator-api = {{ git = "https://github.com/dora-rs/dora.git", tag = "v{VERSION}" }}"#
)
};
let cargo_toml = CARGO_TOML
.replace("___name___", &name)
.replace("___version___", VERSION);
.replace("dora-operator-api = {}", &dep);

let cargo_toml_path = root.join("Cargo.toml");
fs::write(&cargo_toml_path, &cargo_toml)
.with_context(|| format!("failed to write `{}`", cargo_toml_path.display()))?;
Expand All @@ -101,7 +117,11 @@ fn create_operator(name: String, path: Option<PathBuf>) -> Result<(), eyre::ErrR
Ok(())
}

fn create_custom_node(name: String, path: Option<PathBuf>) -> Result<(), eyre::ErrReport> {
fn create_custom_node(
name: String,
path: Option<PathBuf>,
use_path_deps: bool,
) -> Result<(), eyre::ErrReport> {
const CARGO_TOML: &str = include_str!("node/Cargo-template.toml");
const MAIN_RS: &str = include_str!("node/main-template.rs");

Expand All @@ -120,9 +140,16 @@ fn create_custom_node(name: String, path: Option<PathBuf>) -> Result<(), eyre::E
fs::create_dir(&src)
.with_context(|| format!("failed to create directory `{}`", src.display()))?;

let dep = if use_path_deps {
r#"dora-node-api = { path = "../../apis/rust/node" }"#.to_string()
} else {
format!(
r#"dora-node-api = {{ git = "https://github.com/dora-rs/dora.git", tag = "v{VERSION}" }}"#
)
};
let cargo_toml = CARGO_TOML
.replace("___name___", &name)
.replace("___version___", VERSION);
.replace("dora-node-api = {}", &dep);
let cargo_toml_path = root.join("Cargo.toml");
fs::write(&cargo_toml_path, &cargo_toml)
.with_context(|| format!("failed to write `{}`", cargo_toml_path.display()))?;
Expand Down
2 changes: 1 addition & 1 deletion binaries/cli/src/template/rust/node/Cargo-template.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
dora-node-api = { git = "https://github.com/dora-rs/dora.git", tag = "v___version___" }
dora-node-api = {}
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ edition = "2021"
crate-type = ["cdylib"]

[dependencies]
dora-operator-api = { git = "https://github.com/dora-rs/dora.git", tag = "v___version___" }
dora-operator-api = {}

0 comments on commit 6e4a651

Please sign in to comment.