@@ -125,6 +125,9 @@ class Target(namedtuple("Target", "name json_data resolution_order resolution_or
125
125
# Current/new location of the 'targets.json' file
126
126
__targets_json_location = None
127
127
128
+ # Extra custom targets files
129
+ __extra_target_json_files = []
130
+
128
131
@staticmethod
129
132
def _merge_dict (dct , merge_dct ):
130
133
""" Recursive dict merge. Inspired by `dict.update()` however instead of
@@ -148,13 +151,18 @@ def get_json_target_data():
148
151
"""Load the description of JSON target data"""
149
152
targets = json_file_to_dict (Target .__targets_json_location or
150
153
Target .__targets_json_location_default )
154
+
155
+ for extra_target in Target .__extra_target_json_files :
156
+ Target ._merge_dict (targets , json_file_to_dict (extra_target ))
157
+
151
158
return targets
152
159
153
160
@staticmethod
154
- @cached
155
- def add_extra_targets (extra ):
156
- if os .path .exists (extra ):
157
- Target ._merge_dict (targets , json_file_to_dict (extra ))
161
+ def add_extra_targets (source_dir ):
162
+ extra_targets_file = os .path .join (source_dir , "custom_targets.json" )
163
+ if os .path .exists (extra_targets_file ):
164
+ Target .__extra_target_json_files .append (extra_targets_file )
165
+ CACHES .clear ()
158
166
159
167
@staticmethod
160
168
def set_targets_json_location (location = None ):
@@ -531,14 +539,20 @@ def binary_hook(t_self, resources, elf, binf):
531
539
################################################################################
532
540
533
541
# Instantiate all public targets
534
- TARGETS = [Target .get_target (name ) for name , value
535
- in Target .get_json_target_data ().items ()
536
- if value .get ("public" , True )]
542
+ def update_target_data ():
543
+ TARGETS [:] = [Target .get_target (tgt ) for tgt , obj
544
+ in Target .get_json_target_data ().items ()
545
+ if obj .get ("public" , True )]
546
+ # Map each target name to its unique instance
547
+ TARGET_MAP .clear ()
548
+ TARGET_MAP .update (dict ([(tgt .name , tgt ) for tgt in TARGETS ]))
549
+ TARGET_NAMES [:] = TARGET_MAP .keys ()
537
550
538
- # Map each target name to its unique instance
539
- TARGET_MAP = dict ([(t .name , t ) for t in TARGETS ])
551
+ TARGETS = []
552
+ TARGET_MAP = dict ()
553
+ TARGET_NAMES = []
540
554
541
- TARGET_NAMES = TARGET_MAP . keys ()
555
+ update_target_data ()
542
556
543
557
# Some targets with different name have the same exporters
544
558
EXPORT_MAP = {}
@@ -563,10 +577,3 @@ def set_targets_json_location(location=None):
563
577
# "from tools.targets import TARGET_NAMES"
564
578
update_target_data ()
565
579
566
- def update_target_data ():
567
- TARGETS [:] = [Target .get_target (tgt ) for tgt , obj
568
- in Target .get_json_target_data ().items ()
569
- if obj .get ("public" , True )]
570
- TARGET_MAP .clear ()
571
- TARGET_MAP .update (dict ([(tgt .name , tgt ) for tgt in TARGETS ]))
572
- TARGET_NAMES [:] = TARGET_MAP .keys ()
0 commit comments