Skip to content

Commit

Permalink
Updates for PIO Check (#3640)
Browse files Browse the repository at this point in the history
* Update check tools to the latest versions

* Use language standard when exporting defines to check tools

* Buffer Cppcheck output to detect multiline messages

* Add new test for PIO Check

* Pass include paths to Clang-Tidy as individual compiler arguments

Clang-tidy doesn't support response files which can exceed command
length limitations on Windows

* Simplify tests for PIO Check

* Update history

* Sync changelog
  • Loading branch information
valeros authored Aug 25, 2020
1 parent b9fe493 commit 3e72f09
Show file tree
Hide file tree
Showing 6 changed files with 101 additions and 50 deletions.
1 change: 1 addition & 0 deletions HISTORY.rst
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ PlatformIO Core 4
* Added `PlatformIO CLI Shell Completion <https://docs.platformio.org/page/core/userguide/system/completion/index.html>`__ for Fish, Zsh, Bash, and PowerShell (`issue #3435 <https://github.com/platformio/platformio-core/issues/3435>`_)
* Automatically build ``contrib-pysite`` package on a target machine when pre-built package is not compatible (`issue #3482 <https://github.com/platformio/platformio-core/issues/3482>`_)
* Fixed an issue on Windows when installing a library dependency from Git repository (`issue #2844 <https://github.com/platformio/platformio-core/issues/2844>`_, `issue #3328 <https://github.com/platformio/platformio-core/issues/3328>`_)
* Fixed an issue with PIO Check when a defect with multiline error message is not reported in verbose mode (`issue #3631 <https://github.com/platformio/platformio-core/issues/3631>`_)

4.3.3 (2020-04-28)
~~~~~~~~~~~~~~~~~~
Expand Down
4 changes: 2 additions & 2 deletions platformio/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,9 @@
"contrib-pysite": "~2.%d%d.0" % (sys.version_info.major, sys.version_info.minor),
"tool-unity": "~1.20500.0",
"tool-scons": "~2.20501.7" if sys.version_info.major == 2 else "~4.40001.0",
"tool-cppcheck": "~1.190.0",
"tool-cppcheck": "~1.210.0",
"tool-clangtidy": "~1.100000.0",
"tool-pvs-studio": "~7.7.0",
"tool-pvs-studio": "~7.8.0",
}

__check_internet_hosts__ = [
Expand Down
4 changes: 3 additions & 1 deletion platformio/commands/check/tools/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,9 @@ def _extract_defines(language, includes_file):
cmd = "echo | %s -x %s %s %s -dM -E -" % (
self.cc_path,
language,
" ".join([f for f in build_flags if f.startswith(("-m", "-f"))]),
" ".join(
[f for f in build_flags if f.startswith(("-m", "-f", "-std"))]
),
includes_file,
)
result = proc.exec_command(cmd, shell=True)
Expand Down
7 changes: 2 additions & 5 deletions platformio/commands/check/tools/clangtidy.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,7 @@ def configure_command(self):
for scope in project_files:
src_files.extend(project_files[scope])

cmd.extend(flags)
cmd.extend(src_files)
cmd.append("--")

cmd.extend(flags + src_files + ["--"])
cmd.extend(
["-D%s" % d for d in self.cpp_defines + self.toolchain_defines["c++"]]
)
Expand All @@ -79,6 +76,6 @@ def configure_command(self):
continue
includes.append(inc)

cmd.append("--extra-arg=" + self._long_includes_hook(includes))
cmd.extend(["-I%s" % inc for inc in includes])

return cmd
18 changes: 13 additions & 5 deletions platformio/commands/check/tools/cppcheck.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@

class CppcheckCheckTool(CheckToolBase):
def __init__(self, *args, **kwargs):
self._field_delimiter = "<&PIO&>"
self._buffer = ""
self.defect_fields = [
"severity",
"message",
Expand Down Expand Up @@ -55,13 +57,15 @@ def tool_output_filter(self, line):
return line

def parse_defect(self, raw_line):
if "<&PIO&>" not in raw_line or any(
f not in raw_line for f in self.defect_fields
):
if self._field_delimiter not in raw_line:
return None

self._buffer += raw_line
if any(f not in self._buffer for f in self.defect_fields):
return None

args = dict()
for field in raw_line.split("<&PIO&>"):
for field in self._buffer.split(self._field_delimiter):
field = field.strip().replace('"', "")
name, value = field.split("=", 1)
args[name] = value
Expand Down Expand Up @@ -94,6 +98,7 @@ def parse_defect(self, raw_line):
self._bad_input = True
return None

self._buffer = ""
return DefectItem(**args)

def configure_command(
Expand All @@ -103,13 +108,16 @@ def configure_command(

cmd = [
tool_path,
"--addon-python=%s" % proc.get_pythonexe_path(),
"--error-exitcode=1",
"--verbose" if self.options.get("verbose") else "--quiet",
]

cmd.append(
'--template="%s"'
% "<&PIO&>".join(["{0}={{{0}}}".format(f) for f in self.defect_fields])
% self._field_delimiter.join(
["{0}={{{0}}}".format(f) for f in self.defect_fields]
)
)

flags = self.get_flags("cppcheck")
Expand Down
Loading

0 comments on commit 3e72f09

Please sign in to comment.