Automatically detect source files language when invoking cppcheck

This commit is contained in:
valeros
2019-10-25 20:08:04 +03:00
parent f3b8ae4224
commit 0e7a2b3141
2 changed files with 14 additions and 0 deletions

View File

@ -13,6 +13,7 @@
# limitations under the License.
import click
import os
from platformio import fs, proc
from platformio.commands.check.defect import DefectItem
@ -126,6 +127,16 @@ class CheckToolBase(object): # pylint: disable=too-many-instance-attributes
get_project_dir(), self.options.get("filter"), file_extensions
)
def get_source_language(self):
with fs.cd(get_project_dir()):
for _, __, files in os.walk(self.config.get_optional_dir("src")):
for name in files:
if "." not in name:
continue
if os.path.splitext(name)[1].lower() in (".cpp", ".cxx", ".ino"):
return "c++"
return "c"
def check(self, on_defect_callback=None):
self._on_defect_callback = on_defect_callback
cmd = self.configure_command()

View File

@ -90,6 +90,9 @@ class CppcheckCheckTool(CheckToolBase):
% "<&PIO&>".join(["{0}={{{0}}}".format(f) for f in self.defect_fields])
)
if self.get_source_language() == "c++":
cmd.append("--language=c++")
flags = self.get_flags("cppcheck")
if not self.is_flag_set("--platform", flags):
cmd.append("--platform=unspecified")