20
20
from tools .toolchains import mbedToolchain , TOOLCHAIN_PATHS
21
21
from tools .hooks import hook_tool
22
22
23
+
23
24
class GCC (mbedToolchain ):
24
25
LINKER_EXT = '.ld'
25
26
LIBRARY_EXT = '.a'
@@ -34,7 +35,7 @@ class GCC(mbedToolchain):
34
35
35
36
def __init__ (self , target , notify = None , macros = None ,
36
37
silent = False , tool_path = "" , extra_verbose = False ,
37
- build_profile = None , coverage_filter = None ):
38
+ build_profile = None , coverage_filter = [] ):
38
39
mbedToolchain .__init__ (self , target , notify , macros , silent ,
39
40
extra_verbose = extra_verbose ,
40
41
build_profile = build_profile )
@@ -90,6 +91,10 @@ def __init__(self, target, notify=None, macros=None,
90
91
91
92
self .flags ["common" ] += self .cpu
92
93
94
+ if self .coverage_filter :
95
+ self .flags ["common" ].append ("-g" )
96
+ self .flags ["common" ].append ("-O0" )
97
+
93
98
main_cc = join (tool_path , "arm-none-eabi-gcc" )
94
99
main_cppc = join (tool_path , "arm-none-eabi-g++" )
95
100
self .asm = [main_cc ] + self .flags ['asm' ] + self .flags ["common" ]
@@ -185,7 +190,7 @@ def get_compile_options(self, defines, includes, for_asm=False):
185
190
@hook_tool
186
191
def assemble (self , source , object , includes ):
187
192
# Build assemble command
188
- if self .coverage_filter and re . search ( self . coverage_filter , source ):
193
+ if self .check_if_coverage_enabled ( source ):
189
194
cmd = self .asm + self .COVERAGE_COMPILE_FLAGS + self .get_compile_options (self .get_symbols (True ), includes ) + ["-o" , object , source ]
190
195
else :
191
196
cmd = self .asm + self .get_compile_options (self .get_symbols (True ), includes ) + ["-o" , object , source ]
@@ -199,7 +204,7 @@ def assemble(self, source, object, includes):
199
204
@hook_tool
200
205
def compile (self , cc , source , object , includes ):
201
206
# Build compile command
202
- if self .coverage_filter and re . search ( self . coverage_filter , source ):
207
+ if self .check_if_coverage_enabled ( source ):
203
208
cmd = cc + self .COVERAGE_COMPILE_FLAGS + self .get_compile_options (self .get_symbols (), includes )
204
209
else :
205
210
cmd = cc + self .get_compile_options (self .get_symbols (), includes )
@@ -276,6 +281,18 @@ def binary(self, resources, elf, bin):
276
281
self .cc_verbose ("FromELF: %s" % ' ' .join (cmd ))
277
282
self .default_cmd (cmd )
278
283
284
+ def check_if_coverage_enabled (self , src_path ):
285
+ """
286
+ Checks if coverage is enabled on the source path.
287
+
288
+ :param src_path:
289
+ :return:
290
+ """
291
+ for exp in self .coverage_filter :
292
+ if re .search (exp , src_path ):
293
+ return True
294
+ return False
295
+
279
296
280
297
class GCC_ARM (GCC ):
281
298
@staticmethod
@@ -286,7 +303,7 @@ def check_executable():
286
303
return mbedToolchain .generic_check_executable ("GCC_ARM" , 'arm-none-eabi-gcc' , 1 )
287
304
288
305
def __init__ (self , target , notify = None , macros = None ,
289
- silent = False , extra_verbose = False , build_profile = None , coverage_filter = None ):
306
+ silent = False , extra_verbose = False , build_profile = None , coverage_filter = [] ):
290
307
GCC .__init__ (self , target , notify , macros , silent ,
291
308
TOOLCHAIN_PATHS ['GCC_ARM' ], extra_verbose = extra_verbose ,
292
309
build_profile = build_profile , coverage_filter = coverage_filter )
0 commit comments