Skip to content

Commit 6f54a8f

Browse files
committed
Check version of Mbed CLI compile
1 parent 701d49d commit 6f54a8f

File tree

5 files changed

+65
-1
lines changed

5 files changed

+65
-1
lines changed

tools/build_api.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -552,6 +552,7 @@ def build_project(src_paths, build_path, target, toolchain_name,
552552
src_paths, build_path, target, toolchain_name, macros=macros,
553553
clean=clean, jobs=jobs, notify=notify, config=config,
554554
app_config=app_config, build_profile=build_profile, ignore=ignore)
555+
toolchain.version_check()
555556

556557
# The first path will give the name to the library
557558
name = (name or toolchain.config.name or

tools/toolchains/__init__.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1539,6 +1539,13 @@ def redirect_symbol(source, sync, build_dir):
15391539
def get_config_macros(self):
15401540
return self.config.config_to_macros(self.config_data) if self.config_data else []
15411541

1542+
@abstractmethod
1543+
def version_check(self):
1544+
"""Check the version of a compiler being used and raise a
1545+
NotSupportedException when it's incorrect.
1546+
"""
1547+
raise NotImplemented
1548+
15421549
@property
15431550
def report(self):
15441551
to_ret = {}

tools/toolchains/arm.py

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626

2727
from tools.toolchains import mbedToolchain, TOOLCHAIN_PATHS
2828
from tools.hooks import hook_tool
29-
from tools.utils import mkdir, NotSupportedException
29+
from tools.utils import mkdir, NotSupportedException, run_cmd
3030

3131
class ARM(mbedToolchain):
3232
LINKER_EXT = '.sct'
@@ -39,6 +39,8 @@ class ARM(mbedToolchain):
3939
SHEBANG = "#! armcc -E"
4040
SUPPORTED_CORES = ["Cortex-M0", "Cortex-M0+", "Cortex-M3", "Cortex-M4",
4141
"Cortex-M4F", "Cortex-M7", "Cortex-M7F", "Cortex-M7FD", "Cortex-A9"]
42+
ARMCC_VERSION = "5.06"
43+
ARMCC_VERSION_RE = re.compile("^Product: ARM Compiler (.*)$")
4244

4345
@staticmethod
4446
def check_executable():
@@ -91,6 +93,17 @@ def __init__(self, target, notify=None, macros=None,
9193

9294
self.SHEBANG += " --cpu=%s" % cpu
9395

96+
def version_check(self):
97+
stdout, _, retcode = run_cmd([self.cc[0], "--vsn"], redirect=True)
98+
first_line = stdout.splitlines()[0]
99+
match = self.ARMCC_VERSION_RE.match(first_line)
100+
if match:
101+
found_version = match.group(1)
102+
if not found_version.startswith(self.ARMCC_VERSION):
103+
raise NotSupportedException(
104+
"ARM compiler version mismatch: Have {}; expected {}"
105+
.format(found_version, self.ARMCC_VERSION))
106+
94107
def _get_toolchain_labels(self):
95108
if getattr(self.target, "default_lib", "std") == "small":
96109
return ["ARM", "ARM_MICRO"]
@@ -324,6 +337,8 @@ class ARMC6(ARM_STD):
324337
"Cortex-M4F", "Cortex-M7", "Cortex-M7F", "Cortex-M7FD",
325338
"Cortex-M23", "Cortex-M23-NS", "Cortex-M33",
326339
"CortexM33-NS", "Cortex-A9"]
340+
ARMCC_VERSION = "6.10"
341+
327342
@staticmethod
328343
def check_executable():
329344
return mbedToolchain.generic_check_executable("ARMC6", "armclang", 1)

tools/toolchains/gcc.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020

2121
from tools.toolchains import mbedToolchain, TOOLCHAIN_PATHS
2222
from tools.hooks import hook_tool
23+
from tools.utils import run_cmd, NotSupportedException
2324

2425
class GCC(mbedToolchain):
2526
LINKER_EXT = '.ld'
@@ -28,6 +29,9 @@ class GCC(mbedToolchain):
2829
STD_LIB_NAME = "lib%s.a"
2930
DIAGNOSTIC_PATTERN = re.compile('((?P<file>[^:]+):(?P<line>\d+):)(?P<col>\d+):? (?P<severity>warning|[eE]rror|fatal error): (?P<message>.+)')
3031

32+
GCC_MAJOR = "6"
33+
GCC_VERSION_RE = re.compile("[0-9]*\.[0-9]*\.[0-9]*")
34+
3135
def __init__(self, target, notify=None, macros=None, build_profile=None,
3236
build_dir=None):
3337
mbedToolchain.__init__(self, target, notify, macros,
@@ -107,6 +111,23 @@ def __init__(self, target, notify=None, macros=None, build_profile=None,
107111
self.ar = join(tool_path, "arm-none-eabi-ar")
108112
self.elf2bin = join(tool_path, "arm-none-eabi-objcopy")
109113

114+
def version_check(self):
115+
stdout, _, retcode = run_cmd([self.cc[0], "--version"], redirect=True)
116+
found_version = None
117+
for line in stdout.splitlines():
118+
for word in line.split():
119+
match = self.GCC_VERSION_RE.match(word)
120+
if match:
121+
found_version = match.group(0)
122+
if found_version and not found_version.startswith(self.GCC_MAJOR + "."):
123+
raise NotSupportedException(
124+
"GCC_ARM compiler version mismatch: Have {}; expected major version {}"
125+
.format(found_version, self.GCC_MAJOR))
126+
elif not found_version:
127+
raise NotSupportedException(
128+
"GCC_ARM compiler version mismatch: Could Not detect compiler "
129+
"version; expected {}".format(self.GCC_MAJOR))
130+
110131
def is_not_supported_error(self, output):
111132
return "error: #error [NOT_SUPPORTED]" in output
112133

tools/toolchains/iar.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020

2121
from tools.toolchains import mbedToolchain, TOOLCHAIN_PATHS
2222
from tools.hooks import hook_tool
23+
from tools.utils import run_cmd, NotSupportedException
2324

2425
class IAR(mbedToolchain):
2526
LIBRARY_EXT = '.a'
@@ -28,6 +29,8 @@ class IAR(mbedToolchain):
2829

2930
DIAGNOSTIC_PATTERN = re.compile('"(?P<file>[^"]+)",(?P<line>[\d]+)\s+(?P<severity>Warning|Error|Fatal error)(?P<message>.+)')
3031
INDEX_PATTERN = re.compile('(?P<col>\s*)\^')
32+
IAR_VERSION_RE = re.compile("IAR ANSI C/C\+\+ Compiler V([0-9]+.[0-9]+)")
33+
IAR_VERSION = "7.80"
3134

3235
@staticmethod
3336
def check_executable():
@@ -91,6 +94,23 @@ def __init__(self, target, notify=None, macros=None, build_profile=None,
9194
self.ar = join(IAR_BIN, "iarchive")
9295
self.elf2bin = join(IAR_BIN, "ielftool")
9396

97+
def version_check(self):
98+
stdout, _, retcode = run_cmd([self.cc[0], "--version"], redirect=True)
99+
found_version = None
100+
for line in stdout.splitlines():
101+
match = self.IAR_VERSION_RE.match(line)
102+
if match:
103+
found_version = match.group(1)
104+
if found_version and not found_version.startswith(self.IAR_VERSION):
105+
raise NotSupportedException(
106+
"IAR compiler version mismatch: Have {}; expected {}"
107+
.format(found_version, self.IAR_VERSION))
108+
elif not found_version:
109+
raise NotSupportedException(
110+
"IAR compiler version mismatch: Could Not detect compiler "
111+
"version; expected {}".format(self.IAR_VERSION))
112+
113+
94114
def parse_dependencies(self, dep_path):
95115
return [(self.CHROOT if self.CHROOT else '')+path.strip() for path in open(dep_path).readlines()
96116
if (path and not path.isspace())]

0 commit comments

Comments
 (0)