10
10
from tools .targets import Target , set_targets_json_location , TARGET_MAP
11
11
12
12
def must_have_keys (keys , dict ):
13
+ """Require keys in an MCU/Board
14
+
15
+ is a generator for errors
16
+ """
13
17
for key in keys :
14
18
if key not in dict :
15
19
yield "%s not found, and is required" % key
16
20
17
21
def may_have_keys (keys , dict ):
22
+ """Disable all other keys in an MCU/Board
23
+
24
+ is a generator for errors
25
+ """
18
26
for key in dict .keys ():
19
27
if key not in keys :
20
28
yield "%s found, and is not allowed" % key
21
29
22
30
23
31
MCU_REQUIRED_KEYS = ["release_versions" , "supported_toolchains" ,
24
32
"default_lib" , "public" , "inherits" ]
25
- MCU_ALLOWED_KEYS = ["device_has" , "core" , "extra_labels" , "features" , "bootloader_supported" , "device_name" , "post_binary_hook" , "default_toolchain" ] + MCU_REQUIRED_KEYS
33
+ MCU_ALLOWED_KEYS = ["device_has" , "core" , "extra_labels" , "features" ,
34
+ "bootloader_supported" , "device_name" , "post_binary_hook" ,
35
+ "default_toolchain" ] + MCU_REQUIRED_KEYS
26
36
def check_mcu (mcu_json , strict = False ):
27
- """Generate a list of problems with an mcu"""
37
+ """Generate a list of problems with an MCU
38
+
39
+ :param: mcu_json the MCU's dict to check
40
+ :param: strict enforce required keys
41
+ """
28
42
if strict :
29
43
for err in must_have_keys (MCU_REQUIRED_KEYS , mcu_json ):
30
44
yield err
31
45
for err in may_have_keys (MCU_ALLOWED_KEYS , mcu_json ):
32
46
yield err
33
47
if 'public' in mcu_json and mcu_json ['public' ]:
34
48
yield "public must be false"
35
- if ("release_versions" in mcu_json and
36
- "5" in mcu_json ["release_versions" ] and
37
- "supported_toolchains" in mcu_json ):
38
- for tc in ["GCC_ARM" , "ARM" , "IAR" ]:
39
- if tc not in mcu_json ["supported_toolchains" ]:
49
+ if ("release_versions" in mcu_json and
50
+ "5" in mcu_json ["release_versions" ] and
51
+ "supported_toolchains" in mcu_json ):
52
+ for toolc in ["GCC_ARM" , "ARM" , "IAR" ]:
53
+ if toolc not in mcu_json ["supported_toolchains" ]:
40
54
yield ("%s not found in supported_toolchains, and is "
41
- "required by mbed OS 5" % tc )
55
+ "required by mbed OS 5" % toolc )
42
56
43
57
BOARD_REQUIRED_KEYS = ["inherits" ]
44
- BOARD_ALLOWED_KEYS = ["supported_form_factors" , "is_disk_virtual" , "detect_code" , "device_name" , "extra_labels" , "public" ] + BOARD_REQUIRED_KEYS
58
+ BOARD_ALLOWED_KEYS = ["supported_form_factors" , "is_disk_virtual" ,
59
+ "detect_code" , "device_name" , "extra_labels" ,
60
+ "public" ] + BOARD_REQUIRED_KEYS
45
61
def check_board (board_json , strict = False ):
62
+ """Generate a list of problems with an board
63
+
64
+ :param: board_json the mcus dict to check
65
+ :param: strict enforce required keys
66
+ """
46
67
if strict :
47
68
for err in must_have_keys (BOARD_REQUIRED_KEYS , board_json ):
48
69
yield err
@@ -51,10 +72,12 @@ def check_board(board_json, strict=False):
51
72
52
73
53
74
def add_if (dict , key , val ):
75
+ """Add a value to a dict if it's non-empty"""
54
76
if val :
55
77
dict [key ] = val
56
78
57
79
def _split_boards (resolution_order , tgt ):
80
+ """Split the resolution order between boards and mcus"""
58
81
mcus = []
59
82
boards = []
60
83
iterable = iter (resolution_order )
@@ -128,11 +151,13 @@ def check_hierarchy(tgt):
128
151
129
152
130
153
def main ():
154
+ """entry point"""
131
155
import argparse
132
156
parser = argparse .ArgumentParser ()
133
- parser .add_argument ("mcu" , choices = TARGET_MAP .keys (), metavar = "MCU" )
157
+ parser .add_argument ("mcu" , choices = TARGET_MAP .keys (), metavar = "MCU" , )
134
158
options = parser .parse_args ()
135
- print dump (check_hierarchy (TARGET_MAP [options .mcu ]), default_flow_style = False )
159
+ print dump (check_hierarchy (TARGET_MAP [options .mcu ]),
160
+ default_flow_style = False )
136
161
return 0
137
162
138
163
if __name__ == "__main__" :
0 commit comments