From 44b85f6e4bbf73d8492b5afc8616ad1096966974 Mon Sep 17 00:00:00 2001 From: valeros Date: Thu, 11 Mar 2021 13:49:27 +0200 Subject: [PATCH] Switch Cppcheck to analyze project per file // Issue #3797 Cppcheck doesn't provide a proper report when one of the files in the check list is broken. If we run the analysis on a per-file basis, then Cppcheck will be able report at least defects from valid source files. --- platformio/commands/check/tools/cppcheck.py | 33 +++++++++++---------- 1 file changed, 17 insertions(+), 16 deletions(-) diff --git a/platformio/commands/check/tools/cppcheck.py b/platformio/commands/check/tools/cppcheck.py index eb7197b295..c1fe3e3bb2 100644 --- a/platformio/commands/check/tools/cppcheck.py +++ b/platformio/commands/check/tools/cppcheck.py @@ -96,14 +96,13 @@ def parse_defect(self, raw_line): ) click.echo() self._bad_input = True + self._buffer = "" return None self._buffer = "" return DefectItem(**args) - def configure_command( - self, language, src_files - ): # pylint: disable=arguments-differ + def configure_command(self, language, src_file): # pylint: disable=arguments-differ tool_path = os.path.join(get_core_package_dir("tool-cppcheck"), "cppcheck") cmd = [ @@ -157,8 +156,8 @@ def configure_command( "--include=" + inc for inc in self.get_forced_includes(build_flags, self.cpp_includes) ) - cmd.append("--file-list=%s" % self._generate_src_file(src_files)) cmd.append("--includes-file=%s" % self._generate_inc_file()) + cmd.append('"%s"' % src_file) return cmd @@ -227,23 +226,25 @@ def is_check_successful(cmd_result): def check(self, on_defect_callback=None): self._on_defect_callback = on_defect_callback - project_files = self.get_project_target_files(self.options["patterns"]) - languages = ("c", "c++") - if not any(project_files[t] for t in languages): + project_files = self.get_project_target_files(self.options["patterns"]) + src_files_scope = ("c", "c++") + if not any(project_files[t] for t in src_files_scope): click.echo("Error: Nothing to check.") return True - for language in languages: - if not project_files[language]: - continue - cmd = self.configure_command(language, project_files[language]) - if not cmd: - self._bad_input = True + + for scope, files in project_files.items(): + if scope not in src_files_scope: continue - if self.options.get("verbose"): - click.echo(" ".join(cmd)) + for src_file in files: + cmd = self.configure_command(scope, src_file) + if not cmd: + self._bad_input = True + continue + if self.options.get("verbose"): + click.echo(" ".join(cmd)) - self.execute_check_cmd(cmd) + self.execute_check_cmd(cmd) self.clean_up()