mirror of https://github.com/ARMmbed/mbed-os.git
Stylize and add function docs
parent
ae2268490f
commit
32966bbcbe
|
@ -10,11 +10,19 @@ from yaml import dump
|
||||||
from tools.targets import Target, set_targets_json_location, TARGET_MAP
|
from tools.targets import Target, set_targets_json_location, TARGET_MAP
|
||||||
|
|
||||||
def must_have_keys(keys, dict):
|
def must_have_keys(keys, dict):
|
||||||
|
"""Require keys in an MCU/Board
|
||||||
|
|
||||||
|
is a generator for errors
|
||||||
|
"""
|
||||||
for key in keys:
|
for key in keys:
|
||||||
if key not in dict:
|
if key not in dict:
|
||||||
yield "%s not found, and is required" % key
|
yield "%s not found, and is required" % key
|
||||||
|
|
||||||
def may_have_keys(keys, dict):
|
def may_have_keys(keys, dict):
|
||||||
|
"""Disable all other keys in an MCU/Board
|
||||||
|
|
||||||
|
is a generator for errors
|
||||||
|
"""
|
||||||
for key in dict.keys():
|
for key in dict.keys():
|
||||||
if key not in keys:
|
if key not in keys:
|
||||||
yield "%s found, and is not allowed" % key
|
yield "%s found, and is not allowed" % key
|
||||||
|
@ -22,9 +30,15 @@ def may_have_keys(keys, dict):
|
||||||
|
|
||||||
MCU_REQUIRED_KEYS = ["release_versions", "supported_toolchains",
|
MCU_REQUIRED_KEYS = ["release_versions", "supported_toolchains",
|
||||||
"default_lib", "public", "inherits"]
|
"default_lib", "public", "inherits"]
|
||||||
MCU_ALLOWED_KEYS = ["device_has", "core", "extra_labels", "features", "bootloader_supported", "device_name", "post_binary_hook", "default_toolchain"] + MCU_REQUIRED_KEYS
|
MCU_ALLOWED_KEYS = ["device_has", "core", "extra_labels", "features",
|
||||||
|
"bootloader_supported", "device_name", "post_binary_hook",
|
||||||
|
"default_toolchain"] + MCU_REQUIRED_KEYS
|
||||||
def check_mcu(mcu_json, strict=False):
|
def check_mcu(mcu_json, strict=False):
|
||||||
"""Generate a list of problems with an mcu"""
|
"""Generate a list of problems with an MCU
|
||||||
|
|
||||||
|
:param: mcu_json the MCU's dict to check
|
||||||
|
:param: strict enforce required keys
|
||||||
|
"""
|
||||||
if strict:
|
if strict:
|
||||||
for err in must_have_keys(MCU_REQUIRED_KEYS, mcu_json):
|
for err in must_have_keys(MCU_REQUIRED_KEYS, mcu_json):
|
||||||
yield err
|
yield err
|
||||||
|
@ -32,17 +46,24 @@ def check_mcu(mcu_json, strict=False):
|
||||||
yield err
|
yield err
|
||||||
if 'public' in mcu_json and mcu_json['public']:
|
if 'public' in mcu_json and mcu_json['public']:
|
||||||
yield "public must be false"
|
yield "public must be false"
|
||||||
if ("release_versions" in mcu_json and
|
if ("release_versions" in mcu_json and
|
||||||
"5" in mcu_json["release_versions"] and
|
"5" in mcu_json["release_versions"] and
|
||||||
"supported_toolchains" in mcu_json):
|
"supported_toolchains" in mcu_json):
|
||||||
for tc in ["GCC_ARM", "ARM", "IAR"]:
|
for toolc in ["GCC_ARM", "ARM", "IAR"]:
|
||||||
if tc not in mcu_json["supported_toolchains"]:
|
if toolc not in mcu_json["supported_toolchains"]:
|
||||||
yield ("%s not found in supported_toolchains, and is "
|
yield ("%s not found in supported_toolchains, and is "
|
||||||
"required by mbed OS 5" % tc)
|
"required by mbed OS 5" % toolc)
|
||||||
|
|
||||||
BOARD_REQUIRED_KEYS = ["inherits"]
|
BOARD_REQUIRED_KEYS = ["inherits"]
|
||||||
BOARD_ALLOWED_KEYS = ["supported_form_factors", "is_disk_virtual", "detect_code", "device_name", "extra_labels", "public"] + BOARD_REQUIRED_KEYS
|
BOARD_ALLOWED_KEYS = ["supported_form_factors", "is_disk_virtual",
|
||||||
|
"detect_code", "device_name", "extra_labels",
|
||||||
|
"public"] + BOARD_REQUIRED_KEYS
|
||||||
def check_board(board_json, strict=False):
|
def check_board(board_json, strict=False):
|
||||||
|
"""Generate a list of problems with an board
|
||||||
|
|
||||||
|
:param: board_json the mcus dict to check
|
||||||
|
:param: strict enforce required keys
|
||||||
|
"""
|
||||||
if strict:
|
if strict:
|
||||||
for err in must_have_keys(BOARD_REQUIRED_KEYS, board_json):
|
for err in must_have_keys(BOARD_REQUIRED_KEYS, board_json):
|
||||||
yield err
|
yield err
|
||||||
|
@ -51,10 +72,12 @@ def check_board(board_json, strict=False):
|
||||||
|
|
||||||
|
|
||||||
def add_if(dict, key, val):
|
def add_if(dict, key, val):
|
||||||
|
"""Add a value to a dict if it's non-empty"""
|
||||||
if val:
|
if val:
|
||||||
dict[key] = val
|
dict[key] = val
|
||||||
|
|
||||||
def _split_boards(resolution_order, tgt):
|
def _split_boards(resolution_order, tgt):
|
||||||
|
"""Split the resolution order between boards and mcus"""
|
||||||
mcus = []
|
mcus = []
|
||||||
boards = []
|
boards = []
|
||||||
iterable = iter(resolution_order)
|
iterable = iter(resolution_order)
|
||||||
|
@ -128,11 +151,13 @@ def check_hierarchy(tgt):
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
|
"""entry point"""
|
||||||
import argparse
|
import argparse
|
||||||
parser = argparse.ArgumentParser()
|
parser = argparse.ArgumentParser()
|
||||||
parser.add_argument("mcu", choices=TARGET_MAP.keys(), metavar="MCU")
|
parser.add_argument("mcu", choices=TARGET_MAP.keys(), metavar="MCU", )
|
||||||
options = parser.parse_args()
|
options = parser.parse_args()
|
||||||
print dump(check_hierarchy(TARGET_MAP[options.mcu]), default_flow_style=False)
|
print dump(check_hierarchy(TARGET_MAP[options.mcu]),
|
||||||
|
default_flow_style=False)
|
||||||
return 0
|
return 0
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
|
Loading…
Reference in New Issue