18
18
from builtins import str # noqa: F401
19
19
20
20
import re
21
- import os
22
21
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
24
23
from os import makedirs , write , remove
25
24
from tempfile import mkstemp
26
25
from shutil import rmtree
27
26
from distutils .version import LooseVersion
28
27
29
28
from tools .targets import CORE_ARCH
30
29
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
32
31
33
32
ARMC5_MIGRATION_WARNING = (
34
33
"Warning: We noticed that you are using Arm Compiler 5. "
38
37
"please visit https://os.mbed.com/docs/mbed-os/latest/tools/index.html"
39
38
)
40
39
40
+
41
41
class ARM (mbedToolchain ):
42
42
LINKER_EXT = '.sct'
43
43
LIBRARY_EXT = '.ar'
@@ -184,7 +184,8 @@ def parse_dependencies(self, dep_path):
184
184
def parse_output (self , output ):
185
185
msg = None
186
186
for line in output .splitlines ():
187
- match = ARM .DIAGNOSTIC_PATTERN .match (line )
187
+ match = self .DIAGNOSTIC_PATTERN .match (line )
188
+ print (line , match )
188
189
if match is not None :
189
190
if msg is not None :
190
191
self .notify .cc_info (msg )
@@ -306,7 +307,14 @@ def correct_scatter_shebang(self, scatter_file, cur_dir_name=None):
306
307
307
308
return new_scatter
308
309
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
+ ):
310
318
base , _ = splitext (output )
311
319
map_file = base + ".map"
312
320
args = ["-o" , output , "--info=totals" , "--map" , "--list=%s" % map_file ]
@@ -378,6 +386,7 @@ def redirect_symbol(source, sync, build_dir):
378
386
write (handle , "RESOLVE %s AS %s\n " % (source , sync ))
379
387
return "--edit=%s" % filename
380
388
389
+
381
390
class ARM_STD (ARM ):
382
391
383
392
OFFICIALLY_SUPPORTED = True
@@ -399,9 +408,11 @@ def __init__(
399
408
build_profile = build_profile
400
409
)
401
410
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
403
412
# 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
+ ):
405
416
raise NotSupportedException (
406
417
"ARM compiler 5 support is required for ARM build"
407
418
)
@@ -413,6 +424,7 @@ def __init__(
413
424
"ARM/uARM compiler support is required for ARM build"
414
425
)
415
426
427
+
416
428
class ARM_MICRO (ARM ):
417
429
418
430
PATCHED_LIBRARY = False
@@ -434,7 +446,7 @@ def __init__(
434
446
# At this point we already know that we want to use ARMC5+Microlib
435
447
# so check for if they are supported For, AC6+Microlib we still
436
448
# use ARMC6 class
437
- if not set (("ARMC5" ,"uARM" )).issubset (set (
449
+ if not set (("ARMC5" , "uARM" )).issubset (set (
438
450
target .supported_toolchains
439
451
)):
440
452
raise NotSupportedException (
@@ -469,6 +481,10 @@ class ARMC6(ARM_STD):
469
481
"Cortex-A9"
470
482
]
471
483
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>.+)' )
472
488
473
489
@staticmethod
474
490
def check_executable ():
@@ -586,9 +602,9 @@ def __init__(self, target, *args, **kwargs):
586
602
self .ar = join (TOOLCHAIN_PATHS ["ARMC6" ], "armar" )
587
603
self .elf2bin = join (TOOLCHAIN_PATHS ["ARMC6" ], "fromelf" )
588
604
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.
592
608
self .product_name = None
593
609
594
610
def _get_toolchain_labels (self ):
@@ -608,7 +624,58 @@ def is_not_supported_error(self, output):
608
624
return "#error [NOT_SUPPORTED]" in output
609
625
610
626
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 )
612
679
613
680
def get_config_option (self , config_header ):
614
681
return ["-include" , config_header ]
@@ -660,7 +727,14 @@ def compile(self, cc, source, object, includes):
660
727
cmd .extend (["-o" , object , source ])
661
728
return [cmd ]
662
729
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
+ ):
664
738
cmd = ARM .get_link_command (
665
739
self , output , objects , libraries , lib_dirs , scatter_file
666
740
)
0 commit comments