Automatically detect C++ standard version when invoking cppcheck

This commit is contained in:
valeros
2019-10-25 20:59:36 +03:00
parent 0e7a2b3141
commit 48651286b6
2 changed files with 14 additions and 4 deletions

View File

@ -12,9 +12,10 @@
# See the License for the specific language governing permissions and
# limitations under the License.
import click
import os
import click
from platformio import fs, proc
from platformio.commands.check.defect import DefectItem
from platformio.project.helpers import get_project_dir, load_project_ide_data
@ -26,6 +27,7 @@ class CheckToolBase(object): # pylint: disable=too-many-instance-attributes
self.envname = envname
self.options = options
self.cpp_defines = []
self.cpp_flags = []
self.cpp_includes = []
self._defects = []
@ -50,6 +52,7 @@ class CheckToolBase(object): # pylint: disable=too-many-instance-attributes
data = load_project_ide_data(project_dir, envname)
if not data:
return
self.cpp_flags = data.get("cxx_flags", "").split(" ")
self.cpp_includes = data.get("includes", [])
self.cpp_defines = data.get("defines", [])
self.cpp_defines.extend(self._get_toolchain_defines(data.get("cc_path")))

View File

@ -90,9 +90,6 @@ 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")
@ -106,6 +103,16 @@ class CppcheckCheckTool(CheckToolBase):
]
cmd.append("--enable=%s" % ",".join(enabled_checks))
if not self.is_flag_set("--language", flags):
if self.get_source_language() == "c++":
cmd.append("--language=c++")
if not self.is_flag_set("--std", flags):
for f in self.cpp_flags:
if "-std" in f:
# Standards with GNU extensions are not allowed
cmd.append("-" + f.replace("gnu", "c"))
cmd.extend(["-D%s" % d for d in self.cpp_defines])
cmd.extend(flags)