Skip to content

Commit 42c1909

Browse files
author
Amanda Butler
authored
Merge pull request #1007 from kegilbert/tag-based-configupdate
Add tag based configuration parameter splitting
2 parents de0d945 + e6be5fa commit 42c1909

File tree

1 file changed

+53
-2
lines changed

1 file changed

+53
-2
lines changed

check_tools/config-update.py

Lines changed: 53 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
# By default, when run from the check_tools directory, the script runs
2222
# through each Markdown file in `docs/reference/configuration/`. An
2323
# 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.
2525
#
2626
# Note that you need to run this with a local copy of whichever version of
2727
# Mbed OS you wish to update the configuration parameters with.
@@ -45,6 +45,18 @@ def split_into_pairs(l):
4545
for i in range(0, len(l), 2):
4646
yield l[i:i + 2]
4747

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+
4860
def main(file):
4961
file_h = open(file, 'r+')
5062
file = file_h.read()
@@ -69,7 +81,46 @@ def main(file):
6981
lib = blocks[i].split('Name: ')[1].split('.')[0]
7082
print("================= %s =================" % lib)
7183
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
73124

74125
# Originally added for debugging purposes, catch and display exceptions before
75126
# continuing without exiting to provide a complete list of errors found

0 commit comments

Comments
 (0)