Add post-build hook white-list to exporters

We have scripts (written in python) that are run after a binary image is
created in the tools. These scripts are not really exportable, as they
are part of the tools and may include and use any bits of python code
they please. So we don't export them. This patch disables export
combinations that would not work because the post-binary hook is not
exported. A white-list is used for forward compatibility.
pull/3875/head
Jimmy Brisson 2017-03-02 14:18:23 -06:00
parent 3a27568a50
commit fcef9a7c50
5 changed files with 42 additions and 25 deletions

View File

@ -16,14 +16,20 @@ limitations under the License.
"""
from os.path import splitext, basename
from tools.targets import TARGET_MAP
from tools.export.exporters import Exporter
from tools.export.exporters import Exporter, filter_supported
POST_BINARY_WHITELIST = set([
"TEENSY3_1Code.binary_hook"
])
class EmBitz(Exporter):
NAME = 'EmBitz'
TOOLCHAIN = 'GCC_ARM'
TARGETS = [target for target, obj in TARGET_MAP.iteritems()
if "GCC_ARM" in obj.supported_toolchains]
TARGETS = filter_supported("GCC_ARM", POST_BINARY_WHITELIST)
MBED_CONFIG_HEADER_SUPPORTED = True

View File

@ -176,3 +176,20 @@ class Exporter(object):
def generate(self):
"""Generate an IDE/tool specific project file"""
raise NotImplemented("Implement a generate function in Exporter child class")
def filter_supported(compiler, whitelist):
"""Generate a list of supported targets for a given compiler and post-binary hook
white-list."""
def supported_p(obj):
"""Internal inner function used for filtering"""
if compiler not in obj.supported_toolchains:
return False
if not hasattr(obj, "post_binary_hook"):
return True
if obj.post_binary_hook['function'] in whitelist:
return True
else:
return False
return list(target for target, obj in TARGET_MAP.iteritems()
if supported_p(obj))

View File

@ -33,7 +33,7 @@ from os.path import splitext, basename, relpath, dirname, exists, join, dirname
from random import randint
from json import load
from tools.export.exporters import Exporter
from tools.export.exporters import Exporter, filter_supported
from tools.options import list_profiles
from tools.targets import TARGET_MAP
from tools.utils import NotSupportedException
@ -58,13 +58,16 @@ u = UID()
# =============================================================================
POST_BINARY_WHITELIST = set([
"TEENSY3_1Code.binary_hook",
"MCU_NRF51Code.binary_hook",
])
class GNUARMEclipse(Exporter):
NAME = 'GNU ARM Eclipse'
TOOLCHAIN = 'GCC_ARM'
# Indirectly support all GCC_ARM targets.
TARGETS = [target for target, obj in TARGET_MAP.iteritems()
if 'GCC_ARM' in obj.supported_toolchains]
TARGETS = filter_supported("GCC_ARM", POST_BINARY_WHITELIST)
# override
@property

View File

@ -21,7 +21,7 @@ import sys
from subprocess import check_output, CalledProcessError, Popen, PIPE
import shutil
from jinja2.exceptions import TemplateNotFound
from tools.export.exporters import Exporter
from tools.export.exporters import Exporter, filter_supported
from tools.utils import NotSupportedException
from tools.targets import TARGET_MAP
@ -35,6 +35,11 @@ class Makefile(Exporter):
MBED_CONFIG_HEADER_SUPPORTED = True
POST_BINARY_WHITELIST = set([
"MCU_NRF51Code.binary_hook",
"TEENSY3_1Code.binary_hook"
])
def generate(self):
"""Generate the makefile
@ -168,8 +173,7 @@ class Makefile(Exporter):
class GccArm(Makefile):
"""GCC ARM specific makefile target"""
TARGETS = [target for target, obj in TARGET_MAP.iteritems()
if "GCC_ARM" in obj.supported_toolchains]
TARGETS = filter_supported("GCC_ARM", Makefile.POST_BINARY_WHITELIST)
NAME = 'Make-GCC-ARM'
TEMPLATE = 'make-gcc-arm'
TOOLCHAIN = "GCC_ARM"
@ -187,8 +191,7 @@ class GccArm(Makefile):
class Armc5(Makefile):
"""ARM Compiler 5 specific makefile target"""
TARGETS = [target for target, obj in TARGET_MAP.iteritems()
if "ARM" in obj.supported_toolchains]
TARGETS = filter_supported("ARM", Makefile.POST_BINARY_WHITELIST)
NAME = 'Make-ARMc5'
TEMPLATE = 'make-armc5'
TOOLCHAIN = "ARM"
@ -206,8 +209,7 @@ class Armc5(Makefile):
class IAR(Makefile):
"""IAR specific makefile target"""
TARGETS = [target for target, obj in TARGET_MAP.iteritems()
if "IAR" in obj.supported_toolchains]
TARGETS = filter_supported("IAR", Makefile.POST_BINARY_WHITELIST)
NAME = 'Make-IAR'
TEMPLATE = 'make-iar'
TOOLCHAIN = "IAR"

View File

@ -1,11 +0,0 @@
{% extends "makefile/make-gcc-arm.tmpl" %}
{% block target_project_elf %}
{{ super() }}
@echo ""
@echo "*****"
@echo "***** You must modify vector checksum value in *.bin and *.hex files."
@echo "*****"
@echo ""
{% endblock %}