Skip to content

Commit bc8e2ec

Browse files
authored
Merge pull request #3875 from theotherjimmy/export-postbuild-whitelist
Add post-build hook white-list to exporters
2 parents f39deb5 + fcef9a7 commit bc8e2ec

File tree

5 files changed

+42
-25
lines changed

5 files changed

+42
-25
lines changed

tools/export/embitz/__init__.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,20 @@
1616
"""
1717
from os.path import splitext, basename
1818
from tools.targets import TARGET_MAP
19-
from tools.export.exporters import Exporter
19+
from tools.export.exporters import Exporter, filter_supported
20+
21+
22+
POST_BINARY_WHITELIST = set([
23+
"TEENSY3_1Code.binary_hook"
24+
])
25+
2026

2127
class EmBitz(Exporter):
2228
NAME = 'EmBitz'
2329
TOOLCHAIN = 'GCC_ARM'
2430

25-
TARGETS = [target for target, obj in TARGET_MAP.iteritems()
26-
if "GCC_ARM" in obj.supported_toolchains]
31+
32+
TARGETS = filter_supported("GCC_ARM", POST_BINARY_WHITELIST)
2733

2834
MBED_CONFIG_HEADER_SUPPORTED = True
2935

tools/export/exporters.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,3 +176,20 @@ def build(project_name, log_name='build_log.txt', cleanup=True):
176176
def generate(self):
177177
"""Generate an IDE/tool specific project file"""
178178
raise NotImplemented("Implement a generate function in Exporter child class")
179+
180+
181+
def filter_supported(compiler, whitelist):
182+
"""Generate a list of supported targets for a given compiler and post-binary hook
183+
white-list."""
184+
def supported_p(obj):
185+
"""Internal inner function used for filtering"""
186+
if compiler not in obj.supported_toolchains:
187+
return False
188+
if not hasattr(obj, "post_binary_hook"):
189+
return True
190+
if obj.post_binary_hook['function'] in whitelist:
191+
return True
192+
else:
193+
return False
194+
return list(target for target, obj in TARGET_MAP.iteritems()
195+
if supported_p(obj))

tools/export/gnuarmeclipse/__init__.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
from random import randint
3434
from json import load
3535

36-
from tools.export.exporters import Exporter
36+
from tools.export.exporters import Exporter, filter_supported
3737
from tools.options import list_profiles
3838
from tools.targets import TARGET_MAP
3939
from tools.utils import NotSupportedException
@@ -58,13 +58,16 @@ def id(self):
5858
# =============================================================================
5959

6060

61+
POST_BINARY_WHITELIST = set([
62+
"TEENSY3_1Code.binary_hook",
63+
"MCU_NRF51Code.binary_hook",
64+
])
65+
6166
class GNUARMEclipse(Exporter):
6267
NAME = 'GNU ARM Eclipse'
6368
TOOLCHAIN = 'GCC_ARM'
6469

65-
# Indirectly support all GCC_ARM targets.
66-
TARGETS = [target for target, obj in TARGET_MAP.iteritems()
67-
if 'GCC_ARM' in obj.supported_toolchains]
70+
TARGETS = filter_supported("GCC_ARM", POST_BINARY_WHITELIST)
6871

6972
# override
7073
@property

tools/export/makefile/__init__.py

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
from subprocess import check_output, CalledProcessError, Popen, PIPE
2222
import shutil
2323
from jinja2.exceptions import TemplateNotFound
24-
from tools.export.exporters import Exporter
24+
from tools.export.exporters import Exporter, filter_supported
2525
from tools.utils import NotSupportedException
2626
from tools.targets import TARGET_MAP
2727

@@ -35,6 +35,11 @@ class Makefile(Exporter):
3535

3636
MBED_CONFIG_HEADER_SUPPORTED = True
3737

38+
POST_BINARY_WHITELIST = set([
39+
"MCU_NRF51Code.binary_hook",
40+
"TEENSY3_1Code.binary_hook"
41+
])
42+
3843
def generate(self):
3944
"""Generate the makefile
4045
@@ -168,8 +173,7 @@ def build(project_name, log_name="build_log.txt", cleanup=True):
168173

169174
class GccArm(Makefile):
170175
"""GCC ARM specific makefile target"""
171-
TARGETS = [target for target, obj in TARGET_MAP.iteritems()
172-
if "GCC_ARM" in obj.supported_toolchains]
176+
TARGETS = filter_supported("GCC_ARM", Makefile.POST_BINARY_WHITELIST)
173177
NAME = 'Make-GCC-ARM'
174178
TEMPLATE = 'make-gcc-arm'
175179
TOOLCHAIN = "GCC_ARM"
@@ -187,8 +191,7 @@ def prepare_sys_lib(libname):
187191

188192
class Armc5(Makefile):
189193
"""ARM Compiler 5 specific makefile target"""
190-
TARGETS = [target for target, obj in TARGET_MAP.iteritems()
191-
if "ARM" in obj.supported_toolchains]
194+
TARGETS = filter_supported("ARM", Makefile.POST_BINARY_WHITELIST)
192195
NAME = 'Make-ARMc5'
193196
TEMPLATE = 'make-armc5'
194197
TOOLCHAIN = "ARM"
@@ -206,8 +209,7 @@ def prepare_sys_lib(libname):
206209

207210
class IAR(Makefile):
208211
"""IAR specific makefile target"""
209-
TARGETS = [target for target, obj in TARGET_MAP.iteritems()
210-
if "IAR" in obj.supported_toolchains]
212+
TARGETS = filter_supported("IAR", Makefile.POST_BINARY_WHITELIST)
211213
NAME = 'Make-IAR'
212214
TEMPLATE = 'make-iar'
213215
TOOLCHAIN = "IAR"

tools/export/makefile/make-gcc-arm_nxp.tmpl

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

0 commit comments

Comments
 (0)