22
22
import inspect
23
23
import sys
24
24
from copy import copy
25
- from collections import namedtuple
25
+ from collections import namedtuple , Mapping
26
26
from tools .targets .LPC import patch
27
27
from tools .paths import TOOLS_BOOTLOADERS
28
28
from tools .utils import json_file_to_dict
@@ -125,6 +125,23 @@ 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
+ @staticmethod
129
+ def _merge_dict (dct , merge_dct ):
130
+ """ Recursive dict merge. Inspired by `dict.update()` however instead of
131
+ updating only top-level keys, dict_merge recurses down into dicts nested
132
+ to an arbitrary depth, updating keys.
133
+ The provided ``merge_dct`` is merged into ``dct`` in place.
134
+ :param dct: dict onto which the merge is executed
135
+ :param merge_dct: dct merged into dct
136
+ :return: None
137
+ """
138
+ for k , v in merge_dct .iteritems ():
139
+ if (k in dct and isinstance (dct [k ], dict )
140
+ and isinstance (merge_dct [k ], Mapping )):
141
+ Target ._merge_dict (dct [k ], merge_dct [k ])
142
+ else :
143
+ dct [k ] = merge_dct [k ]
144
+
128
145
@staticmethod
129
146
@cached
130
147
def get_json_target_data ():
@@ -135,7 +152,7 @@ def get_json_target_data():
135
152
# If extra_targets.json exists in working directory load it over the top
136
153
extra = os .path .join ('.' , 'extra_targets.json' )
137
154
if os .path .exists (extra ):
138
- targets . update ( json_file_to_dict (extra ))
155
+ Target . _merge_dict ( targets , json_file_to_dict (extra ))
139
156
140
157
return targets
141
158
0 commit comments