Check version of Mbed CLI compile

pull/7247/head
Jimmy Brisson 2018-06-18 14:03:09 -05:00
parent 701d49d8eb
commit 6f54a8fdd7
5 changed files with 65 additions and 1 deletions

View File

@ -552,6 +552,7 @@ def build_project(src_paths, build_path, target, toolchain_name,
src_paths, build_path, target, toolchain_name, macros=macros,
clean=clean, jobs=jobs, notify=notify, config=config,
app_config=app_config, build_profile=build_profile, ignore=ignore)
toolchain.version_check()
# The first path will give the name to the library
name = (name or toolchain.config.name or

View File

@ -1539,6 +1539,13 @@ class mbedToolchain:
def get_config_macros(self):
return self.config.config_to_macros(self.config_data) if self.config_data else []
@abstractmethod
def version_check(self):
"""Check the version of a compiler being used and raise a
NotSupportedException when it's incorrect.
"""
raise NotImplemented
@property
def report(self):
to_ret = {}

View File

@ -26,7 +26,7 @@ from shutil import rmtree
from tools.toolchains import mbedToolchain, TOOLCHAIN_PATHS
from tools.hooks import hook_tool
from tools.utils import mkdir, NotSupportedException
from tools.utils import mkdir, NotSupportedException, run_cmd
class ARM(mbedToolchain):
LINKER_EXT = '.sct'
@ -39,6 +39,8 @@ class ARM(mbedToolchain):
SHEBANG = "#! armcc -E"
SUPPORTED_CORES = ["Cortex-M0", "Cortex-M0+", "Cortex-M3", "Cortex-M4",
"Cortex-M4F", "Cortex-M7", "Cortex-M7F", "Cortex-M7FD", "Cortex-A9"]
ARMCC_VERSION = "5.06"
ARMCC_VERSION_RE = re.compile("^Product: ARM Compiler (.*)$")
@staticmethod
def check_executable():
@ -91,6 +93,17 @@ class ARM(mbedToolchain):
self.SHEBANG += " --cpu=%s" % cpu
def version_check(self):
stdout, _, retcode = run_cmd([self.cc[0], "--vsn"], redirect=True)
first_line = stdout.splitlines()[0]
match = self.ARMCC_VERSION_RE.match(first_line)
if match:
found_version = match.group(1)
if not found_version.startswith(self.ARMCC_VERSION):
raise NotSupportedException(
"ARM compiler version mismatch: Have {}; expected {}"
.format(found_version, self.ARMCC_VERSION))
def _get_toolchain_labels(self):
if getattr(self.target, "default_lib", "std") == "small":
return ["ARM", "ARM_MICRO"]
@ -324,6 +337,8 @@ class ARMC6(ARM_STD):
"Cortex-M4F", "Cortex-M7", "Cortex-M7F", "Cortex-M7FD",
"Cortex-M23", "Cortex-M23-NS", "Cortex-M33",
"CortexM33-NS", "Cortex-A9"]
ARMCC_VERSION = "6.10"
@staticmethod
def check_executable():
return mbedToolchain.generic_check_executable("ARMC6", "armclang", 1)

View File

@ -20,6 +20,7 @@ from distutils.spawn import find_executable
from tools.toolchains import mbedToolchain, TOOLCHAIN_PATHS
from tools.hooks import hook_tool
from tools.utils import run_cmd, NotSupportedException
class GCC(mbedToolchain):
LINKER_EXT = '.ld'
@ -28,6 +29,9 @@ class GCC(mbedToolchain):
STD_LIB_NAME = "lib%s.a"
DIAGNOSTIC_PATTERN = re.compile('((?P<file>[^:]+):(?P<line>\d+):)(?P<col>\d+):? (?P<severity>warning|[eE]rror|fatal error): (?P<message>.+)')
GCC_MAJOR = "6"
GCC_VERSION_RE = re.compile("[0-9]*\.[0-9]*\.[0-9]*")
def __init__(self, target, notify=None, macros=None, build_profile=None,
build_dir=None):
mbedToolchain.__init__(self, target, notify, macros,
@ -107,6 +111,23 @@ class GCC(mbedToolchain):
self.ar = join(tool_path, "arm-none-eabi-ar")
self.elf2bin = join(tool_path, "arm-none-eabi-objcopy")
def version_check(self):
stdout, _, retcode = run_cmd([self.cc[0], "--version"], redirect=True)
found_version = None
for line in stdout.splitlines():
for word in line.split():
match = self.GCC_VERSION_RE.match(word)
if match:
found_version = match.group(0)
if found_version and not found_version.startswith(self.GCC_MAJOR + "."):
raise NotSupportedException(
"GCC_ARM compiler version mismatch: Have {}; expected major version {}"
.format(found_version, self.GCC_MAJOR))
elif not found_version:
raise NotSupportedException(
"GCC_ARM compiler version mismatch: Could Not detect compiler "
"version; expected {}".format(self.GCC_MAJOR))
def is_not_supported_error(self, output):
return "error: #error [NOT_SUPPORTED]" in output

View File

@ -20,6 +20,7 @@ from os.path import join, splitext, exists
from tools.toolchains import mbedToolchain, TOOLCHAIN_PATHS
from tools.hooks import hook_tool
from tools.utils import run_cmd, NotSupportedException
class IAR(mbedToolchain):
LIBRARY_EXT = '.a'
@ -28,6 +29,8 @@ class IAR(mbedToolchain):
DIAGNOSTIC_PATTERN = re.compile('"(?P<file>[^"]+)",(?P<line>[\d]+)\s+(?P<severity>Warning|Error|Fatal error)(?P<message>.+)')
INDEX_PATTERN = re.compile('(?P<col>\s*)\^')
IAR_VERSION_RE = re.compile("IAR ANSI C/C\+\+ Compiler V([0-9]+.[0-9]+)")
IAR_VERSION = "7.80"
@staticmethod
def check_executable():
@ -91,6 +94,23 @@ class IAR(mbedToolchain):
self.ar = join(IAR_BIN, "iarchive")
self.elf2bin = join(IAR_BIN, "ielftool")
def version_check(self):
stdout, _, retcode = run_cmd([self.cc[0], "--version"], redirect=True)
found_version = None
for line in stdout.splitlines():
match = self.IAR_VERSION_RE.match(line)
if match:
found_version = match.group(1)
if found_version and not found_version.startswith(self.IAR_VERSION):
raise NotSupportedException(
"IAR compiler version mismatch: Have {}; expected {}"
.format(found_version, self.IAR_VERSION))
elif not found_version:
raise NotSupportedException(
"IAR compiler version mismatch: Could Not detect compiler "
"version; expected {}".format(self.IAR_VERSION))
def parse_dependencies(self, dep_path):
return [(self.CHROOT if self.CHROOT else '')+path.strip() for path in open(dep_path).readlines()
if (path and not path.isspace())]