utils/checkpackagelib: CommentsMenusPackagesOrder: fix non-package/Config.in
v3 cover utils/checkpackagelib: CommentsMenusPackagesOrder: fix non-package/Config.in
The recently introduced CommentsMenusPackagesOrder check is broken in various small ways. This series fixes the breakage.
Versions of these patches have been floating around on the mailing list already, this series consolidates them.
Note that this doesn't fix any gitlab-CI issue any more, since we currently only check package/Config.in and package/Config.in.host and those work.
Regards,
Arnout
PATCH v3 1/3 utils/checkpackagelib: CommentsMenusPackagesOrder: fix 'menuconfig' handling
The CommentsMenusPackagesOrder check builds the 'state' to track the depth of menus and conditions. However, a menuconfig doesn't create a menu by itself - it is always followed by a condition that implies the menu. As a result, when unwinding the 'state', the level will be wrong.
Fix this by checking for menu followed by a space, so it no longer matches menuconfig. For consistency, do the same for comment and if as well.
---
v3: use Jerzy's approach of adding a space after all conditions, not
just menu.
v2: Jerzy independently did a similar change.
--- utils/checkpackagelib/lib_config.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
utils/checkpackagelib/lib_config.py +2 -2
@@ -77,8 +77,8 @@ class CommentsMenusPackagesOrder(_CheckFunction): "package/Config.in.host"]: return - if text.startswith("comment") or text.startswith("if") or \ - text.startswith("menu"): + if text.startswith("comment ") or text.startswith("if ") or \ + text.startswith("menu "): if text.startswith("comment"): if not self.state.endswith("-comment"):
Signature · 1 line
2.21.0
PATCH v3 2/3 utils/checkpackagelib: CommentsMenusPackagesOrder: append elements to arrays if needed
In reply to Arnout Vandecappelle (Essensium/Mind)From: Jerzy Grzegorek <[email protected]>
In the future, the nesting level of menus, comments and conditions may increase. The fixed array length used now is not appropriate. Therefore, append elements to the arrays if needed.
Also change order of variables.
---
Changes v2 -> v3:
- Initialize arrays to empty
- Rewrite commit log
Changes v1 -> v2:
- use try/except statement instead of if one (Yann)
At the beginning self.state is empty and variable level (index of arrays) is equal 0. We append elements to arrays for the first time when a line begining with "comment ", "if " or "menu ". At that moment level is equal 1 and each array should have two elements (index 0 and 1). To achieve this we can use empty arrays or arrays with an initial value (index 0).
1. Arrays with an initial value and if statement (previous version)
...
if level > len(array) - 1
append elements
...
2. Empty arrays and while statement
...
while level > len(array) - 1
append elements
...
3. Arrays with an initial value and try/except statement (this version)
...
try:
assigment staff
except IndexError:
append elements
...
--- utils/checkpackagelib/lib_config.py | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-)
utils/checkpackagelib/lib_config.py +12 -6
@@ -61,9 +61,9 @@ class AttributesOrder(_CheckFunction): class CommentsMenusPackagesOrder(_CheckFunction): - print_package_warning = [True, True, True, True, True, True] - menu_of_packages = ["", "", "", "", "", ""] - package = ["", "", "", "", "", ""] + menu_of_packages = [] + package = [] + print_package_warning = [] def before(self): self.state = ""
@@ -92,9 +92,15 @@ class CommentsMenusPackagesOrder(_CheckFunction): self.state += "-menu" level = self.get_level() - self.package[level] = "" - self.print_package_warning[level] = True - self.menu_of_packages[level] = text[:-1] + + try: + self.menu_of_packages[level] = text[:-1] + self.package[level] = "" + self.print_package_warning[level] = True + except IndexError: + self.menu_of_packages.append(text[:-1]) + self.package.append("") + self.print_package_warning.append(True) elif text.startswith("endif") or text.startswith("endmenu"): if self.state.endswith("comment"):
Signature · 1 line
2.21.0
PATCH v3 3/3 utils/checkpackagelib: CommentsMenusPackagesOrder: use regex for source
In reply to Arnout Vandecappelle (Essensium/Mind)The 'source' strings identify which package is incorrectly ordered. We need to extract the actual package name from that string, which is currently done with constants that assume the file is package/Config.in.
In addition, only 'source' lines that are indented with a tab are checked. This kind of indentation is done in package/Config.in, but not e.g. boot/Config.in.
Therefore, use a regular expression to match the 'source' lines, and to extract the directory part from it.
---
v3: new patch
--- utils/checkpackagelib/lib_config.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
utils/checkpackagelib/lib_config.py +3 -2
@@ -77,6 +77,7 @@ class CommentsMenusPackagesOrder(_CheckFunction): "package/Config.in.host"]: return + m = re.match(r'^\s*source ".*/([^/]*)/Config.in(.host)?"', text) if text.startswith("comment ") or text.startswith("if ") or \ text.startswith("menu "):
@@ -112,9 +113,9 @@ class CommentsMenusPackagesOrder(_CheckFunction): elif text.startswith("endmenu"): self.state = self.state[:-5] - elif text.startswith('\tsource "package/'): + elif m: level = self.get_level() - new_package = text[17: -(len(self.filename)-5):] + new_package = m.group(1) # We order _ before A, so replace it with . new_package_ord = new_package.replace('_', '.')
Signature · 1 line
2.21.0