From baa7aab1d7eb614863ad6652317c702c855dc025 Mon Sep 17 00:00:00 2001 From: valeros Date: Tue, 7 Apr 2020 11:35:17 +0300 Subject: [PATCH] Specify C++ as the language for .ino files when preprocessing them for PVS-Studio // Resolve #3450 --- platformio/commands/check/tools/pvsstudio.py | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/platformio/commands/check/tools/pvsstudio.py b/platformio/commands/check/tools/pvsstudio.py index 7407da63..8c49fdb1 100644 --- a/platformio/commands/check/tools/pvsstudio.py +++ b/platformio/commands/check/tools/pvsstudio.py @@ -140,9 +140,7 @@ class PvsStudioCheckTool(CheckToolBase): # pylint: disable=too-many-instance-at os.remove(self._tmp_output_file) if not os.path.isfile(self._tmp_preprocessed_file): - click.echo( - "Error: Missing preprocessed file '%s'" % (self._tmp_preprocessed_file) - ) + click.echo("Error: Missing preprocessed file for '%s'" % src_file) return "" cmd = [ @@ -175,6 +173,9 @@ class PvsStudioCheckTool(CheckToolBase): # pylint: disable=too-many-instance-at return os.path.join(self._tmp_dir, next(tempfile._get_candidate_names())) def _prepare_preprocessed_file(self, src_file): + if os.path.isfile(self._tmp_preprocessed_file): + os.remove(self._tmp_preprocessed_file) + flags = self.cxx_flags compiler = self.cxx_path if src_file.endswith(".c"): @@ -186,8 +187,12 @@ class PvsStudioCheckTool(CheckToolBase): # pylint: disable=too-many-instance-at cmd.extend(["-D%s" % d for d in self.cpp_defines]) cmd.append('@"%s"' % self._tmp_cmd_file) + # Explicitly specify C++ as the language used in .ino files + if src_file.endswith(".ino"): + cmd.insert(1, "-xc++") + result = proc.exec_command(" ".join(cmd), shell=True) - if result["returncode"] != 0: + if result["returncode"] != 0 or result["err"]: if self.options.get("verbose"): click.echo(" ".join(cmd)) click.echo(result["err"])