From 340e5e1a0716d910d0c40f7750cb1cc294819c5a Mon Sep 17 00:00:00 2001 From: Alexandru Popenta Date: Wed, 27 Sep 2023 18:44:38 +0300 Subject: [PATCH] remove clang installation --- multiversx_sdk_cli/cli_deps.py | 4 +-- multiversx_sdk_cli/config.py | 4 --- multiversx_sdk_cli/dependencies/install.py | 23 +++----------- multiversx_sdk_cli/dependencies/modules.py | 24 ++++++--------- multiversx_sdk_cli/projects/project_base.py | 2 ++ multiversx_sdk_cli/projects/project_clang.py | 9 +++++- multiversx_sdk_cli/projects/project_cpp.py | 13 ++++++-- multiversx_sdk_cli/projects/project_rust.py | 2 +- multiversx_sdk_cli/projects/shared.py | 32 ++++++++++++++++++++ 9 files changed, 67 insertions(+), 46 deletions(-) diff --git a/multiversx_sdk_cli/cli_deps.py b/multiversx_sdk_cli/cli_deps.py index 1f0d9188..471e0610 100644 --- a/multiversx_sdk_cli/cli_deps.py +++ b/multiversx_sdk_cli/cli_deps.py @@ -16,7 +16,6 @@ def setup_parser(subparsers: Any) -> Any: sub = cli_shared.add_command_subparser(subparsers, "deps", "install", "Install dependencies or multiversx-sdk modules.") sub.add_argument("name", choices=choices, help="the dependency to install") sub.add_argument("--overwrite", action="store_true", default=False, help="whether to overwrite an existing installation") - sub.add_argument("--tag", help="the tag or version to install") sub.set_defaults(func=install) sub = cli_shared.add_command_subparser(subparsers, "deps", "check", "Check whether a dependency is installed.") @@ -30,9 +29,8 @@ def setup_parser(subparsers: Any) -> Any: def install(args: Any): name: str = args.name - tag: str = args.tag overwrite: bool = args.overwrite - dependencies.install_module(name, tag, overwrite) + dependencies.install_module(name, overwrite) def check(args: Any): diff --git a/multiversx_sdk_cli/config.py b/multiversx_sdk_cli/config.py index 71a90f56..31972ffb 100644 --- a/multiversx_sdk_cli/config.py +++ b/multiversx_sdk_cli/config.py @@ -150,10 +150,6 @@ def get_defaults() -> Dict[str, Any]: "dependencies.vmtools.urlTemplate.linux": "https://github.com/multiversx/mx-chain-vm-go/archive/{TAG}.tar.gz", "dependencies.vmtools.urlTemplate.osx": "https://github.com/multiversx/mx-chain-vm-go/archive/{TAG}.tar.gz", "dependencies.vmtools.urlTemplate.windows": "https://github.com/multiversx/mx-chain-vm-go/archive/{TAG}.tar.gz", - "dependencies.llvm.tag": "v9-19feb", - # ide.elrond.com will be removed, TBD if clang will still be downloaded - "dependencies.llvm.urlTemplate.linux": "https://ide.elrond.com/vendor-llvm/{TAG}/linux-amd64.tar.gz?t=19feb", - "dependencies.llvm.urlTemplate.osx": "https://ide.elrond.com/vendor-llvm/{TAG}/darwin-amd64.tar.gz?t=19feb", "dependencies.rust.tag": "nightly-2023-05-26", "dependencies.golang.resolution": "SDK", "dependencies.golang.tag": "go1.20.7", diff --git a/multiversx_sdk_cli/dependencies/install.py b/multiversx_sdk_cli/dependencies/install.py index ca5951c9..64945e4f 100644 --- a/multiversx_sdk_cli/dependencies/install.py +++ b/multiversx_sdk_cli/dependencies/install.py @@ -5,21 +5,20 @@ from multiversx_sdk_cli import config, errors from multiversx_sdk_cli.dependencies.modules import (DependencyModule, GolangModule, Rust, - StandaloneModule, TestWalletsModule, VMToolsModule) logger = logging.getLogger("install") -def install_module(key: str, tag: str = "", overwrite: bool = False): +def install_module(key: str, overwrite: bool = False): if key == 'all': - modules = _get_implicitly_installable_deps() + modules = _get_all_deps() else: modules = [get_module_by_key(key)] for module in modules: - module.install(tag, overwrite) + module.install(overwrite) def get_module_directory(key: str) -> Path: @@ -49,24 +48,10 @@ def get_deps_dict() -> Dict[str, DependencyModule]: def _get_all_deps() -> List[DependencyModule]: - return _get_explicitly_installable_deps() + _get_implicitly_installable_deps() - - -def _get_explicitly_installable_deps() -> List[DependencyModule]: return [ - StandaloneModule(key="llvm", aliases=["clang", "cpp"]), Rust(key="rust"), - GolangModule(key="golang") - ] - - -def _get_implicitly_installable_deps() -> List[DependencyModule]: - # See: https://github.com/multiversx/mx-sdk-py-cli/pull/55 - - return [ + GolangModule(key="golang"), VMToolsModule(key="vmtools"), - StandaloneModule(key="mx_chain_go", repo_name="mx-chain-go", organisation="multiversx"), - StandaloneModule(key="mx_chain_proxy_go", repo_name="mx-chain-proxy-go", organisation="multiversx"), TestWalletsModule(key="testwallets") ] diff --git a/multiversx_sdk_cli/dependencies/modules.py b/multiversx_sdk_cli/dependencies/modules.py index 6c95d5e2..d672d8bc 100644 --- a/multiversx_sdk_cli/dependencies/modules.py +++ b/multiversx_sdk_cli/dependencies/modules.py @@ -22,9 +22,9 @@ def __init__(self, key: str, aliases: List[str] = []): def get_directory(self, tag: str) -> Path: raise NotImplementedError() - def install(self, tag: str, overwrite: bool) -> None: - # Fallback to default tag if not provided - tag = tag or config.get_dependency_tag(self.key) + def install(self, overwrite: bool) -> None: + # We install the default tag + tag = config.get_dependency_tag(self.key) if tag == 'latest': tag = self.get_latest_release() @@ -267,10 +267,11 @@ def is_installed(self, tag: str) -> bool: dependencies = [which_rustc, which_cargo, which_sc_meta, which_wasm_opt, which_twiggy] return all(dependency is not None for dependency in dependencies) - def install(self, tag: str, overwrite: bool) -> None: - # Fallback to default tag if not provided - tag = tag or config.get_dependency_tag(self.key) + def install(self, overwrite: bool) -> None: + module = dependencies.get_module_by_key("rust") + tag: str = config.get_dependency_tag(module.key) + show_warning(f"We recommend using rust {tag}. If you'd like to overwrite your current version please run `mxpy deps install rust --overwrite`.") logger.info(f"install: key={self.key}, tag={tag}, overwrite={overwrite}") if overwrite: @@ -343,15 +344,8 @@ def _is_installed_and_set_to_nightly(self) -> bool: is_rust_installed = self.is_installed("") if not is_rust_installed: - return is_rust_installed - else: - self._recommend_default_rust_version() - return True - - def _recommend_default_rust_version(self): - module = dependencies.get_module_by_key("rust") - default_tag: str = config.get_dependency_tag(module.key) - show_warning(f"We recommend using rust {default_tag}. If you'd like to overwrite your current version please run `mxpy deps install rust --overwrite`.") + return False + return True def get_directory(self, tag: str) -> Path: tools_folder = workstation.get_tools_folder() diff --git a/multiversx_sdk_cli/projects/project_base.py b/multiversx_sdk_cli/projects/project_base.py index aadd5ebc..74777af1 100644 --- a/multiversx_sdk_cli/projects/project_base.py +++ b/multiversx_sdk_cli/projects/project_base.py @@ -38,6 +38,8 @@ def clean(self): def _ensure_dependencies_installed(self): module_keys = self.get_dependencies() for module_key in module_keys: + if module_key == "": + continue dependencies.install_module(module_key) def get_dependencies(self) -> List[str]: diff --git a/multiversx_sdk_cli/projects/project_clang.py b/multiversx_sdk_cli/projects/project_clang.py index 3985955c..467cafc0 100644 --- a/multiversx_sdk_cli/projects/project_clang.py +++ b/multiversx_sdk_cli/projects/project_clang.py @@ -1,11 +1,14 @@ 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 logger = logging.getLogger('ProjectClang') @@ -26,6 +29,10 @@ 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) + self.do_clang() self.do_llvm_link() self.do_llc() @@ -151,4 +158,4 @@ def get_source_files_from_folder(self): return list(map(str, self.path.rglob('*.c'))) def get_dependencies(self): - return ['llvm'] + return [""] diff --git a/multiversx_sdk_cli/projects/project_cpp.py b/multiversx_sdk_cli/projects/project_cpp.py index 12b62dc5..72567927 100644 --- a/multiversx_sdk_cli/projects/project_cpp.py +++ b/multiversx_sdk_cli/projects/project_cpp.py @@ -1,12 +1,15 @@ import logging import os -from pathlib import Path 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 logger = logging.getLogger("ProjectCpp") @@ -23,6 +26,10 @@ 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) + self._do_clang() self._do_llc() self._do_wasm() @@ -87,7 +94,7 @@ def _do_after_build_custom(self) -> List[Path]: os.remove(source_file.with_suffix(".wasm")) os.remove(source_file.with_suffix(".ll")) os.remove(source_file.with_suffix(".o")) - + paths = rename_wasm_files([output_wasm_file], self.options.get("wasm-name")) return paths @@ -95,7 +102,7 @@ def _get_llvm_path(self): return dependencies.get_module_directory("llvm") def get_dependencies(self): - return ["llvm"] + return [""] class CppBuildConfiguration: diff --git a/multiversx_sdk_cli/projects/project_rust.py b/multiversx_sdk_cli/projects/project_rust.py index 2bd7fdc3..879ccb8e 100644 --- a/multiversx_sdk_cli/projects/project_rust.py +++ b/multiversx_sdk_cli/projects/project_rust.py @@ -58,7 +58,7 @@ 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. Run 'cargo install multiversx-sc-meta' then try again.") + 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() diff --git a/multiversx_sdk_cli/projects/shared.py b/multiversx_sdk_cli/projects/shared.py index ef7f375d..51ebbd32 100644 --- a/multiversx_sdk_cli/projects/shared.py +++ b/multiversx_sdk_cli/projects/shared.py @@ -1,5 +1,11 @@ +import logging +import shutil from pathlib import Path +from multiversx_sdk_cli.ux import show_critical_error + +logger = logging.getLogger("projects.shared") + def is_source_clang(directory: Path) -> bool: return _directory_contains_file(directory, ".c") @@ -22,3 +28,29 @@ def _directory_contains_file(directory: Path, name_suffix: str) -> bool: if str(file).lower().endswith(name_suffix.lower()): return True return False + + +def are_clang_and_cpp_dependencies_installed() -> bool: + which_clang = shutil.which("clang") + which_llc = shutil.which("llc") + which_wasm_ld = shutil.which("wasm-ld") + which_llvm_link = shutil.which("llvm-link") + + logger.info(f"which_clang: {which_clang}") + logger.info(f"which_llc: {which_llc}") + logger.info(f"which_wasm_ld: {which_wasm_ld}") + logger.info(f"which_llvm_link: {which_llvm_link}") + + 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 = """ +`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