Skip to content

Commit

Permalink
Switch Cppcheck to analyze project per file // Issue #3797
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
valeros committed Mar 11, 2021
1 parent 7f1f760 commit 44b85f6
Showing 1 changed file with 17 additions and 16 deletions.
33 changes: 17 additions & 16 deletions platformio/commands/check/tools/cppcheck.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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()

Expand Down

0 comments on commit 44b85f6

Please sign in to comment.