Skip to content

Commit a87575f

Browse files
committed
Use Non-blocking Error and LooseVersion
1 parent 6f54a8f commit a87575f

File tree

3 files changed

+59
-25
lines changed

3 files changed

+59
-25
lines changed

tools/toolchains/arm.py

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
from os import makedirs, write, curdir, remove
2424
from tempfile import mkstemp
2525
from shutil import rmtree
26+
from distutils.version import LooseVersion
2627

2728
from tools.toolchains import mbedToolchain, TOOLCHAIN_PATHS
2829
from tools.hooks import hook_tool
@@ -39,8 +40,8 @@ class ARM(mbedToolchain):
3940
SHEBANG = "#! armcc -E"
4041
SUPPORTED_CORES = ["Cortex-M0", "Cortex-M0+", "Cortex-M3", "Cortex-M4",
4142
"Cortex-M4F", "Cortex-M7", "Cortex-M7F", "Cortex-M7FD", "Cortex-A9"]
42-
ARMCC_VERSION = "5.06"
43-
ARMCC_VERSION_RE = re.compile("^Product: ARM Compiler (.*)$")
43+
ARMCC_RANGE = (LooseVersion("5.06"), LooseVersion("5.07"))
44+
ARMCC_VERSION_RE = re.compile("^Product: ARM Compiler ([.0-9]*)")
4445

4546
@staticmethod
4647
def check_executable():
@@ -95,14 +96,29 @@ def __init__(self, target, notify=None, macros=None,
9596

9697
def version_check(self):
9798
stdout, _, retcode = run_cmd([self.cc[0], "--vsn"], redirect=True)
99+
msg = None
100+
min_ver, max_ver = self.ARMCC_RANGE
98101
first_line = stdout.splitlines()[0]
99102
match = self.ARMCC_VERSION_RE.match(first_line)
100103
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))
104+
found_version = LooseVersion(match.group(1))
105+
if found_version < min_ver or found_version > max_ver:
106+
msg = ("Compiler version mismatch: Have {}; "
107+
"expected >= {} < {}"
108+
.format(found_version, min_ver, max_ver))
109+
else:
110+
msg = ("Compiler version mismatch: Could not detect version; "
111+
"expected >= {} < {}"
112+
.format(min_ver, max_ver))
113+
114+
if msg:
115+
self.notify.cc_info({
116+
"message": msg,
117+
"file": "",
118+
"line": "",
119+
"col": "",
120+
"severity": "ERROR",
121+
})
106122

107123
def _get_toolchain_labels(self):
108124
if getattr(self.target, "default_lib", "std") == "small":
@@ -337,7 +353,7 @@ class ARMC6(ARM_STD):
337353
"Cortex-M4F", "Cortex-M7", "Cortex-M7F", "Cortex-M7FD",
338354
"Cortex-M23", "Cortex-M23-NS", "Cortex-M33",
339355
"CortexM33-NS", "Cortex-A9"]
340-
ARMCC_VERSION = "6.10"
356+
ARMCC_RANGE = (LooseVersion("6.10"), LooseVersion("7.0"))
341357

342358
@staticmethod
343359
def check_executable():

tools/toolchains/gcc.py

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
import re
1818
from os.path import join, basename, splitext, dirname, exists
1919
from distutils.spawn import find_executable
20+
from distutils.version import LooseVersion
2021

2122
from tools.toolchains import mbedToolchain, TOOLCHAIN_PATHS
2223
from tools.hooks import hook_tool
@@ -29,7 +30,7 @@ class GCC(mbedToolchain):
2930
STD_LIB_NAME = "lib%s.a"
3031
DIAGNOSTIC_PATTERN = re.compile('((?P<file>[^:]+):(?P<line>\d+):)(?P<col>\d+):? (?P<severity>warning|[eE]rror|fatal error): (?P<message>.+)')
3132

32-
GCC_MAJOR = "6"
33+
GCC_RANGE = (LooseVersion("6.0.0"), LooseVersion("7.0.0"))
3334
GCC_VERSION_RE = re.compile("[0-9]*\.[0-9]*\.[0-9]*")
3435

3536
def __init__(self, target, notify=None, macros=None, build_profile=None,
@@ -118,15 +119,24 @@ def version_check(self):
118119
for word in line.split():
119120
match = self.GCC_VERSION_RE.match(word)
120121
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))
122+
found_version = LooseVersion(match.group(0))
123+
min_ver, max_ver = self.GCC_RANGE
124+
if found_version and (found_version < min_ver or found_version >= max_ver):
125+
msg = ("Compiler version mismatch: Have {}; "
126+
"expected version >= {} and < {}"
127+
.format(found_version, min_ver, max_ver))
126128
elif not found_version:
127-
raise NotSupportedException(
128-
"GCC_ARM compiler version mismatch: Could Not detect compiler "
129-
"version; expected {}".format(self.GCC_MAJOR))
129+
msg = ("Compiler version mismatch: Could not detect version; "
130+
"expected version >= {} and < {}"
131+
.format(min_ver, max_ver))
132+
if msg:
133+
self.notify.cc_info({
134+
"message": msg,
135+
"file": "",
136+
"line": "",
137+
"col": "",
138+
"severity": "ERROR",
139+
})
130140

131141
def is_not_supported_error(self, output):
132142
return "error: #error [NOT_SUPPORTED]" in output

tools/toolchains/iar.py

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
import re
1818
from os import remove
1919
from os.path import join, splitext, exists
20+
from distutils.version import LooseVersion
2021

2122
from tools.toolchains import mbedToolchain, TOOLCHAIN_PATHS
2223
from tools.hooks import hook_tool
@@ -30,7 +31,7 @@ class IAR(mbedToolchain):
3031
DIAGNOSTIC_PATTERN = re.compile('"(?P<file>[^"]+)",(?P<line>[\d]+)\s+(?P<severity>Warning|Error|Fatal error)(?P<message>.+)')
3132
INDEX_PATTERN = re.compile('(?P<col>\s*)\^')
3233
IAR_VERSION_RE = re.compile("IAR ANSI C/C\+\+ Compiler V([0-9]+.[0-9]+)")
33-
IAR_VERSION = "7.80"
34+
IAR_VERSION = LooseVersion("7.80")
3435

3536
@staticmethod
3637
def check_executable():
@@ -101,14 +102,21 @@ def version_check(self):
101102
match = self.IAR_VERSION_RE.match(line)
102103
if match:
103104
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))
105+
msg = None
106+
if found_version and LooseVersion(found_version) != self.IAR_VERSION:
107+
msg = "Compiler version mismatch: Have {}; expected {}".format(
108+
found_version, self.IAR_VERSION)
108109
elif not found_version:
109-
raise NotSupportedException(
110-
"IAR compiler version mismatch: Could Not detect compiler "
111-
"version; expected {}".format(self.IAR_VERSION))
110+
msg = ("Compiler version mismatch: Could Not detect compiler "
111+
"version; expected {}".format(self.IAR_VERSION))
112+
if msg:
113+
self.notify.cc_info({
114+
"message": msg,
115+
"file": "",
116+
"line": "",
117+
"col": "",
118+
"severity": "ERROR",
119+
})
112120

113121

114122
def parse_dependencies(self, dep_path):

0 commit comments

Comments
 (0)