From d86f7fc25e61e68b5656b2f3ca7c8e4f938301a3 Mon Sep 17 00:00:00 2001 From: Ivan Kravets Date: Fri, 1 Apr 2022 22:05:30 +0300 Subject: [PATCH] Added ability to override a tool version using the "platform_packages" option // Resolve #3798 --- HISTORY.rst | 8 +++++++- docs | 2 +- platformio/commands/check/command.py | 7 +++++-- platformio/commands/check/tools/base.py | 9 +++++++++ platformio/commands/check/tools/clangtidy.py | 3 +-- platformio/commands/check/tools/cppcheck.py | 5 ++--- platformio/commands/check/tools/pvsstudio.py | 7 +++---- platformio/package/manager/core.py | 4 ++-- 8 files changed, 30 insertions(+), 15 deletions(-) diff --git a/HISTORY.rst b/HISTORY.rst index f4907a69..4b9179b7 100644 --- a/HISTORY.rst +++ b/HISTORY.rst @@ -30,7 +30,13 @@ PlatformIO Core 5 - Dropped automatic updates of global libraries and development platforms (`issue #4179 `_) - Dropped support for "pythonPackages" field in "platform.json" manifest in favor of `Extra Python Dependencies `__ -* Added support for the custom `Clang-Tidy `__ configuration file (`issue #4186 `_) +* **Static Code Analysis** + + - Added support for the custom `Clang-Tidy `__ configuration file (`issue #4186 `_) + - Added ability to override a tool version using the `platform_packages `__ option (`issue #3798 `_) + +* **Miscellaneous** + * Improved PIO Remote setup on credit-card sized computers (Raspberry Pi, BeagleBon, etc) (`issue #3865 `_) * Better handling of the failed tests using `Unit Testing `__ solution diff --git a/docs b/docs index d754678c..b953caef 160000 --- a/docs +++ b/docs @@ -1 +1 @@ -Subproject commit d754678ca2ca04e770f796c02e24079fd76df900 +Subproject commit b953caefb78f6b6a09b944c13162426aa34a18cb diff --git a/platformio/commands/check/command.py b/platformio/commands/check/command.py index 61e7ee56..e24836cc 100644 --- a/platformio/commands/check/command.py +++ b/platformio/commands/check/command.py @@ -118,6 +118,7 @@ def cli( if silent else severity or config.get("env:" + envname, "check_severity"), skip_packages=skip_packages or env_options.get("check_skip_packages"), + platform_packages=env_options.get("platform_packages"), ) for tool in config.get("env:" + envname, "check_tool"): @@ -166,7 +167,7 @@ def cli( if json_output: click.echo(json.dumps(results_to_json(results))) elif not silent: - print_check_summary(results) + print_check_summary(results, verbose=verbose) # Reset custom project config app.set_session_var("custom_project_conf", None) @@ -270,7 +271,7 @@ def print_defects_stats(results): click.echo() -def print_check_summary(results): +def print_check_summary(results, verbose=False): click.echo() tabular_data = [] @@ -287,6 +288,8 @@ def print_check_summary(results): status_str = click.style("FAILED", fg="red") elif result.get("succeeded") is None: status_str = "IGNORED" + if not verbose: + continue else: succeeded_nums += 1 status_str = click.style("PASSED", fg="green") diff --git a/platformio/commands/check/tools/base.py b/platformio/commands/check/tools/base.py index d5328d1a..36ecbe9e 100644 --- a/platformio/commands/check/tools/base.py +++ b/platformio/commands/check/tools/base.py @@ -20,6 +20,8 @@ import click from platformio import fs, proc from platformio.commands.check.defect import DefectItem +from platformio.package.manager.core import get_core_package_dir +from platformio.package.meta import PackageSpec from platformio.project.helpers import load_project_ide_data @@ -66,6 +68,13 @@ class CheckToolBase(object): # pylint: disable=too-many-instance-attributes self.cxx_path = data.get("cxx_path") self.toolchain_defines = self._get_toolchain_defines() + def get_tool_dir(self, pkg_name): + for spec in self.options["platform_packages"] or []: + spec = PackageSpec(spec) + if spec.name == pkg_name: + return get_core_package_dir(pkg_name, spec=spec) + return get_core_package_dir(pkg_name) + def get_flags(self, tool): result = [] flags = self.options.get("flags") or [] diff --git a/platformio/commands/check/tools/clangtidy.py b/platformio/commands/check/tools/clangtidy.py index e130903e..c357cf4d 100644 --- a/platformio/commands/check/tools/clangtidy.py +++ b/platformio/commands/check/tools/clangtidy.py @@ -17,7 +17,6 @@ from os.path import join from platformio.commands.check.defect import DefectItem from platformio.commands.check.tools.base import CheckToolBase -from platformio.package.manager.core import get_core_package_dir class ClangtidyCheckTool(CheckToolBase): @@ -56,7 +55,7 @@ class ClangtidyCheckTool(CheckToolBase): return cmd_result["returncode"] < 2 def configure_command(self): - tool_path = join(get_core_package_dir("tool-clangtidy"), "clang-tidy") + tool_path = join(self.get_tool_dir("tool-clangtidy"), "clang-tidy") cmd = [tool_path, "--quiet"] flags = self.get_flags("clangtidy") diff --git a/platformio/commands/check/tools/cppcheck.py b/platformio/commands/check/tools/cppcheck.py index ec50d144..81272947 100644 --- a/platformio/commands/check/tools/cppcheck.py +++ b/platformio/commands/check/tools/cppcheck.py @@ -19,11 +19,11 @@ import click from platformio import proc from platformio.commands.check.defect import DefectItem from platformio.commands.check.tools.base import CheckToolBase -from platformio.package.manager.core import get_core_package_dir class CppcheckCheckTool(CheckToolBase): def __init__(self, *args, **kwargs): + super(CppcheckCheckTool, self).__init__(*args, **kwargs) self._field_delimiter = "<&PIO&>" self._buffer = "" self.defect_fields = [ @@ -36,7 +36,6 @@ class CppcheckCheckTool(CheckToolBase): "cwe", "id", ] - super(CppcheckCheckTool, self).__init__(*args, **kwargs) def tool_output_filter(self, line): # pylint: disable=arguments-differ if ( @@ -103,7 +102,7 @@ class CppcheckCheckTool(CheckToolBase): return DefectItem(**args) def configure_command(self, language, src_file): # pylint: disable=arguments-differ - tool_path = os.path.join(get_core_package_dir("tool-cppcheck"), "cppcheck") + tool_path = os.path.join(self.get_tool_dir("tool-cppcheck"), "cppcheck") cmd = [ tool_path, diff --git a/platformio/commands/check/tools/pvsstudio.py b/platformio/commands/check/tools/pvsstudio.py index 4f5e0440..d1981817 100644 --- a/platformio/commands/check/tools/pvsstudio.py +++ b/platformio/commands/check/tools/pvsstudio.py @@ -23,22 +23,21 @@ from platformio import proc from platformio.commands.check.defect import DefectItem from platformio.commands.check.tools.base import CheckToolBase from platformio.compat import IS_WINDOWS -from platformio.package.manager.core import get_core_package_dir class PvsStudioCheckTool(CheckToolBase): # pylint: disable=too-many-instance-attributes def __init__(self, *args, **kwargs): + super(PvsStudioCheckTool, self).__init__(*args, **kwargs) self._tmp_dir = tempfile.mkdtemp(prefix="piocheck") self._tmp_preprocessed_file = self._generate_tmp_file_path() + ".i" self._tmp_output_file = self._generate_tmp_file_path() + ".pvs" self._tmp_cfg_file = self._generate_tmp_file_path() + ".cfg" self._tmp_cmd_file = self._generate_tmp_file_path() + ".cmd" self.tool_path = os.path.join( - get_core_package_dir("tool-pvs-studio"), + self.get_tool_dir("tool-pvs-studio"), "x64" if IS_WINDOWS else "bin", "pvs-studio", ) - super(PvsStudioCheckTool, self).__init__(*args, **kwargs) with open(self._tmp_cfg_file, mode="w", encoding="utf8") as fp: fp.write( @@ -70,7 +69,7 @@ class PvsStudioCheckTool(CheckToolBase): # pylint: disable=too-many-instance-at def _demangle_report(self, output_file): converter_tool = os.path.join( - get_core_package_dir("tool-pvs-studio"), + self.get_tool_dir("tool-pvs-studio"), "HtmlGenerator" if IS_WINDOWS else os.path.join("bin", "plog-converter"), ) diff --git a/platformio/package/manager/core.py b/platformio/package/manager/core.py index d9694217..d9a05cb5 100644 --- a/platformio/package/manager/core.py +++ b/platformio/package/manager/core.py @@ -38,11 +38,11 @@ def get_installed_core_packages(): return result -def get_core_package_dir(name, auto_install=True): +def get_core_package_dir(name, spec=None, auto_install=True): if name not in __core_packages__: raise exception.PlatformioException("Please upgrade PlatformIO Core") pm = ToolPackageManager() - spec = PackageSpec( + spec = spec or PackageSpec( owner="platformio", name=name, requirements=__core_packages__[name] ) pkg = pm.get_package(spec)