mirror of https://github.com/ARMmbed/mbed-os.git
Prevent modifying existing targets.
A warning will be printed if it is attempted.pull/4103/head
parent
6bd55a16fe
commit
4491d2e3f7
|
@ -128,23 +128,6 @@ class Target(namedtuple("Target", "name json_data resolution_order resolution_or
|
||||||
# Extra custom targets files
|
# Extra custom targets files
|
||||||
__extra_target_json_files = []
|
__extra_target_json_files = []
|
||||||
|
|
||||||
@staticmethod
|
|
||||||
def _merge_dict(dct, merge_dct):
|
|
||||||
""" Recursive dict merge. Inspired by `dict.update()` however instead of
|
|
||||||
updating only top-level keys, dict_merge recurses down into dicts nested
|
|
||||||
to an arbitrary depth, updating keys.
|
|
||||||
The provided ``merge_dct`` is merged into ``dct`` in place.
|
|
||||||
:param dct: dict onto which the merge is executed
|
|
||||||
:param merge_dct: dct merged into dct
|
|
||||||
:return: None
|
|
||||||
"""
|
|
||||||
for k, v in merge_dct.iteritems():
|
|
||||||
if (k in dct and isinstance(dct[k], dict)
|
|
||||||
and isinstance(merge_dct[k], Mapping)):
|
|
||||||
Target._merge_dict(dct[k], merge_dct[k])
|
|
||||||
else:
|
|
||||||
dct[k] = merge_dct[k]
|
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
@cached
|
@cached
|
||||||
def get_json_target_data():
|
def get_json_target_data():
|
||||||
|
@ -153,7 +136,11 @@ class Target(namedtuple("Target", "name json_data resolution_order resolution_or
|
||||||
Target.__targets_json_location_default)
|
Target.__targets_json_location_default)
|
||||||
|
|
||||||
for extra_target in Target.__extra_target_json_files:
|
for extra_target in Target.__extra_target_json_files:
|
||||||
Target._merge_dict(targets, json_file_to_dict(extra_target))
|
for k, v in json_file_to_dict(extra_target).iteritems():
|
||||||
|
if k in targets:
|
||||||
|
print 'WARNING: Custom target "%s" cannot replace existing target.' % k
|
||||||
|
else:
|
||||||
|
targets[k] = v
|
||||||
|
|
||||||
return targets
|
return targets
|
||||||
|
|
||||||
|
|
|
@ -76,7 +76,7 @@ class TestTargets(unittest.TestCase):
|
||||||
assert TARGET_MAP['Test_Target'].core is None, \
|
assert TARGET_MAP['Test_Target'].core is None, \
|
||||||
"attributes should be inherited from Target"
|
"attributes should be inherited from Target"
|
||||||
|
|
||||||
def test_modify_default_target(self):
|
def test_modify_existing_target(self):
|
||||||
"""Set default targets file, then override base Target definition"""
|
"""Set default targets file, then override base Target definition"""
|
||||||
initial_target_json = """
|
initial_target_json = """
|
||||||
{
|
{
|
||||||
|
@ -132,8 +132,9 @@ class TestTargets(unittest.TestCase):
|
||||||
update_target_data()
|
update_target_data()
|
||||||
|
|
||||||
assert TARGET_MAP["Test_Target"].core == "Cortex-M4"
|
assert TARGET_MAP["Test_Target"].core == "Cortex-M4"
|
||||||
assert TARGET_MAP["Test_Target"].default_toolchain == 'GCC_ARM'
|
# The existing target should not be modified by custom targets
|
||||||
assert TARGET_MAP["Test_Target"].bootloader_supported == True
|
assert TARGET_MAP["Test_Target"].default_toolchain != 'GCC_ARM'
|
||||||
|
assert TARGET_MAP["Test_Target"].bootloader_supported != True
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
|
Loading…
Reference in New Issue