diff --git a/cli/src/create.rs b/cli/src/create.rs index ab610248..315594cd 100644 --- a/cli/src/create.rs +++ b/cli/src/create.rs @@ -1,6 +1,7 @@ +use crate::foundry::FoundryToolchain; use clap::Args; +use gadget_sdk::tracing; use std::path::PathBuf; -use std::process::Command; #[derive(thiserror::Error, Debug)] pub enum Error { @@ -103,26 +104,22 @@ pub fn new_blueprint(name: String, source: Option) -> Result<(), Error> .map_err(Error::GenerationFailed)?; println!("Blueprint generated at: {}", path.display()); + let contracts = path.join("contracts"); + if !contracts.exists() { + return Ok(()); + } - // TODO: Hack, we have to initialize submodules ourselves, cargo-generate just copies - // them as normal directories: https://github.com/cargo-generate/cargo-generate/issues/1317 - std::env::set_current_dir(path)?; - std::fs::remove_dir_all("./contracts/lib/tnt-core")?; - - let output = Command::new("git") - .args([ - "submodule", - "add", - "https://github.com/tangle-network/tnt-core", - "contracts/lib/tnt-core", - ]) - .output()?; + let foundry = FoundryToolchain::new(); + if !foundry.forge.is_installed() { + tracing::warn!("Forge not installed, skipping dependencies"); + tracing::warn!("NOTE: See "); + tracing::warn!("NOTE: After installing Forge, you can run `forge soldeer update -d` to install dependencies"); + return Ok(()); + } - if !output.status.success() { - eprintln!( - "Failed to add tnt-core submodule: {}", - String::from_utf8_lossy(&output.stderr) - ); + std::env::set_current_dir(contracts)?; + if let Err(e) = foundry.forge.install_dependencies() { + tracing::error!("{e}"); } Ok(()) diff --git a/cli/src/deploy.rs b/cli/src/deploy.rs index c52d1941..aceecbf7 100644 --- a/cli/src/deploy.rs +++ b/cli/src/deploy.rs @@ -256,7 +256,7 @@ fn build_contracts_if_needed( let needs_build = abs_pathes_to_check.iter().any(|path| !path.exists()); if needs_build { - let mut foundry = crate::foundry::FoundryToolchain::new(); + let foundry = crate::foundry::FoundryToolchain::new(); foundry.check_installed_or_exit(); foundry.forge.build()?; } diff --git a/cli/src/foundry/forge.rs b/cli/src/foundry/forge.rs index 6f671b53..5ef77adf 100644 --- a/cli/src/foundry/forge.rs +++ b/cli/src/foundry/forge.rs @@ -1,8 +1,8 @@ +use super::CommandInstalled; use color_eyre::{eyre::eyre, Result}; +use gadget_sdk::tracing; use std::process::Command; -use super::CommandInstalled; - pub struct Forge { cmd: Command, } @@ -32,7 +32,7 @@ impl Forge { } /// Builds the contracts. - pub fn build(&mut self) -> Result<()> { + pub fn build(mut self) -> Result<()> { eprintln!("Building contracts..."); let status = self .cmd @@ -46,4 +46,18 @@ impl Forge { } Ok(()) } + + pub fn install_dependencies(mut self) -> Result<()> { + tracing::info!("Installing dependencies..."); + let output = self + .cmd + .args(["soldeer", "update", "-d"]) + .stderr(std::process::Stdio::inherit()) + .stdout(std::process::Stdio::inherit()) + .output()?; + if !output.status.success() { + return Err(eyre!("Failed to install dependencies")); + } + Ok(()) + } }