aboutsummaryrefslogtreecommitdiff
path: root/utils
diff options
context:
space:
mode:
authorGravatar Jerzy Grzegorek <jerzy.m.grzegorek@gmail.com>2019-06-11 22:49:46 +0200
committerGravatar Arnout Vandecappelle (Essensium/Mind) <arnout@mind.be>2019-07-14 00:21:26 +0200
commite36a63cf6b325f76ad62c1e06b8a6d4fb4c9f062 (patch)
tree9d8441ad3657d002cef79e0fc712820ba06d92a3 /utils
parent4e655134cd6043323d65118960c140f80480869d (diff)
downloadbuildroot-e36a63cf6b325f76ad62c1e06b8a6d4fb4c9f062.tar.gz
buildroot-e36a63cf6b325f76ad62c1e06b8a6d4fb4c9f062.tar.bz2
checkpackagelib/lib_config.py: check packages alphabetical order in {Config.in, Config.in.host}
Signed-off-by: Jerzy Grzegorek <jerzy.m.grzegorek@gmail.com> [Arnout: - calculate level by counting - instead of with a static array; - new_package is only used locally, so don't make it a class member; - do indentation according to length of prefix; - don't split string in the middle of a line; - report first wrong package per menu; - do replace() only once; - add comment why we do replace(). ] Signed-off-by: Arnout Vandecappelle (Essensium/Mind) <arnout@mind.be>
Diffstat (limited to 'utils')
-rw-r--r--utils/checkpackagelib/lib_config.py66
1 files changed, 66 insertions, 0 deletions
diff --git a/utils/checkpackagelib/lib_config.py b/utils/checkpackagelib/lib_config.py
index 89d44da57e..f0edb9993d 100644
--- a/utils/checkpackagelib/lib_config.py
+++ b/utils/checkpackagelib/lib_config.py
@@ -60,6 +60,72 @@ class AttributesOrder(_CheckFunction):
text]
+class CommentsMenusPackagesOrder(_CheckFunction):
+ print_package_warning = [True, True, True, True, True, True]
+ menu_of_packages = ["", "", "", "", "", ""]
+ package = ["", "", "", "", "", ""]
+
+ def before(self):
+ self.state = ""
+
+ def get_level(self):
+ return len(self.state.split('-')) - 1
+
+ def check_line(self, lineno, text):
+ if text.startswith("comment") or text.startswith("if") or \
+ text.startswith("menu"):
+
+ if text.startswith("comment"):
+ if not self.state.endswith("-comment"):
+ self.state += "-comment"
+
+ elif text.startswith("if") or text.startswith("menu"):
+ if text.startswith("if"):
+ self.state += "-if"
+
+ elif text.startswith("menu"):
+ self.state += "-menu"
+
+ level = self.get_level()
+ self.package[level] = ""
+ self.print_package_warning[level] = True
+ self.menu_of_packages[level] = text[:-1]
+
+ elif text.startswith("endif") or text.startswith("endmenu"):
+ if self.state.endswith("comment"):
+ self.state = self.state[:-8]
+
+ if text.startswith("endif"):
+ self.state = self.state[:-3]
+
+ elif text.startswith("endmenu"):
+ self.state = self.state[:-5]
+
+ elif text.startswith('\tsource "package/'):
+ level = self.get_level()
+ new_package = text[17: -(len(self.filename)-5):]
+
+ # We order _ before A, so replace it with .
+ new_package_ord = new_package.replace('_', '.')
+
+ if self.package[level] != "" and \
+ self.print_package_warning[level] and \
+ new_package_ord < self.package[level]:
+ self.print_package_warning[level] = False
+ prefix = "{}:{}: ".format(self.filename, lineno)
+ spaces = " " * len(prefix)
+ return ["{prefix}Packages in: {menu},\n"
+ "{spaces}are not alphabetically ordered;\n"
+ "{spaces}correct order: '-', '_', digits, capitals, lowercase;\n"
+ "{spaces}first incorrect package: {package}"
+ .format(prefix=prefix, spaces=spaces,
+ menu=self.menu_of_packages[level],
+ package=new_package),
+ text]
+
+ self.package[level] = new_package_ord
+
+
class HelpText(_CheckFunction):
HELP_TEXT_FORMAT = re.compile("^\t .{,62}$")
URL_ONLY = re.compile("^(http|https|git)://\S*$")