Skip to content

Commit 1a9474e

Browse files
committed
Search all stdout for version regex; check > 1 matches
1 parent 2aea6c3 commit 1a9474e

File tree

3 files changed

+17
-24
lines changed

3 files changed

+17
-24
lines changed

tools/toolchains/arm.py

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ class ARM(mbedToolchain):
4141
SUPPORTED_CORES = ["Cortex-M0", "Cortex-M0+", "Cortex-M3", "Cortex-M4",
4242
"Cortex-M4F", "Cortex-M7", "Cortex-M7F", "Cortex-M7FD", "Cortex-A9"]
4343
ARMCC_RANGE = (LooseVersion("5.06"), LooseVersion("5.07"))
44-
ARMCC_VERSION_RE = re.compile("^Product: ARM Compiler (\d+.\d+)")
44+
ARMCC_VERSION_RE = re.compile("Product: ARM Compiler (\d+.\d+)")
4545

4646
@staticmethod
4747
def check_executable():
@@ -98,17 +98,16 @@ def version_check(self):
9898
stdout, _, retcode = run_cmd([self.cc[0], "--vsn"], redirect=True)
9999
msg = None
100100
min_ver, max_ver = self.ARMCC_RANGE
101-
first_line = stdout.splitlines()[0]
102-
match = self.ARMCC_VERSION_RE.match(first_line)
103-
if match:
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:
101+
match = self.ARMCC_VERSION_RE.search(stdout)
102+
found_version = LooseVersion(match.group(0)) if match else None
103+
min_ver, max_ver = self.ARM_RANGE
104+
if found_version and (found_version < min_ver or found_version >= max_ver):
105+
msg = ("Compiler version mismatch: Have {}; "
106+
"expected version >= {} and < {}"
107+
.format(found_version, min_ver, max_ver))
108+
elif len(match.groups()) != 1:
110109
msg = ("Compiler version mismatch: Could not detect version; "
111-
"expected >= {} < {}"
110+
"expected version >= {} and < {}"
112111
.format(min_ver, max_ver))
113112

114113
if msg:

tools/toolchains/gcc.py

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -114,18 +114,15 @@ def __init__(self, target, notify=None, macros=None, build_profile=None,
114114

115115
def version_check(self):
116116
stdout, _, retcode = run_cmd([self.cc[0], "--version"], redirect=True)
117-
found_version = None
118-
for line in stdout.splitlines():
119-
for word in line.split():
120-
match = self.GCC_VERSION_RE.match(word)
121-
if match:
122-
found_version = LooseVersion(match.group(0))
117+
msg = None
118+
match = self.GCC_VERSION_RE.search(stdout)
119+
found_version = LooseVersion(match.group(0)) if match else None
123120
min_ver, max_ver = self.GCC_RANGE
124121
if found_version and (found_version < min_ver or found_version >= max_ver):
125122
msg = ("Compiler version mismatch: Have {}; "
126123
"expected version >= {} and < {}"
127124
.format(found_version, min_ver, max_ver))
128-
elif not found_version:
125+
elif len(match.groups()) != 1:
129126
msg = ("Compiler version mismatch: Could not detect version; "
130127
"expected version >= {} and < {}"
131128
.format(min_ver, max_ver))

tools/toolchains/iar.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -97,16 +97,13 @@ def __init__(self, target, notify=None, macros=None, build_profile=None,
9797

9898
def version_check(self):
9999
stdout, _, retcode = run_cmd([self.cc[0], "--version"], redirect=True)
100-
found_version = None
101-
for line in stdout.splitlines():
102-
match = self.IAR_VERSION_RE.match(line)
103-
if match:
104-
found_version = match.group(1)
105100
msg = None
101+
match = self.IAR_VERSION_RE.search(stdout)
102+
found_version = match.group(1) if match else None
106103
if found_version and LooseVersion(found_version) != self.IAR_VERSION:
107104
msg = "Compiler version mismatch: Have {}; expected {}".format(
108105
found_version, self.IAR_VERSION)
109-
elif not found_version:
106+
elif len(match.groups()) != 1:
110107
msg = ("Compiler version mismatch: Could Not detect compiler "
111108
"version; expected {}".format(self.IAR_VERSION))
112109
if msg:

0 commit comments

Comments
 (0)