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,21 @@ 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
+ True if the string contains [a-z], else False
56
+ """
57
+ regexp = re .compile (r'[a-z]' , re .IGNORECASE )
58
+ if regexp .search (line ):
59
+ return True
60
+ else :
61
+ return False
62
+
48
63
def main (file ):
49
64
file_h = open (file , 'r+' )
50
65
file = file_h .read ()
@@ -69,7 +84,44 @@ def main(file):
69
84
lib = blocks [i ].split ('Name: ' )[1 ].split ('.' )[0 ]
70
85
print ("================= %s =================" % lib )
71
86
out = str (subprocess .check_output (["mbed" , "compile" , "--config" , "-v" , "--prefix" , lib ]))
72
- file = file [:start + 4 ] + out [:out .index ("Macros" ) - 1 ] + file [end :]
87
+
88
+ # Some APIs break config optioins into logical blocks in their config files.
89
+ # If a tag is applied to a parameter block, only display parameter names that contains that tag
90
+ # For example:
91
+ # ```heap
92
+ # mbed-mesh-api.heap-size
93
+ # ...
94
+ # mbed-mesh-api.heap-stat-info
95
+ # ..
96
+ # ......
97
+ # ```
98
+ #
99
+ # On encountering a block with tag, collect the common parameter token
100
+ # and split the configuration list output into its components.
101
+ # Collect tag (if present), split <TAG> from ```<TAG> at current index
102
+ # Check with regex for string to cover for potential trailing whitespaces
103
+ tag = file [start : file .find ('\n ' , start )].split ('`' )[- 1 ]
104
+ if is_string (tag ):
105
+ print ("\t ------- Tag: %s -------" % tag )
106
+
107
+ start_of_config_block = file .find ('Name:' , start )
108
+ updated_config = str (file [ : start_of_config_block ]) # + "Configuration parameters\n------------------------\n")
109
+ for line in out .splitlines ():
110
+ if 'Name' in line and tag in line :
111
+ updated_config += line
112
+
113
+ # Collect all text until next parameter name. If there's no following 'Name:' token, its the last
114
+ # config option, match to 'Macros' instead to termiante the block
115
+ if out .find ('Name:' , out .find (line ) + 4 ) > 0 :
116
+ updated_config += out [out .find ('\n ' , out .find (line )) : out .find ('Name:' , out .find (line ) + 4 )]
117
+ else :
118
+ updated_config += out [out .find ('\n ' , out .find (line )) : out .find ('Macros' , out .find (line ) + 4 )]
119
+
120
+ updated_config += str (file [end :])
121
+ else :
122
+ updated_config = str (file [:start + 4 ] + out [:out .index ("Macros" ) - 1 ] + file [end :])
123
+
124
+ file = updated_config
73
125
74
126
# Originally added for debugging purposes, catch and display exceptions before
75
127
# continuing without exiting to provide a complete list of errors found
0 commit comments