21
21
# By default, when run from the check_tools directory, the script runs
22
22
# through each Markdown file in `docs/reference/configuration/`. An
23
23
# optional file or directory path may be passed in a parameter to run the
24
- # script on a specific file or directroy outside the default path.
24
+ # script on a specific file or directroy outside the default path.
25
25
#
26
26
# Note that you need to run this with a local copy of whichever version of
27
27
# Mbed OS you wish to update the configuration parameters with.
@@ -45,6 +45,18 @@ def split_into_pairs(l):
45
45
for i in range (0 , len (l ), 2 ):
46
46
yield l [i :i + 2 ]
47
47
48
+ def is_string (line ):
49
+ """ Determine if the provided string contains
50
+ alphabetical characters (case insensitive)
51
+ Args:
52
+ line - string to scan
53
+
54
+ Returns:
55
+ Match object if the string contains [a-z], else None
56
+ """
57
+ regexp = re .compile (r'[a-z]' , re .IGNORECASE )
58
+ return regexp .search (line )
59
+
48
60
def main (file ):
49
61
file_h = open (file , 'r+' )
50
62
file = file_h .read ()
@@ -69,7 +81,46 @@ def main(file):
69
81
lib = blocks [i ].split ('Name: ' )[1 ].split ('.' )[0 ]
70
82
print ("================= %s =================" % lib )
71
83
out = str (subprocess .check_output (["mbed" , "compile" , "--config" , "-v" , "--prefix" , lib ]))
72
- file = file [:start + 4 ] + out [:out .index ("Macros" ) - 1 ] + file [end :]
84
+
85
+ # Some APIs break config options into logical blocks in their config files.
86
+ # If a tag is applied to a parameter block, only display parameter names that contain that tag
87
+ # For example:
88
+ # ```heap
89
+ # mbed-mesh-api.heap-size
90
+ # ...
91
+ # mbed-mesh-api.heap-stat-info
92
+ # ..
93
+ # ......
94
+ # ```
95
+ #
96
+ # On encountering a block with a tag, collect the common parameter token,
97
+ # and split the configuration list output into its components.
98
+ # Collect tag (if present), split <TAG> from ```<TAG> at current index
99
+ # Check with regex for string to cover for potential trailing whitespaces
100
+ tag = file [start : file .find ('\n ' , start )].split ('`' )[- 1 ]
101
+ if is_string (tag ):
102
+ print ("\t ------- Tag: %s -------" % tag )
103
+
104
+ start_of_config_block = file .find ('Name:' , start )
105
+ updated_config = str (file [ : start_of_config_block ])
106
+ for line in out .splitlines ():
107
+ if 'Name' in line and tag in line :
108
+ updated_config += line
109
+
110
+ # Collect all text until next parameter name. If there's no following 'Name:' token, its the last
111
+ # config option, match to 'Macros' instead to termiante the block. Offset starting index to avoid finding
112
+ # the current line's 'Name:' token.
113
+ eol = out .find ('\n ' , out .find (line ))
114
+ if out .find ('Name:' , out .find (line ) + len ('Name:' )) > 0 :
115
+ updated_config += out [eol : out .find ('Name:' , out .find (line ) + len ('Name:' ))]
116
+ else :
117
+ updated_config += out [eol : out .find ('Macros' , out .find (line ))]
118
+
119
+ updated_config += str (file [end :])
120
+ else :
121
+ updated_config = str (file [:start + 4 ] + out [:out .index ("Macros" ) - 1 ] + file [end :])
122
+
123
+ file = updated_config
73
124
74
125
# Originally added for debugging purposes, catch and display exceptions before
75
126
# continuing without exiting to provide a complete list of errors found
0 commit comments