Skip to content

Commit 136e0e3

Browse files
author
Cruz Monrreal
authored
Merge pull request #10276 from theotherjimmy/armc6-parse
Parse Errors and Warnings from Arm Compiler 6
2 parents cdc2579 + 992cb26 commit 136e0e3

File tree

2 files changed

+60
-13
lines changed

2 files changed

+60
-13
lines changed

tools/toolchains/arm.py

Lines changed: 59 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,7 @@ 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)
188188
if match is not None:
189189
if msg is not None:
190190
self.notify.cc_info(msg)
@@ -306,7 +306,14 @@ def correct_scatter_shebang(self, scatter_file, cur_dir_name=None):
306306

307307
return new_scatter
308308

309-
def get_link_command(self, output, objects, libraries, lib_dirs, scatter_file):
309+
def get_link_command(
310+
self,
311+
output,
312+
objects,
313+
libraries,
314+
lib_dirs,
315+
scatter_file
316+
):
310317
base, _ = splitext(output)
311318
map_file = base + ".map"
312319
args = ["-o", output, "--info=totals", "--map", "--list=%s" % map_file]
@@ -378,6 +385,7 @@ def redirect_symbol(source, sync, build_dir):
378385
write(handle, "RESOLVE %s AS %s\n" % (source, sync))
379386
return "--edit=%s" % filename
380387

388+
381389
class ARM_STD(ARM):
382390

383391
OFFICIALLY_SUPPORTED = True
@@ -399,9 +407,11 @@ def __init__(
399407
build_profile=build_profile
400408
)
401409
if int(target.build_tools_metadata["version"]) > 0:
402-
#check only for ARMC5 because ARM_STD means using ARMC5, and thus
410+
# check only for ARMC5 because ARM_STD means using ARMC5, and thus
403411
# supported_toolchains must include ARMC5
404-
if not set(target.supported_toolchains).intersection(set(("ARMC5", "ARM"))):
412+
if not set(target.supported_toolchains).intersection(
413+
set(("ARMC5", "ARM"))
414+
):
405415
raise NotSupportedException(
406416
"ARM compiler 5 support is required for ARM build"
407417
)
@@ -413,6 +423,7 @@ def __init__(
413423
"ARM/uARM compiler support is required for ARM build"
414424
)
415425

426+
416427
class ARM_MICRO(ARM):
417428

418429
PATCHED_LIBRARY = False
@@ -434,7 +445,7 @@ def __init__(
434445
# At this point we already know that we want to use ARMC5+Microlib
435446
# so check for if they are supported For, AC6+Microlib we still
436447
# use ARMC6 class
437-
if not set(("ARMC5","uARM")).issubset(set(
448+
if not set(("ARMC5", "uARM")).issubset(set(
438449
target.supported_toolchains
439450
)):
440451
raise NotSupportedException(
@@ -469,6 +480,10 @@ class ARMC6(ARM_STD):
469480
"Cortex-A9"
470481
]
471482
ARMCC_RANGE = (LooseVersion("6.10"), LooseVersion("7.0"))
483+
LD_DIAGNOSTIC_PATTERN = re.compile(
484+
'(?P<severity>Warning|Error): (?P<message>.+)'
485+
)
486+
DIAGNOSTIC_PATTERN = re.compile('((?P<file>[^:]+):(?P<line>\d+):)(?P<col>\d+):? (?P<severity>warning|[eE]rror|fatal error): (?P<message>.+)')
472487

473488
@staticmethod
474489
def check_executable():
@@ -586,9 +601,9 @@ def __init__(self, target, *args, **kwargs):
586601
self.ar = join(TOOLCHAIN_PATHS["ARMC6"], "armar")
587602
self.elf2bin = join(TOOLCHAIN_PATHS["ARMC6"], "fromelf")
588603

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.
604+
# Adding this for safety since this inherits the `version_check`
605+
# function but does not call the constructor of ARM_STD, so the
606+
# `product_name` variable is not initialized.
592607
self.product_name = None
593608

594609
def _get_toolchain_labels(self):
@@ -608,7 +623,31 @@ def is_not_supported_error(self, output):
608623
return "#error [NOT_SUPPORTED]" in output
609624

610625
def parse_output(self, output):
611-
pass
626+
for line in output.splitlines():
627+
match = self.LD_DIAGNOSTIC_PATTERN.match(line)
628+
if match is not None:
629+
self.notify.cc_info({
630+
'severity': match.group('severity').lower(),
631+
'message': match.group('message'),
632+
'text': '',
633+
'target_name': self.target.name,
634+
'toolchain_name': self.name,
635+
'col': 0,
636+
'file': "",
637+
'line': 0
638+
})
639+
match = self.DIAGNOSTIC_PATTERN.search(line)
640+
if match is not None:
641+
self.notify.cc_info({
642+
'severity': match.group('severity').lower(),
643+
'file': match.group('file'),
644+
'line': match.group('line'),
645+
'col': match.group('col'),
646+
'message': match.group('message'),
647+
'text': '',
648+
'target_name': self.target.name,
649+
'toolchain_name': self.name
650+
})
612651

613652
def get_config_option(self, config_header):
614653
return ["-include", config_header]
@@ -660,7 +699,14 @@ def compile(self, cc, source, object, includes):
660699
cmd.extend(["-o", object, source])
661700
return [cmd]
662701

663-
def get_link_command(self, output, objects, libraries, lib_dirs, scatter_file):
702+
def get_link_command(
703+
self,
704+
output,
705+
objects,
706+
libraries,
707+
lib_dirs,
708+
scatter_file
709+
):
664710
cmd = ARM.get_link_command(
665711
self, output, objects, libraries, lib_dirs, scatter_file
666712
)

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)