Skip to content

Commit aeeb43f

Browse files
committed
Simplify hook tool implementation
The "hook tools" were capable of hooking into many commands run by the build system. To my knowlage, the only hook is the "post-build-hook". The post build hook could be easier to reason about if the implementation is specialized for just post-build hooking. This commit make it much easier to point out where post build hooks are called by making the call explicit.
1 parent 355f09b commit aeeb43f

File tree

6 files changed

+7
-282
lines changed

6 files changed

+7
-282
lines changed

tools/hooks.py

Lines changed: 0 additions & 214 deletions
This file was deleted.

tools/targets/__init__.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -355,7 +355,7 @@ def is_PSA_secure_target(self):
355355
def is_PSA_non_secure_target(self):
356356
return 'NSPE_Target' in self.labels
357357

358-
def init_hooks(self, hook, toolchain):
358+
def get_post_build_hook(self, toolchain):
359359
"""Initialize the post-build hooks for a toolchain. For now, this
360360
function only allows "post binary" hooks (hooks that are executed
361361
after the binary image is extracted from the executable file)
@@ -404,8 +404,7 @@ def init_hooks(self, hook, toolchain):
404404
if toolchain_restrictions and \
405405
not toolchain_labels.intersection(toolchain_restrictions):
406406
return
407-
# Finally, hook the requested function
408-
hook.hook_add_binary("post", getattr(cls, function_name))
407+
return getattr(cls, function_name)
409408

410409
################################################################################
411410
# Target specific code goes in this section

tools/toolchains/__init__.py

Lines changed: 4 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@
3636
from ..utils import (run_cmd, mkdir, rel_path, ToolException,
3737
NotSupportedException, split_path, compile_worker)
3838
from ..settings import MBED_ORG_USER, PRINT_COMPILER_OUTPUT_AS_LINK
39-
from .. import hooks
4039
from ..notifier.term import TerminalNotifier
4140
from ..resources import FileType
4241
from ..memap import MemapParser
@@ -96,7 +95,7 @@ def __init__(self, target, notify=None, macros=None, build_profile=None,
9695
self.name = self.__class__.__name__
9796

9897
# compile/assemble/link/binary hooks
99-
self.hook = hooks.Hook(target, self)
98+
self._post_build_hook = target.get_post_build_hook(self.name)
10099

101100
# Toolchain flags
102101
self.flags = deepcopy(build_profile or self.profile_template)
@@ -653,6 +652,9 @@ def link_program(self, r, tmp_path, name):
653652
self.progress("elf2bin", name)
654653
self.binary(r, elf, bin)
655654

655+
if self._post_build_hook:
656+
self.progress("post-build", name)
657+
self._post_build_hook(self, r, elf, bin)
656658
# Initialize memap and process map file. This doesn't generate output.
657659
self.mem_stats(mapfile)
658660

@@ -1002,9 +1004,6 @@ def assemble(self, source, object, includes):
10021004
10031005
Side effects:
10041006
None
1005-
1006-
Note:
1007-
This method should be decorated with @hook_tool.
10081007
"""
10091008
raise NotImplemented
10101009

@@ -1024,9 +1023,6 @@ def compile_c(self, source, object, includes):
10241023
10251024
Side effects:
10261025
None
1027-
1028-
Note:
1029-
This method should be decorated with @hook_tool.
10301026
"""
10311027
raise NotImplemented
10321028

@@ -1046,9 +1042,6 @@ def compile_cpp(self, source, object, includes):
10461042
10471043
Side effects:
10481044
None
1049-
1050-
Note:
1051-
This method should be decorated with @hook_tool.
10521045
"""
10531046
raise NotImplemented
10541047

@@ -1068,9 +1061,6 @@ def link(self, output, objects, libraries, lib_dirs, mem_map):
10681061
10691062
Side effect:
10701063
Runs the linker to produce the executable.
1071-
1072-
Note:
1073-
This method should be decorated with @hook_tool.
10741064
"""
10751065
raise NotImplemented
10761066

@@ -1087,9 +1077,6 @@ def archive(self, objects, lib_path):
10871077
10881078
Side effect:
10891079
Runs the archiving tool to produce the library file.
1090-
1091-
Note:
1092-
This method should be decorated with @hook_tool.
10931080
"""
10941081
raise NotImplemented
10951082

@@ -1107,9 +1094,6 @@ def binary(self, resources, elf, bin):
11071094
11081095
Side effect:
11091096
Runs the elf2bin tool to produce the simplified binary file.
1110-
1111-
Note:
1112-
This method should be decorated with @hook_tool.
11131097
"""
11141098
raise NotImplemented
11151099

0 commit comments

Comments
 (0)