From 6f8ef5ab5b844f6a370b348c0bf7c40574346639 Mon Sep 17 00:00:00 2001 From: Abhishek Shah Date: Wed, 1 May 2024 12:36:15 +0530 Subject: [PATCH 01/29] scaffold pop install --- Cargo.lock | 1 + crates/pop-cli/Cargo.toml | 1 + crates/pop-cli/src/commands/mod.rs | 1 + crates/pop-cli/src/main.rs | 28 ++++++++++++++++------------ crates/pop-parachains/src/up.rs | 2 +- 5 files changed, 20 insertions(+), 13 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index b61ae280..4b5ba4ba 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -5476,6 +5476,7 @@ dependencies = [ "pop-contracts", "pop-parachains", "predicates", + "reqwest", "sp-core 30.0.0", "sp-weights", "strum 0.26.2", diff --git a/crates/pop-cli/Cargo.toml b/crates/pop-cli/Cargo.toml index 1d027f9e..c6c59c55 100644 --- a/crates/pop-cli/Cargo.toml +++ b/crates/pop-cli/Cargo.toml @@ -14,6 +14,7 @@ duct.workspace = true tempfile.workspace = true url.workspace = true tokio.workspace = true +reqwest.workspace = true # pop-cli clap.workspace = true diff --git a/crates/pop-cli/src/commands/mod.rs b/crates/pop-cli/src/commands/mod.rs index 9dde6917..e2407e1c 100644 --- a/crates/pop-cli/src/commands/mod.rs +++ b/crates/pop-cli/src/commands/mod.rs @@ -5,3 +5,4 @@ pub(crate) mod call; pub(crate) mod new; pub(crate) mod test; pub(crate) mod up; +pub(crate) mod install; diff --git a/crates/pop-cli/src/main.rs b/crates/pop-cli/src/main.rs index af707305..cf750226 100644 --- a/crates/pop-cli/src/main.rs +++ b/crates/pop-cli/src/main.rs @@ -36,20 +36,23 @@ enum Commands { #[clap(alias = "t")] #[cfg(feature = "contract")] Test(commands::test::TestArgs), + /// Install tools for Substrate development + #[clap(alias = "i")] + Install(commands::install::InstallArgs) } #[tokio::main] async fn main() -> Result<()> { let cli = Cli::parse(); match cli.command { - Commands::New(args) => Ok(match &args.command { + Commands::New(args) => match &args.command { #[cfg(feature = "parachain")] - commands::new::NewCommands::Parachain(cmd) => cmd.execute().await?, + commands::new::NewCommands::Parachain(cmd) => cmd.execute().await, #[cfg(feature = "parachain")] - commands::new::NewCommands::Pallet(cmd) => cmd.execute().await?, + commands::new::NewCommands::Pallet(cmd) => cmd.execute().await, #[cfg(feature = "contract")] - commands::new::NewCommands::Contract(cmd) => cmd.execute().await?, - }), + commands::new::NewCommands::Contract(cmd) => cmd.execute().await, + }, Commands::Build(args) => match &args.command { #[cfg(feature = "parachain")] commands::build::BuildCommands::Parachain(cmd) => cmd.execute(), @@ -57,19 +60,20 @@ async fn main() -> Result<()> { commands::build::BuildCommands::Contract(cmd) => cmd.execute(), }, #[cfg(feature = "contract")] - Commands::Call(args) => Ok(match &args.command { - commands::call::CallCommands::Contract(cmd) => cmd.execute().await?, - }), - Commands::Up(args) => Ok(match &args.command { + Commands::Call(args) => match &args.command { + commands::call::CallCommands::Contract(cmd) => cmd.execute().await, + }, + Commands::Up(args) => match &args.command { #[cfg(feature = "parachain")] - commands::up::UpCommands::Parachain(cmd) => cmd.execute().await?, + commands::up::UpCommands::Parachain(cmd) => cmd.execute().await, #[cfg(feature = "contract")] - commands::up::UpCommands::Contract(cmd) => cmd.execute().await?, - }), + commands::up::UpCommands::Contract(cmd) => cmd.execute().await, + }, #[cfg(feature = "contract")] Commands::Test(args) => match &args.command { commands::test::TestCommands::Contract(cmd) => cmd.execute(), }, + Commands::Install(args) => args.execute().await, } } diff --git a/crates/pop-parachains/src/up.rs b/crates/pop-parachains/src/up.rs index 612e11b5..79fb446b 100644 --- a/crates/pop-parachains/src/up.rs +++ b/crates/pop-parachains/src/up.rs @@ -18,7 +18,7 @@ use zombienet_sdk::{Network, NetworkConfig, NetworkConfigExt}; use zombienet_support::fs::local::LocalFileSystem; const POLKADOT_SDK: &str = "https://github.com/paritytech/polkadot-sdk"; -const POLKADOT_DEFAULT_VERSION: &str = "v1.10.0"; +const POLKADOT_DEFAULT_VERSION: &str = "v1.11.0"; pub struct Zombienet { /// The cache location, used for caching binaries. From 7c2cc63aaf2f33e847069f2d9999fe960639f65a Mon Sep 17 00:00:00 2001 From: Abhishek Shah Date: Wed, 1 May 2024 12:38:34 +0530 Subject: [PATCH 02/29] include scripts --- crates/pop-cli/src/commands/install/mod.rs | 53 +++++++++++++++ scripts/get_substrate.sh | 76 ++++++++++++++++++++++ 2 files changed, 129 insertions(+) create mode 100644 crates/pop-cli/src/commands/install/mod.rs create mode 100644 scripts/get_substrate.sh diff --git a/crates/pop-cli/src/commands/install/mod.rs b/crates/pop-cli/src/commands/install/mod.rs new file mode 100644 index 00000000..4a3c9bcf --- /dev/null +++ b/crates/pop-cli/src/commands/install/mod.rs @@ -0,0 +1,53 @@ +// SPDX-License-Identifier: GPL-3.0 + +use clap::{Args, Subcommand}; +use std::fs; + +#[derive(Args)] +#[command(args_conflicts_with_subcommands = true)] +/// Setup user environment for substrate development +/// Runs script `scripts/get_substrate.sh` +pub(crate) struct InstallArgs { + #[command(subcommand)] + pub command: Option, +} + +#[derive(Subcommand)] +pub(crate) enum InstallCommands { + /// Install necessary tools for parachain development. + /// Same as `pop install` + #[clap(alias = "p")] + Parachain, + /// Install tools for ink! contract development + #[clap(alias = "c")] + Contract, + /// Install all tools + #[clap(alias = "a")] + All, +} + +impl InstallArgs { + pub(crate) async fn execute(self) -> anyhow::Result<()> { + let scripts_temp = tempfile::tempdir()?; + let client = reqwest::Client::new(); + let pre_substrate = client + .get("https://raw.githubusercontent.com/r0gue-io/pop-cli/main/scripts/get_substrate.sh") + .send() + .await? + .text() + .await?; + fs::write(scripts_temp.path().join("substrate.sh"), pre_substrate)?; + + // match self.command { + // InstallCommands::Parachain => install_parachain().await, + // InstallCommands::Contract => install_contract().await, + // InstallCommands::Zombienet => install_zombienet().await, + // InstallCommands::All => install_all().await, + // } + Ok(()) + } +} + +// async fn install_parachain() -> anyhow::Result<()> { +// Ok(()) +// } diff --git a/scripts/get_substrate.sh b/scripts/get_substrate.sh new file mode 100644 index 00000000..8719f0be --- /dev/null +++ b/scripts/get_substrate.sh @@ -0,0 +1,76 @@ +#!/bin/bash +# Copyright 2015-2020 Parity Technologies (UK) Ltd. + +if [[ "$OSTYPE" == "linux-gnu" ]]; then + set -e + if [[ $(whoami) == "root" ]]; then + MAKE_ME_ROOT= + else + MAKE_ME_ROOT=sudo + fi + + if [ -f /etc/redhat-release ]; then + echo "Redhat Linux detected." + $MAKE_ME_ROOT yum update -y + $MAKE_ME_ROOT yum groupinstall -y "Development Tools" + $MAKE_ME_ROOT yum install -y cmake openssl-devel git protobuf protobuf-compiler clang clang-devel + elif [ -f /etc/SuSE-release ]; then + echo "Suse Linux detected." + echo "This OS is not supported with this script at present. Sorry." + echo "Please refer to https://github.com/paritytech/polkadot-sdk for setup information." + exit 1 + elif [ -f /etc/arch-release ]; then + echo "Arch Linux detected." + $MAKE_ME_ROOT pacman -Syu --needed --noconfirm cmake gcc openssl-1.0 pkgconf git clang + export OPENSSL_LIB_DIR="/usr/lib/openssl-1.0"; + export OPENSSL_INCLUDE_DIR="/usr/include/openssl-1.0" + elif [ -f /etc/mandrake-release ]; then + echo "Mandrake Linux detected." + echo "This OS is not supported with this script at present. Sorry." + echo "Please refer to https://github.com/paritytech/polkadot-sdk for setup information." + exit 1 + elif [ -f /etc/debian_version ]; then + echo "Ubuntu/Debian Linux detected." + $MAKE_ME_ROOT apt update + $MAKE_ME_ROOT apt install -y cmake pkg-config libssl-dev git gcc build-essential git protobuf protobuf-compiler clang libclang-dev + else + echo "Unknown Linux distribution." + echo "This OS is not supported with this script at present. Sorry." + echo "Please refer to https://github.com/paritytech/polkadot-sdk for setup information." + exit 1 + fi +elif [[ "$OSTYPE" == "darwin"* ]]; then + set -e + echo "Mac OS (Darwin) detected." + + if ! which brew >/dev/null 2>&1; then + /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)" + fi + + brew update + brew install openssl cmake llvm +elif [[ "$OSTYPE" == "freebsd"* ]]; then + echo "FreeBSD detected." + echo "This OS is not supported with this script at present. Sorry." + echo "Please refer to https://github.com/paritytech/polkadot-sdk for setup information." + exit 1 +else + echo "Unknown operating system." + echo "This OS is not supported with this script at present. Sorry." + echo "Please refer to https://github.com/paritytech/polkadot-sdk for setup information." + exit 1 +fi + +if ! which rustup >/dev/null 2>&1; then + curl https://sh.rustup.rs -sSf | sh -s -- -y + source ~/.cargo/env + rustup default stable +else + rustup update + rustup default stable +fi + +rustup update nightly +rustup target add wasm32-unknown-unknown --toolchain nightly + +echo "Run source ~/.cargo/env now to update environment" \ No newline at end of file From 6ebc25b5c434ea1a103473fc4bae81dbaeae10d2 Mon Sep 17 00:00:00 2001 From: Abhishek Shah Date: Thu, 2 May 2024 10:48:19 +0530 Subject: [PATCH 03/29] implement script execution --- crates/pop-cli/src/commands/install/mod.rs | 51 +++++++--------------- scripts/get_substrate.sh | 1 - 2 files changed, 15 insertions(+), 37 deletions(-) diff --git a/crates/pop-cli/src/commands/install/mod.rs b/crates/pop-cli/src/commands/install/mod.rs index 4a3c9bcf..bd0c3506 100644 --- a/crates/pop-cli/src/commands/install/mod.rs +++ b/crates/pop-cli/src/commands/install/mod.rs @@ -1,53 +1,32 @@ // SPDX-License-Identifier: GPL-3.0 -use clap::{Args, Subcommand}; -use std::fs; +use anyhow::Context; +use clap::Args; +use tokio::{fs, process::Command}; #[derive(Args)] #[command(args_conflicts_with_subcommands = true)] /// Setup user environment for substrate development /// Runs script `scripts/get_substrate.sh` -pub(crate) struct InstallArgs { - #[command(subcommand)] - pub command: Option, -} - -#[derive(Subcommand)] -pub(crate) enum InstallCommands { - /// Install necessary tools for parachain development. - /// Same as `pop install` - #[clap(alias = "p")] - Parachain, - /// Install tools for ink! contract development - #[clap(alias = "c")] - Contract, - /// Install all tools - #[clap(alias = "a")] - All, -} +pub(crate) struct InstallArgs; impl InstallArgs { pub(crate) async fn execute(self) -> anyhow::Result<()> { - let scripts_temp = tempfile::tempdir()?; + let temp = tempfile::tempdir()?; + let scripts_path = temp.path().join("get_substrate.sh"); let client = reqwest::Client::new(); - let pre_substrate = client - .get("https://raw.githubusercontent.com/r0gue-io/pop-cli/main/scripts/get_substrate.sh") + let script = client + .get("https://raw.githubusercontent.com/r0gue-io/pop-cli/pop-install/scripts/get_substrate.sh") .send() - .await? + .await + .context("Network Error: Failed to fetch script from Github")? .text() .await?; - fs::write(scripts_temp.path().join("substrate.sh"), pre_substrate)?; - - // match self.command { - // InstallCommands::Parachain => install_parachain().await, - // InstallCommands::Contract => install_contract().await, - // InstallCommands::Zombienet => install_zombienet().await, - // InstallCommands::All => install_all().await, - // } + fs::write(scripts_path.as_path(), script).await?; + if cfg!(target_os = "windows") { + return Ok(cliclack::log::error("Windows is supported only with WSL2")?); + } + Command::new("bash").arg(scripts_path).spawn()?; Ok(()) } } - -// async fn install_parachain() -> anyhow::Result<()> { -// Ok(()) -// } diff --git a/scripts/get_substrate.sh b/scripts/get_substrate.sh index 8719f0be..aac4e316 100644 --- a/scripts/get_substrate.sh +++ b/scripts/get_substrate.sh @@ -1,5 +1,4 @@ #!/bin/bash -# Copyright 2015-2020 Parity Technologies (UK) Ltd. if [[ "$OSTYPE" == "linux-gnu" ]]; then set -e From 54a23a19a23abf250ef4012efb4c4a3d3cc73012 Mon Sep 17 00:00:00 2001 From: Abhishek Shah Date: Fri, 3 May 2024 11:48:42 +0530 Subject: [PATCH 04/29] update script --- crates/pop-cli/src/commands/install/mod.rs | 11 +++++++---- scripts/get_substrate.sh | 2 +- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/crates/pop-cli/src/commands/install/mod.rs b/crates/pop-cli/src/commands/install/mod.rs index bd0c3506..d8b17171 100644 --- a/crates/pop-cli/src/commands/install/mod.rs +++ b/crates/pop-cli/src/commands/install/mod.rs @@ -1,5 +1,7 @@ // SPDX-License-Identifier: GPL-3.0 +use std::process::Stdio; + use anyhow::Context; use clap::Args; use tokio::{fs, process::Command}; @@ -12,6 +14,9 @@ pub(crate) struct InstallArgs; impl InstallArgs { pub(crate) async fn execute(self) -> anyhow::Result<()> { + if cfg!(target_os = "windows") { + return Ok(cliclack::log::error("Windows is supported only with WSL2")?); + } let temp = tempfile::tempdir()?; let scripts_path = temp.path().join("get_substrate.sh"); let client = reqwest::Client::new(); @@ -23,10 +28,8 @@ impl InstallArgs { .text() .await?; fs::write(scripts_path.as_path(), script).await?; - if cfg!(target_os = "windows") { - return Ok(cliclack::log::error("Windows is supported only with WSL2")?); - } - Command::new("bash").arg(scripts_path).spawn()?; + Command::new("bash").arg(scripts_path).status().await?; + temp.close()?; Ok(()) } } diff --git a/scripts/get_substrate.sh b/scripts/get_substrate.sh index aac4e316..b993aa59 100644 --- a/scripts/get_substrate.sh +++ b/scripts/get_substrate.sh @@ -31,7 +31,7 @@ if [[ "$OSTYPE" == "linux-gnu" ]]; then elif [ -f /etc/debian_version ]; then echo "Ubuntu/Debian Linux detected." $MAKE_ME_ROOT apt update - $MAKE_ME_ROOT apt install -y cmake pkg-config libssl-dev git gcc build-essential git protobuf protobuf-compiler clang libclang-dev + $MAKE_ME_ROOT apt install -y cmake pkg-config libssl-dev git gcc build-essential git protobuf-compiler clang libclang-dev else echo "Unknown Linux distribution." echo "This OS is not supported with this script at present. Sorry." From 440791f86417147f7655182ad6790d0342911438 Mon Sep 17 00:00:00 2001 From: Abhishek Shah Date: Fri, 3 May 2024 12:00:00 +0530 Subject: [PATCH 05/29] links --- crates/pop-cli/src/commands/install/mod.rs | 2 -- crates/pop-cli/src/main.rs | 2 +- scripts/get_substrate.sh | 12 ++++++------ 3 files changed, 7 insertions(+), 9 deletions(-) diff --git a/crates/pop-cli/src/commands/install/mod.rs b/crates/pop-cli/src/commands/install/mod.rs index d8b17171..5ca1cb0d 100644 --- a/crates/pop-cli/src/commands/install/mod.rs +++ b/crates/pop-cli/src/commands/install/mod.rs @@ -1,7 +1,5 @@ // SPDX-License-Identifier: GPL-3.0 -use std::process::Stdio; - use anyhow::Context; use clap::Args; use tokio::{fs, process::Command}; diff --git a/crates/pop-cli/src/main.rs b/crates/pop-cli/src/main.rs index cf750226..20587c75 100644 --- a/crates/pop-cli/src/main.rs +++ b/crates/pop-cli/src/main.rs @@ -36,7 +36,7 @@ enum Commands { #[clap(alias = "t")] #[cfg(feature = "contract")] Test(commands::test::TestArgs), - /// Install tools for Substrate development + /// Install prerequisites for Substrate development #[clap(alias = "i")] Install(commands::install::InstallArgs) } diff --git a/scripts/get_substrate.sh b/scripts/get_substrate.sh index b993aa59..38ef9f17 100644 --- a/scripts/get_substrate.sh +++ b/scripts/get_substrate.sh @@ -16,7 +16,7 @@ if [[ "$OSTYPE" == "linux-gnu" ]]; then elif [ -f /etc/SuSE-release ]; then echo "Suse Linux detected." echo "This OS is not supported with this script at present. Sorry." - echo "Please refer to https://github.com/paritytech/polkadot-sdk for setup information." + echo "Please refer to https://docs.substrate.io/install/ for setup information." exit 1 elif [ -f /etc/arch-release ]; then echo "Arch Linux detected." @@ -26,7 +26,7 @@ if [[ "$OSTYPE" == "linux-gnu" ]]; then elif [ -f /etc/mandrake-release ]; then echo "Mandrake Linux detected." echo "This OS is not supported with this script at present. Sorry." - echo "Please refer to https://github.com/paritytech/polkadot-sdk for setup information." + echo "Please refer to https://docs.substrate.io/install/ for setup information." exit 1 elif [ -f /etc/debian_version ]; then echo "Ubuntu/Debian Linux detected." @@ -35,7 +35,7 @@ if [[ "$OSTYPE" == "linux-gnu" ]]; then else echo "Unknown Linux distribution." echo "This OS is not supported with this script at present. Sorry." - echo "Please refer to https://github.com/paritytech/polkadot-sdk for setup information." + echo "Please refer to https://docs.substrate.io/install/ for setup information." exit 1 fi elif [[ "$OSTYPE" == "darwin"* ]]; then @@ -51,12 +51,12 @@ elif [[ "$OSTYPE" == "darwin"* ]]; then elif [[ "$OSTYPE" == "freebsd"* ]]; then echo "FreeBSD detected." echo "This OS is not supported with this script at present. Sorry." - echo "Please refer to https://github.com/paritytech/polkadot-sdk for setup information." + echo "Please refer to https://docs.substrate.io/install/ for setup information." exit 1 else echo "Unknown operating system." echo "This OS is not supported with this script at present. Sorry." - echo "Please refer to https://github.com/paritytech/polkadot-sdk for setup information." + echo "Please refer to https://docs.substrate.io/install/ for setup information." exit 1 fi @@ -72,4 +72,4 @@ fi rustup update nightly rustup target add wasm32-unknown-unknown --toolchain nightly -echo "Run source ~/.cargo/env now to update environment" \ No newline at end of file +echo "Run \`source ~/.cargo/env\` now to update environment" \ No newline at end of file From ebe83d18252787f756eee663de23e9a5f167dfdb Mon Sep 17 00:00:00 2001 From: Abhishek Shah Date: Fri, 3 May 2024 12:03:02 +0530 Subject: [PATCH 06/29] fix formatting --- crates/pop-cli/src/commands/mod.rs | 2 +- crates/pop-cli/src/main.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/crates/pop-cli/src/commands/mod.rs b/crates/pop-cli/src/commands/mod.rs index e2407e1c..bd9e2a00 100644 --- a/crates/pop-cli/src/commands/mod.rs +++ b/crates/pop-cli/src/commands/mod.rs @@ -2,7 +2,7 @@ pub(crate) mod build; pub(crate) mod call; +pub(crate) mod install; pub(crate) mod new; pub(crate) mod test; pub(crate) mod up; -pub(crate) mod install; diff --git a/crates/pop-cli/src/main.rs b/crates/pop-cli/src/main.rs index 20587c75..c7b55330 100644 --- a/crates/pop-cli/src/main.rs +++ b/crates/pop-cli/src/main.rs @@ -38,7 +38,7 @@ enum Commands { Test(commands::test::TestArgs), /// Install prerequisites for Substrate development #[clap(alias = "i")] - Install(commands::install::InstallArgs) + Install(commands::install::InstallArgs), } #[tokio::main] From 6130f51990eb644b9c08717d59e178925ca870c9 Mon Sep 17 00:00:00 2001 From: AlexD10S Date: Wed, 8 May 2024 13:33:28 +0200 Subject: [PATCH 07/29] feat: installation process in rust code --- Cargo.lock | 11 + Cargo.toml | 1 + crates/pop-cli/Cargo.toml | 1 + crates/pop-cli/src/commands/install/mod.rs | 228 +++++++++++++++++++-- crates/pop-cli/src/main.rs | 2 +- scripts/get_substrate.sh | 75 ------- 6 files changed, 226 insertions(+), 92 deletions(-) delete mode 100644 scripts/get_substrate.sh diff --git a/Cargo.lock b/Cargo.lock index 4b5ba4ba..75941f52 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4963,6 +4963,16 @@ dependencies = [ "num-traits", ] +[[package]] +name = "os_info" +version = "3.8.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ae99c7fa6dd38c7cafe1ec085e804f8f555a2f8659b0dbe03f1f9963a9b51092" +dependencies = [ + "log", + "windows-sys 0.52.0", +] + [[package]] name = "os_pipe" version = "1.1.5" @@ -5473,6 +5483,7 @@ dependencies = [ "dirs", "duct", "git2", + "os_info", "pop-contracts", "pop-parachains", "predicates", diff --git a/Cargo.toml b/Cargo.toml index 023946d4..434ef0c2 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -50,3 +50,4 @@ cliclack = "0.1" console = "0.15" strum = "0.26" strum_macros = "0.26" +os_info = { version = "3", default-features = false } diff --git a/crates/pop-cli/Cargo.toml b/crates/pop-cli/Cargo.toml index c6c59c55..4a4bedf4 100644 --- a/crates/pop-cli/Cargo.toml +++ b/crates/pop-cli/Cargo.toml @@ -15,6 +15,7 @@ tempfile.workspace = true url.workspace = true tokio.workspace = true reqwest.workspace = true +os_info.workspace = true # pop-cli clap.workspace = true diff --git a/crates/pop-cli/src/commands/install/mod.rs b/crates/pop-cli/src/commands/install/mod.rs index 5ca1cb0d..8fbb85d7 100644 --- a/crates/pop-cli/src/commands/install/mod.rs +++ b/crates/pop-cli/src/commands/install/mod.rs @@ -2,32 +2,228 @@ use anyhow::Context; use clap::Args; +use cliclack::{confirm, log, outro, outro_cancel}; +use duct::cmd; +use os_info::Type; use tokio::{fs, process::Command}; #[derive(Args)] #[command(args_conflicts_with_subcommands = true)] /// Setup user environment for substrate development -/// Runs script `scripts/get_substrate.sh` pub(crate) struct InstallArgs; impl InstallArgs { pub(crate) async fn execute(self) -> anyhow::Result<()> { if cfg!(target_os = "windows") { - return Ok(cliclack::log::error("Windows is supported only with WSL2")?); + return not_supported_message(); + } else if cfg!(target_os = "macos") { + log::info("ℹ️ Mac OS (Darwin) detected.")?; + return install_mac().await; + } else if cfg!(target_os = "linux") { + let info = os_info::get(); + match info.os_type() { + Type::Arch => { + log::info("ℹ️ Arch Linux detected.")?; + return install_arch().await; + }, + Type::Debian => { + log::info("ℹ️ Ubuntu/Debian Linux detected.")?; + return install_debian().await; + }, + Type::Redhat => { + log::info("ℹ️ Redhat Linux detected.")?; + return install_redhat().await; + }, + _ => return not_supported_message(), + } + } else { + return not_supported_message(); } - let temp = tempfile::tempdir()?; - let scripts_path = temp.path().join("get_substrate.sh"); - let client = reqwest::Client::new(); - let script = client - .get("https://raw.githubusercontent.com/r0gue-io/pop-cli/pop-install/scripts/get_substrate.sh") - .send() - .await - .context("Network Error: Failed to fetch script from Github")? - .text() - .await?; - fs::write(scripts_path.as_path(), script).await?; - Command::new("bash").arg(scripts_path).status().await?; - temp.close()?; - Ok(()) } } + +async fn install_mac() -> anyhow::Result<()> { + log::info("More information about the packages to be installed here: https://docs.substrate.io/install/macos/")?; + if !confirm("📦 Do you want to proceed with the installation of the following packages: Homebrew, protobuf, openssl, rustup, and cmake?") + .initial_value(true) + .interact()? + { + outro_cancel("🚫 You have cancelled the installation process.")?; + return Ok(()); + } + match cmd("which", vec!["brew"]).read() { + Ok(output) => log::info(format!("ℹ️ Homebrew installed already at {}.", output))?, + Err(_) => install_homebrew().await?, + } + cmd("brew", vec!["update"]).run()?; + cmd("brew", vec!["install", "protobuf", "openssl", "cmake"]).run()?; + install_rustup().await?; + + log::success("✅ Installation complete."); + Ok(()) +} + +async fn install_arch() -> anyhow::Result<()> { + log::info("More information about the packages to be installed here: https://docs.substrate.io/install/linux/")?; + if !confirm("📦 Do you want to proceed with the installation of the following packages:cmake gcc openssl-1.0 pkgconf git clang?") + .initial_value(true) + .interact()? + { + outro_cancel("🚫 You have cancelled the installation process.")?; + return Ok(()); + } + cmd( + "sudo", + vec![ + "pacman", + "-Syu", + "--needed", + "--noconfirm", + "cmake", + "gcc", + "openssl-1.0", + "pkgconf", + "git", + "clang", + ], + ) + .run()?; + cmd("export", vec!["OPENSSL_LIB_DIR='/usr/lib/openssl-1.0'"]).run()?; + cmd("export", vec!["OPENSSL_INCLUDE_DIR='/usr/include/openssl-1.0'"]).run()?; + install_rustup().await?; + + log::success("✅ Installation complete."); + Ok(()) +} +async fn install_debian() -> anyhow::Result<()> { + log::info("More information about the packages to be installed here: https://docs.substrate.io/install/linux/")?; + if !confirm("📦 Do you want to proceed with the installation of the following packages:cmake pkg-config libssl-dev git gcc build-essential git protobuf-compiler clang libclang-dev?") + .initial_value(true) + .interact()? + { + outro_cancel("🚫 You have cancelled the installation process.")?; + return Ok(()); + } + cmd("sudo", vec!["apt", "update"]).run()?; + cmd( + "sudo", + vec![ + "apt", + "install", + "-y", + "cmake", + "pkg-config", + "libssl-dev", + "git", + "gcc", + "build-essential", + "git", + "protobuf-compiler", + "clang", + "libclang-dev", + ], + ) + .run()?; + install_rustup().await?; + + log::success("✅ Installation complete."); + Ok(()) +} + +async fn install_redhat() -> anyhow::Result<()> { + log::info("More information about the packages to be installed here: https://docs.substrate.io/install/linux/")?; + if !confirm("📦 Do you want to proceed with the installation of the following packages:cmake, openssl-devel, git, protobuf, protobuf-compiler, clang, clang-devel and srustup?") + .initial_value(true) + .interact()? + { + outro_cancel("🚫 You have cancelled the installation process.")?; + return Ok(()); + } + cmd("sudo", vec!["yum", "update", "-y"]).run()?; + cmd("sudo", vec!["yum", "groupinstall", "-y", "'Development Tool"]).run()?; + cmd( + "sudo", + vec![ + "yum", + "install", + "-y", + "cmake", + "openssl-devel", + "git", + "protobuf", + "protobuf-compiler", + "clang", + "clang-devel", + ], + ) + .run()?; + install_rustup().await?; + + log::success("✅ Installation complete."); + Ok(()) +} + +fn not_supported_message() -> anyhow::Result<()> { + log::error("This OS is not supported at present")?; + log::warning("⚠️ Please refer to https://docs.substrate.io/install/ for setup information.")?; + Ok(()) +} + +async fn install_rustup() -> anyhow::Result<()> { + match cmd("which", vec!["rustup"]).read() { + Ok(output) => { + log::info(format!("ℹ️ rustup installed already at {}.", output))?; + cmd("rustup", vec!["update"]).run()?; + cmd("rustup", vec!["default", "stable"]).run()?; + }, + Err(_) => { + let mut spinner = cliclack::spinner(); + spinner.start("Installing rustup ..."); + let temp = tempfile::tempdir()?; + let scripts_path = temp.path().join("rustup.sh"); + let client = reqwest::Client::new(); + let script = client + .get("https://sh.rustup.rs") + .send() + .await + .context("Network Error: Failed to fetch script from Github")? + .text() + .await?; + fs::write(scripts_path.as_path(), script).await?; + Command::new("sh").arg(scripts_path).status().await?; + temp.close()?; + outro("rustup installed!"); + cmd( + "source", + vec![ + "~/.cargo/env +", + ], + ) + .run()?; + cmd("rustup", vec!["default", "stable"]).run()?; + }, + } + cmd("rustup", vec!["update", "nightly"]).run()?; + cmd("rustup", vec!["target", "add", "wasm32-unknown-unknown", "--toolchain", "nightly"]) + .run()?; + + Ok(()) +} + +async fn install_homebrew() -> anyhow::Result<()> { + let temp = tempfile::tempdir()?; + let scripts_path = temp.path().join("install.sh"); + let client = reqwest::Client::new(); + let script = client + .get("https://raw.githubusercontent.com/Homebrew/install/master/install.sh") + .send() + .await + .context("Network Error: Failed to fetch script from Github")? + .text() + .await?; + fs::write(scripts_path.as_path(), script).await?; + Command::new("bash").arg(scripts_path).status().await?; + temp.close()?; + Ok(()) +} diff --git a/crates/pop-cli/src/main.rs b/crates/pop-cli/src/main.rs index c7b55330..705a582b 100644 --- a/crates/pop-cli/src/main.rs +++ b/crates/pop-cli/src/main.rs @@ -36,7 +36,7 @@ enum Commands { #[clap(alias = "t")] #[cfg(feature = "contract")] Test(commands::test::TestArgs), - /// Install prerequisites for Substrate development + /// Set up the environment for Substrate development #[clap(alias = "i")] Install(commands::install::InstallArgs), } diff --git a/scripts/get_substrate.sh b/scripts/get_substrate.sh deleted file mode 100644 index 38ef9f17..00000000 --- a/scripts/get_substrate.sh +++ /dev/null @@ -1,75 +0,0 @@ -#!/bin/bash - -if [[ "$OSTYPE" == "linux-gnu" ]]; then - set -e - if [[ $(whoami) == "root" ]]; then - MAKE_ME_ROOT= - else - MAKE_ME_ROOT=sudo - fi - - if [ -f /etc/redhat-release ]; then - echo "Redhat Linux detected." - $MAKE_ME_ROOT yum update -y - $MAKE_ME_ROOT yum groupinstall -y "Development Tools" - $MAKE_ME_ROOT yum install -y cmake openssl-devel git protobuf protobuf-compiler clang clang-devel - elif [ -f /etc/SuSE-release ]; then - echo "Suse Linux detected." - echo "This OS is not supported with this script at present. Sorry." - echo "Please refer to https://docs.substrate.io/install/ for setup information." - exit 1 - elif [ -f /etc/arch-release ]; then - echo "Arch Linux detected." - $MAKE_ME_ROOT pacman -Syu --needed --noconfirm cmake gcc openssl-1.0 pkgconf git clang - export OPENSSL_LIB_DIR="/usr/lib/openssl-1.0"; - export OPENSSL_INCLUDE_DIR="/usr/include/openssl-1.0" - elif [ -f /etc/mandrake-release ]; then - echo "Mandrake Linux detected." - echo "This OS is not supported with this script at present. Sorry." - echo "Please refer to https://docs.substrate.io/install/ for setup information." - exit 1 - elif [ -f /etc/debian_version ]; then - echo "Ubuntu/Debian Linux detected." - $MAKE_ME_ROOT apt update - $MAKE_ME_ROOT apt install -y cmake pkg-config libssl-dev git gcc build-essential git protobuf-compiler clang libclang-dev - else - echo "Unknown Linux distribution." - echo "This OS is not supported with this script at present. Sorry." - echo "Please refer to https://docs.substrate.io/install/ for setup information." - exit 1 - fi -elif [[ "$OSTYPE" == "darwin"* ]]; then - set -e - echo "Mac OS (Darwin) detected." - - if ! which brew >/dev/null 2>&1; then - /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)" - fi - - brew update - brew install openssl cmake llvm -elif [[ "$OSTYPE" == "freebsd"* ]]; then - echo "FreeBSD detected." - echo "This OS is not supported with this script at present. Sorry." - echo "Please refer to https://docs.substrate.io/install/ for setup information." - exit 1 -else - echo "Unknown operating system." - echo "This OS is not supported with this script at present. Sorry." - echo "Please refer to https://docs.substrate.io/install/ for setup information." - exit 1 -fi - -if ! which rustup >/dev/null 2>&1; then - curl https://sh.rustup.rs -sSf | sh -s -- -y - source ~/.cargo/env - rustup default stable -else - rustup update - rustup default stable -fi - -rustup update nightly -rustup target add wasm32-unknown-unknown --toolchain nightly - -echo "Run \`source ~/.cargo/env\` now to update environment" \ No newline at end of file From 98c4a1ecc1b4006c21a083f7b09076bb2e509150 Mon Sep 17 00:00:00 2001 From: AlexD10S Date: Wed, 8 May 2024 19:29:14 +0200 Subject: [PATCH 08/29] feat: flag --skip-confirmation --- crates/pop-cli/src/commands/install/mod.rs | 66 +++++++++++++++------- 1 file changed, 47 insertions(+), 19 deletions(-) diff --git a/crates/pop-cli/src/commands/install/mod.rs b/crates/pop-cli/src/commands/install/mod.rs index 8fbb85d7..0e63eec8 100644 --- a/crates/pop-cli/src/commands/install/mod.rs +++ b/crates/pop-cli/src/commands/install/mod.rs @@ -10,7 +10,11 @@ use tokio::{fs, process::Command}; #[derive(Args)] #[command(args_conflicts_with_subcommands = true)] /// Setup user environment for substrate development -pub(crate) struct InstallArgs; +pub(crate) struct InstallArgs { + /// Before install all the dependencies needed, do not ask the user for confirmation. + #[clap(short('y'), long)] + skip_confirm: bool, +} impl InstallArgs { pub(crate) async fn execute(self) -> anyhow::Result<()> { @@ -18,21 +22,25 @@ impl InstallArgs { return not_supported_message(); } else if cfg!(target_os = "macos") { log::info("ℹ️ Mac OS (Darwin) detected.")?; - return install_mac().await; + return install_mac(self.skip_confirm).await; } else if cfg!(target_os = "linux") { let info = os_info::get(); match info.os_type() { Type::Arch => { log::info("ℹ️ Arch Linux detected.")?; - return install_arch().await; + return install_arch(self.skip_confirm).await; }, Type::Debian => { - log::info("ℹ️ Ubuntu/Debian Linux detected.")?; - return install_debian().await; + log::info("ℹ️ Debian Linux detected.")?; + return install_debian(self.skip_confirm).await; }, Type::Redhat => { log::info("ℹ️ Redhat Linux detected.")?; - return install_redhat().await; + return install_redhat(self.skip_confirm).await; + }, + Type::Ubuntu => { + log::info("ℹ️ Ubuntu detected.")?; + return install_ubuntu(self.skip_confirm).await; }, _ => return not_supported_message(), } @@ -42,9 +50,9 @@ impl InstallArgs { } } -async fn install_mac() -> anyhow::Result<()> { +async fn install_mac(skip_confirm: bool) -> anyhow::Result<()> { log::info("More information about the packages to be installed here: https://docs.substrate.io/install/macos/")?; - if !confirm("📦 Do you want to proceed with the installation of the following packages: Homebrew, protobuf, openssl, rustup, and cmake?") + if !skip_confirm && !confirm("📦 Do you want to proceed with the installation of the following packages: Homebrew, protobuf, openssl, rustup, and cmake?") .initial_value(true) .interact()? { @@ -59,13 +67,13 @@ async fn install_mac() -> anyhow::Result<()> { cmd("brew", vec!["install", "protobuf", "openssl", "cmake"]).run()?; install_rustup().await?; - log::success("✅ Installation complete."); + log::success("✅ Installation complete.")?; Ok(()) } -async fn install_arch() -> anyhow::Result<()> { +async fn install_arch(skip_confirm: bool) -> anyhow::Result<()> { log::info("More information about the packages to be installed here: https://docs.substrate.io/install/linux/")?; - if !confirm("📦 Do you want to proceed with the installation of the following packages:cmake gcc openssl-1.0 pkgconf git clang?") + if !skip_confirm && !confirm("📦 Do you want to proceed with the installation of the following packages:cmake gcc openssl-1.0 pkgconf git clang?") .initial_value(true) .interact()? { @@ -92,12 +100,12 @@ async fn install_arch() -> anyhow::Result<()> { cmd("export", vec!["OPENSSL_INCLUDE_DIR='/usr/include/openssl-1.0'"]).run()?; install_rustup().await?; - log::success("✅ Installation complete."); + log::success("✅ Installation complete.")?; Ok(()) } -async fn install_debian() -> anyhow::Result<()> { +async fn install_debian(skip_confirm: bool) -> anyhow::Result<()> { log::info("More information about the packages to be installed here: https://docs.substrate.io/install/linux/")?; - if !confirm("📦 Do you want to proceed with the installation of the following packages:cmake pkg-config libssl-dev git gcc build-essential git protobuf-compiler clang libclang-dev?") + if !skip_confirm && !confirm("📦 Do you want to proceed with the installation of the following packages:cmake pkg-config libssl-dev git gcc build-essential git protobuf-compiler clang libclang-dev?") .initial_value(true) .interact()? { @@ -126,13 +134,33 @@ async fn install_debian() -> anyhow::Result<()> { .run()?; install_rustup().await?; - log::success("✅ Installation complete."); + log::success("✅ Installation complete.")?; + Ok(()) +} +async fn install_ubuntu(skip_confirm: bool) -> anyhow::Result<()> { + log::info("More information about the packages to be installed here: https://docs.substrate.io/install/linux/")?; + if !skip_confirm && !confirm("📦 Do you want to proceed with the installation of the following packages:git clang curl libssl-dev protobuf-compiler?") + .initial_value(true) + .interact()? + { + outro_cancel("🚫 You have cancelled the installation process.")?; + return Ok(()); + } + cmd("sudo", vec!["apt", "update"]).run()?; + cmd( + "sudo", + vec!["apt", "install", "-y", "git", "clang", "curl", "libssl-dev", "protobuf-compiler"], + ) + .run()?; + install_rustup().await?; + + log::success("✅ Installation complete.")?; Ok(()) } -async fn install_redhat() -> anyhow::Result<()> { +async fn install_redhat(skip_confirm: bool) -> anyhow::Result<()> { log::info("More information about the packages to be installed here: https://docs.substrate.io/install/linux/")?; - if !confirm("📦 Do you want to proceed with the installation of the following packages:cmake, openssl-devel, git, protobuf, protobuf-compiler, clang, clang-devel and srustup?") + if !skip_confirm && !confirm("📦 Do you want to proceed with the installation of the following packages:cmake, openssl-devel, git, protobuf, protobuf-compiler, clang, clang-devel and srustup?") .initial_value(true) .interact()? { @@ -159,7 +187,7 @@ async fn install_redhat() -> anyhow::Result<()> { .run()?; install_rustup().await?; - log::success("✅ Installation complete."); + log::success("✅ Installation complete.")?; Ok(()) } @@ -192,7 +220,7 @@ async fn install_rustup() -> anyhow::Result<()> { fs::write(scripts_path.as_path(), script).await?; Command::new("sh").arg(scripts_path).status().await?; temp.close()?; - outro("rustup installed!"); + outro("rustup installed!")?; cmd( "source", vec![ From dc6fb7f0f1eb05da4da4524653c5cd621e2ca121 Mon Sep 17 00:00:00 2001 From: AlexD10S Date: Wed, 8 May 2024 21:11:29 +0200 Subject: [PATCH 09/29] refactor: avoid repetition --- crates/pop-cli/src/commands/install/mod.rs | 145 +++++++++------------ 1 file changed, 64 insertions(+), 81 deletions(-) diff --git a/crates/pop-cli/src/commands/install/mod.rs b/crates/pop-cli/src/commands/install/mod.rs index 0e63eec8..f423c796 100644 --- a/crates/pop-cli/src/commands/install/mod.rs +++ b/crates/pop-cli/src/commands/install/mod.rs @@ -2,7 +2,7 @@ use anyhow::Context; use clap::Args; -use cliclack::{confirm, log, outro, outro_cancel}; +use cliclack::{confirm, log, outro}; use duct::cmd; use os_info::Type; use tokio::{fs, process::Command}; @@ -18,67 +18,54 @@ pub(crate) struct InstallArgs { impl InstallArgs { pub(crate) async fn execute(self) -> anyhow::Result<()> { - if cfg!(target_os = "windows") { - return not_supported_message(); - } else if cfg!(target_os = "macos") { + if cfg!(target_os = "macos") { log::info("ℹ️ Mac OS (Darwin) detected.")?; - return install_mac(self.skip_confirm).await; + install_mac(self.skip_confirm).await?; } else if cfg!(target_os = "linux") { - let info = os_info::get(); - match info.os_type() { + match os_info::get().os_type() { Type::Arch => { log::info("ℹ️ Arch Linux detected.")?; - return install_arch(self.skip_confirm).await; + install_arch(self.skip_confirm).await?; }, Type::Debian => { log::info("ℹ️ Debian Linux detected.")?; - return install_debian(self.skip_confirm).await; + install_debian(self.skip_confirm).await?; }, Type::Redhat => { log::info("ℹ️ Redhat Linux detected.")?; - return install_redhat(self.skip_confirm).await; + install_redhat(self.skip_confirm).await?; }, Type::Ubuntu => { log::info("ℹ️ Ubuntu detected.")?; - return install_ubuntu(self.skip_confirm).await; + install_ubuntu(self.skip_confirm).await?; }, _ => return not_supported_message(), } } else { return not_supported_message(); } + install_rustup().await?; + log::success("✅ Installation complete.")?; + Ok(()) } } async fn install_mac(skip_confirm: bool) -> anyhow::Result<()> { log::info("More information about the packages to be installed here: https://docs.substrate.io/install/macos/")?; - if !skip_confirm && !confirm("📦 Do you want to proceed with the installation of the following packages: Homebrew, protobuf, openssl, rustup, and cmake?") - .initial_value(true) - .interact()? - { - outro_cancel("🚫 You have cancelled the installation process.")?; - return Ok(()); - } - match cmd("which", vec!["brew"]).read() { - Ok(output) => log::info(format!("ℹ️ Homebrew installed already at {}.", output))?, - Err(_) => install_homebrew().await?, + if !skip_confirm { + prompt_for_confirmation("Homebrew, protobuf, openssl, rustup, and cmake")? } + install_homebrew().await?; cmd("brew", vec!["update"]).run()?; cmd("brew", vec!["install", "protobuf", "openssl", "cmake"]).run()?; - install_rustup().await?; - log::success("✅ Installation complete.")?; Ok(()) } async fn install_arch(skip_confirm: bool) -> anyhow::Result<()> { log::info("More information about the packages to be installed here: https://docs.substrate.io/install/linux/")?; - if !skip_confirm && !confirm("📦 Do you want to proceed with the installation of the following packages:cmake gcc openssl-1.0 pkgconf git clang?") - .initial_value(true) - .interact()? - { - outro_cancel("🚫 You have cancelled the installation process.")?; - return Ok(()); + if !skip_confirm { + prompt_for_confirmation("cmake, gcc, openssl-1.0, pkgconf, git, clang")? } cmd( "sudo", @@ -98,19 +85,29 @@ async fn install_arch(skip_confirm: bool) -> anyhow::Result<()> { .run()?; cmd("export", vec!["OPENSSL_LIB_DIR='/usr/lib/openssl-1.0'"]).run()?; cmd("export", vec!["OPENSSL_INCLUDE_DIR='/usr/include/openssl-1.0'"]).run()?; - install_rustup().await?; - log::success("✅ Installation complete.")?; Ok(()) } + +async fn install_ubuntu(skip_confirm: bool) -> anyhow::Result<()> { + log::info("More information about the packages to be installed here: https://docs.substrate.io/install/linux/")?; + if !skip_confirm { + prompt_for_confirmation("git, clang, curl, libssl-dev, protobuf-compiler")? + } + cmd("sudo", vec!["apt", "update"]).run()?; + cmd( + "sudo", + vec!["apt", "install", "-y", "git", "clang", "curl", "libssl-dev", "protobuf-compiler"], + ) + .run()?; + + Ok(()) +} + async fn install_debian(skip_confirm: bool) -> anyhow::Result<()> { log::info("More information about the packages to be installed here: https://docs.substrate.io/install/linux/")?; - if !skip_confirm && !confirm("📦 Do you want to proceed with the installation of the following packages:cmake pkg-config libssl-dev git gcc build-essential git protobuf-compiler clang libclang-dev?") - .initial_value(true) - .interact()? - { - outro_cancel("🚫 You have cancelled the installation process.")?; - return Ok(()); + if !skip_confirm { + prompt_for_confirmation("cmake, pkg-config, libssl-dev, git, gcc, build-essential, git, protobuf-compiler, clang, libclang-dev")? } cmd("sudo", vec!["apt", "update"]).run()?; cmd( @@ -132,40 +129,14 @@ async fn install_debian(skip_confirm: bool) -> anyhow::Result<()> { ], ) .run()?; - install_rustup().await?; - log::success("✅ Installation complete.")?; - Ok(()) -} -async fn install_ubuntu(skip_confirm: bool) -> anyhow::Result<()> { - log::info("More information about the packages to be installed here: https://docs.substrate.io/install/linux/")?; - if !skip_confirm && !confirm("📦 Do you want to proceed with the installation of the following packages:git clang curl libssl-dev protobuf-compiler?") - .initial_value(true) - .interact()? - { - outro_cancel("🚫 You have cancelled the installation process.")?; - return Ok(()); - } - cmd("sudo", vec!["apt", "update"]).run()?; - cmd( - "sudo", - vec!["apt", "install", "-y", "git", "clang", "curl", "libssl-dev", "protobuf-compiler"], - ) - .run()?; - install_rustup().await?; - - log::success("✅ Installation complete.")?; Ok(()) } async fn install_redhat(skip_confirm: bool) -> anyhow::Result<()> { log::info("More information about the packages to be installed here: https://docs.substrate.io/install/linux/")?; - if !skip_confirm && !confirm("📦 Do you want to proceed with the installation of the following packages:cmake, openssl-devel, git, protobuf, protobuf-compiler, clang, clang-devel and srustup?") - .initial_value(true) - .interact()? - { - outro_cancel("🚫 You have cancelled the installation process.")?; - return Ok(()); + if !skip_confirm { + prompt_for_confirmation("cmake, openssl-devel, git, protobuf, protobuf-compiler, clang, clang-devel and srustup")?; } cmd("sudo", vec!["yum", "update", "-y"]).run()?; cmd("sudo", vec!["yum", "groupinstall", "-y", "'Development Tool"]).run()?; @@ -185,9 +156,20 @@ async fn install_redhat(skip_confirm: bool) -> anyhow::Result<()> { ], ) .run()?; - install_rustup().await?; - log::success("✅ Installation complete.")?; + Ok(()) +} + +fn prompt_for_confirmation(message: &str) -> anyhow::Result<()> { + if !confirm(format!( + "📦 Do you want to proceed with the installation of the following packages: {} ?", + message + )) + .initial_value(true) + .interact()? + { + return Err(anyhow::anyhow!("🚫 You have cancelled the installation process.")); + } Ok(()) } @@ -207,19 +189,7 @@ async fn install_rustup() -> anyhow::Result<()> { Err(_) => { let mut spinner = cliclack::spinner(); spinner.start("Installing rustup ..."); - let temp = tempfile::tempdir()?; - let scripts_path = temp.path().join("rustup.sh"); - let client = reqwest::Client::new(); - let script = client - .get("https://sh.rustup.rs") - .send() - .await - .context("Network Error: Failed to fetch script from Github")? - .text() - .await?; - fs::write(scripts_path.as_path(), script).await?; - Command::new("sh").arg(scripts_path).status().await?; - temp.close()?; + run_external_script("https://sh.rustup.rs").await?; outro("rustup installed!")?; cmd( "source", @@ -240,11 +210,24 @@ async fn install_rustup() -> anyhow::Result<()> { } async fn install_homebrew() -> anyhow::Result<()> { + match cmd("which", vec!["brew"]).read() { + Ok(output) => log::info(format!("ℹ️ Homebrew installed already at {}.", output))?, + Err(_) => { + run_external_script( + "https://raw.githubusercontent.com/Homebrew/install/master/install.sh", + ) + .await? + }, + } + Ok(()) +} + +async fn run_external_script(script_url: &str) -> anyhow::Result<()> { let temp = tempfile::tempdir()?; let scripts_path = temp.path().join("install.sh"); let client = reqwest::Client::new(); let script = client - .get("https://raw.githubusercontent.com/Homebrew/install/master/install.sh") + .get(script_url) .send() .await .context("Network Error: Failed to fetch script from Github")? From d96e9ebf257c4a997ad05ed3f140c5565445c9cf Mon Sep 17 00:00:00 2001 From: AlexD10S Date: Wed, 8 May 2024 21:14:12 +0200 Subject: [PATCH 10/29] test: pop install CI --- .github/workflows/test-pop-install.yml | 46 ++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 .github/workflows/test-pop-install.yml diff --git a/.github/workflows/test-pop-install.yml b/.github/workflows/test-pop-install.yml new file mode 100644 index 00000000..636144be --- /dev/null +++ b/.github/workflows/test-pop-install.yml @@ -0,0 +1,46 @@ +name: Test pop install + +on: + push: + branches: [ "alexd10s/pop-install" ] + pull_request: + branches: [ "alexd10s/pop-install" ] + +env: + CARGO_TERM_COLOR: always + GITHUB_ACTOR: pop-cli + +jobs: + build: + + runs-on: ${{ matrix.platform.os }} + permissions: + contents: write + strategy: + matrix: + platform: + # Linux + - os: ubuntu-22.04 + target: aarch64-unknown-linux-gnu + - os: ubuntu-22.04 + target: x86_64-unknown-linux-gnu + # macOS + - os: macos-14 + target: aarch64-apple-darwin + - os: macos-14 + target: x86_64-apple-darwin + + steps: + - name: Free up space on runner + run: | + sudo rm -rf /usr/share/dotnet + sudo rm -rf /opt/ghc + sudo rm -rf "/usr/local/share/boost" + sudo rm -rf "$AGENT_TOOLSDIRECTORY" + + - uses: actions/checkout@v3 + - name: Build default features + run: cargo build + + - name: Run cargo run install + run: cargo run install -y \ No newline at end of file From 5f44f3eb6ca8b432db4d21eb59bf9ec3c158d56a Mon Sep 17 00:00:00 2001 From: AlexD10S Date: Wed, 8 May 2024 22:02:56 +0200 Subject: [PATCH 11/29] fix: merge main --- crates/pop-cli/src/main.rs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/crates/pop-cli/src/main.rs b/crates/pop-cli/src/main.rs index f5c9f1ea..13ee9e6a 100644 --- a/crates/pop-cli/src/main.rs +++ b/crates/pop-cli/src/main.rs @@ -62,9 +62,11 @@ async fn main() -> Result<()> { #[cfg(feature = "contract")] commands::new::NewCommands::Contract(cmd) => cmd.execute().await, }, + #[cfg(any(feature = "parachain", feature = "contract"))] Commands::Build(args) => match &args.command { #[cfg(feature = "parachain")] commands::build::BuildCommands::Parachain(cmd) => cmd.execute(), + #[cfg(feature = "contract")] commands::build::BuildCommands::Contract(cmd) => cmd.execute(), }, #[cfg(feature = "contract")] @@ -82,6 +84,7 @@ async fn main() -> Result<()> { Commands::Test(args) => match &args.command { commands::test::TestCommands::Contract(cmd) => cmd.execute(), }, + #[cfg(any(feature = "parachain", feature = "contract"))] Commands::Install(args) => args.execute().await, } } From 6894e011bf9aee9c28ab308baf2db424f0bc16af Mon Sep 17 00:00:00 2001 From: AlexD10S Date: Wed, 8 May 2024 22:09:48 +0200 Subject: [PATCH 12/29] docs: remove Substrate word --- crates/pop-cli/src/commands/install/mod.rs | 2 +- crates/pop-cli/src/main.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/crates/pop-cli/src/commands/install/mod.rs b/crates/pop-cli/src/commands/install/mod.rs index f423c796..6f772ca5 100644 --- a/crates/pop-cli/src/commands/install/mod.rs +++ b/crates/pop-cli/src/commands/install/mod.rs @@ -9,7 +9,7 @@ use tokio::{fs, process::Command}; #[derive(Args)] #[command(args_conflicts_with_subcommands = true)] -/// Setup user environment for substrate development +/// Setup user environment for development pub(crate) struct InstallArgs { /// Before install all the dependencies needed, do not ask the user for confirmation. #[clap(short('y'), long)] diff --git a/crates/pop-cli/src/main.rs b/crates/pop-cli/src/main.rs index 5e990309..caaa08c2 100644 --- a/crates/pop-cli/src/main.rs +++ b/crates/pop-cli/src/main.rs @@ -44,7 +44,7 @@ enum Commands { #[clap(alias = "t")] #[cfg(feature = "contract")] Test(commands::test::TestArgs), - /// Set up the environment for Substrate development + /// Set up the environment for development #[clap(alias = "i")] Install(commands::install::InstallArgs), } From d08540455d19bbec374c12331d6c7548b093454e Mon Sep 17 00:00:00 2001 From: AlexD10S Date: Thu, 9 May 2024 14:20:21 +0200 Subject: [PATCH 13/29] fix: remove sudo from commands and merge install.yml --- crates/pop-cli/src/commands/install/mod.rs | 29 +++++++++------------- 1 file changed, 12 insertions(+), 17 deletions(-) diff --git a/crates/pop-cli/src/commands/install/mod.rs b/crates/pop-cli/src/commands/install/mod.rs index 6f772ca5..d6f0276b 100644 --- a/crates/pop-cli/src/commands/install/mod.rs +++ b/crates/pop-cli/src/commands/install/mod.rs @@ -65,21 +65,20 @@ async fn install_mac(skip_confirm: bool) -> anyhow::Result<()> { async fn install_arch(skip_confirm: bool) -> anyhow::Result<()> { log::info("More information about the packages to be installed here: https://docs.substrate.io/install/linux/")?; if !skip_confirm { - prompt_for_confirmation("cmake, gcc, openssl-1.0, pkgconf, git, clang")? + prompt_for_confirmation("curl, git, clang, make, protobuf, openssl-1.0")? } cmd( - "sudo", + "pacman", vec![ - "pacman", "-Syu", "--needed", "--noconfirm", - "cmake", - "gcc", - "openssl-1.0", - "pkgconf", + "curl", "git", "clang", + "make", + "protobuf", + "openssl-1.0", ], ) .run()?; @@ -94,10 +93,9 @@ async fn install_ubuntu(skip_confirm: bool) -> anyhow::Result<()> { if !skip_confirm { prompt_for_confirmation("git, clang, curl, libssl-dev, protobuf-compiler")? } - cmd("sudo", vec!["apt", "update"]).run()?; cmd( - "sudo", - vec!["apt", "install", "-y", "git", "clang", "curl", "libssl-dev", "protobuf-compiler"], + "apt", + vec!["install", "--assume-yes", "git", "clang", "curl", "libssl-dev", "protobuf-compiler"], ) .run()?; @@ -109,11 +107,9 @@ async fn install_debian(skip_confirm: bool) -> anyhow::Result<()> { if !skip_confirm { prompt_for_confirmation("cmake, pkg-config, libssl-dev, git, gcc, build-essential, git, protobuf-compiler, clang, libclang-dev")? } - cmd("sudo", vec!["apt", "update"]).run()?; cmd( - "sudo", + "apt", vec![ - "apt", "install", "-y", "cmake", @@ -138,12 +134,11 @@ async fn install_redhat(skip_confirm: bool) -> anyhow::Result<()> { if !skip_confirm { prompt_for_confirmation("cmake, openssl-devel, git, protobuf, protobuf-compiler, clang, clang-devel and srustup")?; } - cmd("sudo", vec!["yum", "update", "-y"]).run()?; - cmd("sudo", vec!["yum", "groupinstall", "-y", "'Development Tool"]).run()?; + cmd("yum", vec!["update", "-y"]).run()?; + cmd("yum", vec!["groupinstall", "-y", "'Development Tool"]).run()?; cmd( - "sudo", + "yum", vec![ - "yum", "install", "-y", "cmake", From 4df3c9ee0acae6e3ea53c945d8fc02956f4ff7e1 Mon Sep 17 00:00:00 2001 From: AlexD10S Date: Thu, 9 May 2024 14:25:43 +0200 Subject: [PATCH 14/29] chore: merge and refactor .yml --- .github/workflows/install.yml | 17 ++++++++-- .github/workflows/test-pop-install.yml | 46 -------------------------- 2 files changed, 14 insertions(+), 49 deletions(-) delete mode 100644 .github/workflows/test-pop-install.yml diff --git a/.github/workflows/install.yml b/.github/workflows/install.yml index f2f40332..873dfc7d 100644 --- a/.github/workflows/install.yml +++ b/.github/workflows/install.yml @@ -2,9 +2,9 @@ name: pop install on: push: - branches: [ "main" ] + branches: [ "alexd10s/pop-install" ] pull_request: - branches: [ "main" ] + branches: [ "alexd10s/pop-install" ] defaults: run: @@ -24,4 +24,15 @@ jobs: run: | . "$HOME/.cargo/env" cargo install --locked --path ./crates/pop-cli - pop --version \ No newline at end of file + pop install -y + macos: + runs-on: macos-latest + steps: + - uses: actions/checkout@v4 + - name: Install Rust + run: curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y + - name: Install Pop + run: | + . "$HOME/.cargo/env" + cargo install --locked --path ./crates/pop-cli + pop install -y \ No newline at end of file diff --git a/.github/workflows/test-pop-install.yml b/.github/workflows/test-pop-install.yml deleted file mode 100644 index 636144be..00000000 --- a/.github/workflows/test-pop-install.yml +++ /dev/null @@ -1,46 +0,0 @@ -name: Test pop install - -on: - push: - branches: [ "alexd10s/pop-install" ] - pull_request: - branches: [ "alexd10s/pop-install" ] - -env: - CARGO_TERM_COLOR: always - GITHUB_ACTOR: pop-cli - -jobs: - build: - - runs-on: ${{ matrix.platform.os }} - permissions: - contents: write - strategy: - matrix: - platform: - # Linux - - os: ubuntu-22.04 - target: aarch64-unknown-linux-gnu - - os: ubuntu-22.04 - target: x86_64-unknown-linux-gnu - # macOS - - os: macos-14 - target: aarch64-apple-darwin - - os: macos-14 - target: x86_64-apple-darwin - - steps: - - name: Free up space on runner - run: | - sudo rm -rf /usr/share/dotnet - sudo rm -rf /opt/ghc - sudo rm -rf "/usr/local/share/boost" - sudo rm -rf "$AGENT_TOOLSDIRECTORY" - - - uses: actions/checkout@v3 - - name: Build default features - run: cargo build - - - name: Run cargo run install - run: cargo run install -y \ No newline at end of file From c1013b84d5c59766d6aa2207939e4da71733e777 Mon Sep 17 00:00:00 2001 From: AlexD10S Date: Thu, 9 May 2024 14:48:57 +0200 Subject: [PATCH 15/29] chore: add debian too --- .github/workflows/install.yml | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/.github/workflows/install.yml b/.github/workflows/install.yml index 873dfc7d..a5af361a 100644 --- a/.github/workflows/install.yml +++ b/.github/workflows/install.yml @@ -20,7 +20,21 @@ jobs: run: apt-get update && apt-get -y install build-essential cmake curl git - name: Install Rust run: curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y - - name: Install Pop + - name: Pop Install + run: | + . "$HOME/.cargo/env" + cargo install --locked --path ./crates/pop-cli + pop install -y + debian: + runs-on: ubuntu-latest + container: debian + steps: + - uses: actions/checkout@v4 + - name: Install prerequisites + run: apt-get update && apt-get -y install build-essential cmake curl git + - name: Install Rust + run: curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y + - name: Pop Install run: | . "$HOME/.cargo/env" cargo install --locked --path ./crates/pop-cli @@ -31,7 +45,7 @@ jobs: - uses: actions/checkout@v4 - name: Install Rust run: curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y - - name: Install Pop + - name: Pop Install run: | . "$HOME/.cargo/env" cargo install --locked --path ./crates/pop-cli From 9fc66e35e471029fcd14aa3233bcaba2f832d632 Mon Sep 17 00:00:00 2001 From: AlexD10S Date: Thu, 9 May 2024 14:51:32 +0200 Subject: [PATCH 16/29] chore: pop install CI only on main --- .github/workflows/install.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/install.yml b/.github/workflows/install.yml index a5af361a..85259ccd 100644 --- a/.github/workflows/install.yml +++ b/.github/workflows/install.yml @@ -2,9 +2,9 @@ name: pop install on: push: - branches: [ "alexd10s/pop-install" ] + branches: [ "main" ] pull_request: - branches: [ "alexd10s/pop-install" ] + branches: [ "main" ] defaults: run: From 099cca50d31d88bc33728f29142f70fc1d6f1414 Mon Sep 17 00:00:00 2001 From: AlexD10S Date: Thu, 9 May 2024 16:37:09 +0200 Subject: [PATCH 17/29] fix: in CI run install pop and run pop install separately --- .github/workflows/install.yml | 32 ++++++++++++++++++++------------ 1 file changed, 20 insertions(+), 12 deletions(-) diff --git a/.github/workflows/install.yml b/.github/workflows/install.yml index 85259ccd..d08d1e0e 100644 --- a/.github/workflows/install.yml +++ b/.github/workflows/install.yml @@ -11,42 +11,50 @@ defaults: shell: bash jobs: - ubuntu: + debian: runs-on: ubuntu-latest - container: ubuntu + container: debian steps: - uses: actions/checkout@v4 - name: Install prerequisites run: apt-get update && apt-get -y install build-essential cmake curl git - name: Install Rust run: curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y - - name: Pop Install + - name: Install Pop run: | . "$HOME/.cargo/env" cargo install --locked --path ./crates/pop-cli + - name: Run Pop Install + run: | + . "$HOME/.cargo/env" pop install -y - debian: - runs-on: ubuntu-latest - container: debian + macos: + runs-on: macos-latest steps: - uses: actions/checkout@v4 - - name: Install prerequisites - run: apt-get update && apt-get -y install build-essential cmake curl git - name: Install Rust run: curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y - - name: Pop Install + - name: Install Pop run: | . "$HOME/.cargo/env" cargo install --locked --path ./crates/pop-cli + - name: Run Pop Install + run: pop install -y - macos: - runs-on: macos-latest + ubuntu: + runs-on: ubuntu-latest + container: ubuntu steps: - uses: actions/checkout@v4 + - name: Install prerequisites + run: apt-get update && apt-get -y install build-essential cmake curl git - name: Install Rust run: curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y - - name: Pop Install + - name: Install Pop run: | . "$HOME/.cargo/env" cargo install --locked --path ./crates/pop-cli + - name: Run Pop install + run: | + . "$HOME/.cargo/env" pop install -y \ No newline at end of file From 57fbb03223478386c829b5d766b690407984356d Mon Sep 17 00:00:00 2001 From: AlexD10S Date: Thu, 9 May 2024 23:21:12 +0200 Subject: [PATCH 18/29] refactor: dependencies in enum --- crates/pop-cli/src/commands/install/mod.rs | 177 +++++++++++++++++---- 1 file changed, 143 insertions(+), 34 deletions(-) diff --git a/crates/pop-cli/src/commands/install/mod.rs b/crates/pop-cli/src/commands/install/mod.rs index d6f0276b..f608ee60 100644 --- a/crates/pop-cli/src/commands/install/mod.rs +++ b/crates/pop-cli/src/commands/install/mod.rs @@ -1,23 +1,70 @@ // SPDX-License-Identifier: GPL-3.0 - +use crate::style::{style, Theme}; use anyhow::Context; use clap::Args; -use cliclack::{confirm, log, outro}; +use cliclack::{clear_screen, confirm, intro, log, outro, set_theme}; use duct::cmd; use os_info::Type; +use strum::Display; use tokio::{fs, process::Command}; +#[derive(Display)] +pub enum DEPENDENCIES { + #[strum(serialize = "homebrew")] + Homebrew, + #[strum(serialize = "protobuf")] + Protobuf, + #[strum(serialize = "openssl")] + Openssl, + #[strum(serialize = "rustup")] + Rustup, + #[strum(serialize = "cmake")] + Cmake, + #[strum(serialize = "curl")] + Curl, + #[strum(serialize = "git")] + Git, + #[strum(serialize = "clang")] + Clang, + #[strum(serialize = "make")] + Make, + #[strum(serialize = "openssl-1.0")] + Openssl1, + #[strum(serialize = "libssl-dev")] + Libssl, + #[strum(serialize = "protobuf-compiler")] + ProtobufCompiler, + #[strum(serialize = "pkg-config")] + PkgConfig, + #[strum(serialize = "gcc")] + Gcc, + #[strum(serialize = "build-essential")] + BuildEssential, + #[strum(serialize = "libclang-dev")] + LibClang, + #[strum(serialize = "openssl-devel")] + OpenSslDevel, + #[strum(serialize = "clang-devel")] + ClangDevel, +} + #[derive(Args)] #[command(args_conflicts_with_subcommands = true)] /// Setup user environment for development pub(crate) struct InstallArgs { - /// Before install all the dependencies needed, do not ask the user for confirmation. + /// Automatically install all dependencies required without prompting for confirmation. #[clap(short('y'), long)] skip_confirm: bool, } impl InstallArgs { pub(crate) async fn execute(self) -> anyhow::Result<()> { + clear_screen()?; + set_theme(Theme); + intro(format!( + "{}: Install dependencies for development", + style(" Pop CLI ").black().on_magenta() + ))?; if cfg!(target_os = "macos") { log::info("ℹ️ Mac OS (Darwin) detected.")?; install_mac(self.skip_confirm).await?; @@ -53,11 +100,27 @@ impl InstallArgs { async fn install_mac(skip_confirm: bool) -> anyhow::Result<()> { log::info("More information about the packages to be installed here: https://docs.substrate.io/install/macos/")?; if !skip_confirm { - prompt_for_confirmation("Homebrew, protobuf, openssl, rustup, and cmake")? + prompt_for_confirmation(&format!( + "{}, {}, {}, {} and {}", + DEPENDENCIES::Homebrew, + DEPENDENCIES::Protobuf, + DEPENDENCIES::Openssl, + DEPENDENCIES::Rustup, + DEPENDENCIES::Cmake, + ))? } install_homebrew().await?; cmd("brew", vec!["update"]).run()?; - cmd("brew", vec!["install", "protobuf", "openssl", "cmake"]).run()?; + cmd( + "brew", + vec![ + "install", + &DEPENDENCIES::Protobuf.to_string(), + &DEPENDENCIES::Openssl.to_string(), + &DEPENDENCIES::Cmake.to_string(), + ], + ) + .run()?; Ok(()) } @@ -65,7 +128,16 @@ async fn install_mac(skip_confirm: bool) -> anyhow::Result<()> { async fn install_arch(skip_confirm: bool) -> anyhow::Result<()> { log::info("More information about the packages to be installed here: https://docs.substrate.io/install/linux/")?; if !skip_confirm { - prompt_for_confirmation("curl, git, clang, make, protobuf, openssl-1.0")? + prompt_for_confirmation(&format!( + "{}, {}, {}, {}, {}, {} and {}", + DEPENDENCIES::Curl, + DEPENDENCIES::Git, + DEPENDENCIES::Clang, + DEPENDENCIES::Make, + DEPENDENCIES::Protobuf, + DEPENDENCIES::Openssl1, + DEPENDENCIES::Rustup, + ))? } cmd( "pacman", @@ -73,12 +145,12 @@ async fn install_arch(skip_confirm: bool) -> anyhow::Result<()> { "-Syu", "--needed", "--noconfirm", - "curl", - "git", - "clang", - "make", - "protobuf", - "openssl-1.0", + &DEPENDENCIES::Curl.to_string(), + &DEPENDENCIES::Git.to_string(), + &DEPENDENCIES::Clang.to_string(), + &DEPENDENCIES::Make.to_string(), + &DEPENDENCIES::Protobuf.to_string(), + &DEPENDENCIES::Openssl1.to_string(), ], ) .run()?; @@ -91,11 +163,27 @@ async fn install_arch(skip_confirm: bool) -> anyhow::Result<()> { async fn install_ubuntu(skip_confirm: bool) -> anyhow::Result<()> { log::info("More information about the packages to be installed here: https://docs.substrate.io/install/linux/")?; if !skip_confirm { - prompt_for_confirmation("git, clang, curl, libssl-dev, protobuf-compiler")? + prompt_for_confirmation(&format!( + "{}, {}, {}, {}, {} and {}", + DEPENDENCIES::Git, + DEPENDENCIES::Clang, + DEPENDENCIES::Curl, + DEPENDENCIES::Libssl, + DEPENDENCIES::ProtobufCompiler, + DEPENDENCIES::Rustup, + ))? } cmd( "apt", - vec!["install", "--assume-yes", "git", "clang", "curl", "libssl-dev", "protobuf-compiler"], + vec![ + "install", + "--assume-yes", + &DEPENDENCIES::Git.to_string(), + &DEPENDENCIES::Clang.to_string(), + &DEPENDENCIES::Curl.to_string(), + &DEPENDENCIES::Libssl.to_string(), + &DEPENDENCIES::ProtobufCompiler.to_string(), + ], ) .run()?; @@ -105,23 +193,34 @@ async fn install_ubuntu(skip_confirm: bool) -> anyhow::Result<()> { async fn install_debian(skip_confirm: bool) -> anyhow::Result<()> { log::info("More information about the packages to be installed here: https://docs.substrate.io/install/linux/")?; if !skip_confirm { - prompt_for_confirmation("cmake, pkg-config, libssl-dev, git, gcc, build-essential, git, protobuf-compiler, clang, libclang-dev")? + prompt_for_confirmation(&format!( + "{}, {}, {}, {}, {}, {}, {}, {}, {} and {}", + DEPENDENCIES::Cmake, + DEPENDENCIES::PkgConfig, + DEPENDENCIES::Libssl, + DEPENDENCIES::Git, + DEPENDENCIES::Gcc, + DEPENDENCIES::BuildEssential, + DEPENDENCIES::ProtobufCompiler, + DEPENDENCIES::Clang, + DEPENDENCIES::LibClang, + DEPENDENCIES::Rustup, + ))? } cmd( "apt", vec![ "install", "-y", - "cmake", - "pkg-config", - "libssl-dev", - "git", - "gcc", - "build-essential", - "git", - "protobuf-compiler", - "clang", - "libclang-dev", + &DEPENDENCIES::Cmake.to_string(), + &DEPENDENCIES::PkgConfig.to_string(), + &DEPENDENCIES::Libssl.to_string(), + &DEPENDENCIES::Git.to_string(), + &DEPENDENCIES::Gcc.to_string(), + &DEPENDENCIES::BuildEssential.to_string(), + &DEPENDENCIES::ProtobufCompiler.to_string(), + &DEPENDENCIES::Clang.to_string(), + &DEPENDENCIES::LibClang.to_string(), ], ) .run()?; @@ -132,7 +231,17 @@ async fn install_debian(skip_confirm: bool) -> anyhow::Result<()> { async fn install_redhat(skip_confirm: bool) -> anyhow::Result<()> { log::info("More information about the packages to be installed here: https://docs.substrate.io/install/linux/")?; if !skip_confirm { - prompt_for_confirmation("cmake, openssl-devel, git, protobuf, protobuf-compiler, clang, clang-devel and srustup")?; + prompt_for_confirmation(&format!( + "{}, {}, {}, {}, {}, {}, {} and {}", + DEPENDENCIES::Cmake, + DEPENDENCIES::OpenSslDevel, + DEPENDENCIES::Git, + DEPENDENCIES::Protobuf, + DEPENDENCIES::ProtobufCompiler, + DEPENDENCIES::Clang, + DEPENDENCIES::ClangDevel, + DEPENDENCIES::Rustup, + ))? } cmd("yum", vec!["update", "-y"]).run()?; cmd("yum", vec!["groupinstall", "-y", "'Development Tool"]).run()?; @@ -141,13 +250,13 @@ async fn install_redhat(skip_confirm: bool) -> anyhow::Result<()> { vec![ "install", "-y", - "cmake", - "openssl-devel", - "git", - "protobuf", - "protobuf-compiler", - "clang", - "clang-devel", + &DEPENDENCIES::Cmake.to_string(), + &DEPENDENCIES::OpenSslDevel.to_string(), + &DEPENDENCIES::Git.to_string(), + &DEPENDENCIES::Protobuf.to_string(), + &DEPENDENCIES::ProtobufCompiler.to_string(), + &DEPENDENCIES::Clang.to_string(), + &DEPENDENCIES::ClangDevel.to_string(), ], ) .run()?; @@ -182,7 +291,7 @@ async fn install_rustup() -> anyhow::Result<()> { cmd("rustup", vec!["default", "stable"]).run()?; }, Err(_) => { - let mut spinner = cliclack::spinner(); + let spinner = cliclack::spinner(); spinner.start("Installing rustup ..."); run_external_script("https://sh.rustup.rs").await?; outro("rustup installed!")?; From 7d4dac563d266c610c8cebc72fc0c60b5bad8544 Mon Sep 17 00:00:00 2001 From: AlexD10S Date: Thu, 9 May 2024 23:21:30 +0200 Subject: [PATCH 19/29] refactor: dependencies in enum --- .github/workflows/install.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/install.yml b/.github/workflows/install.yml index d08d1e0e..2a479834 100644 --- a/.github/workflows/install.yml +++ b/.github/workflows/install.yml @@ -2,9 +2,9 @@ name: pop install on: push: - branches: [ "main" ] + branches: [ "alexd10s/pop-install" ] pull_request: - branches: [ "main" ] + branches: [ "alexd10s/pop-install" ] defaults: run: From 251a7c937116d9c4b84d45ad97ad822daa00c272 Mon Sep 17 00:00:00 2001 From: AlexD10S Date: Thu, 9 May 2024 23:24:36 +0200 Subject: [PATCH 20/29] refactor: sort enum --- crates/pop-cli/src/commands/install/mod.rs | 48 +++++++++++----------- 1 file changed, 24 insertions(+), 24 deletions(-) diff --git a/crates/pop-cli/src/commands/install/mod.rs b/crates/pop-cli/src/commands/install/mod.rs index f608ee60..d3036555 100644 --- a/crates/pop-cli/src/commands/install/mod.rs +++ b/crates/pop-cli/src/commands/install/mod.rs @@ -10,42 +10,42 @@ use tokio::{fs, process::Command}; #[derive(Display)] pub enum DEPENDENCIES { - #[strum(serialize = "homebrew")] - Homebrew, - #[strum(serialize = "protobuf")] - Protobuf, - #[strum(serialize = "openssl")] - Openssl, - #[strum(serialize = "rustup")] - Rustup, + #[strum(serialize = "build-essential")] + BuildEssential, + #[strum(serialize = "clang")] + Clang, + #[strum(serialize = "clang-devel")] + ClangDevel, #[strum(serialize = "cmake")] Cmake, #[strum(serialize = "curl")] Curl, + #[strum(serialize = "gcc")] + Gcc, #[strum(serialize = "git")] Git, - #[strum(serialize = "clang")] - Clang, + #[strum(serialize = "homebrew")] + Homebrew, + #[strum(serialize = "libclang-dev")] + LibClang, + #[strum(serialize = "libssl-dev")] + Libssl, #[strum(serialize = "make")] Make, + #[strum(serialize = "openssl")] + Openssl, + #[strum(serialize = "openssl-devel")] + OpenSslDevel, #[strum(serialize = "openssl-1.0")] Openssl1, - #[strum(serialize = "libssl-dev")] - Libssl, - #[strum(serialize = "protobuf-compiler")] - ProtobufCompiler, #[strum(serialize = "pkg-config")] PkgConfig, - #[strum(serialize = "gcc")] - Gcc, - #[strum(serialize = "build-essential")] - BuildEssential, - #[strum(serialize = "libclang-dev")] - LibClang, - #[strum(serialize = "openssl-devel")] - OpenSslDevel, - #[strum(serialize = "clang-devel")] - ClangDevel, + #[strum(serialize = "protobuf")] + Protobuf, + #[strum(serialize = "protobuf-compiler")] + ProtobufCompiler, + #[strum(serialize = "rustup")] + Rustup, } #[derive(Args)] From b40beda470321ec963d11f4144ea8490cde3ddcf Mon Sep 17 00:00:00 2001 From: AlexD10S Date: Fri, 10 May 2024 00:27:37 +0200 Subject: [PATCH 21/29] chore: feedback --- crates/pop-cli/src/commands/install/mod.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/pop-cli/src/commands/install/mod.rs b/crates/pop-cli/src/commands/install/mod.rs index d3036555..752d612c 100644 --- a/crates/pop-cli/src/commands/install/mod.rs +++ b/crates/pop-cli/src/commands/install/mod.rs @@ -92,7 +92,7 @@ impl InstallArgs { return not_supported_message(); } install_rustup().await?; - log::success("✅ Installation complete.")?; + outro("✅ Installation complete.")?; Ok(()) } } From dad6e4af99b72697b706fa6f0ff699f43f335e53 Mon Sep 17 00:00:00 2001 From: AlexD10S Date: Fri, 10 May 2024 01:22:50 +0200 Subject: [PATCH 22/29] chore: test in ci for arch and redhat and some fixes --- .github/workflows/install.yml | 39 +++++- README.md | 2 +- crates/pop-cli/src/commands/install/mod.rs | 139 ++++++++++----------- 3 files changed, 108 insertions(+), 72 deletions(-) diff --git a/.github/workflows/install.yml b/.github/workflows/install.yml index 2a479834..d7694bc8 100644 --- a/.github/workflows/install.yml +++ b/.github/workflows/install.yml @@ -11,6 +11,23 @@ defaults: shell: bash jobs: + arch: + runs-on: ubuntu-latest + container: archlinux:latest + steps: + - uses: actions/checkout@v4 + - name: Install prerequisites + run: pacman -Syu --needed --noconfirm cmake curl git base-devel + - name: Install Rust + run: curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y + - name: Install Pop + run: | + . "$HOME/.cargo/env" + cargo install --locked --path ./crates/pop-cli + - name: Run Pop install + run: | + . "$HOME/.cargo/env" + pop install -y debian: runs-on: ubuntu-latest container: debian @@ -32,6 +49,8 @@ jobs: runs-on: macos-latest steps: - uses: actions/checkout@v4 + - name: Install prerequisites + run: brew update && brew install cmake openssl protobuf - name: Install Rust run: curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y - name: Install Pop @@ -39,7 +58,25 @@ jobs: . "$HOME/.cargo/env" cargo install --locked --path ./crates/pop-cli - name: Run Pop Install - run: + run: | + . "$HOME/.cargo/env" + pop install -y + redhat: + runs-on: ubuntu-latest + container: redhat/ubi8 + steps: + - uses: actions/checkout@v4 + - name: Install prerequisites + run: yum update -y && yum install -y perl-IPC-Cmd clang curl git make cmake protobuf-compiler gcc pkg-config openssl-devel + - name: Install Rust + run: curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y + - name: Install Pop + run: | + . "$HOME/.cargo/env" + cargo install --locked --path ./crates/pop-cli + - name: Run Pop install + run: | + . "$HOME/.cargo/env" pop install -y ubuntu: runs-on: ubuntu-latest diff --git a/README.md b/README.md index b1b38244..4e64261b 100644 --- a/README.md +++ b/README.md @@ -11,7 +11,7 @@ You can install Pop CLI as follows: ```shell cargo install --locked --git https://github.com/r0gue-io/pop-cli ``` - +> For detailed instructions on how to install Pop CLI, please refer to our documentation: https://learn.onpop.io/pop/v/pop-cli/welcome/installing-pop-cli > :information_source: A [crates.io](https://crates.io/crates/pop-cli) version will be available soon! ## Getting Started diff --git a/crates/pop-cli/src/commands/install/mod.rs b/crates/pop-cli/src/commands/install/mod.rs index 752d612c..89bd953b 100644 --- a/crates/pop-cli/src/commands/install/mod.rs +++ b/crates/pop-cli/src/commands/install/mod.rs @@ -9,7 +9,7 @@ use strum::Display; use tokio::{fs, process::Command}; #[derive(Display)] -pub enum DEPENDENCIES { +pub enum Dependencies { #[strum(serialize = "build-essential")] BuildEssential, #[strum(serialize = "clang")] @@ -36,8 +36,6 @@ pub enum DEPENDENCIES { Openssl, #[strum(serialize = "openssl-devel")] OpenSslDevel, - #[strum(serialize = "openssl-1.0")] - Openssl1, #[strum(serialize = "pkg-config")] PkgConfig, #[strum(serialize = "protobuf")] @@ -102,11 +100,11 @@ async fn install_mac(skip_confirm: bool) -> anyhow::Result<()> { if !skip_confirm { prompt_for_confirmation(&format!( "{}, {}, {}, {} and {}", - DEPENDENCIES::Homebrew, - DEPENDENCIES::Protobuf, - DEPENDENCIES::Openssl, - DEPENDENCIES::Rustup, - DEPENDENCIES::Cmake, + Dependencies::Homebrew, + Dependencies::Protobuf, + Dependencies::Openssl, + Dependencies::Rustup, + Dependencies::Cmake, ))? } install_homebrew().await?; @@ -115,9 +113,9 @@ async fn install_mac(skip_confirm: bool) -> anyhow::Result<()> { "brew", vec![ "install", - &DEPENDENCIES::Protobuf.to_string(), - &DEPENDENCIES::Openssl.to_string(), - &DEPENDENCIES::Cmake.to_string(), + &Dependencies::Protobuf.to_string(), + &Dependencies::Openssl.to_string(), + &Dependencies::Cmake.to_string(), ], ) .run()?; @@ -129,28 +127,29 @@ async fn install_arch(skip_confirm: bool) -> anyhow::Result<()> { log::info("More information about the packages to be installed here: https://docs.substrate.io/install/linux/")?; if !skip_confirm { prompt_for_confirmation(&format!( - "{}, {}, {}, {}, {}, {} and {}", - DEPENDENCIES::Curl, - DEPENDENCIES::Git, - DEPENDENCIES::Clang, - DEPENDENCIES::Make, - DEPENDENCIES::Protobuf, - DEPENDENCIES::Openssl1, - DEPENDENCIES::Rustup, + "{}, {}, {}, {}, {} and {}", + Dependencies::Curl, + Dependencies::Git, + Dependencies::Clang, + Dependencies::Make, + Dependencies::Openssl, + Dependencies::Rustup, ))? } + cmd("pacman", vec!["-Syu", "--needed", "--noconfirm", &Dependencies::Openssl.to_string()]) + .run()?; + cmd("export", vec!["OPENSSL_LIB_DIR='/usr/lib/openssl-1.0'"]).run()?; + cmd("export", vec!["OPENSSL_INCLUDE_DIR='/usr/include/openssl-1.0'"]).run()?; cmd( "pacman", vec![ "-Syu", "--needed", "--noconfirm", - &DEPENDENCIES::Curl.to_string(), - &DEPENDENCIES::Git.to_string(), - &DEPENDENCIES::Clang.to_string(), - &DEPENDENCIES::Make.to_string(), - &DEPENDENCIES::Protobuf.to_string(), - &DEPENDENCIES::Openssl1.to_string(), + &Dependencies::Curl.to_string(), + &Dependencies::Git.to_string(), + &Dependencies::Clang.to_string(), + &Dependencies::Make.to_string(), ], ) .run()?; @@ -165,12 +164,12 @@ async fn install_ubuntu(skip_confirm: bool) -> anyhow::Result<()> { if !skip_confirm { prompt_for_confirmation(&format!( "{}, {}, {}, {}, {} and {}", - DEPENDENCIES::Git, - DEPENDENCIES::Clang, - DEPENDENCIES::Curl, - DEPENDENCIES::Libssl, - DEPENDENCIES::ProtobufCompiler, - DEPENDENCIES::Rustup, + Dependencies::Git, + Dependencies::Clang, + Dependencies::Curl, + Dependencies::Libssl, + Dependencies::ProtobufCompiler, + Dependencies::Rustup, ))? } cmd( @@ -178,11 +177,11 @@ async fn install_ubuntu(skip_confirm: bool) -> anyhow::Result<()> { vec![ "install", "--assume-yes", - &DEPENDENCIES::Git.to_string(), - &DEPENDENCIES::Clang.to_string(), - &DEPENDENCIES::Curl.to_string(), - &DEPENDENCIES::Libssl.to_string(), - &DEPENDENCIES::ProtobufCompiler.to_string(), + &Dependencies::Git.to_string(), + &Dependencies::Clang.to_string(), + &Dependencies::Curl.to_string(), + &Dependencies::Libssl.to_string(), + &Dependencies::ProtobufCompiler.to_string(), ], ) .run()?; @@ -195,16 +194,16 @@ async fn install_debian(skip_confirm: bool) -> anyhow::Result<()> { if !skip_confirm { prompt_for_confirmation(&format!( "{}, {}, {}, {}, {}, {}, {}, {}, {} and {}", - DEPENDENCIES::Cmake, - DEPENDENCIES::PkgConfig, - DEPENDENCIES::Libssl, - DEPENDENCIES::Git, - DEPENDENCIES::Gcc, - DEPENDENCIES::BuildEssential, - DEPENDENCIES::ProtobufCompiler, - DEPENDENCIES::Clang, - DEPENDENCIES::LibClang, - DEPENDENCIES::Rustup, + Dependencies::Cmake, + Dependencies::PkgConfig, + Dependencies::Libssl, + Dependencies::Git, + Dependencies::Gcc, + Dependencies::BuildEssential, + Dependencies::ProtobufCompiler, + Dependencies::Clang, + Dependencies::LibClang, + Dependencies::Rustup, ))? } cmd( @@ -212,15 +211,15 @@ async fn install_debian(skip_confirm: bool) -> anyhow::Result<()> { vec![ "install", "-y", - &DEPENDENCIES::Cmake.to_string(), - &DEPENDENCIES::PkgConfig.to_string(), - &DEPENDENCIES::Libssl.to_string(), - &DEPENDENCIES::Git.to_string(), - &DEPENDENCIES::Gcc.to_string(), - &DEPENDENCIES::BuildEssential.to_string(), - &DEPENDENCIES::ProtobufCompiler.to_string(), - &DEPENDENCIES::Clang.to_string(), - &DEPENDENCIES::LibClang.to_string(), + &Dependencies::Cmake.to_string(), + &Dependencies::PkgConfig.to_string(), + &Dependencies::Libssl.to_string(), + &Dependencies::Git.to_string(), + &Dependencies::Gcc.to_string(), + &Dependencies::BuildEssential.to_string(), + &Dependencies::ProtobufCompiler.to_string(), + &Dependencies::Clang.to_string(), + &Dependencies::LibClang.to_string(), ], ) .run()?; @@ -233,14 +232,14 @@ async fn install_redhat(skip_confirm: bool) -> anyhow::Result<()> { if !skip_confirm { prompt_for_confirmation(&format!( "{}, {}, {}, {}, {}, {}, {} and {}", - DEPENDENCIES::Cmake, - DEPENDENCIES::OpenSslDevel, - DEPENDENCIES::Git, - DEPENDENCIES::Protobuf, - DEPENDENCIES::ProtobufCompiler, - DEPENDENCIES::Clang, - DEPENDENCIES::ClangDevel, - DEPENDENCIES::Rustup, + Dependencies::Cmake, + Dependencies::OpenSslDevel, + Dependencies::Git, + Dependencies::Protobuf, + Dependencies::ProtobufCompiler, + Dependencies::Clang, + Dependencies::ClangDevel, + Dependencies::Rustup, ))? } cmd("yum", vec!["update", "-y"]).run()?; @@ -250,13 +249,13 @@ async fn install_redhat(skip_confirm: bool) -> anyhow::Result<()> { vec![ "install", "-y", - &DEPENDENCIES::Cmake.to_string(), - &DEPENDENCIES::OpenSslDevel.to_string(), - &DEPENDENCIES::Git.to_string(), - &DEPENDENCIES::Protobuf.to_string(), - &DEPENDENCIES::ProtobufCompiler.to_string(), - &DEPENDENCIES::Clang.to_string(), - &DEPENDENCIES::ClangDevel.to_string(), + &Dependencies::Cmake.to_string(), + &Dependencies::OpenSslDevel.to_string(), + &Dependencies::Git.to_string(), + &Dependencies::Protobuf.to_string(), + &Dependencies::ProtobufCompiler.to_string(), + &Dependencies::Clang.to_string(), + &Dependencies::ClangDevel.to_string(), ], ) .run()?; From 47102f917a0266736b40cae185d7bdb98f42e8e2 Mon Sep 17 00:00:00 2001 From: AlexD10S Date: Fri, 10 May 2024 01:25:51 +0200 Subject: [PATCH 23/29] chore: change in ci --- .github/workflows/install.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/install.yml b/.github/workflows/install.yml index d7694bc8..4174f1ce 100644 --- a/.github/workflows/install.yml +++ b/.github/workflows/install.yml @@ -4,7 +4,7 @@ on: push: branches: [ "alexd10s/pop-install" ] pull_request: - branches: [ "alexd10s/pop-install" ] + branches: [ "main" ] defaults: run: From 491e765c41051b31bb58e8a662bf4aeb14891d23 Mon Sep 17 00:00:00 2001 From: AlexD10S Date: Fri, 10 May 2024 09:50:56 +0200 Subject: [PATCH 24/29] fix: ci arch distribution --- crates/pop-cli/src/commands/install/mod.rs | 5 ----- 1 file changed, 5 deletions(-) diff --git a/crates/pop-cli/src/commands/install/mod.rs b/crates/pop-cli/src/commands/install/mod.rs index 89bd953b..96448ec6 100644 --- a/crates/pop-cli/src/commands/install/mod.rs +++ b/crates/pop-cli/src/commands/install/mod.rs @@ -138,8 +138,6 @@ async fn install_arch(skip_confirm: bool) -> anyhow::Result<()> { } cmd("pacman", vec!["-Syu", "--needed", "--noconfirm", &Dependencies::Openssl.to_string()]) .run()?; - cmd("export", vec!["OPENSSL_LIB_DIR='/usr/lib/openssl-1.0'"]).run()?; - cmd("export", vec!["OPENSSL_INCLUDE_DIR='/usr/include/openssl-1.0'"]).run()?; cmd( "pacman", vec![ @@ -153,12 +151,9 @@ async fn install_arch(skip_confirm: bool) -> anyhow::Result<()> { ], ) .run()?; - cmd("export", vec!["OPENSSL_LIB_DIR='/usr/lib/openssl-1.0'"]).run()?; - cmd("export", vec!["OPENSSL_INCLUDE_DIR='/usr/include/openssl-1.0'"]).run()?; Ok(()) } - async fn install_ubuntu(skip_confirm: bool) -> anyhow::Result<()> { log::info("More information about the packages to be installed here: https://docs.substrate.io/install/linux/")?; if !skip_confirm { From d1093224b48c3191a8e6bead5e86e3954da75d1d Mon Sep 17 00:00:00 2001 From: AlexD10S Date: Fri, 10 May 2024 09:53:47 +0200 Subject: [PATCH 25/29] chore: change ci to only triggers in main --- .github/workflows/install.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/install.yml b/.github/workflows/install.yml index 4174f1ce..d747e2bd 100644 --- a/.github/workflows/install.yml +++ b/.github/workflows/install.yml @@ -2,7 +2,7 @@ name: pop install on: push: - branches: [ "alexd10s/pop-install" ] + branches: [ "main" ] pull_request: branches: [ "main" ] From f16ad638fd018be2bf9f860227b3e5b76047747e Mon Sep 17 00:00:00 2001 From: AlexD10S Date: Fri, 10 May 2024 10:09:18 +0200 Subject: [PATCH 26/29] fix: command help message --- crates/pop-cli/src/main.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/pop-cli/src/main.rs b/crates/pop-cli/src/main.rs index caaa08c2..032d004b 100644 --- a/crates/pop-cli/src/main.rs +++ b/crates/pop-cli/src/main.rs @@ -44,7 +44,7 @@ enum Commands { #[clap(alias = "t")] #[cfg(feature = "contract")] Test(commands::test::TestArgs), - /// Set up the environment for development + /// Set up the environment for development by installing required packages #[clap(alias = "i")] Install(commands::install::InstallArgs), } From 26f9aa54428c34666d5cb0abf03eaf6578b0ae16 Mon Sep 17 00:00:00 2001 From: AlexD10S Date: Fri, 10 May 2024 15:41:19 +0200 Subject: [PATCH 27/29] refactor: remove unnecesary prefix and merge commands --- crates/pop-cli/src/commands/install/mod.rs | 111 ++++++++------------- 1 file changed, 43 insertions(+), 68 deletions(-) diff --git a/crates/pop-cli/src/commands/install/mod.rs b/crates/pop-cli/src/commands/install/mod.rs index 96448ec6..998fc2fa 100644 --- a/crates/pop-cli/src/commands/install/mod.rs +++ b/crates/pop-cli/src/commands/install/mod.rs @@ -7,6 +7,7 @@ use duct::cmd; use os_info::Type; use strum::Display; use tokio::{fs, process::Command}; +use Dependencies::*; #[derive(Display)] pub enum Dependencies { @@ -45,7 +46,7 @@ pub enum Dependencies { #[strum(serialize = "rustup")] Rustup, } - +const MACOS_PACKAGES: [Dependencies; 5] = [Homebrew, Protobuf, Openssl, Rustup, Cmake]; #[derive(Args)] #[command(args_conflicts_with_subcommands = true)] /// Setup user environment for development @@ -109,16 +110,8 @@ async fn install_mac(skip_confirm: bool) -> anyhow::Result<()> { } install_homebrew().await?; cmd("brew", vec!["update"]).run()?; - cmd( - "brew", - vec![ - "install", - &Dependencies::Protobuf.to_string(), - &Dependencies::Openssl.to_string(), - &Dependencies::Cmake.to_string(), - ], - ) - .run()?; + cmd("brew", vec!["install", &Protobuf.to_string(), &Openssl.to_string(), &Cmake.to_string()]) + .run()?; Ok(()) } @@ -128,26 +121,20 @@ async fn install_arch(skip_confirm: bool) -> anyhow::Result<()> { if !skip_confirm { prompt_for_confirmation(&format!( "{}, {}, {}, {}, {} and {}", - Dependencies::Curl, - Dependencies::Git, - Dependencies::Clang, - Dependencies::Make, - Dependencies::Openssl, - Dependencies::Rustup, + Curl, Git, Clang, Make, Openssl, Rustup, ))? } - cmd("pacman", vec!["-Syu", "--needed", "--noconfirm", &Dependencies::Openssl.to_string()]) - .run()?; cmd( "pacman", vec![ "-Syu", "--needed", "--noconfirm", - &Dependencies::Curl.to_string(), - &Dependencies::Git.to_string(), - &Dependencies::Clang.to_string(), - &Dependencies::Make.to_string(), + &Curl.to_string(), + &Git.to_string(), + &Clang.to_string(), + &Make.to_string(), + &Openssl.to_string(), ], ) .run()?; @@ -159,12 +146,7 @@ async fn install_ubuntu(skip_confirm: bool) -> anyhow::Result<()> { if !skip_confirm { prompt_for_confirmation(&format!( "{}, {}, {}, {}, {} and {}", - Dependencies::Git, - Dependencies::Clang, - Dependencies::Curl, - Dependencies::Libssl, - Dependencies::ProtobufCompiler, - Dependencies::Rustup, + Git, Clang, Curl, Libssl, ProtobufCompiler, Rustup, ))? } cmd( @@ -172,11 +154,11 @@ async fn install_ubuntu(skip_confirm: bool) -> anyhow::Result<()> { vec![ "install", "--assume-yes", - &Dependencies::Git.to_string(), - &Dependencies::Clang.to_string(), - &Dependencies::Curl.to_string(), - &Dependencies::Libssl.to_string(), - &Dependencies::ProtobufCompiler.to_string(), + &Git.to_string(), + &Clang.to_string(), + &Curl.to_string(), + &Libssl.to_string(), + &ProtobufCompiler.to_string(), ], ) .run()?; @@ -189,16 +171,16 @@ async fn install_debian(skip_confirm: bool) -> anyhow::Result<()> { if !skip_confirm { prompt_for_confirmation(&format!( "{}, {}, {}, {}, {}, {}, {}, {}, {} and {}", - Dependencies::Cmake, - Dependencies::PkgConfig, - Dependencies::Libssl, - Dependencies::Git, - Dependencies::Gcc, - Dependencies::BuildEssential, - Dependencies::ProtobufCompiler, - Dependencies::Clang, - Dependencies::LibClang, - Dependencies::Rustup, + Cmake, + PkgConfig, + Libssl, + Git, + Gcc, + BuildEssential, + ProtobufCompiler, + Clang, + LibClang, + Rustup, ))? } cmd( @@ -206,15 +188,15 @@ async fn install_debian(skip_confirm: bool) -> anyhow::Result<()> { vec![ "install", "-y", - &Dependencies::Cmake.to_string(), - &Dependencies::PkgConfig.to_string(), - &Dependencies::Libssl.to_string(), - &Dependencies::Git.to_string(), - &Dependencies::Gcc.to_string(), - &Dependencies::BuildEssential.to_string(), - &Dependencies::ProtobufCompiler.to_string(), - &Dependencies::Clang.to_string(), - &Dependencies::LibClang.to_string(), + &Cmake.to_string(), + &PkgConfig.to_string(), + &Libssl.to_string(), + &Git.to_string(), + &Gcc.to_string(), + &BuildEssential.to_string(), + &ProtobufCompiler.to_string(), + &Clang.to_string(), + &LibClang.to_string(), ], ) .run()?; @@ -227,14 +209,7 @@ async fn install_redhat(skip_confirm: bool) -> anyhow::Result<()> { if !skip_confirm { prompt_for_confirmation(&format!( "{}, {}, {}, {}, {}, {}, {} and {}", - Dependencies::Cmake, - Dependencies::OpenSslDevel, - Dependencies::Git, - Dependencies::Protobuf, - Dependencies::ProtobufCompiler, - Dependencies::Clang, - Dependencies::ClangDevel, - Dependencies::Rustup, + Cmake, OpenSslDevel, Git, Protobuf, ProtobufCompiler, Clang, ClangDevel, Rustup, ))? } cmd("yum", vec!["update", "-y"]).run()?; @@ -244,13 +219,13 @@ async fn install_redhat(skip_confirm: bool) -> anyhow::Result<()> { vec![ "install", "-y", - &Dependencies::Cmake.to_string(), - &Dependencies::OpenSslDevel.to_string(), - &Dependencies::Git.to_string(), - &Dependencies::Protobuf.to_string(), - &Dependencies::ProtobufCompiler.to_string(), - &Dependencies::Clang.to_string(), - &Dependencies::ClangDevel.to_string(), + &Cmake.to_string(), + &OpenSslDevel.to_string(), + &Git.to_string(), + &Protobuf.to_string(), + &ProtobufCompiler.to_string(), + &Clang.to_string(), + &ClangDevel.to_string(), ], ) .run()?; From b1b7f6dafe027270189254c8878c828080e57a33 Mon Sep 17 00:00:00 2001 From: AlexD10S Date: Fri, 10 May 2024 16:32:07 +0200 Subject: [PATCH 28/29] refactor: remove unnecesary code --- crates/pop-cli/src/commands/install/mod.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/crates/pop-cli/src/commands/install/mod.rs b/crates/pop-cli/src/commands/install/mod.rs index 998fc2fa..d9c88cc4 100644 --- a/crates/pop-cli/src/commands/install/mod.rs +++ b/crates/pop-cli/src/commands/install/mod.rs @@ -46,7 +46,6 @@ pub enum Dependencies { #[strum(serialize = "rustup")] Rustup, } -const MACOS_PACKAGES: [Dependencies; 5] = [Homebrew, Protobuf, Openssl, Rustup, Cmake]; #[derive(Args)] #[command(args_conflicts_with_subcommands = true)] /// Setup user environment for development From a3b625915d2cfd13dcc208790c3c49fce81d02fa Mon Sep 17 00:00:00 2001 From: AlexD10S Date: Fri, 10 May 2024 16:58:24 +0200 Subject: [PATCH 29/29] chore: fix formatting --- crates/pop-cli/src/commands/install/mod.rs | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/crates/pop-cli/src/commands/install/mod.rs b/crates/pop-cli/src/commands/install/mod.rs index d9c88cc4..66af7b08 100644 --- a/crates/pop-cli/src/commands/install/mod.rs +++ b/crates/pop-cli/src/commands/install/mod.rs @@ -263,14 +263,7 @@ async fn install_rustup() -> anyhow::Result<()> { spinner.start("Installing rustup ..."); run_external_script("https://sh.rustup.rs").await?; outro("rustup installed!")?; - cmd( - "source", - vec![ - "~/.cargo/env -", - ], - ) - .run()?; + cmd("source", vec!["~/.cargo/env"]).run()?; cmd("rustup", vec!["default", "stable"]).run()?; }, }