2121
2222from tools .targets import CORE_ARCH
2323from tools .toolchains .mbed_toolchain import mbedToolchain , TOOLCHAIN_PATHS
24- from tools .utils import run_cmd , NotSupportedException
24+ from tools .utils import run_cmd
25+
2526
2627class IAR (mbedToolchain ):
2728 OFFICIALLY_SUPPORTED = True
@@ -30,20 +31,29 @@ class IAR(mbedToolchain):
3031 STD_LIB_NAME = "%s.a"
3132
3233 DIAGNOSTIC_PATTERN = re .compile ('"(?P<file>[^"]+)",(?P<line>[\d]+)\s+(?P<severity>Warning|Error|Fatal error)(?P<message>.+)' )
33- INDEX_PATTERN = re .compile ('(?P<col>\s*)\^' )
34+ INDEX_PATTERN = re .compile ('(?P<col>\s*)\^' )
3435 IAR_VERSION_RE = re .compile (b"IAR ANSI C/C\+\+ Compiler V(\d+\.\d+)" )
3536 IAR_VERSION = LooseVersion ("8.32" )
3637
3738 @staticmethod
3839 def check_executable ():
3940 """Returns True if the executable (arm-none-eabi-gcc) location
40- specified by the user exists OR the executable can be found on the PATH.
41- Returns False otherwise."""
42- return mbedToolchain .generic_check_executable ("IAR" , 'iccarm' , 2 , "bin" )
41+ specified by the user exists OR the executable can be found on the
42+ PATH. Returns False otherwise."""
43+ return mbedToolchain .generic_check_executable (
44+ "IAR" , 'iccarm' , 2 , "bin"
45+ )
4346
4447 def __init__ (self , target , notify = None , macros = None , build_profile = None ,
4548 build_dir = None ):
46- mbedToolchain .__init__ (self , target , notify , macros , build_dir = build_dir , build_profile = build_profile )
49+ mbedToolchain .__init__ (
50+ self ,
51+ target ,
52+ notify ,
53+ macros ,
54+ build_dir = build_dir ,
55+ build_profile = build_profile
56+ )
4757 core = target .core
4858 if CORE_ARCH [target .core ] == 8 :
4959 # Add linking time preprocessor macro DOMAIN_NS
@@ -65,8 +75,8 @@ def __init__(self, target, notify=None, macros=None, build_profile=None,
6575 "Cortex-M33F" : "Cortex-M33.fp.no_dsp" ,
6676 "Cortex-M33FE" : "Cortex-M33.fp" }.get (core , core )
6777
68- # flags_cmd are used only by our scripts, the project files have them already defined,
69- # using this flags results in the errors (duplication)
78+ # flags_cmd are used only by our scripts, the project files have them
79+ # already defined, using this flags results in the errors (duplication)
7080 # asm accepts --cpu Core or --fpu FPU, not like c/c++ --cpu=Core
7181 asm_flags_cmd = ["--cpu" , cpu ]
7282 # custom c flags
@@ -83,13 +93,22 @@ def __init__(self, target, notify=None, macros=None, build_profile=None,
8393 IAR_BIN = join (TOOLCHAIN_PATHS ['IAR' ], "bin" )
8494 main_cc = join (IAR_BIN , "iccarm" )
8595
86- self .asm = [join (IAR_BIN , "iasmarm" )] + asm_flags_cmd + self .flags ["asm" ]
87- self .cc = [main_cc ]
96+ self .asm = [join (IAR_BIN , "iasmarm" )]
97+ self .asm += asm_flags_cmd
98+ self .asm += self .flags ["asm" ]
99+
100+ self .cc = [main_cc ]
101+ self .cc += self .flags ["common" ]
102+ self .cc += c_flags_cmd
103+ self .cc += self .flags ["c" ]
104+
88105 self .cppc = [main_cc ]
89- self .cc += self .flags ["common" ] + c_flags_cmd + self .flags ["c" ]
90- self .cppc += self .flags ["common" ] + c_flags_cmd + cxx_flags_cmd + self .flags ["cxx" ]
91-
92- self .ld = [join (IAR_BIN , "ilinkarm" )] + self .flags ['ld' ]
106+ self .cppc += self .flags ["common" ]
107+ self .cppc += c_flags_cmd
108+ self .cppc += cxx_flags_cmd
109+ self .cppc += self .flags ["cxx" ]
110+
111+ self .ld = [join (IAR_BIN , "ilinkarm" )] + self .flags ['ld' ]
93112 self .ar = join (IAR_BIN , "iarchive" )
94113 self .elf2bin = join (IAR_BIN , "ielftool" )
95114
@@ -113,10 +132,16 @@ def version_check(self):
113132 "severity" : "Warning" ,
114133 })
115134
135+ def _inner_parse_deps (self , dep_path ):
136+ for path in open (dep_path ).readlines ():
137+ if path and not path .isspace ():
138+ if self .CHROOT :
139+ yield self .CHROOT + path .strip ()
140+ else :
141+ yield path .strip ()
116142
117143 def parse_dependencies (self , dep_path ):
118- return [(self .CHROOT if self .CHROOT else '' )+ path .strip () for path in open (dep_path ).readlines ()
119- if (path and not path .isspace ())]
144+ return list (self ._inner_parse_deps (dep_path ))
120145
121146 def parse_output (self , output ):
122147 msg = None
@@ -137,7 +162,8 @@ def parse_output(self, output):
137162 'toolchain_name' : self .name
138163 }
139164 elif msg is not None :
140- # Determine the warning/error column by calculating the ^ position
165+ # Determine the warning/error column by calculating the '^'
166+ # position
141167 match = IAR .INDEX_PATTERN .match (line )
142168 if match is not None :
143169 msg ['col' ] = len (match .group ('col' ))
@@ -165,7 +191,7 @@ def get_compile_options(self, defines, includes, for_asm=False):
165191 opts = ['-D%s' % d for d in defines ]
166192 if for_asm :
167193 config_macros = self .config .get_config_data_macros ()
168- macros_cmd = ['"-D%s"' % d for d in config_macros if not '"' in d ]
194+ macros_cmd = ['"-D%s"' % d for d in config_macros if '"' not in d ]
169195 if self .RESPONSE_FILES :
170196 via_file = self .make_option_file (
171197 macros_cmd , "asm_macros_{}.xcl" )
@@ -186,21 +212,19 @@ def get_compile_options(self, defines, includes, for_asm=False):
186212
187213 def assemble (self , source , object , includes ):
188214 # Build assemble command
189- cmd = self .asm + self .get_compile_options (self .get_symbols (True ), includes , True ) + ["-o" , object , source ]
215+ cmd = self .asm + self .get_compile_options (
216+ self .get_symbols (True ), includes , True
217+ ) + ["-o" , object , source ]
190218
191219 # Return command array, don't execute
192220 return [cmd ]
193221
194222 def compile (self , cc , source , object , includes ):
195223 # Build compile command
196- cmd = cc + self .get_compile_options (self .get_symbols (), includes )
197-
224+ cmd = cc + self .get_compile_options (self .get_symbols (), includes )
198225 cmd .extend (self .get_dep_option (object ))
199-
200226 cmd .extend (self .cc_extra (object ))
201-
202227 cmd .extend (["-o" , object , source ])
203-
204228 return [cmd ]
205229
206230 def compile_c (self , source , object , includes ):
@@ -212,7 +236,9 @@ def compile_cpp(self, source, object, includes):
212236 def link (self , output , objects , libraries , lib_dirs , mem_map ):
213237 # Build linker command
214238 map_file = splitext (output )[0 ] + ".map"
215- cmd = self .ld + [ "-o" , output , "--map=%s" % map_file ] + objects + libraries
239+ cmd = self .ld + ["-o" , output , "--map=%s" % map_file ]
240+ cmd += objects
241+ cmd += libraries
216242
217243 if mem_map :
218244 cmd .extend (["--config" , mem_map ])
0 commit comments