22
22
import inspect
23
23
import sys
24
24
from copy import copy
25
+ from inspect import getmro
25
26
from collections import namedtuple , Mapping
26
27
from tools .targets .LPC import patch
27
28
from tools .paths import TOOLS_BOOTLOADERS
@@ -310,10 +311,14 @@ def labels(self):
310
311
labels .append ("UVISOR_UNSUPPORTED" )
311
312
return labels
312
313
313
- def init_hooks (self , hook , toolchain_name ):
314
+ def init_hooks (self , hook , toolchain ):
314
315
"""Initialize the post-build hooks for a toolchain. For now, this
315
316
function only allows "post binary" hooks (hooks that are executed
316
317
after the binary image is extracted from the executable file)
318
+
319
+ Positional Arguments:
320
+ hook - the hook object to add post-binary-hooks to
321
+ toolchain - the toolchain object for inspection
317
322
"""
318
323
319
324
# If there's no hook, simply return
@@ -329,7 +334,7 @@ def init_hooks(self, hook, toolchain_name):
329
334
("Invalid format for hook '%s' in target '%s'"
330
335
% (hook_data ["function" ], self .name )) +
331
336
" (must be 'class_name.function_name')" )
332
- class_name , function_name = temp [ 0 ], temp [ 1 ]
337
+ class_name , function_name = temp
333
338
# "class_name" must refer to a class in this file, so check if the
334
339
# class exists
335
340
mdata = self .get_module_data ()
@@ -349,10 +354,11 @@ def init_hooks(self, hook, toolchain_name):
349
354
("required by '%s' " % hook_data ["function" ]) +
350
355
("in target '%s' " % self .name ) +
351
356
("not found in class '%s'" % class_name ))
352
- # Check if the hook specification also has target restrictions
353
- toolchain_restrictions = hook_data .get ("toolchains" , [])
357
+ # Check if the hook specification also has toolchain restrictions
358
+ toolchain_restrictions = set (hook_data .get ("toolchains" , []))
359
+ toolchain_labels = set (c .__name__ for c in getmro (toolchain .__class__ ))
354
360
if toolchain_restrictions and \
355
- ( toolchain_name not in toolchain_restrictions ):
361
+ not toolchain_labels . intersection ( toolchain_restrictions ):
356
362
return
357
363
# Finally, hook the requested function
358
364
hook .hook_add_binary ("post" , getattr (cls , function_name ))
0 commit comments