forked from platformio/platformio-core
Automatically detect source files language when invoking cppcheck
This commit is contained in:
@ -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()
|
||||
|
@ -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")
|
||||
|
Reference in New Issue
Block a user