Skip to content

Commit

Permalink
fixes after review
Browse files Browse the repository at this point in the history
  • Loading branch information
popenta committed Sep 28, 2023
1 parent 851bd30 commit d2af8f5
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 52 deletions.
1 change: 1 addition & 0 deletions multiversx_sdk_cli/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ def get_defaults() -> Dict[str, Any]:
"dependencies.golang.urlTemplate.osx": "https://golang.org/dl/{TAG}.darwin-amd64.tar.gz",
"dependencies.golang.urlTemplate.windows": "https://golang.org/dl/{TAG}.windows-amd64.zip",
"dependencies.twiggy.tag": "latest",
"dependencies.sc-meta.tag": "latest",
"dependencies.testwallets.tag": "latest",
"dependencies.testwallets.urlTemplate.linux": "https://github.com/multiversx/mx-sdk-testwallets/archive/{TAG}.tar.gz",
"dependencies.testwallets.urlTemplate.osx": "https://github.com/multiversx/mx-sdk-testwallets/archive/{TAG}.tar.gz",
Expand Down
25 changes: 11 additions & 14 deletions multiversx_sdk_cli/dependencies/modules.py
Original file line number Diff line number Diff line change
Expand Up @@ -276,15 +276,15 @@ def install(self, overwrite: bool) -> None:

if overwrite:
logger.info("Overwriting the current rust version...")
elif self._is_installed_and_set_to_nightly():
elif self.is_installed(""):
return

self._do_install(tag)
self._install_rust(tag)
self._install_sc_meta()
self._install_wasm_opt()
self._install_twiggy()

def _do_install(self, tag: str) -> None:
def _install_rust(self, tag: str) -> None:
installer_url = self._get_installer_url()
installer_path = self._get_installer_path()

Expand All @@ -304,7 +304,12 @@ def _do_install(self, tag: str) -> None:

def _install_sc_meta(self):
logger.info("Installing multiversx-sc-meta.")
tag = config.get_dependency_tag("sc-meta")
args = ["cargo", "install", "multiversx-sc-meta"]

if tag != "latest":
args.extend(["--version", tag])

myprocess.run_process(args)

def _install_wasm_opt(self):
Expand All @@ -315,11 +320,11 @@ def _install_wasm_opt(self):

def _install_twiggy(self):
logger.info("Installing twiggy.")
default_tag = config.get_dependency_tag("twiggy")
tag = config.get_dependency_tag("twiggy")
args = ["cargo", "install", "twiggy"]

if default_tag != "latest":
args.extend(["--version", default_tag])
if tag != "latest":
args.extend(["--version", tag])

myprocess.run_process(args)

Expand All @@ -340,14 +345,6 @@ def uninstall(self, tag: str):
if os.path.isdir(directory):
shutil.rmtree(directory)

def _is_installed_and_set_to_nightly(self) -> bool:
# the method parameter is not used in this specific module
is_rust_installed = self.is_installed("")

if not is_rust_installed:
return False
return True

def get_directory(self, tag: str) -> Path:
tools_folder = workstation.get_tools_folder()
return tools_folder / "vendor-rust"
Expand Down
7 changes: 2 additions & 5 deletions multiversx_sdk_cli/projects/project_clang.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
import logging
import subprocess
import sys
from os import path
from pathlib import Path
from typing import List

from multiversx_sdk_cli import dependencies, errors, myprocess, utils
from multiversx_sdk_cli.projects.project_base import Project, rename_wasm_files
from multiversx_sdk_cli.projects.shared import \
are_clang_and_cpp_dependencies_installed
check_clang_and_cpp_dependencies_installed

logger = logging.getLogger('ProjectClang')

Expand All @@ -29,9 +28,7 @@ def perform_build(self):
self.file_output = self.unit.with_suffix('.wasm')

try:
is_installed = are_clang_and_cpp_dependencies_installed()
if not is_installed:
sys.exit(1)
check_clang_and_cpp_dependencies_installed()

self.do_clang()
self.do_llvm_link()
Expand Down
7 changes: 2 additions & 5 deletions multiversx_sdk_cli/projects/project_cpp.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
import logging
import os
import subprocess
import sys
from os import path
from pathlib import Path
from typing import List

from multiversx_sdk_cli import dependencies, errors, myprocess, utils
from multiversx_sdk_cli.projects.project_base import Project, rename_wasm_files
from multiversx_sdk_cli.projects.shared import \
are_clang_and_cpp_dependencies_installed
check_clang_and_cpp_dependencies_installed

logger = logging.getLogger("ProjectCpp")

Expand All @@ -26,9 +25,7 @@ def perform_build(self):
self.file_export = self.unit.with_suffix(".export")

try:
is_installed = are_clang_and_cpp_dependencies_installed()
if not is_installed:
sys.exit(1)
check_clang_and_cpp_dependencies_installed()

self._do_clang()
self._do_llc()
Expand Down
12 changes: 3 additions & 9 deletions multiversx_sdk_cli/projects/project_rust.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import logging
import shutil
import subprocess
from pathlib import Path
from typing import Any, Dict, List, Set, cast

from multiversx_sdk_cli import dependencies, errors, utils, workstation
from multiversx_sdk_cli.constants import DEFAULT_CARGO_TARGET_DIR_NAME
from multiversx_sdk_cli.dependencies.modules import Rust
from multiversx_sdk_cli.projects.project_base import Project

logger = logging.getLogger("ProjectRust")
Expand Down Expand Up @@ -54,14 +54,7 @@ def prepare_build_wasm_args(self, args: List[str]):
self.get_output_folder()
])

def check_if_sc_meta_is_installed(self):
which_sc_meta = shutil.which("sc-meta")

if which_sc_meta is None:
raise errors.KnownError("'sc-meta' is not installed. Install it manually or simply run `mxpy deps install rust --overwrite` then try again.")

def run_meta(self):
self.check_if_sc_meta_is_installed()
env = self.get_env()

args = [
Expand Down Expand Up @@ -125,7 +118,8 @@ def get_env(self):
return dependencies.get_module_by_key("rust").get_env()

def build_wasm_with_debug_symbols(self, build_options: Dict[str, Any]):
self.check_if_sc_meta_is_installed()
rust_module = Rust("rust")
rust_module.install(overwrite=False)

cwd = self.path
env = self.get_env()
Expand Down
12 changes: 6 additions & 6 deletions multiversx_sdk_cli/projects/shared.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import shutil
from pathlib import Path

from multiversx_sdk_cli.errors import KnownError
from multiversx_sdk_cli.ux import show_critical_error

logger = logging.getLogger("projects.shared")
Expand Down Expand Up @@ -30,7 +31,7 @@ def _directory_contains_file(directory: Path, name_suffix: str) -> bool:
return False


def are_clang_and_cpp_dependencies_installed() -> bool:
def check_clang_and_cpp_dependencies_installed() -> None:
which_clang = shutil.which("clang")
which_llc = shutil.which("llc")
which_wasm_ld = shutil.which("wasm-ld")
Expand All @@ -43,14 +44,13 @@ def are_clang_and_cpp_dependencies_installed() -> bool:

dependencies = [which_clang, which_llc, which_wasm_ld, which_llvm_link]
is_installed = all(dependency is not None for dependency in dependencies)
if is_installed:
return True

message = """
if is_installed is False:
message = """
`clang` is not installed. Please install it manually, then try again.
How to install on Ubuntu: https://linux.how2shout.com/how-to-install-clang-on-ubuntu-linux/
How to install on MacOS: https://www.incredibuild.com/integrations/clang
For more details check out this page: https://clang.llvm.org/get_started.html"""

show_critical_error(message)
return False
show_critical_error(message)
raise KnownError("The required dependencies are not installed. Please check the above message.")
21 changes: 8 additions & 13 deletions multiversx_sdk_cli/tests/test_cli_deps.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,41 +8,36 @@

def test_deps_install_rust():
return_code = main(["deps", "install", "rust", "--overwrite"])
assert True if return_code == 0 else False
assert return_code == 0


def test_deps_check_rust():
return_code = main(["deps", "check", "rust"])
assert True if return_code == 0 else False

which_rustc = shutil.which("rustc")
if which_rustc:
assert Path.is_file(Path(which_rustc))
assert which_rustc and Path.is_file(Path(which_rustc))

which_cargo = shutil.which("cargo")
if which_cargo:
assert Path.is_file(Path(which_cargo))
assert which_cargo and Path.is_file(Path(which_cargo))

which_sc_meta = shutil.which("sc-meta")
if which_sc_meta:
assert Path.is_file(Path(which_sc_meta))
assert which_sc_meta and Path.is_file(Path(which_sc_meta))

which_wasm_opt = shutil.which("wasm-opt")
if which_wasm_opt:
assert Path.is_file(Path(which_wasm_opt))
assert which_wasm_opt and Path.is_file(Path(which_wasm_opt))

which_twiggy = shutil.which("twiggy")
if which_twiggy:
assert Path.is_file(Path(which_twiggy))
assert which_twiggy and Path.is_file(Path(which_twiggy))


@pytest.mark.skip_on_windows
def test_deps_install_vmtools():
return_code = main(["deps", "install", "vmtools"])
assert True if return_code == 0 else False
assert return_code == 0


@pytest.mark.skip_on_windows
def test_deps_check_vmtools():
return_code = main(["deps", "check", "vmtools"])
assert True if return_code == 0 else False
assert return_code == 0

0 comments on commit d2af8f5

Please sign in to comment.