Skip to content

Commit cc4f337

Browse files
committed
Parse errors and warnings with ARMC6
1 parent 1549c5c commit cc4f337

File tree

2 files changed

+88
-13
lines changed

2 files changed

+88
-13
lines changed

tools/toolchains/arm.py

Lines changed: 87 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -18,17 +18,16 @@
1818
from builtins import str # noqa: F401
1919

2020
import re
21-
import os
2221
from copy import copy
23-
from os.path import join, dirname, splitext, basename, exists, isfile, split
22+
from os.path import join, dirname, splitext, basename, exists, isfile
2423
from os import makedirs, write, remove
2524
from tempfile import mkstemp
2625
from shutil import rmtree
2726
from distutils.version import LooseVersion
2827

2928
from tools.targets import CORE_ARCH
3029
from tools.toolchains.mbed_toolchain import mbedToolchain, TOOLCHAIN_PATHS
31-
from tools.utils import mkdir, NotSupportedException, ToolException, run_cmd
30+
from tools.utils import mkdir, NotSupportedException, run_cmd
3231

3332
ARMC5_MIGRATION_WARNING = (
3433
"Warning: We noticed that you are using Arm Compiler 5. "
@@ -38,6 +37,7 @@
3837
"please visit https://os.mbed.com/docs/mbed-os/latest/tools/index.html"
3938
)
4039

40+
4141
class ARM(mbedToolchain):
4242
LINKER_EXT = '.sct'
4343
LIBRARY_EXT = '.ar'
@@ -184,7 +184,8 @@ def parse_dependencies(self, dep_path):
184184
def parse_output(self, output):
185185
msg = None
186186
for line in output.splitlines():
187-
match = ARM.DIAGNOSTIC_PATTERN.match(line)
187+
match = self.DIAGNOSTIC_PATTERN.match(line)
188+
print(line, match)
188189
if match is not None:
189190
if msg is not None:
190191
self.notify.cc_info(msg)
@@ -306,7 +307,14 @@ def correct_scatter_shebang(self, scatter_file, cur_dir_name=None):
306307

307308
return new_scatter
308309

309-
def get_link_command(self, output, objects, libraries, lib_dirs, scatter_file):
310+
def get_link_command(
311+
self,
312+
output,
313+
objects,
314+
libraries,
315+
lib_dirs,
316+
scatter_file
317+
):
310318
base, _ = splitext(output)
311319
map_file = base + ".map"
312320
args = ["-o", output, "--info=totals", "--map", "--list=%s" % map_file]
@@ -378,6 +386,7 @@ def redirect_symbol(source, sync, build_dir):
378386
write(handle, "RESOLVE %s AS %s\n" % (source, sync))
379387
return "--edit=%s" % filename
380388

389+
381390
class ARM_STD(ARM):
382391

383392
OFFICIALLY_SUPPORTED = True
@@ -399,9 +408,11 @@ def __init__(
399408
build_profile=build_profile
400409
)
401410
if int(target.build_tools_metadata["version"]) > 0:
402-
#check only for ARMC5 because ARM_STD means using ARMC5, and thus
411+
# check only for ARMC5 because ARM_STD means using ARMC5, and thus
403412
# supported_toolchains must include ARMC5
404-
if not set(target.supported_toolchains).intersection(set(("ARMC5", "ARM"))):
413+
if not set(target.supported_toolchains).intersection(
414+
set(("ARMC5", "ARM"))
415+
):
405416
raise NotSupportedException(
406417
"ARM compiler 5 support is required for ARM build"
407418
)
@@ -413,6 +424,7 @@ def __init__(
413424
"ARM/uARM compiler support is required for ARM build"
414425
)
415426

427+
416428
class ARM_MICRO(ARM):
417429

418430
PATCHED_LIBRARY = False
@@ -434,7 +446,7 @@ def __init__(
434446
# At this point we already know that we want to use ARMC5+Microlib
435447
# so check for if they are supported For, AC6+Microlib we still
436448
# use ARMC6 class
437-
if not set(("ARMC5","uARM")).issubset(set(
449+
if not set(("ARMC5", "uARM")).issubset(set(
438450
target.supported_toolchains
439451
)):
440452
raise NotSupportedException(
@@ -469,6 +481,10 @@ class ARMC6(ARM_STD):
469481
"Cortex-A9"
470482
]
471483
ARMCC_RANGE = (LooseVersion("6.10"), LooseVersion("7.0"))
484+
LD_DIAGNOSTIC_PATTERN = re.compile(
485+
'(?P<severity>Warning|Error): (?P<message>.+)'
486+
)
487+
DIAGNOSTIC_PATTERN = re.compile('((?P<file>[^:]+):(?P<line>\d+):)(?P<col>\d+):? (?P<severity>warning|[eE]rror|fatal error): (?P<message>.+)')
472488

473489
@staticmethod
474490
def check_executable():
@@ -586,9 +602,9 @@ def __init__(self, target, *args, **kwargs):
586602
self.ar = join(TOOLCHAIN_PATHS["ARMC6"], "armar")
587603
self.elf2bin = join(TOOLCHAIN_PATHS["ARMC6"], "fromelf")
588604

589-
# Adding this for safety since this inherits the `version_check` function
590-
# but does not call the constructor of ARM_STD, so the `product_name` variable
591-
# is not initialized.
605+
# Adding this for safety since this inherits the `version_check`
606+
# function but does not call the constructor of ARM_STD, so the
607+
# `product_name` variable is not initialized.
592608
self.product_name = None
593609

594610
def _get_toolchain_labels(self):
@@ -608,7 +624,58 @@ def is_not_supported_error(self, output):
608624
return "#error [NOT_SUPPORTED]" in output
609625

610626
def parse_output(self, output):
611-
pass
627+
msg = None
628+
for line in output.splitlines():
629+
match = self.LD_DIAGNOSTIC_PATTERN.match(line)
630+
if match is not None:
631+
if msg is not None:
632+
self.notify.cc_info(msg)
633+
msg = None
634+
msg = {
635+
'severity': match.group('severity').lower(),
636+
'message': match.group('message'),
637+
'text': '',
638+
'target_name': self.target.name,
639+
'toolchain_name': self.name,
640+
'col': 0,
641+
'file': "",
642+
'line': 0
643+
}
644+
elif msg is not None:
645+
# Determine the warning/error column by calculating the '^'
646+
# position
647+
match = ARM.INDEX_PATTERN.match(line)
648+
if match is not None:
649+
msg['col'] = len(match.group('col'))
650+
self.notify.cc_info(msg)
651+
msg = None
652+
else:
653+
msg['text'] += line+"\n"
654+
655+
if msg is not None:
656+
self.notify.cc_info(msg)
657+
658+
# The warning/error notification is multiline
659+
msg = None
660+
for line in output.splitlines():
661+
match = self.DIAGNOSTIC_PATTERN.search(line)
662+
if match is not None:
663+
if msg is not None:
664+
self.notify.cc_info(msg)
665+
msg = None
666+
msg = {
667+
'severity': match.group('severity').lower(),
668+
'file': match.group('file'),
669+
'line': match.group('line'),
670+
'col': match.group('col'),
671+
'message': match.group('message'),
672+
'text': '',
673+
'target_name': self.target.name,
674+
'toolchain_name': self.name
675+
}
676+
677+
if msg is not None:
678+
self.notify.cc_info(msg)
612679

613680
def get_config_option(self, config_header):
614681
return ["-include", config_header]
@@ -660,7 +727,14 @@ def compile(self, cc, source, object, includes):
660727
cmd.extend(["-o", object, source])
661728
return [cmd]
662729

663-
def get_link_command(self, output, objects, libraries, lib_dirs, scatter_file):
730+
def get_link_command(
731+
self,
732+
output,
733+
objects,
734+
libraries,
735+
lib_dirs,
736+
scatter_file
737+
):
664738
cmd = ARM.get_link_command(
665739
self, output, objects, libraries, lib_dirs, scatter_file
666740
)

tools/toolchains/mbed_toolchain.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -775,6 +775,7 @@ def default_cmd(self, command):
775775
)
776776
self.notify.debug("Return: %s" % rc)
777777

778+
self.parse_output(stderr)
778779
for output_line in stdout.splitlines():
779780
self.notify.debug("Output: %s" % output_line)
780781
for error_line in stderr.splitlines():

0 commit comments

Comments
 (0)