From 5570c1ac776dd2ec954a2257103f30912f95c5a4 Mon Sep 17 00:00:00 2001 From: Liam Monninger Date: Thu, 25 Jan 2024 10:35:15 -0800 Subject: [PATCH] fix: bad release. --- movement-sdk/Cargo.lock | 46 +++++---- movement-sdk/Cargo.toml | 1 + .../third_party/avalanche/avalanche.rs | 6 +- .../third_party/avalanche/avalanchego.rs | 3 + .../third_party/cargo/cargo.rs | 3 + .../known_artifacts/third_party/sys/brew.rs | 7 +- .../known_artifacts/third_party/sys/curl.rs | 6 +- .../known_artifacts/third_party/sys/git.rs | 5 +- .../known_artifacts/third_party/sys/mod.rs | 3 +- .../known_artifacts/third_party/sys/node.rs | 95 +++++++++++++++++++ .../clis/movement/src/ctl/start/m1/m1.rs | 14 ++- .../clis/movement/src/ctl/start/m1/mevm.rs | 53 +++++++++++ .../clis/movement/src/ctl/start/m1/mod.rs | 1 + .../clis/movement/src/ctl/start/m1/proxy.rs | 53 +++++++++++ movement-sdk/package-lock.json | 6 ++ movement-sdk/services/src/m1/localnet.rs | 46 +++++++++ movement-sdk/services/src/m1/mevm.rs | 47 +++++++++ movement-sdk/services/src/m1/mod.rs | 5 +- movement-sdk/services/src/m1/proxy.rs | 47 +++++++++ movement-sdk/util/util/Cargo.toml | 1 + .../util/util/src/util/artifact/artifact.rs | 9 +- .../util/util/src/util/checker/checker.rs | 13 +++ .../util/src/util/checker/command_exists.rs | 21 ++++ .../util/util/src/util/checker/mod.rs | 3 +- .../util/src/util/release/http_get_release.rs | 2 +- 25 files changed, 465 insertions(+), 31 deletions(-) create mode 100644 movement-sdk/artifacts/src/known_artifacts/third_party/sys/node.rs create mode 100644 movement-sdk/clis/movement/src/ctl/start/m1/mevm.rs create mode 100644 movement-sdk/package-lock.json create mode 100644 movement-sdk/services/src/m1/localnet.rs create mode 100644 movement-sdk/services/src/m1/mevm.rs create mode 100644 movement-sdk/services/src/m1/proxy.rs diff --git a/movement-sdk/Cargo.lock b/movement-sdk/Cargo.lock index 6344aaef..ef3a1c39 100644 --- a/movement-sdk/Cargo.lock +++ b/movement-sdk/Cargo.lock @@ -5638,7 +5638,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ef033ed5e9bad94e55838ca0ca906db0e043f517adda0c8b79c7a8c66c93c1b5" dependencies = [ "cfg-if", - "rustix 0.38.28", + "rustix 0.38.30", "windows-sys 0.48.0", ] @@ -6821,7 +6821,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0bad00257d07be169d870ab665980b06cdb366d792ad690bf2e76876dc503455" dependencies = [ "hermit-abi 0.3.3", - "rustix 0.38.28", + "rustix 0.38.30", "windows-sys 0.52.0", ] @@ -7127,9 +7127,9 @@ dependencies = [ [[package]] name = "libc" -version = "0.2.150" +version = "0.2.152" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "89d92a4743f9a61002fae18374ed11e7973f530cb3a3255fb354818118b2203c" +checksum = "13e3bf6590cbc649f4d1a3eefc9d5d6eb746f5200ffb04e5e142700b8faa56e7" [[package]] name = "libgit2-sys" @@ -7260,9 +7260,9 @@ checksum = "f051f77a7c8e6957c0696eac88f26b0117e54f52d3fc682ab19397a8812846a4" [[package]] name = "linux-raw-sys" -version = "0.4.11" +version = "0.4.13" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "969488b55f8ac402214f3f5fd243ebb7206cf82de60d3172994707a4bcc2b829" +checksum = "01cda141df6706de531b6c46c3a33ecca755538219bd484262fa09410c13539c" [[package]] name = "lock_api" @@ -10855,7 +10855,7 @@ dependencies = [ "regex", "syn 2.0.48", "tempfile", - "which", + "which 4.4.2", ] [[package]] @@ -11750,14 +11750,14 @@ dependencies = [ [[package]] name = "rustix" -version = "0.38.28" +version = "0.38.30" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "72e572a5e8ca657d7366229cdde4bd14c4eb5499a9573d4d366fe1b599daa316" +checksum = "322394588aaf33c24007e8bb3238ee3e4c5c09c084ab32bc73890b99ff326bca" dependencies = [ "bitflags 2.4.1", "errno", "libc", - "linux-raw-sys 0.4.11", + "linux-raw-sys 0.4.13", "windows-sys 0.52.0", ] @@ -14226,7 +14226,7 @@ dependencies = [ "cfg-if", "fastrand", "redox_syscall 0.4.1", - "rustix 0.38.28", + "rustix 0.38.30", "windows-sys 0.48.0", ] @@ -14267,7 +14267,7 @@ version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "21bebf2b7c9e0a515f6e0f8c51dc0f8e4696391e6f1ff30379559f8365fb0df7" dependencies = [ - "rustix 0.38.28", + "rustix 0.38.30", "windows-sys 0.48.0", ] @@ -15409,7 +15409,7 @@ dependencies = [ "errno", "js-sys", "libc", - "rustix 0.38.28", + "rustix 0.38.30", "wasi 0.11.0+wasi-snapshot-preview1", "wasm-bindgen", "winapi 0.3.9", @@ -15449,6 +15449,7 @@ dependencies = [ "tempfile", "tokio", "toml 0.8.2", + "which 6.0.0", "zip", "zip-extensions", ] @@ -15724,7 +15725,20 @@ dependencies = [ "either", "home", "once_cell", - "rustix 0.38.28", + "rustix 0.38.30", +] + +[[package]] +name = "which" +version = "6.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7fa5e0c10bf77f44aac573e498d1a82d5fbd5e91f6fc0a99e7be4b38e85e101c" +dependencies = [ + "either", + "home", + "once_cell", + "rustix 0.38.30", + "windows-sys 0.52.0", ] [[package]] @@ -16061,8 +16075,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "914566e6413e7fa959cc394fb30e563ba80f3541fbd40816d4c05a0fc3f2a0f1" dependencies = [ "libc", - "linux-raw-sys 0.4.11", - "rustix 0.38.28", + "linux-raw-sys 0.4.13", + "rustix 0.38.30", ] [[package]] diff --git a/movement-sdk/Cargo.toml b/movement-sdk/Cargo.toml index 3d41e377..856b813b 100644 --- a/movement-sdk/Cargo.toml +++ b/movement-sdk/Cargo.toml @@ -69,6 +69,7 @@ tar = "0.4.35" zip = "0.6" zip-extensions = "0.6" flate2 = "1.0.19" +which = "6.0" base64 = "0.13.0" bcs = { git = "https://github.com/aptos-labs/bcs.git", rev = "d31fab9d81748e2594be5cd5cdf845786a30562d" } diff --git a/movement-sdk/artifacts/src/known_artifacts/third_party/avalanche/avalanche.rs b/movement-sdk/artifacts/src/known_artifacts/third_party/avalanche/avalanche.rs index 9122a9eb..4513dd1e 100644 --- a/movement-sdk/artifacts/src/known_artifacts/third_party/avalanche/avalanche.rs +++ b/movement-sdk/artifacts/src/known_artifacts/third_party/avalanche/avalanche.rs @@ -1,4 +1,5 @@ use util::{ + checker::Checker, artifact::Artifact, util::util::patterns::constructor::ConstructorOperations }; @@ -45,7 +46,10 @@ impl ConstructorOperations for Constructor { #[cfg(target_os = "windows")] let avalanche = Artifact::unsupported("avalanche".to_string()); - avalanche + avalanche.with_checker( + Checker::command_exists("avalanche".to_string()) + ) + } fn default_with_version(_ : &util::util::util::Version) -> Self::Artifact { diff --git a/movement-sdk/artifacts/src/known_artifacts/third_party/avalanche/avalanchego.rs b/movement-sdk/artifacts/src/known_artifacts/third_party/avalanche/avalanchego.rs index 9a33772f..2f3b8e6f 100644 --- a/movement-sdk/artifacts/src/known_artifacts/third_party/avalanche/avalanchego.rs +++ b/movement-sdk/artifacts/src/known_artifacts/third_party/avalanche/avalanchego.rs @@ -1,4 +1,5 @@ use util::{ + checker::Checker, artifact::Artifact, util::util::patterns::constructor::ConstructorOperations }; @@ -41,6 +42,8 @@ impl ConstructorOperations for Constructor { vec![ git::Constructor::default().into(), ].into_iter().collect() + ).with_checker( + Checker::command_exists("avalanchego".to_string()) ) } diff --git a/movement-sdk/artifacts/src/known_artifacts/third_party/cargo/cargo.rs b/movement-sdk/artifacts/src/known_artifacts/third_party/cargo/cargo.rs index d8df615d..35cc13c4 100644 --- a/movement-sdk/artifacts/src/known_artifacts/third_party/cargo/cargo.rs +++ b/movement-sdk/artifacts/src/known_artifacts/third_party/cargo/cargo.rs @@ -1,4 +1,5 @@ use util::{ + checker::Checker, artifact::Artifact, util::util::patterns::constructor::ConstructorOperations }; @@ -22,6 +23,8 @@ impl ConstructorOperations for Constructor { source "$HOME/.cargo/env" cargo --version "#.to_string(), + ).with_checker( + Checker::command_exists("cargo".to_string()) ) } diff --git a/movement-sdk/artifacts/src/known_artifacts/third_party/sys/brew.rs b/movement-sdk/artifacts/src/known_artifacts/third_party/sys/brew.rs index 55d81546..67f5593a 100644 --- a/movement-sdk/artifacts/src/known_artifacts/third_party/sys/brew.rs +++ b/movement-sdk/artifacts/src/known_artifacts/third_party/sys/brew.rs @@ -1,4 +1,5 @@ use util::{ + checker::Checker, artifact::Artifact, util::util::patterns::constructor::ConstructorOperations }; @@ -35,10 +36,12 @@ impl ConstructorOperations for Constructor { ].into_iter().collect() ); - #[cfg(target_os = "windows")] + #[cfg(not(target_os = "macos"))] let avalanche = Artifact::unsupported("brew".to_string()); - avalanche + avalanche.with_checker( + Checker::command_exists("brew".to_string()) + ) } fn default_with_version(_ : &util::util::util::Version) -> Self::Artifact { diff --git a/movement-sdk/artifacts/src/known_artifacts/third_party/sys/curl.rs b/movement-sdk/artifacts/src/known_artifacts/third_party/sys/curl.rs index 7227bab8..1a1deaa2 100644 --- a/movement-sdk/artifacts/src/known_artifacts/third_party/sys/curl.rs +++ b/movement-sdk/artifacts/src/known_artifacts/third_party/sys/curl.rs @@ -1,4 +1,5 @@ use util::{ + checker::Checker, artifact::Artifact, util::util::patterns::constructor::ConstructorOperations }; @@ -16,8 +17,9 @@ impl ConstructorOperations for Constructor { fn default() -> Self::Artifact { - #[cfg(target_os = "macos")] - Artifact::noop("curl".to_string()) // Should already be installed on macOS + Artifact::noop("curl".to_string()).with_checker( + Checker::command_exists("curl".to_string()) + ) // Should already be installed on macOS } diff --git a/movement-sdk/artifacts/src/known_artifacts/third_party/sys/git.rs b/movement-sdk/artifacts/src/known_artifacts/third_party/sys/git.rs index 06ed82d9..acb83188 100644 --- a/movement-sdk/artifacts/src/known_artifacts/third_party/sys/git.rs +++ b/movement-sdk/artifacts/src/known_artifacts/third_party/sys/git.rs @@ -1,4 +1,5 @@ use util::{ + checker::Checker, artifact::Artifact, util::util::patterns::constructor::ConstructorOperations }; @@ -31,7 +32,9 @@ impl ConstructorOperations for Constructor { // todo: update for windows - git + git.with_checker( + Checker::command_exists("git".to_string()) + ) } diff --git a/movement-sdk/artifacts/src/known_artifacts/third_party/sys/mod.rs b/movement-sdk/artifacts/src/known_artifacts/third_party/sys/mod.rs index ebc708f5..92866d9e 100644 --- a/movement-sdk/artifacts/src/known_artifacts/third_party/sys/mod.rs +++ b/movement-sdk/artifacts/src/known_artifacts/third_party/sys/mod.rs @@ -1,3 +1,4 @@ pub mod curl; pub mod brew; -pub mod git; \ No newline at end of file +pub mod git; +pub mod node; \ No newline at end of file diff --git a/movement-sdk/artifacts/src/known_artifacts/third_party/sys/node.rs b/movement-sdk/artifacts/src/known_artifacts/third_party/sys/node.rs new file mode 100644 index 00000000..e04064ed --- /dev/null +++ b/movement-sdk/artifacts/src/known_artifacts/third_party/sys/node.rs @@ -0,0 +1,95 @@ +use util::{ + checker::Checker, + artifact::Artifact, + util::util::patterns::constructor::ConstructorOperations, +}; + +#[derive(Debug, Clone)] +pub struct Config; + +#[derive(Debug, Clone)] +pub struct Constructor; + +impl ConstructorOperations for Constructor { + type Artifact = Artifact; + type Config = Config; + + fn default() -> Self::Artifact { + #[cfg(target_os = "macos")] + let node_artifact = Artifact::self_contained_script( + "node".to_string(), + r#" + brew install node@18 + brew link --force --overwrite node@18 + + # Verify installation + node --version + "# + .to_string(), + ); + + #[cfg(target_os = "linux")] + let node_artifact = Artifact::self_contained_script( + "node".to_string(), + r#" + sudo apt-get update + + curl -fsSL https://deb.nodesource.com/setup_18.x | sudo -E bash - + sudo apt-get install -y nodejs + + # Verify installation + node --version + "# + .to_string(), + ); + + // Placeholder for Windows, adjust as necessary for your application + #[cfg(target_os = "windows")] + let node_artifact = Artifact::unsupported("node".to_string()); + + node_artifact.with_checker( + Checker::command_exists("node".to_string()) + ) + + } + + + fn default_with_version(_: &util::util::util::Version) -> Self::Artifact { + Self::default() + } + + fn from_config(_: &util::util::util::Version, _: &Self::Config) -> Self::Artifact { + Self::default() + } +} + +#[cfg(test)] +pub mod test { + use super::*; + use util::movement_dir::MovementDir; + + #[tokio::test] + async fn test_node_installation() -> Result<(), anyhow::Error> { + let temp_home = tempfile::tempdir()?; + let dir = temp_home.path().to_path_buf(); + let movement_dir = MovementDir::new(&dir); + let artifact = Constructor::default(); + + test_helpers::clean_path(vec![ + "/usr/bin".to_string(), "/bin".to_string(), + "/opt/homebrew/bin".to_string(), "/usr/local/bin".to_string(), + ])?; + std::env::set_var("HOME", temp_home.path()); + + artifact.install(&movement_dir).await?; + + let exists = match std::process::Command::new("node").arg("--version").output() { + Ok(output) => output.status.success(), + Err(_) => false, + }; + + assert!(exists); + + Ok(()) + } +} diff --git a/movement-sdk/clis/movement/src/ctl/start/m1/m1.rs b/movement-sdk/clis/movement/src/ctl/start/m1/m1.rs index 8491e392..4456d70b 100644 --- a/movement-sdk/clis/movement/src/ctl/start/m1/m1.rs +++ b/movement-sdk/clis/movement/src/ctl/start/m1/m1.rs @@ -1,6 +1,10 @@ use clap::Subcommand; use util::cli::Command; -use super::testnet::Testnet; +use super::{ + testnet::Testnet, + mevm::Mevm, + proxy::Proxy +}; #[derive(Subcommand, Debug)] #[clap( @@ -8,7 +12,9 @@ use super::testnet::Testnet; about = "Start an M1 service" )] pub enum M1 { - Testnet(Testnet) + Testnet(Testnet), + Mevm(Mevm), + Proxy(Proxy) } #[async_trait::async_trait] @@ -21,7 +27,9 @@ impl Command for M1 { async fn execute(self) -> Result { match self { - M1::Testnet(testnet) => testnet.execute().await? + M1::Testnet(testnet) => testnet.execute().await?, + M1::Mevm(mevm) => mevm.execute().await?, + M1::Proxy(proxy) => proxy.execute().await? }; Ok("SUCCESS".to_string()) diff --git a/movement-sdk/clis/movement/src/ctl/start/m1/mevm.rs b/movement-sdk/clis/movement/src/ctl/start/m1/mevm.rs new file mode 100644 index 00000000..347ab544 --- /dev/null +++ b/movement-sdk/clis/movement/src/ctl/start/m1/mevm.rs @@ -0,0 +1,53 @@ +use services::m1::mevm; +use async_trait::async_trait; +use clap::Parser; +use util::{cli::Command, util::util::constructor::ConstructorOperations}; +use crate::manage::{ + InstallationArgs, + VersionArgs +}; +use util::util::util::Version; +use util::service::ServiceOperations; +use util::movement_dir::MovementDir; + +#[derive(Debug, Parser, Clone)] +pub struct Mevm { + + #[clap(flatten)] + pub version_args : VersionArgs, + + #[clap(flatten)] + pub installation_args : InstallationArgs + +} + +impl Into for Mevm { + fn into(self) -> mevm::Config { + mevm::Config + } +} + + +#[async_trait] +impl Command for Mevm { + + async fn get_name(&self) -> String { + "mevm".to_string() + } + + async fn execute(self) -> Result { + + let movement_dir = MovementDir::default(); + + // todo: handle config and version + let config : mevm::Config = self.clone().into(); + let version : Version = self.version_args.try_into()?; + + let service = mevm::Constructor::default(); + + service.start(&movement_dir).await?; + + Ok("SUCCESS".to_string()) + } + +} \ No newline at end of file diff --git a/movement-sdk/clis/movement/src/ctl/start/m1/mod.rs b/movement-sdk/clis/movement/src/ctl/start/m1/mod.rs index ca94c7e5..a0a3a3ab 100644 --- a/movement-sdk/clis/movement/src/ctl/start/m1/mod.rs +++ b/movement-sdk/clis/movement/src/ctl/start/m1/mod.rs @@ -1,4 +1,5 @@ pub mod proxy; +pub mod mevm; pub mod testnet; pub mod indexer; pub mod m1; diff --git a/movement-sdk/clis/movement/src/ctl/start/m1/proxy.rs b/movement-sdk/clis/movement/src/ctl/start/m1/proxy.rs index e69de29b..7112f3f7 100644 --- a/movement-sdk/clis/movement/src/ctl/start/m1/proxy.rs +++ b/movement-sdk/clis/movement/src/ctl/start/m1/proxy.rs @@ -0,0 +1,53 @@ +use services::m1::proxy; +use async_trait::async_trait; +use clap::Parser; +use util::{cli::Command, util::util::constructor::ConstructorOperations}; +use crate::manage::{ + InstallationArgs, + VersionArgs +}; +use util::util::util::Version; +use util::service::ServiceOperations; +use util::movement_dir::MovementDir; + +#[derive(Debug, Parser, Clone)] +pub struct Proxy { + + #[clap(flatten)] + pub version_args : VersionArgs, + + #[clap(flatten)] + pub installation_args : InstallationArgs + +} + +impl Into for Proxy { + fn into(self) -> proxy::Config { + proxy::Config + } +} + + +#[async_trait] +impl Command for Proxy { + + async fn get_name(&self) -> String { + "proxy".to_string() + } + + async fn execute(self) -> Result { + + let movement_dir = MovementDir::default(); + + // todo: handle config and version + let config : proxy::Config = self.clone().into(); + let version : Version = self.version_args.try_into()?; + + let service = proxy::Constructor::default(); + + service.start(&movement_dir).await?; + + Ok("SUCCESS".to_string()) + } + +} \ No newline at end of file diff --git a/movement-sdk/package-lock.json b/movement-sdk/package-lock.json new file mode 100644 index 00000000..95f473e3 --- /dev/null +++ b/movement-sdk/package-lock.json @@ -0,0 +1,6 @@ +{ + "name": "movement-sdk", + "lockfileVersion": 3, + "requires": true, + "packages": {} +} diff --git a/movement-sdk/services/src/m1/localnet.rs b/movement-sdk/services/src/m1/localnet.rs new file mode 100644 index 00000000..de897982 --- /dev/null +++ b/movement-sdk/services/src/m1/localnet.rs @@ -0,0 +1,46 @@ +use util::{ + service::Service, + util::util::patterns::constructor::ConstructorOperations, + util::util::version +}; +use artifacts::known_artifacts::m1::localnet; + +#[derive(Debug, Clone)] +pub struct Config; + +#[derive(Debug, Clone)] +pub struct Constructor; + +impl ConstructorOperations for Constructor { + + type Artifact = Service; + type Config = Config; + + fn default() -> Self::Artifact { + + Self::default_with_version(&version::Version::Latest) + + } + + fn default_with_version(version : &util::util::util::Version) -> Self::Artifact { + + Service::foreground( + "localnet".to_string(), + r#" + cd $MOVEMENT_DIR/src/m1-with-submodules/m1 + ./scripts/run.debug.sh + "#.to_string(), + vec![ + localnet::Constructor::default_with_version( + version + ).into() + ] + ) + + } + + fn from_config(version : &util::util::util::Version, _ : &Self::Config) -> Self::Artifact { + Self::default_with_version(version) + } + +} diff --git a/movement-sdk/services/src/m1/mevm.rs b/movement-sdk/services/src/m1/mevm.rs new file mode 100644 index 00000000..b4faef93 --- /dev/null +++ b/movement-sdk/services/src/m1/mevm.rs @@ -0,0 +1,47 @@ +use util::{ + service::Service, + util::util::patterns::constructor::ConstructorOperations, + util::util::version +}; +use artifacts::known_artifacts::m1::m1_with_submodules; + +#[derive(Debug, Clone)] +pub struct Config; + +#[derive(Debug, Clone)] +pub struct Constructor; + +impl ConstructorOperations for Constructor { + + type Artifact = Service; + type Config = Config; + + fn default() -> Self::Artifact { + + Self::default_with_version(&version::Version::Latest) + + } + + fn default_with_version(version : &util::util::util::Version) -> Self::Artifact { + + Service::foreground( + "mevm".to_string(), + r#" + cd $MOVEMENT_DIR/src/m1-with-submodules/m1/infrastructure/evm-rpc + npm install + npm run start + "#.to_string(), + vec![ + m1_with_submodules::Constructor::default_with_version( + version + ).into() + ] + ) + + } + + fn from_config(version : &util::util::util::Version, _ : &Self::Config) -> Self::Artifact { + Self::default_with_version(version) + } + +} diff --git a/movement-sdk/services/src/m1/mod.rs b/movement-sdk/services/src/m1/mod.rs index 2c72c6b3..8439faf0 100644 --- a/movement-sdk/services/src/m1/mod.rs +++ b/movement-sdk/services/src/m1/mod.rs @@ -1 +1,4 @@ -pub mod testnet; \ No newline at end of file +pub mod testnet; +pub mod localnet; +pub mod proxy; +pub mod mevm; \ No newline at end of file diff --git a/movement-sdk/services/src/m1/proxy.rs b/movement-sdk/services/src/m1/proxy.rs new file mode 100644 index 00000000..c70abda4 --- /dev/null +++ b/movement-sdk/services/src/m1/proxy.rs @@ -0,0 +1,47 @@ +use util::{ + service::Service, + util::util::patterns::constructor::ConstructorOperations, + util::util::version +}; +use artifacts::known_artifacts::m1::m1_with_submodules; + +#[derive(Debug, Clone)] +pub struct Config; + +#[derive(Debug, Clone)] +pub struct Constructor; + +impl ConstructorOperations for Constructor { + + type Artifact = Service; + type Config = Config; + + fn default() -> Self::Artifact { + + Self::default_with_version(&version::Version::Latest) + + } + + fn default_with_version(version : &util::util::util::Version) -> Self::Artifact { + + Service::foreground( + "proxy".to_string(), + r#" + cd $MOVEMENT_DIR/src/m1-with-submodules/m1/infrastructure/subnet-proxy + npm install + npm run start + "#.to_string(), + vec![ + m1_with_submodules::Constructor::default_with_version( + version + ).into() + ] + ) + + } + + fn from_config(version : &util::util::util::Version, _ : &Self::Config) -> Self::Artifact { + Self::default_with_version(version) + } + +} diff --git a/movement-sdk/util/util/Cargo.toml b/movement-sdk/util/util/Cargo.toml index a1d90a12..122676a0 100644 --- a/movement-sdk/util/util/Cargo.toml +++ b/movement-sdk/util/util/Cargo.toml @@ -24,6 +24,7 @@ tar = { workspace = true } zip = { workspace = true } zip-extensions = { workspace = true } flate2 = { workspace = true } +which = { workspace = true } [features] logging = [] \ No newline at end of file diff --git a/movement-sdk/util/util/src/util/artifact/artifact.rs b/movement-sdk/util/util/src/util/artifact/artifact.rs index 94ae0759..62541d22 100644 --- a/movement-sdk/util/util/src/util/artifact/artifact.rs +++ b/movement-sdk/util/util/src/util/artifact/artifact.rs @@ -327,14 +327,19 @@ impl Artifact { Self { known_artifact : KnownArtifact::Name(name.clone()), release, - location : PathBuf::from("bin").join(name).into(), + location : PathBuf::from("bin").join(name.clone()).into(), version : Version::Latest, builder : Builder::Release(builder::release::Release::new()), - checker : Checker::Noop, + checker : Checker::command_exists(name), dependencies : BTreeSet::new() } } + pub fn with_checker(mut self, checker : Checker) -> Self { + self.checker = checker; + self + } + } impl Display for Artifact { diff --git a/movement-sdk/util/util/src/util/checker/checker.rs b/movement-sdk/util/util/src/util/checker/checker.rs index 1b4de937..28201d32 100644 --- a/movement-sdk/util/util/src/util/checker/checker.rs +++ b/movement-sdk/util/util/src/util/checker/checker.rs @@ -1,5 +1,6 @@ use serde::{Serialize, Deserialize}; use crate::util::artifact::{Artifact, ArtifactStatus}; +use super::command_exists::CommandExists; #[async_trait::async_trait] pub trait CheckerOperations { @@ -12,9 +13,18 @@ pub trait CheckerOperations { pub enum Checker { AcceptAll, Noop, + CommandExists(CommandExists), Unknown } +impl Checker { + + pub fn command_exists(command : String) -> Self { + Checker::CommandExists(CommandExists(command)) + } + +} + #[async_trait::async_trait] impl CheckerOperations for Checker { @@ -23,6 +33,9 @@ impl CheckerOperations for Checker { Checker::AcceptAll => { Ok(ArtifactStatus::Installed) }, + Checker::CommandExists(command_exists) => { + command_exists.check(artifact).await + }, _ => { Ok(ArtifactStatus::Unknown) } diff --git a/movement-sdk/util/util/src/util/checker/command_exists.rs b/movement-sdk/util/util/src/util/checker/command_exists.rs index e69de29b..1be9f6f2 100644 --- a/movement-sdk/util/util/src/util/checker/command_exists.rs +++ b/movement-sdk/util/util/src/util/checker/command_exists.rs @@ -0,0 +1,21 @@ +use serde::{Serialize, Deserialize}; +use crate::util::artifact::{Artifact, ArtifactStatus}; +use super::CheckerOperations; + +#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq, Hash, PartialOrd, Ord)] +pub struct CommandExists(pub String); + +#[async_trait::async_trait] +impl CheckerOperations for CommandExists { + + async fn check(&self, artifact : &Artifact) -> Result { + let command = &self.0; + let command_exists = which::which(command).is_ok(); + if command_exists { + Ok(ArtifactStatus::Installed) + } else { + Ok(ArtifactStatus::Unknown) + } + } + +} \ No newline at end of file diff --git a/movement-sdk/util/util/src/util/checker/mod.rs b/movement-sdk/util/util/src/util/checker/mod.rs index 14538102..e9b558ec 100644 --- a/movement-sdk/util/util/src/util/checker/mod.rs +++ b/movement-sdk/util/util/src/util/checker/mod.rs @@ -1,2 +1,3 @@ pub mod checker; -pub use checker::*; \ No newline at end of file +pub use checker::*; +pub mod command_exists; \ No newline at end of file diff --git a/movement-sdk/util/util/src/util/release/http_get_release.rs b/movement-sdk/util/util/src/util/release/http_get_release.rs index 764efb3d..d3e13667 100644 --- a/movement-sdk/util/util/src/util/release/http_get_release.rs +++ b/movement-sdk/util/util/src/util/release/http_get_release.rs @@ -1,6 +1,6 @@ use serde::{Deserialize, Serialize}; use super::{ReleaseOperations, Release}; -use crate::util::location::{Location, self}; +use crate::util::location::Location; use std::path::PathBuf; use std::io::Write; use reqwest;