Allow ARMC6 to run post-binary-hooks marked for ARM

pull/5091/head
Jimmy Brisson 2017-09-13 11:08:03 -05:00
parent 7b428916f5
commit 58372d3fdf
3 changed files with 14 additions and 9 deletions

View File

@ -65,7 +65,7 @@ class Hook(object):
_HOOKS.clear() _HOOKS.clear()
self._cmdline_hooks = {} self._cmdline_hooks = {}
self.toolchain = toolchain self.toolchain = toolchain
target.init_hooks(self, toolchain.__class__.__name__) target.init_hooks(self, toolchain)
# Hook various functions directly # Hook various functions directly
@staticmethod @staticmethod

View File

@ -22,6 +22,7 @@ import shutil
import inspect import inspect
import sys import sys
from copy import copy from copy import copy
from inspect import getmro
from collections import namedtuple, Mapping from collections import namedtuple, Mapping
from tools.targets.LPC import patch from tools.targets.LPC import patch
from tools.paths import TOOLS_BOOTLOADERS from tools.paths import TOOLS_BOOTLOADERS
@ -310,10 +311,14 @@ class Target(namedtuple("Target", "name json_data resolution_order resolution_or
labels.append("UVISOR_UNSUPPORTED") labels.append("UVISOR_UNSUPPORTED")
return labels return labels
def init_hooks(self, hook, toolchain_name): def init_hooks(self, hook, toolchain):
"""Initialize the post-build hooks for a toolchain. For now, this """Initialize the post-build hooks for a toolchain. For now, this
function only allows "post binary" hooks (hooks that are executed function only allows "post binary" hooks (hooks that are executed
after the binary image is extracted from the executable file) after the binary image is extracted from the executable file)
Positional Arguments:
hook - the hook object to add post-binary-hooks to
toolchain - the toolchain object for inspection
""" """
# If there's no hook, simply return # If there's no hook, simply return
@ -329,7 +334,7 @@ class Target(namedtuple("Target", "name json_data resolution_order resolution_or
("Invalid format for hook '%s' in target '%s'" ("Invalid format for hook '%s' in target '%s'"
% (hook_data["function"], self.name)) + % (hook_data["function"], self.name)) +
" (must be 'class_name.function_name')") " (must be 'class_name.function_name')")
class_name, function_name = temp[0], temp[1] class_name, function_name = temp
# "class_name" must refer to a class in this file, so check if the # "class_name" must refer to a class in this file, so check if the
# class exists # class exists
mdata = self.get_module_data() mdata = self.get_module_data()
@ -349,10 +354,11 @@ class Target(namedtuple("Target", "name json_data resolution_order resolution_or
("required by '%s' " % hook_data["function"]) + ("required by '%s' " % hook_data["function"]) +
("in target '%s' " % self.name) + ("in target '%s' " % self.name) +
("not found in class '%s'" % class_name)) ("not found in class '%s'" % class_name))
# Check if the hook specification also has target restrictions # Check if the hook specification also has toolchain restrictions
toolchain_restrictions = hook_data.get("toolchains", []) toolchain_restrictions = set(hook_data.get("toolchains", []))
toolchain_labels = set(c.__name__ for c in getmro(toolchain.__class__))
if toolchain_restrictions and \ if toolchain_restrictions and \
(toolchain_name not in toolchain_restrictions): not toolchain_labels.intersection(toolchain_restrictions):
return return
# Finally, hook the requested function # Finally, hook the requested function
hook.hook_add_binary("post", getattr(cls, function_name)) hook.hook_add_binary("post", getattr(cls, function_name))

View File

@ -26,7 +26,6 @@ from os.path import join, splitext, exists, relpath, dirname, basename, split, a
from itertools import chain from itertools import chain
from inspect import getmro from inspect import getmro
from copy import deepcopy from copy import deepcopy
from tools.config import Config
from abc import ABCMeta, abstractmethod from abc import ABCMeta, abstractmethod
from distutils.spawn import find_executable from distutils.spawn import find_executable
@ -1257,7 +1256,7 @@ class mbedToolchain:
else: else:
prev_data = None prev_data = None
# Get the current configuration data # Get the current configuration data
crt_data = Config.config_to_header(self.config_data) if self.config_data else None crt_data = self.config.config_to_header(self.config_data) if self.config_data else None
# "changed" indicates if a configuration change was detected # "changed" indicates if a configuration change was detected
changed = False changed = False
if prev_data is not None: # a previous mbed_config.h exists if prev_data is not None: # a previous mbed_config.h exists
@ -1553,7 +1552,7 @@ class mbedToolchain:
# Return the list of macros geenrated by the build system # Return the list of macros geenrated by the build system
def get_config_macros(self): def get_config_macros(self):
return Config.config_to_macros(self.config_data) if self.config_data else [] return self.config.config_to_macros(self.config_data) if self.config_data else []
@property @property
def report(self): def report(self):