Initial Commit
- initial default booting image
This commit is contained in:
0
utils/checkpackagelib/__init__.py
Normal file
0
utils/checkpackagelib/__init__.py
Normal file
38
utils/checkpackagelib/base.py
Normal file
38
utils/checkpackagelib/base.py
Normal file
@@ -0,0 +1,38 @@
|
||||
# See utils/checkpackagelib/readme.txt before editing this file.
|
||||
import re
|
||||
import os
|
||||
|
||||
|
||||
class _CheckFunction(object):
|
||||
def __init__(self, filename, url_to_manual):
|
||||
self.filename = filename
|
||||
self.url_to_manual = url_to_manual
|
||||
self.disable = re.compile(r"^\s*# check-package .*\b{}\b".format(self.__class__.__name__))
|
||||
|
||||
def before(self):
|
||||
pass
|
||||
|
||||
def check_line(self, lineno, text):
|
||||
pass
|
||||
|
||||
def after(self):
|
||||
pass
|
||||
|
||||
|
||||
class _Tool(object):
|
||||
def __init__(self, filename):
|
||||
self.filename = filename
|
||||
|
||||
def run(self):
|
||||
pass
|
||||
|
||||
def hint(self):
|
||||
return ""
|
||||
|
||||
|
||||
def run_test_suite():
|
||||
import pytest
|
||||
return pytest.main(
|
||||
# Disable writing/loading a cache with: -p no:cacheprovider
|
||||
["-v", "-p", "no:cacheprovider", os.path.dirname(__file__)]
|
||||
)
|
||||
68
utils/checkpackagelib/lib.py
Normal file
68
utils/checkpackagelib/lib.py
Normal file
@@ -0,0 +1,68 @@
|
||||
# See utils/checkpackagelib/readme.txt before editing this file.
|
||||
|
||||
from checkpackagelib.base import _CheckFunction
|
||||
|
||||
|
||||
class ConsecutiveEmptyLines(_CheckFunction):
|
||||
def before(self):
|
||||
self.lastline = "non empty"
|
||||
|
||||
def check_line(self, lineno, text):
|
||||
if text.strip() == "" == self.lastline.strip():
|
||||
return ["{}:{}: consecutive empty lines"
|
||||
.format(self.filename, lineno)]
|
||||
self.lastline = text
|
||||
|
||||
|
||||
class EmptyLastLine(_CheckFunction):
|
||||
def before(self):
|
||||
self.lastlineno = 0
|
||||
self.lastline = "non empty"
|
||||
|
||||
def check_line(self, lineno, text):
|
||||
self.lastlineno = lineno
|
||||
self.lastline = text
|
||||
|
||||
def after(self):
|
||||
if self.lastline.strip() == "":
|
||||
return ["{}:{}: empty line at end of file"
|
||||
.format(self.filename, self.lastlineno)]
|
||||
|
||||
|
||||
class NewlineAtEof(_CheckFunction):
|
||||
def before(self):
|
||||
self.lastlineno = 0
|
||||
self.lastline = "\n"
|
||||
|
||||
def check_line(self, lineno, text):
|
||||
self.lastlineno = lineno
|
||||
self.lastline = text
|
||||
|
||||
def after(self):
|
||||
if self.lastline == self.lastline.rstrip("\r\n"):
|
||||
return ["{}:{}: missing newline at end of file"
|
||||
.format(self.filename, self.lastlineno),
|
||||
self.lastline]
|
||||
|
||||
|
||||
class TrailingSpace(_CheckFunction):
|
||||
def check_line(self, lineno, text):
|
||||
line = text.rstrip("\r\n")
|
||||
if line != line.rstrip():
|
||||
return ["{}:{}: line contains trailing whitespace"
|
||||
.format(self.filename, lineno),
|
||||
text]
|
||||
|
||||
|
||||
class Utf8Characters(_CheckFunction):
|
||||
def is_ascii(self, s):
|
||||
try:
|
||||
return all(ord(c) < 128 for c in s)
|
||||
except TypeError:
|
||||
return False
|
||||
|
||||
def check_line(self, lineno, text):
|
||||
if not self.is_ascii(text):
|
||||
return ["{}:{}: line contains UTF-8 characters"
|
||||
.format(self.filename, lineno),
|
||||
text]
|
||||
291
utils/checkpackagelib/lib_config.py
Normal file
291
utils/checkpackagelib/lib_config.py
Normal file
@@ -0,0 +1,291 @@
|
||||
# See utils/checkpackagelib/readme.txt before editing this file.
|
||||
# Kconfig generates errors if someone introduces a typo like "boool" instead of
|
||||
# "bool", so below check functions don't need to check for things already
|
||||
# checked by running "make menuconfig".
|
||||
|
||||
import re
|
||||
|
||||
from checkpackagelib.base import _CheckFunction
|
||||
from checkpackagelib.lib import ConsecutiveEmptyLines # noqa: F401
|
||||
from checkpackagelib.lib import EmptyLastLine # noqa: F401
|
||||
from checkpackagelib.lib import NewlineAtEof # noqa: F401
|
||||
from checkpackagelib.lib import TrailingSpace # noqa: F401
|
||||
from checkpackagelib.tool import NotExecutable # noqa: F401
|
||||
|
||||
|
||||
def _empty_or_comment(text):
|
||||
line = text.strip()
|
||||
# ignore empty lines and comment lines indented or not
|
||||
return line == "" or line.startswith("#")
|
||||
|
||||
|
||||
def _part_of_help_text(text):
|
||||
return text.startswith("\t ")
|
||||
|
||||
|
||||
# used in more than one check
|
||||
entries_that_should_not_be_indented = [
|
||||
"choice", "comment", "config", "endchoice", "endif", "endmenu", "if",
|
||||
"menu", "menuconfig", "source"]
|
||||
|
||||
|
||||
class AttributesOrder(_CheckFunction):
|
||||
attributes_order_convention = {
|
||||
"bool": 1, "prompt": 1, "string": 1, "default": 2, "depends": 3,
|
||||
"select": 4, "help": 5}
|
||||
|
||||
def before(self):
|
||||
self.state = 0
|
||||
|
||||
def check_line(self, lineno, text):
|
||||
if _empty_or_comment(text) or _part_of_help_text(text):
|
||||
return
|
||||
|
||||
attribute = text.split()[0]
|
||||
|
||||
if attribute in entries_that_should_not_be_indented:
|
||||
self.state = 0
|
||||
return
|
||||
if attribute not in self.attributes_order_convention.keys():
|
||||
return
|
||||
new_state = self.attributes_order_convention[attribute]
|
||||
wrong_order = self.state > new_state
|
||||
|
||||
# save to process next line
|
||||
self.state = new_state
|
||||
|
||||
if wrong_order:
|
||||
return ["{}:{}: attributes order: type, default, depends on,"
|
||||
" select, help ({}#_config_files)"
|
||||
.format(self.filename, lineno, self.url_to_manual),
|
||||
text]
|
||||
|
||||
|
||||
class CommentsMenusPackagesOrder(_CheckFunction):
|
||||
def before(self):
|
||||
self.level = 0
|
||||
self.menu_of_packages = ["The top level menu"]
|
||||
self.new_package = ""
|
||||
self.package = [""]
|
||||
self.print_package_warning = [True]
|
||||
self.state = ""
|
||||
|
||||
def get_level(self):
|
||||
return len(self.state.split('-')) - 1
|
||||
|
||||
def initialize_package_level_elements(self, text):
|
||||
try:
|
||||
self.menu_of_packages[self.level] = text[:-1]
|
||||
self.package[self.level] = ""
|
||||
self.print_package_warning[self.level] = True
|
||||
except IndexError:
|
||||
self.menu_of_packages.append(text[:-1])
|
||||
self.package.append("")
|
||||
self.print_package_warning.append(True)
|
||||
|
||||
def initialize_level_elements(self, text):
|
||||
self.level = self.get_level()
|
||||
self.initialize_package_level_elements(text)
|
||||
|
||||
def check_line(self, lineno, text):
|
||||
# We only want to force sorting for the top-level menus
|
||||
if self.filename not in ["fs/Config.in",
|
||||
"package/Config.in",
|
||||
"package/Config.in.host",
|
||||
"package/kodi/Config.in"]:
|
||||
return
|
||||
|
||||
source_line = re.match(r'^\s*source ".*/([^/]*)/Config.in(.host)?"', text)
|
||||
|
||||
if text.startswith("comment "):
|
||||
if not self.state.endswith("-comment"):
|
||||
self.state += "-comment"
|
||||
|
||||
self.initialize_level_elements(text)
|
||||
|
||||
elif text.startswith("if "):
|
||||
self.state += "-if"
|
||||
|
||||
self.initialize_level_elements(text)
|
||||
|
||||
elif text.startswith("menu "):
|
||||
if self.state.endswith("-comment"):
|
||||
self.state = self.state[:-8]
|
||||
|
||||
self.state += "-menu"
|
||||
|
||||
self.initialize_level_elements(text)
|
||||
|
||||
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]
|
||||
|
||||
self.level = self.get_level()
|
||||
|
||||
elif source_line:
|
||||
self.new_package = source_line.group(1)
|
||||
|
||||
# We order _ before A, so replace it with .
|
||||
new_package_ord = self.new_package.replace('_', '.')
|
||||
|
||||
if self.package[self.level] != "" and \
|
||||
self.print_package_warning[self.level] and \
|
||||
new_package_ord < self.package[self.level]:
|
||||
self.print_package_warning[self.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[self.level],
|
||||
package=self.new_package),
|
||||
text]
|
||||
|
||||
self.package[self.level] = new_package_ord
|
||||
|
||||
|
||||
class HelpText(_CheckFunction):
|
||||
HELP_TEXT_FORMAT = re.compile(r"^\t .{,62}$")
|
||||
HELP_TEXT_FORMAT_1 = re.compile(r"^\t \S.{,61}$")
|
||||
URL_ONLY = re.compile(r"^(http|https|git)://\S*$")
|
||||
|
||||
def before(self):
|
||||
self.help_text = False
|
||||
|
||||
def check_line(self, lineno, text):
|
||||
if _empty_or_comment(text):
|
||||
return
|
||||
|
||||
entry = text.split()[0]
|
||||
|
||||
if entry in entries_that_should_not_be_indented:
|
||||
self.help_text = False
|
||||
return
|
||||
if text.strip() == "help":
|
||||
self.help_text = True
|
||||
self.help_first_line = True
|
||||
return
|
||||
|
||||
if not self.help_text:
|
||||
return
|
||||
|
||||
if self.help_first_line:
|
||||
help_text_match = self.HELP_TEXT_FORMAT_1
|
||||
self.help_first_line = False
|
||||
else:
|
||||
help_text_match = self.HELP_TEXT_FORMAT
|
||||
if help_text_match.match(text.rstrip()):
|
||||
return
|
||||
if self.URL_ONLY.match(text.strip()):
|
||||
return
|
||||
return ["{}:{}: help text: <tab><2 spaces><62 chars>"
|
||||
" ({}#writing-rules-config-in)"
|
||||
.format(self.filename, lineno, self.url_to_manual),
|
||||
text,
|
||||
"\t " + "123456789 " * 6 + "12"]
|
||||
|
||||
|
||||
class Indent(_CheckFunction):
|
||||
ENDS_WITH_BACKSLASH = re.compile(r"^[^#].*\\$")
|
||||
entries_that_should_be_indented = [
|
||||
"bool", "default", "depends", "help", "prompt", "select", "string"]
|
||||
|
||||
def before(self):
|
||||
self.backslash = False
|
||||
|
||||
def check_line(self, lineno, text):
|
||||
if _empty_or_comment(text) or _part_of_help_text(text):
|
||||
self.backslash = False
|
||||
return
|
||||
|
||||
entry = text.split()[0]
|
||||
|
||||
last_line_ends_in_backslash = self.backslash
|
||||
|
||||
# calculate for next line
|
||||
if self.ENDS_WITH_BACKSLASH.search(text):
|
||||
self.backslash = True
|
||||
else:
|
||||
self.backslash = False
|
||||
|
||||
if last_line_ends_in_backslash:
|
||||
if text.startswith("\t"):
|
||||
return
|
||||
return ["{}:{}: continuation line should be indented using tabs"
|
||||
.format(self.filename, lineno),
|
||||
text]
|
||||
|
||||
if entry in self.entries_that_should_be_indented:
|
||||
if not text.startswith("\t{}".format(entry)):
|
||||
return ["{}:{}: should be indented with one tab"
|
||||
" ({}#_config_files)"
|
||||
.format(self.filename, lineno, self.url_to_manual),
|
||||
text]
|
||||
elif entry in entries_that_should_not_be_indented:
|
||||
if not text.startswith(entry):
|
||||
# four Config.in files have a special but legitimate indentation rule
|
||||
if self.filename in ["package/Config.in",
|
||||
"package/Config.in.host",
|
||||
"package/kodi/Config.in",
|
||||
"package/x11r7/Config.in"]:
|
||||
return
|
||||
return ["{}:{}: should not be indented"
|
||||
.format(self.filename, lineno),
|
||||
text]
|
||||
|
||||
|
||||
class NoDefaultN(_CheckFunction):
|
||||
DEFAULTN = re.compile(r"^\tdefault n$")
|
||||
|
||||
def check_line(self, lineno, text):
|
||||
text_nocomments = text.split("#")[0].rstrip()
|
||||
if self.DEFAULTN.match(text_nocomments):
|
||||
return ["{}:{}: boolean symbols default to 'n', so 'default n' is redundant"
|
||||
.format(self.filename, lineno),
|
||||
text]
|
||||
|
||||
|
||||
class RedefinedConfig(_CheckFunction):
|
||||
CONFIG = re.compile(r"^\s*(menu|)config\s+(BR2_\w+)\b")
|
||||
IF = re.compile(r"^\s*if\s+([^#]*)\b")
|
||||
ENDIF = re.compile(r"^\s*endif\b")
|
||||
|
||||
def before(self):
|
||||
self.configs = {}
|
||||
self.conditional = []
|
||||
|
||||
def check_line(self, lineno, text):
|
||||
if _empty_or_comment(text) or _part_of_help_text(text):
|
||||
return
|
||||
|
||||
m = self.IF.search(text)
|
||||
if m is not None:
|
||||
condition = m.group(1)
|
||||
self.conditional.append(condition)
|
||||
return
|
||||
|
||||
m = self.ENDIF.search(text)
|
||||
if m is not None:
|
||||
self.conditional.pop()
|
||||
return
|
||||
|
||||
m = self.CONFIG.search(text)
|
||||
if m is None:
|
||||
return
|
||||
config = m.group(2)
|
||||
|
||||
key = (config, ' AND '.join(self.conditional))
|
||||
if key in self.configs.keys():
|
||||
previous_line = self.configs[key]
|
||||
return ["{}:{}: config {} redeclared (previous line: {})"
|
||||
.format(self.filename, lineno, config, previous_line),
|
||||
text]
|
||||
self.configs[key] = lineno
|
||||
20
utils/checkpackagelib/lib_defconfig.py
Normal file
20
utils/checkpackagelib/lib_defconfig.py
Normal file
@@ -0,0 +1,20 @@
|
||||
# See utils/checkpackagelib/readme.txt before editing this file.
|
||||
|
||||
from checkpackagelib.base import _CheckFunction
|
||||
|
||||
|
||||
class ForceCheckHash(_CheckFunction):
|
||||
"""Checks that a defconfig does force checking all hashes"""
|
||||
|
||||
def before(self):
|
||||
self.forces = False
|
||||
|
||||
def check_line(self, lineno, text):
|
||||
if self.forces:
|
||||
return
|
||||
if text == "BR2_DOWNLOAD_FORCE_CHECK_HASHES=y\n":
|
||||
self.forces = True
|
||||
|
||||
def after(self):
|
||||
if not self.forces:
|
||||
return [f"{self.filename}:0: missing BR2_DOWNLOAD_FORCE_CHECK_HASHES"]
|
||||
70
utils/checkpackagelib/lib_hash.py
Normal file
70
utils/checkpackagelib/lib_hash.py
Normal file
@@ -0,0 +1,70 @@
|
||||
# See utils/checkpackagelib/readme.txt before editing this file.
|
||||
# The validity of the hashes itself is checked when building, so below check
|
||||
# functions don't need to check for things already checked by running
|
||||
# "make package-dirclean package-source".
|
||||
|
||||
import re
|
||||
|
||||
from checkpackagelib.base import _CheckFunction
|
||||
from checkpackagelib.lib import ConsecutiveEmptyLines # noqa: F401
|
||||
from checkpackagelib.lib import EmptyLastLine # noqa: F401
|
||||
from checkpackagelib.lib import NewlineAtEof # noqa: F401
|
||||
from checkpackagelib.lib import TrailingSpace # noqa: F401
|
||||
from checkpackagelib.tool import NotExecutable # noqa: F401
|
||||
|
||||
|
||||
def _empty_line_or_comment(text):
|
||||
return text.strip() == "" or text.startswith("#")
|
||||
|
||||
|
||||
class HashNumberOfFields(_CheckFunction):
|
||||
def check_line(self, lineno, text):
|
||||
if _empty_line_or_comment(text):
|
||||
return
|
||||
|
||||
fields = text.split()
|
||||
if len(fields) != 3:
|
||||
return ["{}:{}: expected three fields ({}#adding-packages-hash)"
|
||||
.format(self.filename, lineno, self.url_to_manual),
|
||||
text]
|
||||
|
||||
|
||||
class HashType(_CheckFunction):
|
||||
len_of_hash = {"md5": 32, "sha1": 40, "sha224": 56, "sha256": 64,
|
||||
"sha384": 96, "sha512": 128}
|
||||
|
||||
def check_line(self, lineno, text):
|
||||
if _empty_line_or_comment(text):
|
||||
return
|
||||
|
||||
fields = text.split()
|
||||
if len(fields) < 2:
|
||||
return
|
||||
|
||||
htype, hexa = fields[:2]
|
||||
if htype not in self.len_of_hash.keys():
|
||||
return ["{}:{}: unexpected type of hash ({}#adding-packages-hash)"
|
||||
.format(self.filename, lineno, self.url_to_manual),
|
||||
text]
|
||||
if not re.match("^[0-9A-Fa-f]{%s}$" % self.len_of_hash[htype], hexa):
|
||||
return ["{}:{}: hash size does not match type "
|
||||
"({}#adding-packages-hash)"
|
||||
.format(self.filename, lineno, self.url_to_manual),
|
||||
text,
|
||||
"expected {} hex digits".format(self.len_of_hash[htype])]
|
||||
|
||||
|
||||
class HashSpaces(_CheckFunction):
|
||||
def check_line(self, lineno, text):
|
||||
if _empty_line_or_comment(text):
|
||||
return
|
||||
|
||||
fields = text.split()
|
||||
if len(fields) != 3:
|
||||
# Handled by HashNumberOfFields
|
||||
return
|
||||
|
||||
if not re.match(re.escape("{} {} {}".format(*fields)), text):
|
||||
return ["{}:{}: separation does not match expectation "
|
||||
"({}#adding-packages-hash)"
|
||||
.format(self.filename, lineno, self.url_to_manual), text]
|
||||
14
utils/checkpackagelib/lib_ignore.py
Normal file
14
utils/checkpackagelib/lib_ignore.py
Normal file
@@ -0,0 +1,14 @@
|
||||
# See utils/checkpackagelib/readme.txt before editing this file.
|
||||
|
||||
import os
|
||||
|
||||
from checkpackagelib.base import _CheckFunction
|
||||
|
||||
|
||||
class IgnoreMissingFile(_CheckFunction):
|
||||
def check_line(self, lineno, text):
|
||||
fields = text.split()
|
||||
if not os.path.exists(fields[0]):
|
||||
return ["{}:{}: ignored file {} is missing"
|
||||
.format(self.filename, lineno, fields[0]),
|
||||
text]
|
||||
445
utils/checkpackagelib/lib_mk.py
Normal file
445
utils/checkpackagelib/lib_mk.py
Normal file
@@ -0,0 +1,445 @@
|
||||
# See utils/checkpackagelib/readme.txt before editing this file.
|
||||
# There are already dependency checks during the build, so below check
|
||||
# functions don't need to check for things already checked by exploring the
|
||||
# menu options using "make menuconfig" and by running "make" with appropriate
|
||||
# packages enabled.
|
||||
|
||||
import os
|
||||
import re
|
||||
|
||||
from checkpackagelib.base import _CheckFunction
|
||||
from checkpackagelib.lib import ConsecutiveEmptyLines # noqa: F401
|
||||
from checkpackagelib.lib import EmptyLastLine # noqa: F401
|
||||
from checkpackagelib.lib import NewlineAtEof # noqa: F401
|
||||
from checkpackagelib.lib import TrailingSpace # noqa: F401
|
||||
from checkpackagelib.lib import Utf8Characters # noqa: F401
|
||||
from checkpackagelib.tool import NotExecutable # noqa: F401
|
||||
|
||||
# used in more than one check
|
||||
start_conditional = ["ifdef", "ifeq", "ifndef", "ifneq"]
|
||||
continue_conditional = ["elif", "else"]
|
||||
end_conditional = ["endif"]
|
||||
|
||||
|
||||
class DoNotInstallToHostdirUsr(_CheckFunction):
|
||||
INSTALL_TO_HOSTDIR_USR = re.compile(r"^[^#].*\$\(HOST_DIR\)/usr")
|
||||
|
||||
def check_line(self, lineno, text):
|
||||
if self.INSTALL_TO_HOSTDIR_USR.match(text.rstrip()):
|
||||
return ["{}:{}: install files to $(HOST_DIR)/ instead of $(HOST_DIR)/usr/"
|
||||
.format(self.filename, lineno),
|
||||
text]
|
||||
|
||||
|
||||
class Ifdef(_CheckFunction):
|
||||
IFDEF = re.compile(r"^\s*(else\s+|)(ifdef|ifndef)\s")
|
||||
|
||||
def check_line(self, lineno, text):
|
||||
m = self.IFDEF.search(text)
|
||||
if m is None:
|
||||
return
|
||||
word = m.group(2)
|
||||
if word == 'ifdef':
|
||||
return ["{}:{}: use ifeq ($(SYMBOL),y) instead of ifdef SYMBOL"
|
||||
.format(self.filename, lineno),
|
||||
text]
|
||||
else:
|
||||
return ["{}:{}: use ifneq ($(SYMBOL),y) instead of ifndef SYMBOL"
|
||||
.format(self.filename, lineno),
|
||||
text]
|
||||
|
||||
|
||||
def get_package_prefix_from_filename(filename):
|
||||
"""Return a tuple (pkgname, PKGNAME) with the package name derived from the file name"""
|
||||
# Double splitext to support .mk.in
|
||||
package = os.path.splitext(os.path.splitext(os.path.basename(filename))[0])[0]
|
||||
# linux tools do not use LINUX_TOOL_ prefix for variables
|
||||
package = package.replace("linux-tool-", "")
|
||||
# linux extensions do not use LINUX_EXT_ prefix for variables
|
||||
package = package.replace("linux-ext-", "")
|
||||
package_upper = package.replace("-", "_").upper()
|
||||
return package, package_upper
|
||||
|
||||
|
||||
class Indent(_CheckFunction):
|
||||
COMMENT = re.compile(r"^\s*#")
|
||||
CONDITIONAL = re.compile(r"^\s*({})\s".format("|".join(start_conditional + end_conditional + continue_conditional)))
|
||||
ENDS_WITH_BACKSLASH = re.compile(r"^[^#].*\\$")
|
||||
END_DEFINE = re.compile(r"^\s*endef\s")
|
||||
MAKEFILE_TARGET = re.compile(r"^[^# \t]+:\s")
|
||||
START_DEFINE = re.compile(r"^\s*define\s")
|
||||
|
||||
def before(self):
|
||||
self.define = False
|
||||
self.backslash = False
|
||||
self.makefile_target = False
|
||||
|
||||
def check_line(self, lineno, text):
|
||||
if self.START_DEFINE.search(text):
|
||||
self.define = True
|
||||
return
|
||||
if self.END_DEFINE.search(text):
|
||||
self.define = False
|
||||
return
|
||||
|
||||
expect_tabs = False
|
||||
if self.define or self.backslash or self.makefile_target:
|
||||
expect_tabs = True
|
||||
if not self.backslash and self.CONDITIONAL.search(text):
|
||||
expect_tabs = False
|
||||
|
||||
# calculate for next line
|
||||
if self.ENDS_WITH_BACKSLASH.search(text):
|
||||
self.backslash = True
|
||||
else:
|
||||
self.backslash = False
|
||||
|
||||
if self.MAKEFILE_TARGET.search(text):
|
||||
self.makefile_target = True
|
||||
return
|
||||
if text.strip() == "":
|
||||
self.makefile_target = False
|
||||
return
|
||||
|
||||
# comment can be indented or not inside define ... endef, so ignore it
|
||||
if self.define and self.COMMENT.search(text):
|
||||
return
|
||||
|
||||
if expect_tabs:
|
||||
if not text.startswith("\t"):
|
||||
return ["{}:{}: expected indent with tabs"
|
||||
.format(self.filename, lineno),
|
||||
text]
|
||||
else:
|
||||
if text.startswith("\t"):
|
||||
return ["{}:{}: unexpected indent with tabs"
|
||||
.format(self.filename, lineno),
|
||||
text]
|
||||
|
||||
|
||||
class OverriddenVariable(_CheckFunction):
|
||||
CONCATENATING = re.compile(r"^([A-Z0-9_]+)\s*(\+|:|)=\s*\$\(\1\)")
|
||||
END_CONDITIONAL = re.compile(r"^\s*({})".format("|".join(end_conditional)))
|
||||
OVERRIDING_ASSIGNMENTS = [':=', "="]
|
||||
START_CONDITIONAL = re.compile(r"^\s*({})".format("|".join(start_conditional)))
|
||||
VARIABLE = re.compile(r"^([A-Z0-9_]+)\s*((\+|:|)=)")
|
||||
USUALLY_OVERRIDDEN = re.compile(r"^[A-Z0-9_]+({})".format("|".join([
|
||||
r"_ARCH\s*=\s*",
|
||||
r"_CPU\s*=\s*",
|
||||
r"_SITE\s*=\s*",
|
||||
r"_SOURCE\s*=\s*",
|
||||
r"_VERSION\s*=\s*"])))
|
||||
FORBIDDEN_OVERRIDDEN = re.compile(r"^[A-Z0-9_]+({})".format("|".join([
|
||||
r"_CONF_OPTS\s*=\s*",
|
||||
r"_DEPENDENCIES\s*=\s*"])))
|
||||
|
||||
def before(self):
|
||||
self.conditional = 0
|
||||
self.unconditionally_set = []
|
||||
self.conditionally_set = []
|
||||
|
||||
def check_line(self, lineno, text):
|
||||
if self.START_CONDITIONAL.search(text):
|
||||
self.conditional += 1
|
||||
return
|
||||
if self.END_CONDITIONAL.search(text):
|
||||
self.conditional -= 1
|
||||
return
|
||||
|
||||
m = self.VARIABLE.search(text)
|
||||
if m is None:
|
||||
return
|
||||
variable, assignment = m.group(1, 2)
|
||||
|
||||
if self.conditional == 0:
|
||||
if variable in self.conditionally_set:
|
||||
self.unconditionally_set.append(variable)
|
||||
if assignment in self.OVERRIDING_ASSIGNMENTS:
|
||||
return ["{}:{}: unconditional override of variable {} previously conditionally set"
|
||||
.format(self.filename, lineno, variable),
|
||||
text]
|
||||
|
||||
if variable not in self.unconditionally_set:
|
||||
self.unconditionally_set.append(variable)
|
||||
return
|
||||
if assignment in self.OVERRIDING_ASSIGNMENTS:
|
||||
return ["{}:{}: unconditional override of variable {}"
|
||||
.format(self.filename, lineno, variable),
|
||||
text]
|
||||
else:
|
||||
if self.FORBIDDEN_OVERRIDDEN.search(text):
|
||||
return ["{}:{}: conditional override of variable {}"
|
||||
.format(self.filename, lineno, variable),
|
||||
text]
|
||||
if variable not in self.unconditionally_set:
|
||||
self.conditionally_set.append(variable)
|
||||
return
|
||||
if self.CONCATENATING.search(text):
|
||||
return ["{}:{}: immediate assignment to append to variable {}"
|
||||
.format(self.filename, lineno, variable),
|
||||
text]
|
||||
if self.USUALLY_OVERRIDDEN.search(text):
|
||||
return
|
||||
if assignment in self.OVERRIDING_ASSIGNMENTS:
|
||||
return ["{}:{}: conditional override of variable {}"
|
||||
.format(self.filename, lineno, variable),
|
||||
text]
|
||||
|
||||
|
||||
class PackageHeader(_CheckFunction):
|
||||
def before(self):
|
||||
self.skip = False
|
||||
|
||||
def check_line(self, lineno, text):
|
||||
if self.skip or lineno > 6:
|
||||
return
|
||||
|
||||
if lineno in [1, 5]:
|
||||
if lineno == 1 and text.startswith("include "):
|
||||
self.skip = True
|
||||
return
|
||||
if text.rstrip() != "#" * 80:
|
||||
return ["{}:{}: should be 80 hashes ({}#writing-rules-mk)"
|
||||
.format(self.filename, lineno, self.url_to_manual),
|
||||
text,
|
||||
"#" * 80]
|
||||
elif lineno in [2, 4]:
|
||||
if text.rstrip() != "#":
|
||||
return ["{}:{}: should be 1 hash ({}#writing-rules-mk)"
|
||||
.format(self.filename, lineno, self.url_to_manual),
|
||||
text]
|
||||
elif lineno == 6:
|
||||
if text.rstrip() != "":
|
||||
return ["{}:{}: should be a blank line ({}#writing-rules-mk)"
|
||||
.format(self.filename, lineno, self.url_to_manual),
|
||||
text]
|
||||
|
||||
|
||||
class RemoveDefaultPackageSourceVariable(_CheckFunction):
|
||||
packages_that_may_contain_default_source = ["binutils", "gcc", "gdb"]
|
||||
|
||||
def before(self):
|
||||
self.package, package_upper = get_package_prefix_from_filename(self.filename)
|
||||
self.FIND_SOURCE = re.compile(
|
||||
r"^{}_SOURCE\s*=\s*{}-\$\({}_VERSION\)\.tar\.gz"
|
||||
.format(package_upper, self.package, package_upper))
|
||||
|
||||
def check_line(self, lineno, text):
|
||||
if self.FIND_SOURCE.search(text):
|
||||
|
||||
if self.package in self.packages_that_may_contain_default_source:
|
||||
return
|
||||
|
||||
return ["{}:{}: remove default value of _SOURCE variable "
|
||||
"({}#generic-package-reference)"
|
||||
.format(self.filename, lineno, self.url_to_manual),
|
||||
text]
|
||||
|
||||
|
||||
class SpaceBeforeBackslash(_CheckFunction):
|
||||
TAB_OR_MULTIPLE_SPACES_BEFORE_BACKSLASH = re.compile(r"^.*( |\t ?)\\$")
|
||||
|
||||
def check_line(self, lineno, text):
|
||||
if self.TAB_OR_MULTIPLE_SPACES_BEFORE_BACKSLASH.match(text.rstrip()):
|
||||
return ["{}:{}: use only one space before backslash"
|
||||
.format(self.filename, lineno),
|
||||
text]
|
||||
|
||||
|
||||
class TrailingBackslash(_CheckFunction):
|
||||
ENDS_WITH_BACKSLASH = re.compile(r"^[^#].*\\$")
|
||||
|
||||
def before(self):
|
||||
self.backslash = False
|
||||
|
||||
def check_line(self, lineno, text):
|
||||
last_line_ends_in_backslash = self.backslash
|
||||
|
||||
# calculate for next line
|
||||
if self.ENDS_WITH_BACKSLASH.search(text):
|
||||
self.backslash = True
|
||||
self.lastline = text
|
||||
return
|
||||
self.backslash = False
|
||||
|
||||
if last_line_ends_in_backslash and text.strip() == "":
|
||||
return ["{}:{}: remove trailing backslash"
|
||||
.format(self.filename, lineno - 1),
|
||||
self.lastline]
|
||||
|
||||
|
||||
class TypoInPackageVariable(_CheckFunction):
|
||||
ALLOWED = re.compile(r"|".join([
|
||||
"ACLOCAL_DIR",
|
||||
"ACLOCAL_HOST_DIR",
|
||||
"ACLOCAL_PATH",
|
||||
"BR_CCACHE_INITIAL_SETUP",
|
||||
"BR_LIBC",
|
||||
"BR_NO_CHECK_HASH_FOR",
|
||||
"GCC_TARGET",
|
||||
"LINUX_EXTENSIONS",
|
||||
"LINUX_POST_PATCH_HOOKS",
|
||||
"LINUX_TOOLS",
|
||||
"LUA_RUN",
|
||||
"MKFS_JFFS2",
|
||||
"MKIMAGE_ARCH",
|
||||
"PACKAGES_PERMISSIONS_TABLE",
|
||||
"PKG_CONFIG_HOST_BINARY",
|
||||
"SUMTOOL",
|
||||
"TARGET_FINALIZE_HOOKS",
|
||||
"TARGETS_ROOTFS",
|
||||
"XTENSA_CORE_NAME"]))
|
||||
VARIABLE = re.compile(r"^(define\s+)?([A-Z0-9_]+_[A-Z0-9_]+)")
|
||||
|
||||
def before(self):
|
||||
_, self.package = get_package_prefix_from_filename(self.filename)
|
||||
self.REGEX = re.compile(r"(HOST_|ROOTFS_)?({}_[A-Z0-9_]+)".format(self.package))
|
||||
self.FIND_VIRTUAL = re.compile(
|
||||
r"^{}_PROVIDES\s*(\+|)=\s*(.*)".format(self.package))
|
||||
self.virtual = []
|
||||
|
||||
def check_line(self, lineno, text):
|
||||
m = self.VARIABLE.search(text)
|
||||
if m is None:
|
||||
return
|
||||
|
||||
variable = m.group(2)
|
||||
|
||||
# allow to set variables for virtual package this package provides
|
||||
v = self.FIND_VIRTUAL.search(text)
|
||||
if v:
|
||||
self.virtual += v.group(2).upper().split()
|
||||
return
|
||||
for virtual in self.virtual:
|
||||
if variable.startswith("{}_".format(virtual)):
|
||||
return
|
||||
|
||||
if self.ALLOWED.match(variable):
|
||||
return
|
||||
if self.REGEX.search(variable) is None:
|
||||
return ["{}:{}: possible typo, variable not properly prefixed: {} -> *{}_XXXX* ({}#_tips_and_tricks)"
|
||||
.format(self.filename, lineno, variable, self.package, self.url_to_manual),
|
||||
text]
|
||||
|
||||
|
||||
class UselessFlag(_CheckFunction):
|
||||
DEFAULT_AUTOTOOLS_FLAG = re.compile(r"^.*{}".format("|".join([
|
||||
r"_AUTORECONF\s*=\s*NO",
|
||||
r"_LIBTOOL_PATCH\s*=\s*YES"])))
|
||||
DEFAULT_GENERIC_FLAG = re.compile(r"^.*{}".format("|".join([
|
||||
r"_INSTALL_IMAGES\s*=\s*NO",
|
||||
r"_REDISTRIBUTE\s*=\s*YES",
|
||||
r"_INSTALL_STAGING\s*=\s*NO",
|
||||
r"_INSTALL_TARGET\s*=\s*YES"])))
|
||||
END_CONDITIONAL = re.compile(r"^\s*({})".format("|".join(end_conditional)))
|
||||
START_CONDITIONAL = re.compile(r"^\s*({})".format("|".join(start_conditional)))
|
||||
|
||||
def before(self):
|
||||
self.conditional = 0
|
||||
|
||||
def check_line(self, lineno, text):
|
||||
if self.START_CONDITIONAL.search(text):
|
||||
self.conditional += 1
|
||||
return
|
||||
if self.END_CONDITIONAL.search(text):
|
||||
self.conditional -= 1
|
||||
return
|
||||
|
||||
# allow non-default conditionally overridden by default
|
||||
if self.conditional > 0:
|
||||
return
|
||||
|
||||
if self.DEFAULT_GENERIC_FLAG.search(text):
|
||||
return ["{}:{}: useless default value ({}#"
|
||||
"_infrastructure_for_packages_with_specific_build_systems)"
|
||||
.format(self.filename, lineno, self.url_to_manual),
|
||||
text]
|
||||
|
||||
if self.DEFAULT_AUTOTOOLS_FLAG.search(text) and not text.lstrip().startswith("HOST_"):
|
||||
return ["{}:{}: useless default value "
|
||||
"({}#_infrastructure_for_autotools_based_packages)"
|
||||
.format(self.filename, lineno, self.url_to_manual),
|
||||
text]
|
||||
|
||||
|
||||
class VariableWithBraces(_CheckFunction):
|
||||
VARIABLE_WITH_BRACES = re.compile(r"^[^#].*[^$]\${\w+}")
|
||||
|
||||
def check_line(self, lineno, text):
|
||||
if self.VARIABLE_WITH_BRACES.match(text.rstrip()):
|
||||
return ["{}:{}: use $() to delimit variables, not ${{}}"
|
||||
.format(self.filename, lineno),
|
||||
text]
|
||||
|
||||
|
||||
class CPEVariables(_CheckFunction):
|
||||
"""
|
||||
Check that the values for the CPE variables are not the default.
|
||||
- CPE_ID_* variables must not be set to their default
|
||||
- CPE_ID_VALID must not be set if a non-default CPE_ID variable is set
|
||||
"""
|
||||
def before(self):
|
||||
pkg, _ = os.path.splitext(os.path.basename(self.filename))
|
||||
self.CPE_fields_defaults = {
|
||||
"VALID": "NO",
|
||||
"PREFIX": "cpe:2.3:a",
|
||||
"VENDOR": f"{pkg}_project",
|
||||
"PRODUCT": pkg,
|
||||
"VERSION": None,
|
||||
"UPDATE": "*",
|
||||
}
|
||||
self.valid = None
|
||||
self.non_defaults = 0
|
||||
self.CPE_FIELDS_RE = re.compile(
|
||||
r"^\s*(.+_CPE_ID_({}))\s*=\s*(.+)$"
|
||||
.format("|".join(self.CPE_fields_defaults)),
|
||||
)
|
||||
self.VERSION_RE = re.compile(
|
||||
rf"^(HOST_)?{pkg.upper().replace('-', '_')}_VERSION\s*=\s*(.+)$",
|
||||
)
|
||||
self.COMMENT_RE = re.compile(r"^\s*#.*")
|
||||
|
||||
def check_line(self, lineno, text):
|
||||
text = self.COMMENT_RE.sub('', text.rstrip())
|
||||
|
||||
# WARNING! The VERSION_RE can _also_ match the same lines as CPE_FIELDS_RE,
|
||||
# but not the other way around. So we must first check for CPE_FIELDS_RE,
|
||||
# and if not matched, then and only then check for VERSION_RE.
|
||||
match = self.CPE_FIELDS_RE.match(text)
|
||||
if match:
|
||||
var, field, val = match.groups()
|
||||
return self._check_field(lineno, text, field, var, val)
|
||||
|
||||
match = self.VERSION_RE.match(text)
|
||||
if match:
|
||||
self.CPE_fields_defaults["VERSION"] = match.groups()[1]
|
||||
|
||||
def after(self):
|
||||
# "VALID" counts in the non-defaults; so when "VALID" is present,
|
||||
# 1 non-default means only "VALID" is present, so that's OK.
|
||||
if self.valid and self.non_defaults > 1:
|
||||
return ["{}:{}: 'YES' is implied when a non-default CPE_ID field is specified: {} ({}#cpe-id)".format(
|
||||
self.filename,
|
||||
self.valid["lineno"],
|
||||
self.valid["text"],
|
||||
self.url_to_manual,
|
||||
)]
|
||||
|
||||
def _check_field(self, lineno, text, field, var, val):
|
||||
if field == "VERSION" and self.CPE_fields_defaults[field] is None:
|
||||
return ["{}:{}: expecting package version to be set before CPE_ID_VERSION".format(
|
||||
self.filename,
|
||||
lineno,
|
||||
)]
|
||||
if val == self.CPE_fields_defaults[field]:
|
||||
return ["{}:{}: '{}' is the default value for {} ({}#cpe-id)".format(
|
||||
self.filename,
|
||||
lineno,
|
||||
val,
|
||||
var,
|
||||
self.url_to_manual,
|
||||
)]
|
||||
else:
|
||||
if field == "VALID":
|
||||
self.valid = {"lineno": lineno, "text": text}
|
||||
self.non_defaults += 1
|
||||
82
utils/checkpackagelib/lib_patch.py
Normal file
82
utils/checkpackagelib/lib_patch.py
Normal file
@@ -0,0 +1,82 @@
|
||||
# See utils/checkpackagelib/readme.txt before editing this file.
|
||||
# The format of the patch files is tested during the build, so below check
|
||||
# functions don't need to check for things already checked by running
|
||||
# "make package-dirclean package-patch".
|
||||
|
||||
import os
|
||||
import re
|
||||
|
||||
from checkpackagelib.base import _CheckFunction
|
||||
from checkpackagelib.lib import NewlineAtEof # noqa: F401
|
||||
from checkpackagelib.tool import NotExecutable # noqa: F401
|
||||
|
||||
|
||||
class ApplyOrder(_CheckFunction):
|
||||
APPLY_ORDER = re.compile(r"\d{1,4}-[^/]*$")
|
||||
|
||||
def before(self):
|
||||
if not self.APPLY_ORDER.match(os.path.basename(self.filename)):
|
||||
return ["{}:0: use name <number>-<description>.patch "
|
||||
"({}#_providing_patches)"
|
||||
.format(self.filename, self.url_to_manual)]
|
||||
|
||||
|
||||
class NumberedSubject(_CheckFunction):
|
||||
NUMBERED_PATCH = re.compile(r"Subject:\s*\[PATCH\s*\d+/\d+\]")
|
||||
|
||||
def before(self):
|
||||
self.git_patch = False
|
||||
self.lineno = 0
|
||||
self.text = None
|
||||
|
||||
def check_line(self, lineno, text):
|
||||
if text.startswith("diff --git"):
|
||||
self.git_patch = True
|
||||
return
|
||||
if self.NUMBERED_PATCH.search(text):
|
||||
self.lineno = lineno
|
||||
self.text = text
|
||||
|
||||
def after(self):
|
||||
if self.git_patch and self.text:
|
||||
return ["{}:{}: generate your patches with 'git format-patch -N'"
|
||||
.format(self.filename, self.lineno),
|
||||
self.text]
|
||||
|
||||
|
||||
class Sob(_CheckFunction):
|
||||
SOB_ENTRY = re.compile(r"^Signed-off-by: .*$")
|
||||
|
||||
def before(self):
|
||||
self.found = False
|
||||
|
||||
def check_line(self, lineno, text):
|
||||
if self.found:
|
||||
return
|
||||
if self.SOB_ENTRY.search(text):
|
||||
self.found = True
|
||||
|
||||
def after(self):
|
||||
if not self.found:
|
||||
return ["{}:0: missing Signed-off-by in the header "
|
||||
"({}#_format_and_licensing_of_the_package_patches)"
|
||||
.format(self.filename, self.url_to_manual)]
|
||||
|
||||
|
||||
class Upstream(_CheckFunction):
|
||||
UPSTREAM_ENTRY = re.compile(r"^Upstream: .*$")
|
||||
|
||||
def before(self):
|
||||
self.found = False
|
||||
|
||||
def check_line(self, lineno, text):
|
||||
if self.found:
|
||||
return
|
||||
if self.UPSTREAM_ENTRY.search(text):
|
||||
self.found = True
|
||||
|
||||
def after(self):
|
||||
if not self.found:
|
||||
return ["{}:0: missing Upstream in the header "
|
||||
"({}#_additional_patch_documentation)"
|
||||
.format(self.filename, self.url_to_manual)]
|
||||
1
utils/checkpackagelib/lib_python.py
Normal file
1
utils/checkpackagelib/lib_python.py
Normal file
@@ -0,0 +1 @@
|
||||
from checkpackagelib.tool import Flake8 # noqa: F401
|
||||
5
utils/checkpackagelib/lib_shellscript.py
Normal file
5
utils/checkpackagelib/lib_shellscript.py
Normal file
@@ -0,0 +1,5 @@
|
||||
from checkpackagelib.lib import ConsecutiveEmptyLines # noqa: F401
|
||||
from checkpackagelib.lib import EmptyLastLine # noqa: F401
|
||||
from checkpackagelib.lib import NewlineAtEof # noqa: F401
|
||||
from checkpackagelib.lib import TrailingSpace # noqa: F401
|
||||
from checkpackagelib.tool import Shellcheck # noqa: F401
|
||||
72
utils/checkpackagelib/lib_sysv.py
Normal file
72
utils/checkpackagelib/lib_sysv.py
Normal file
@@ -0,0 +1,72 @@
|
||||
import os
|
||||
import re
|
||||
|
||||
from checkpackagelib.base import _CheckFunction
|
||||
from checkpackagelib.lib import ConsecutiveEmptyLines # noqa: F401
|
||||
from checkpackagelib.lib import EmptyLastLine # noqa: F401
|
||||
from checkpackagelib.lib import NewlineAtEof # noqa: F401
|
||||
from checkpackagelib.lib import TrailingSpace # noqa: F401
|
||||
import checkpackagelib.tool
|
||||
from checkpackagelib.tool import Shellcheck # noqa: F401
|
||||
|
||||
|
||||
class Indent(_CheckFunction):
|
||||
INDENTED_WITH_SPACES = re.compile(r"^[\t]* ")
|
||||
|
||||
def check_line(self, lineno, text):
|
||||
if self.INDENTED_WITH_SPACES.search(text.rstrip()):
|
||||
return ["{}:{}: should be indented with tabs ({}#adding-packages-start-script)"
|
||||
.format(self.filename, lineno, self.url_to_manual),
|
||||
text]
|
||||
|
||||
|
||||
class NotExecutable(checkpackagelib.tool.NotExecutable):
|
||||
def ignore(self):
|
||||
return 'etc/init.d/' in self.filename
|
||||
|
||||
def hint(self):
|
||||
return ", just make sure you use '$(INSTALL) -D -m 0755' in the .mk file"
|
||||
|
||||
|
||||
class Variables(_CheckFunction):
|
||||
DAEMON_VAR = re.compile(r"^DAEMON=[\"']{0,1}([^\"']*)[\"']{0,1}")
|
||||
PIDFILE_PATTERN = re.compile(r"/var/run/(\$DAEMON|\$\{DAEMON\}).pid")
|
||||
PIDFILE_VAR = re.compile(r"^PIDFILE=[\"']{0,1}([^\"']*)[\"']{0,1}")
|
||||
|
||||
def before(self):
|
||||
self.name = None
|
||||
|
||||
def check_line(self, lineno, text):
|
||||
name_found = self.DAEMON_VAR.search(text.rstrip())
|
||||
if name_found:
|
||||
if self.name:
|
||||
return ["{}:{}: DAEMON variable redefined ({}#adding-packages-start-script)"
|
||||
.format(self.filename, lineno, self.url_to_manual),
|
||||
text]
|
||||
self.name = name_found.group(1)
|
||||
if '/' in self.name:
|
||||
self.name = os.path.basename(self.name) # to be used in after() to check the expected filename
|
||||
return ["{}:{}: Do not include path in DAEMON ({}#adding-packages-start-script)"
|
||||
.format(self.filename, lineno, self.url_to_manual),
|
||||
text,
|
||||
'DAEMON="{}"'.format(self.name)]
|
||||
return
|
||||
|
||||
pidfile_found = self.PIDFILE_VAR.search(text.rstrip())
|
||||
if pidfile_found:
|
||||
pidfile = pidfile_found.group(1)
|
||||
if not self.PIDFILE_PATTERN.match(pidfile):
|
||||
return ["{}:{}: Incorrect PIDFILE value ({}#adding-packages-start-script)"
|
||||
.format(self.filename, lineno, self.url_to_manual),
|
||||
text,
|
||||
'PIDFILE="/var/run/$DAEMON.pid"']
|
||||
|
||||
def after(self):
|
||||
if self.name is None:
|
||||
return ["{}:0: DAEMON variable not defined ({}#adding-packages-start-script)"
|
||||
.format(self.filename, self.url_to_manual)]
|
||||
expected_filename = re.compile(r"S\d\d{}$".format(self.name))
|
||||
if not expected_filename.match(os.path.basename(self.filename)):
|
||||
return ["{}:0: filename should be S<number><number><daemon name> ({}#adding-packages-start-script)"
|
||||
.format(self.filename, self.url_to_manual),
|
||||
"expecting S<number><number>{}".format(self.name)]
|
||||
74
utils/checkpackagelib/readme.txt
Normal file
74
utils/checkpackagelib/readme.txt
Normal file
@@ -0,0 +1,74 @@
|
||||
How the scripts are structured:
|
||||
- check-package is the main engine, called by the user.
|
||||
For each input file, this script decides which parser should be used and it
|
||||
collects all classes declared in the library file and instantiates them.
|
||||
The main engine opens the input files and it serves each raw line (including
|
||||
newline!) to the method check_line() of every check object.
|
||||
Two special methods before() and after() are used to call the initialization
|
||||
of variables (for the case it needs to keep data across calls) and the
|
||||
equivalent finalization (e.g. for the case a warning must be issued if some
|
||||
pattern is not in the input file).
|
||||
- base.py contains the base class for all check functions.
|
||||
- lib.py contains the classes for common check functions.
|
||||
Each check function is explicitly included in a given type-parsing library.
|
||||
Do not include every single check function in this file, a class that will
|
||||
only parse hash files should be implemented in the hash-parsing library.
|
||||
When a warning must be issued, the check function returns an array of strings.
|
||||
Each string is a warning message and is displayed if the corresponding verbose
|
||||
level is active. When the script is called without --verbose only the first
|
||||
warning in the returned array is printed; when called with --verbose both
|
||||
first and second warnings are printed; when called with -vv until the third
|
||||
warning is printed; an so on.
|
||||
Helper functions can be defined and will not be called by the main script.
|
||||
- lib_type.py contains check functions specific to files of this type.
|
||||
|
||||
Some hints when changing this code:
|
||||
- test your changes: utils/check-package --test-suite
|
||||
- prefer O(n) algorithms, where n is the total number of lines in the files
|
||||
processed.
|
||||
- when there is no other reason for ordering, use alphabetical order (e.g. keep
|
||||
the check functions in alphabetical order, keep the imports in alphabetical
|
||||
order, and so on).
|
||||
- keep in mind that for every class the method before() will be called before
|
||||
any line is served to be checked by the method check_line(). A class that
|
||||
checks the filename should only implement the method before(). A function that
|
||||
needs to keep data across calls (e.g. keep the last line before the one being
|
||||
processed) should initialize all variables using this method.
|
||||
- keep in mind that for every class the method after() will be called after all
|
||||
lines were served to be checked by the method check_line(). A class that
|
||||
checks the absence of a pattern in the file will need to use this method.
|
||||
- try to avoid false warnings. It's better to not issue a warning message to a
|
||||
corner case than have too many false warnings. The second can make users stop
|
||||
using the script.
|
||||
- do not check spacing in the input line in every single function. Trailing
|
||||
whitespace and wrong indentation should be checked by separate functions.
|
||||
- avoid duplicate tests. Try to test only one thing in each function.
|
||||
- in the warning message, include the url to a section from the manual, when
|
||||
applicable. It potentially will make more people know the manual.
|
||||
- use short sentences in the warning messages. A complete explanation can be
|
||||
added to show when --verbose is used.
|
||||
- when testing, verify the error message is displayed when the error pattern is
|
||||
found, but also verify the error message is not displayed for few
|
||||
well-formatted packages... there are many of these, just pick your favorite
|
||||
as golden package that should not trigger any warning message.
|
||||
- check the url displayed by the warning message works.
|
||||
|
||||
Usage examples:
|
||||
- to get a list of check functions that would be called without actually
|
||||
calling them you can use the --dry-run option:
|
||||
$ utils/check-package --dry-run package/yourfavorite/*
|
||||
|
||||
- when you just added a new check function, e.g. Something, check how it behaves
|
||||
for all current packages:
|
||||
$ utils/check-package --include-only Something $(find package -type f)
|
||||
|
||||
- the effective processing time (when the .pyc were already generated and all
|
||||
files to be processed are cached in the RAM) should stay in the order of few
|
||||
seconds:
|
||||
$ utils/check-package $(find package -type f) >/dev/null ; \
|
||||
time utils/check-package $(find package -type f) >/dev/null
|
||||
|
||||
- vim users can navigate the warnings (most editors probably have similar
|
||||
function) since warnings are generated in the form 'path/file:line: warning':
|
||||
$ find package/ -name 'Config.*' > filelist && vim -c \
|
||||
'set makeprg=utils/check-package\ $(cat\ filelist)' -c make -c copen
|
||||
212
utils/checkpackagelib/test_lib.py
Normal file
212
utils/checkpackagelib/test_lib.py
Normal file
@@ -0,0 +1,212 @@
|
||||
import pytest
|
||||
import checkpackagelib.test_util as util
|
||||
import checkpackagelib.lib as m
|
||||
|
||||
|
||||
ConsecutiveEmptyLines = [
|
||||
('1 line (no newline)',
|
||||
'any',
|
||||
'',
|
||||
[]),
|
||||
('1 line',
|
||||
'any',
|
||||
'\n',
|
||||
[]),
|
||||
('2 lines',
|
||||
'any',
|
||||
'\n'
|
||||
'\n',
|
||||
[['any:2: consecutive empty lines']]),
|
||||
('more than 2 consecutive',
|
||||
'any',
|
||||
'\n'
|
||||
'\n'
|
||||
'\n',
|
||||
[['any:2: consecutive empty lines'],
|
||||
['any:3: consecutive empty lines']]),
|
||||
('ignore whitespace 1',
|
||||
'any',
|
||||
'\n'
|
||||
' ',
|
||||
[['any:2: consecutive empty lines']]),
|
||||
('ignore whitespace 2',
|
||||
'any',
|
||||
' \n'
|
||||
'\t\n',
|
||||
[['any:2: consecutive empty lines']]),
|
||||
]
|
||||
|
||||
|
||||
@pytest.mark.parametrize('testname,filename,string,expected', ConsecutiveEmptyLines)
|
||||
def test_ConsecutiveEmptyLines(testname, filename, string, expected):
|
||||
warnings = util.check_file(m.ConsecutiveEmptyLines, filename, string)
|
||||
assert warnings == expected
|
||||
|
||||
|
||||
EmptyLastLine = [
|
||||
('ignore empty file',
|
||||
'any',
|
||||
'',
|
||||
[]),
|
||||
('empty line (newline)',
|
||||
'any',
|
||||
'\n',
|
||||
[['any:1: empty line at end of file']]),
|
||||
('empty line (space, newline)',
|
||||
'any',
|
||||
' \n',
|
||||
[['any:1: empty line at end of file']]),
|
||||
('empty line (space, no newline)',
|
||||
'any',
|
||||
' ',
|
||||
[['any:1: empty line at end of file']]),
|
||||
('warn for the last of 2',
|
||||
'any',
|
||||
'\n'
|
||||
'\n',
|
||||
[['any:2: empty line at end of file']]),
|
||||
('warn for the last of 3',
|
||||
'any',
|
||||
'\n'
|
||||
'\n'
|
||||
'\n',
|
||||
[['any:3: empty line at end of file']]),
|
||||
('ignore whitespace',
|
||||
'any',
|
||||
' \n'
|
||||
'\t\n',
|
||||
[['any:2: empty line at end of file']]),
|
||||
]
|
||||
|
||||
|
||||
@pytest.mark.parametrize('testname,filename,string,expected', EmptyLastLine)
|
||||
def test_EmptyLastLine(testname, filename, string, expected):
|
||||
warnings = util.check_file(m.EmptyLastLine, filename, string)
|
||||
assert warnings == expected
|
||||
|
||||
|
||||
NewlineAtEof = [
|
||||
('good',
|
||||
'any',
|
||||
'text\n',
|
||||
[]),
|
||||
('text (bad)',
|
||||
'any',
|
||||
'\n'
|
||||
'text',
|
||||
[['any:2: missing newline at end of file',
|
||||
'text']]),
|
||||
('space (bad)',
|
||||
'any',
|
||||
'\n'
|
||||
' ',
|
||||
[['any:2: missing newline at end of file',
|
||||
' ']]),
|
||||
('tab (bad)',
|
||||
'any',
|
||||
'\n'
|
||||
'\t',
|
||||
[['any:2: missing newline at end of file',
|
||||
'\t']]),
|
||||
('even for file with one line',
|
||||
'any',
|
||||
' ',
|
||||
[['any:1: missing newline at end of file',
|
||||
' ']]),
|
||||
]
|
||||
|
||||
|
||||
@pytest.mark.parametrize('testname,filename,string,expected', NewlineAtEof)
|
||||
def test_NewlineAtEof(testname, filename, string, expected):
|
||||
warnings = util.check_file(m.NewlineAtEof, filename, string)
|
||||
assert warnings == expected
|
||||
|
||||
|
||||
TrailingSpace = [
|
||||
('good',
|
||||
'any',
|
||||
'text\n',
|
||||
[]),
|
||||
('ignore missing newline',
|
||||
'any',
|
||||
'\n'
|
||||
'text',
|
||||
[]),
|
||||
('spaces',
|
||||
'any',
|
||||
'text \n',
|
||||
[['any:1: line contains trailing whitespace',
|
||||
'text \n']]),
|
||||
('tabs after text',
|
||||
'any',
|
||||
'text\t\t\n',
|
||||
[['any:1: line contains trailing whitespace',
|
||||
'text\t\t\n']]),
|
||||
('mix of tabs and spaces',
|
||||
'any',
|
||||
' \n'
|
||||
' ',
|
||||
[['any:1: line contains trailing whitespace',
|
||||
' \n'],
|
||||
['any:2: line contains trailing whitespace',
|
||||
' ']]),
|
||||
('blank line with tabs',
|
||||
'any',
|
||||
'\n'
|
||||
'\t',
|
||||
[['any:2: line contains trailing whitespace',
|
||||
'\t']]),
|
||||
]
|
||||
|
||||
|
||||
@pytest.mark.parametrize('testname,filename,string,expected', TrailingSpace)
|
||||
def test_TrailingSpace(testname, filename, string, expected):
|
||||
warnings = util.check_file(m.TrailingSpace, filename, string)
|
||||
assert warnings == expected
|
||||
|
||||
|
||||
Utf8Characters = [
|
||||
('usual',
|
||||
'any',
|
||||
'text\n',
|
||||
[]),
|
||||
('acceptable character',
|
||||
'any',
|
||||
'\x60',
|
||||
[]),
|
||||
('unacceptable character',
|
||||
'any',
|
||||
'\x81',
|
||||
[['any:1: line contains UTF-8 characters',
|
||||
'\x81']]),
|
||||
('2 warnings',
|
||||
'any',
|
||||
'text\n'
|
||||
'text \xc8 text\n'
|
||||
'\xc9\n',
|
||||
[['any:2: line contains UTF-8 characters',
|
||||
'text \xc8 text\n'],
|
||||
['any:3: line contains UTF-8 characters',
|
||||
'\xc9\n']]),
|
||||
]
|
||||
|
||||
|
||||
@pytest.mark.parametrize('testname,filename,string,expected', Utf8Characters)
|
||||
def test_Utf8Characters(testname, filename, string, expected):
|
||||
warnings = util.check_file(m.Utf8Characters, filename, string)
|
||||
assert warnings == expected
|
||||
|
||||
|
||||
def test_all_check_functions_are_used():
|
||||
import inspect
|
||||
import checkpackagelib.lib_config as lib_config
|
||||
import checkpackagelib.lib_hash as lib_hash
|
||||
import checkpackagelib.lib_mk as lib_mk
|
||||
import checkpackagelib.lib_patch as lib_patch
|
||||
c_config = [c[0] for c in inspect.getmembers(lib_config, inspect.isclass)]
|
||||
c_hash = [c[0] for c in inspect.getmembers(lib_hash, inspect.isclass)]
|
||||
c_mk = [c[0] for c in inspect.getmembers(lib_mk, inspect.isclass)]
|
||||
c_patch = [c[0] for c in inspect.getmembers(lib_patch, inspect.isclass)]
|
||||
c_all = c_config + c_hash + c_mk + c_patch
|
||||
c_common = [c[0] for c in inspect.getmembers(m, inspect.isclass)]
|
||||
assert set(c_common) <= set(c_all)
|
||||
498
utils/checkpackagelib/test_lib_config.py
Normal file
498
utils/checkpackagelib/test_lib_config.py
Normal file
@@ -0,0 +1,498 @@
|
||||
import pytest
|
||||
import checkpackagelib.test_util as util
|
||||
import checkpackagelib.lib_config as m
|
||||
|
||||
|
||||
AttributesOrder = [
|
||||
('good example',
|
||||
'any',
|
||||
'config BR2_PACKAGE_FOO\n'
|
||||
'bool "foo"\n'
|
||||
'default y\n'
|
||||
'depends on BR2_USE_BAR # runtime\n'
|
||||
'select BR2_PACKAGE_BAZ\n'
|
||||
'help\n'
|
||||
'\t help text\n',
|
||||
[]),
|
||||
('depends before default',
|
||||
'any',
|
||||
'config BR2_PACKAGE_FOO\n'
|
||||
'bool "foo"\n'
|
||||
'depends on BR2_USE_BAR\n'
|
||||
'default y\n',
|
||||
[['any:4: attributes order: type, default, depends on, select, help (url#_config_files)',
|
||||
'default y\n']]),
|
||||
('select after help',
|
||||
'any',
|
||||
'config BR2_PACKAGE_FOO\n'
|
||||
'bool "foo"\n'
|
||||
'help\n'
|
||||
'\t help text\n'
|
||||
'select BR2_PACKAGE_BAZ\n',
|
||||
[['any:5: attributes order: type, default, depends on, select, help (url#_config_files)',
|
||||
'select BR2_PACKAGE_BAZ\n']]),
|
||||
('string',
|
||||
'any',
|
||||
'config BR2_PACKAGE_FOO_PLUGINS\n'
|
||||
'string "foo plugins"\n'
|
||||
'default "all"\n',
|
||||
[]),
|
||||
('ignore tabs',
|
||||
'any',
|
||||
'config\tBR2_PACKAGE_FOO_PLUGINS\n'
|
||||
'default\t"all"\n'
|
||||
'string\t"foo plugins"\n',
|
||||
[['any:3: attributes order: type, default, depends on, select, help (url#_config_files)',
|
||||
'string\t"foo plugins"\n']]),
|
||||
('choice',
|
||||
'any',
|
||||
'config BR2_PACKAGE_FOO\n'
|
||||
'bool "foo"\n'
|
||||
'if BR2_PACKAGE_FOO\n'
|
||||
'\n'
|
||||
'choice\n'
|
||||
'prompt "type of foo"\n'
|
||||
'default BR2_PACKAGE_FOO_STRING\n'
|
||||
'\n'
|
||||
'config BR2_PACKAGE_FOO_NONE\n'
|
||||
'bool "none"\n'
|
||||
'\n'
|
||||
'config BR2_PACKAGE_FOO_STRING\n'
|
||||
'bool "string"\n'
|
||||
'\n'
|
||||
'endchoice\n'
|
||||
'\n'
|
||||
'endif\n'
|
||||
'\n',
|
||||
[]),
|
||||
('type after default',
|
||||
'any',
|
||||
'config BR2_PACKAGE_FOO\n'
|
||||
'bool "foo"\n'
|
||||
'if BR2_PACKAGE_FOO\n'
|
||||
'\n'
|
||||
'choice\n'
|
||||
'default BR2_PACKAGE_FOO_STRING\n'
|
||||
'prompt "type of foo"\n',
|
||||
[['any:7: attributes order: type, default, depends on, select, help (url#_config_files)',
|
||||
'prompt "type of foo"\n']]),
|
||||
('menu',
|
||||
'any',
|
||||
'menuconfig BR2_PACKAGE_FOO\n'
|
||||
'bool "foo"\n'
|
||||
'help\n'
|
||||
'\t help text\n'
|
||||
'\t help text\n'
|
||||
'\n'
|
||||
'if BR2_PACKAGE_FOO\n'
|
||||
'\n'
|
||||
'menu "foo plugins"\n'
|
||||
'config BR2_PACKAGE_FOO_COUNTER\n'
|
||||
'bool "counter"\n'
|
||||
'\n'
|
||||
'endmenu\n'
|
||||
'\n'
|
||||
'endif\n',
|
||||
[]),
|
||||
]
|
||||
|
||||
|
||||
@pytest.mark.parametrize('testname,filename,string,expected', AttributesOrder)
|
||||
def test_AttributesOrder(testname, filename, string, expected):
|
||||
warnings = util.check_file(m.AttributesOrder, filename, string)
|
||||
assert warnings == expected
|
||||
|
||||
|
||||
CommentsMenusPackagesOrder = [
|
||||
('top menu (good)',
|
||||
'package/Config.in',
|
||||
'menu "Target packages"\n'
|
||||
'source "package/busybox/Config.in"\n'
|
||||
'source "package/skeleton/Config.in"\n',
|
||||
[]),
|
||||
('top menu (bad)',
|
||||
'package/Config.in',
|
||||
'source "package/skeleton/Config.in"\n'
|
||||
'source "package/busybox/Config.in"\n',
|
||||
[['package/Config.in:2: Packages in: The top level menu,\n'
|
||||
' are not alphabetically ordered;\n'
|
||||
" correct order: '-', '_', digits, capitals, lowercase;\n"
|
||||
' first incorrect package: busybox',
|
||||
'source "package/busybox/Config.in"\n']]),
|
||||
('menu (bad)',
|
||||
'package/Config.in',
|
||||
'menu "Target packages"\n'
|
||||
'source "package/skeleton/Config.in"\n'
|
||||
'source "package/busybox/Config.in"\n',
|
||||
[['package/Config.in:3: Packages in: menu "Target packages",\n'
|
||||
' are not alphabetically ordered;\n'
|
||||
" correct order: '-', '_', digits, capitals, lowercase;\n"
|
||||
' first incorrect package: busybox',
|
||||
'source "package/busybox/Config.in"\n']]),
|
||||
('underscore (good)',
|
||||
'package/Config.in.host',
|
||||
'menu "Hardware handling"\n'
|
||||
'menu "Firmware"\n'
|
||||
'endmenu\n'
|
||||
'source "package/usb_modeswitch/Config.in"\n'
|
||||
'source "package/usbmount/Config.in"\n',
|
||||
[]),
|
||||
('underscore (bad)',
|
||||
'package/Config.in.host',
|
||||
'menu "Hardware handling"\n'
|
||||
'menu "Firmware"\n'
|
||||
'endmenu\n'
|
||||
'source "package/usbmount/Config.in"\n'
|
||||
'source "package/usb_modeswitch/Config.in"\n',
|
||||
[['package/Config.in.host:5: Packages in: menu "Hardware handling",\n'
|
||||
' are not alphabetically ordered;\n'
|
||||
" correct order: '-', '_', digits, capitals, lowercase;\n"
|
||||
' first incorrect package: usb_modeswitch',
|
||||
'source "package/usb_modeswitch/Config.in"\n']]),
|
||||
('ignore other files',
|
||||
'any other file',
|
||||
'menu "Hardware handling"\n'
|
||||
'source "package/bbb/Config.in"\n'
|
||||
'source "package/aaa/Config.in"\n',
|
||||
[]),
|
||||
('dash (bad)',
|
||||
'package/Config.in',
|
||||
'menu "packages"\n'
|
||||
'source "package/a_a/Config.in"\n'
|
||||
'source "package/a-a/Config.in"\n'
|
||||
'source "package/a1a/Config.in"\n'
|
||||
'source "package/aAa/Config.in"\n'
|
||||
'source "package/aaa/Config.in"\n',
|
||||
[['package/Config.in:3: Packages in: menu "packages",\n'
|
||||
' are not alphabetically ordered;\n'
|
||||
" correct order: '-', '_', digits, capitals, lowercase;\n"
|
||||
' first incorrect package: a-a',
|
||||
'source "package/a-a/Config.in"\n']]),
|
||||
('underscore (bad)',
|
||||
'package/Config.in',
|
||||
'menu "packages"\n'
|
||||
'source "package/a-a/Config.in"\n'
|
||||
'source "package/a1a/Config.in"\n'
|
||||
'source "package/a_a/Config.in"\n'
|
||||
'source "package/aAa/Config.in"\n'
|
||||
'source "package/aaa/Config.in"\n',
|
||||
[['package/Config.in:4: Packages in: menu "packages",\n'
|
||||
' are not alphabetically ordered;\n'
|
||||
" correct order: '-', '_', digits, capitals, lowercase;\n"
|
||||
' first incorrect package: a_a',
|
||||
'source "package/a_a/Config.in"\n']]),
|
||||
('digit (bad)',
|
||||
'package/Config.in',
|
||||
'menu "packages"\n'
|
||||
'source "package/a-a/Config.in"\n'
|
||||
'source "package/a_a/Config.in"\n'
|
||||
'source "package/aAa/Config.in"\n'
|
||||
'source "package/a1a/Config.in"\n'
|
||||
'source "package/aaa/Config.in"\n',
|
||||
[['package/Config.in:5: Packages in: menu "packages",\n'
|
||||
' are not alphabetically ordered;\n'
|
||||
" correct order: '-', '_', digits, capitals, lowercase;\n"
|
||||
' first incorrect package: a1a',
|
||||
'source "package/a1a/Config.in"\n']]),
|
||||
('capitals (bad)',
|
||||
'package/Config.in',
|
||||
'menu "packages"\n'
|
||||
'source "package/a-a/Config.in"\n'
|
||||
'source "package/a_a/Config.in"\n'
|
||||
'source "package/a1a/Config.in"\n'
|
||||
'source "package/aaa/Config.in"\n'
|
||||
'source "package/aAa/Config.in"\n',
|
||||
[['package/Config.in:6: Packages in: menu "packages",\n'
|
||||
' are not alphabetically ordered;\n'
|
||||
" correct order: '-', '_', digits, capitals, lowercase;\n"
|
||||
' first incorrect package: aAa',
|
||||
'source "package/aAa/Config.in"\n']]),
|
||||
('digits, capitals, underscore (good)',
|
||||
'package/Config.in',
|
||||
'menu "packages"\n'
|
||||
'source "package/a-a/Config.in"\n'
|
||||
'source "package/a_a/Config.in"\n'
|
||||
'source "package/a1a/Config.in"\n'
|
||||
'source "package/aAa/Config.in"\n'
|
||||
'source "package/aaa/Config.in"\n',
|
||||
[]),
|
||||
('conditional menu (good)',
|
||||
'package/Config.in',
|
||||
'menu "Other"\n'
|
||||
'source "package/linux-pam/Config.in"\n'
|
||||
'if BR2_PACKAGE_LINUX_PAM\n'
|
||||
'comment "linux-pam plugins"\n'
|
||||
'source "package/libpam-radius-auth/Config.in"\n'
|
||||
'source "package/libpam-tacplus/Config.in"\n'
|
||||
'endif\n'
|
||||
'source "package/liquid-dsp/Config.in"\n',
|
||||
[]),
|
||||
('conditional menu (bad)',
|
||||
'package/Config.in',
|
||||
'menu "Other"\n'
|
||||
'source "package/linux-pam/Config.in"\n'
|
||||
'if BR2_PACKAGE_LINUX_PAM\n'
|
||||
'comment "linux-pam plugins"\n'
|
||||
'source "package/libpam-tacplus/Config.in"\n'
|
||||
'source "package/libpam-radius-auth/Config.in"\n'
|
||||
'endif\n'
|
||||
'source "package/liquid-dsp/Config.in"\n',
|
||||
[['package/Config.in:6: Packages in: comment "linux-pam plugins",\n'
|
||||
' are not alphabetically ordered;\n'
|
||||
" correct order: '-', '_', digits, capitals, lowercase;\n"
|
||||
' first incorrect package: libpam-radius-auth',
|
||||
'source "package/libpam-radius-auth/Config.in"\n']]),
|
||||
('no conditional (bad)',
|
||||
'package/Config.in',
|
||||
'menu "Other"\n'
|
||||
'source "package/linux-pam/Config.in"\n'
|
||||
'source "package/libpam-radius-auth/Config.in"\n'
|
||||
'source "package/libpam-tacplus/Config.in"\n'
|
||||
'source "package/liquid-dsp/Config.in"\n',
|
||||
[['package/Config.in:3: Packages in: menu "Other",\n'
|
||||
' are not alphabetically ordered;\n'
|
||||
" correct order: '-', '_', digits, capitals, lowercase;\n"
|
||||
' first incorrect package: libpam-radius-auth',
|
||||
'source "package/libpam-radius-auth/Config.in"\n']]),
|
||||
]
|
||||
|
||||
|
||||
@pytest.mark.parametrize('testname,filename,string,expected', CommentsMenusPackagesOrder)
|
||||
def test_CommentsMenusPackagesOrder(testname, filename, string, expected):
|
||||
warnings = util.check_file(m.CommentsMenusPackagesOrder, filename, string)
|
||||
assert warnings == expected
|
||||
|
||||
|
||||
HelpText = [
|
||||
('single line',
|
||||
'any',
|
||||
'config BR2_PACKAGE_FOO\n'
|
||||
'bool "foo"\n'
|
||||
'default y\n'
|
||||
'depends on BR2_USE_BAR # runtime\n'
|
||||
'select BR2_PACKAGE_BAZ\n'
|
||||
'help\n'
|
||||
'\t help text\n',
|
||||
[]),
|
||||
('larger than 72',
|
||||
'any',
|
||||
'help\n'
|
||||
'\t 123456789 123456789 123456789 123456789 123456789 123456789 12\n'
|
||||
'\t 123456789 123456789 123456789 123456789 123456789 123456789 123\n'
|
||||
'\t help text\n',
|
||||
[['any:3: help text: <tab><2 spaces><62 chars> (url#writing-rules-config-in)',
|
||||
'\t 123456789 123456789 123456789 123456789 123456789 123456789 123\n',
|
||||
'\t 123456789 123456789 123456789 123456789 123456789 123456789 12']]),
|
||||
('long url at beginning of line',
|
||||
'any',
|
||||
'help\n'
|
||||
'\t 123456789 123456789 123456789 123456789 123456789 123456789 12\n'
|
||||
'\t http://url.that.is.longer.than.seventy.two.characthers/folder_name\n'
|
||||
'\t https://url.that.is.longer.than.seventy.two.characthers/folder_name\n'
|
||||
'\t git://url.that.is.longer.than.seventy.two.characthers/folder_name\n',
|
||||
[]),
|
||||
('long url not at beginning of line',
|
||||
'any',
|
||||
'help\n'
|
||||
'\t 123456789 123456789 123456789 123456789 123456789 123456789 12\n'
|
||||
'\t refer to http://url.that.is.longer.than.seventy.two.characthers/folder_name\n'
|
||||
'\n'
|
||||
'\t http://url.that.is.longer.than.seventy.two.characthers/folder_name\n',
|
||||
[['any:3: help text: <tab><2 spaces><62 chars> (url#writing-rules-config-in)',
|
||||
'\t refer to http://url.that.is.longer.than.seventy.two.characthers/folder_name\n',
|
||||
'\t 123456789 123456789 123456789 123456789 123456789 123456789 12']]),
|
||||
('allow beautified items',
|
||||
'any',
|
||||
'help\n'
|
||||
'\t 123456789 123456789 123456789 123456789 123456789 123456789 12\n'
|
||||
'\t summary:\n'
|
||||
'\t - enable that config\n'
|
||||
'\t - built it\n',
|
||||
[]),
|
||||
]
|
||||
|
||||
|
||||
@pytest.mark.parametrize('testname,filename,string,expected', HelpText)
|
||||
def test_HelpText(testname, filename, string, expected):
|
||||
warnings = util.check_file(m.HelpText, filename, string)
|
||||
assert warnings == expected
|
||||
|
||||
|
||||
Indent = [
|
||||
('good example',
|
||||
'any',
|
||||
'config BR2_PACKAGE_FOO\n'
|
||||
'\tbool "foo"\n'
|
||||
'\tdefault y\n'
|
||||
'\tdepends on BR2_TOOLCHAIN_HAS_THREADS\n'
|
||||
'\tdepends on BR2_INSTALL_LIBSTDCPP\n'
|
||||
'# very useful comment\n'
|
||||
'\tselect BR2_PACKAGE_BAZ\n'
|
||||
'\thelp\n'
|
||||
'\t help text\n'
|
||||
'\n'
|
||||
'comment "foo needs toolchain w/ C++, threads"\n'
|
||||
'\tdepends on !BR2_INSTALL_LIBSTDCPP || \\\n'
|
||||
'\t\t!BR2_TOOLCHAIN_HAS_THREADS\n'
|
||||
'\n'
|
||||
'source "package/foo/bar/Config.in"\n',
|
||||
[]),
|
||||
('spaces',
|
||||
'any',
|
||||
'config BR2_PACKAGE_FOO\n'
|
||||
' bool "foo"\n',
|
||||
[['any:2: should be indented with one tab (url#_config_files)',
|
||||
' bool "foo"\n']]),
|
||||
('without indent',
|
||||
'any',
|
||||
'config BR2_PACKAGE_FOO\n'
|
||||
'default y\n',
|
||||
[['any:2: should be indented with one tab (url#_config_files)',
|
||||
'default y\n']]),
|
||||
('too much tabs',
|
||||
'any',
|
||||
'config BR2_PACKAGE_FOO\n'
|
||||
'\t\tdepends on BR2_TOOLCHAIN_HAS_THREADS\n',
|
||||
[['any:2: should be indented with one tab (url#_config_files)',
|
||||
'\t\tdepends on BR2_TOOLCHAIN_HAS_THREADS\n']]),
|
||||
('help',
|
||||
'any',
|
||||
'config BR2_PACKAGE_FOO\n'
|
||||
' help\n',
|
||||
[['any:2: should be indented with one tab (url#_config_files)',
|
||||
' help\n']]),
|
||||
('continuation line',
|
||||
'any',
|
||||
'comment "foo needs toolchain w/ C++, threads"\n'
|
||||
'\tdepends on !BR2_INSTALL_LIBSTDCPP || \\\n'
|
||||
' !BR2_TOOLCHAIN_HAS_THREADS\n',
|
||||
[['any:3: continuation line should be indented using tabs',
|
||||
' !BR2_TOOLCHAIN_HAS_THREADS\n']]),
|
||||
('comment with tabs',
|
||||
'any',
|
||||
'\tcomment "foo needs toolchain w/ C++, threads"\n',
|
||||
[['any:1: should not be indented',
|
||||
'\tcomment "foo needs toolchain w/ C++, threads"\n']]),
|
||||
('comment with spaces',
|
||||
'any',
|
||||
' comment "foo needs toolchain w/ C++, threads"\n',
|
||||
[['any:1: should not be indented',
|
||||
' comment "foo needs toolchain w/ C++, threads"\n']]),
|
||||
]
|
||||
|
||||
|
||||
@pytest.mark.parametrize('testname,filename,string,expected', Indent)
|
||||
def test_Indent(testname, filename, string, expected):
|
||||
warnings = util.check_file(m.Indent, filename, string)
|
||||
assert warnings == expected
|
||||
|
||||
|
||||
NoDefaultN = [
|
||||
('good example',
|
||||
'any',
|
||||
'config BR2_PACKAGE_FOO\n'
|
||||
'\tdefault y\n',
|
||||
[]),
|
||||
('default n',
|
||||
'any',
|
||||
'config BR2_PACKAGE_FOO\n'
|
||||
'\tdefault n\n',
|
||||
[['any:2: boolean symbols default to \'n\', so \'default n\' is redundant',
|
||||
'\tdefault n\n']]),
|
||||
('default n with comment',
|
||||
'any',
|
||||
'config BR2_PACKAGE_FOO\n'
|
||||
'\tdefault n # this is a comment\n',
|
||||
[['any:2: boolean symbols default to \'n\', so \'default n\' is redundant',
|
||||
'\tdefault n # this is a comment\n']]),
|
||||
('default n with trailing whitespace',
|
||||
'any',
|
||||
'config BR2_PACKAGE_FOO\n'
|
||||
'\tdefault n \t\n',
|
||||
[['any:2: boolean symbols default to \'n\', so \'default n\' is redundant',
|
||||
'\tdefault n \t\n']])
|
||||
]
|
||||
|
||||
|
||||
@pytest.mark.parametrize('testname,filename,string,expected', NoDefaultN)
|
||||
def test_NoDefaultN(testname, filename, string, expected):
|
||||
warnings = util.check_file(m.NoDefaultN, filename, string)
|
||||
assert warnings == expected
|
||||
|
||||
|
||||
RedefinedConfig = [
|
||||
('no redefinition',
|
||||
'any',
|
||||
'config BR2_PACKAGE_FOO\n'
|
||||
'bool "foo"\n'
|
||||
'config BR2_PACKAGE_FOO_BAR\n'
|
||||
'bool "foo"\n',
|
||||
[]),
|
||||
('no conditional',
|
||||
'any',
|
||||
'config BR2_PACKAGE_FOO\n'
|
||||
'bool "foo"\n'
|
||||
'config BR2_PACKAGE_BAR\n'
|
||||
'bool "bar"\n'
|
||||
'config BR2_PACKAGE_FOO\n'
|
||||
'bool "foo"\n',
|
||||
[['any:5: config BR2_PACKAGE_FOO redeclared (previous line: 1)',
|
||||
'config BR2_PACKAGE_FOO\n']]),
|
||||
('three times',
|
||||
'any',
|
||||
'config BR2_PACKAGE_FOO\n'
|
||||
'bool "foo"\n'
|
||||
'config BR2_PACKAGE_FOO\n'
|
||||
'bool "foo"\n'
|
||||
'config BR2_PACKAGE_FOO\n'
|
||||
'bool "foo"\n',
|
||||
[['any:3: config BR2_PACKAGE_FOO redeclared (previous line: 1)',
|
||||
'config BR2_PACKAGE_FOO\n'],
|
||||
['any:5: config BR2_PACKAGE_FOO redeclared (previous line: 1)',
|
||||
'config BR2_PACKAGE_FOO\n']]),
|
||||
('same conditional',
|
||||
'any',
|
||||
'if BR2_PACKAGE_BAZ\n'
|
||||
'config BR2_PACKAGE_FOO\n'
|
||||
'bool "foo"\n'
|
||||
'config BR2_PACKAGE_BAR\n'
|
||||
'bool "bar"\n'
|
||||
'config BR2_PACKAGE_FOO\n'
|
||||
'bool "foo"\n'
|
||||
'endif\n',
|
||||
[['any:6: config BR2_PACKAGE_FOO redeclared (previous line: 2)',
|
||||
'config BR2_PACKAGE_FOO\n']]),
|
||||
('equivalent conditional',
|
||||
'any',
|
||||
'if BR2_PACKAGE_BAZ\n'
|
||||
'config BR2_PACKAGE_FOO\n'
|
||||
'bool "foo"\n'
|
||||
'endif\n'
|
||||
'config BR2_PACKAGE_FOO\n'
|
||||
'bool "foo"\n'
|
||||
'if BR2_PACKAGE_BAZ\n'
|
||||
'config BR2_PACKAGE_FOO\n'
|
||||
'bool "foo"\n'
|
||||
'endif\n',
|
||||
[['any:8: config BR2_PACKAGE_FOO redeclared (previous line: 2)',
|
||||
'config BR2_PACKAGE_FOO\n']]),
|
||||
('not equivalent conditional',
|
||||
'any',
|
||||
'if BR2_PACKAGE_BAZ\n'
|
||||
'config BR2_PACKAGE_FOO\n'
|
||||
'bool "foo"\n'
|
||||
'endif\n'
|
||||
'config BR2_PACKAGE_FOO\n'
|
||||
'bool "foo"\n'
|
||||
'if !BR2_PACKAGE_BAZ\n'
|
||||
'config BR2_PACKAGE_FOO\n'
|
||||
'bool "foo"\n'
|
||||
'endif\n',
|
||||
[]),
|
||||
]
|
||||
|
||||
|
||||
@pytest.mark.parametrize('testname,filename,string,expected', RedefinedConfig)
|
||||
def test_RedefinedConfig(testname, filename, string, expected):
|
||||
warnings = util.check_file(m.RedefinedConfig, filename, string)
|
||||
assert warnings == expected
|
||||
183
utils/checkpackagelib/test_lib_hash.py
Normal file
183
utils/checkpackagelib/test_lib_hash.py
Normal file
@@ -0,0 +1,183 @@
|
||||
import pytest
|
||||
import checkpackagelib.test_util as util
|
||||
import checkpackagelib.lib_hash as m
|
||||
|
||||
|
||||
HashNumberOfFields = [
|
||||
('empty file',
|
||||
'any',
|
||||
'',
|
||||
[]),
|
||||
('empty line',
|
||||
'any',
|
||||
'\n',
|
||||
[]),
|
||||
('ignore whitespace',
|
||||
'any',
|
||||
'\t\n',
|
||||
[]),
|
||||
('ignore comments',
|
||||
'any',
|
||||
'# text\n',
|
||||
[]),
|
||||
('1 field',
|
||||
'any',
|
||||
'field1\n',
|
||||
[['any:1: expected three fields (url#adding-packages-hash)',
|
||||
'field1\n']]),
|
||||
('2 fields',
|
||||
'any',
|
||||
'field1 field2\n',
|
||||
[['any:1: expected three fields (url#adding-packages-hash)',
|
||||
'field1 field2\n']]),
|
||||
('4 fields',
|
||||
'any',
|
||||
'field1 field2 field3 field4\n',
|
||||
[['any:1: expected three fields (url#adding-packages-hash)',
|
||||
'field1 field2 field3 field4\n']]),
|
||||
('with 1 space',
|
||||
'any',
|
||||
'field1 field2 field3\n',
|
||||
[]),
|
||||
('many spaces',
|
||||
'any',
|
||||
' field1 field2 field3\n',
|
||||
[]),
|
||||
('tabs',
|
||||
'any',
|
||||
'field1\tfield2\tfield3\n',
|
||||
[]),
|
||||
('mix of tabs and spaces',
|
||||
'any',
|
||||
'\tfield1\t field2\t field3 \n',
|
||||
[]),
|
||||
]
|
||||
|
||||
|
||||
@pytest.mark.parametrize('testname,filename,string,expected', HashNumberOfFields)
|
||||
def test_HashNumberOfFields(testname, filename, string, expected):
|
||||
warnings = util.check_file(m.HashNumberOfFields, filename, string)
|
||||
assert warnings == expected
|
||||
|
||||
|
||||
HashType = [
|
||||
('ignore empty files',
|
||||
'any',
|
||||
'',
|
||||
[]),
|
||||
('ignore 1 field',
|
||||
'any',
|
||||
'text\n',
|
||||
[]),
|
||||
('wrong type',
|
||||
'any',
|
||||
'text text\n',
|
||||
[['any:1: unexpected type of hash (url#adding-packages-hash)',
|
||||
'text text\n']]),
|
||||
('md5 (good)',
|
||||
'any',
|
||||
'md5 12345678901234567890123456789012\n',
|
||||
[]),
|
||||
('md5 (short)',
|
||||
'any',
|
||||
'md5 123456\n',
|
||||
[['any:1: hash size does not match type (url#adding-packages-hash)',
|
||||
'md5 123456\n',
|
||||
'expected 32 hex digits']]),
|
||||
('ignore space before',
|
||||
'any',
|
||||
' md5 12345678901234567890123456789012\n',
|
||||
[]),
|
||||
('2 spaces',
|
||||
'any',
|
||||
'md5 12345678901234567890123456789012\n',
|
||||
[]),
|
||||
('ignore tabs',
|
||||
'any',
|
||||
'md5\t12345678901234567890123456789012\n',
|
||||
[]),
|
||||
('common typo',
|
||||
'any',
|
||||
'md5sum 12345678901234567890123456789012\n',
|
||||
[['any:1: unexpected type of hash (url#adding-packages-hash)',
|
||||
'md5sum 12345678901234567890123456789012\n']]),
|
||||
('md5 (too long)',
|
||||
'any',
|
||||
'md5 123456789012345678901234567890123\n',
|
||||
[['any:1: hash size does not match type (url#adding-packages-hash)',
|
||||
'md5 123456789012345678901234567890123\n',
|
||||
'expected 32 hex digits']]),
|
||||
('sha1 (good)',
|
||||
'any',
|
||||
'sha1 1234567890123456789012345678901234567890\n',
|
||||
[]),
|
||||
('sha256',
|
||||
'any',
|
||||
'sha256 1234567890123456789012345678901234567890123456789012345678901234\n',
|
||||
[]),
|
||||
('sha384',
|
||||
'any',
|
||||
'sha384 123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456\n',
|
||||
[]),
|
||||
('sha512',
|
||||
'any',
|
||||
'sha512 1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678'
|
||||
'9012345678\n',
|
||||
[]),
|
||||
]
|
||||
|
||||
|
||||
@pytest.mark.parametrize('testname,filename,string,expected', HashType)
|
||||
def test_HashType(testname, filename, string, expected):
|
||||
warnings = util.check_file(m.HashType, filename, string)
|
||||
assert warnings == expected
|
||||
|
||||
|
||||
HashSpaces = [
|
||||
('ignore empty files',
|
||||
'any',
|
||||
'',
|
||||
[]),
|
||||
('ignore 1 field',
|
||||
'any',
|
||||
'text\n',
|
||||
[]),
|
||||
('ignore comments',
|
||||
'any',
|
||||
'# type 1234567890123456789012345678901234567890 file\n',
|
||||
[]),
|
||||
('ignore trailing space',
|
||||
'any',
|
||||
'type 1234567890123456789012345678901234567890 file\t \n',
|
||||
[]),
|
||||
('2 spaces',
|
||||
'any',
|
||||
'type 1234567890123456789012345678901234567890 file\n',
|
||||
[]),
|
||||
('1 space',
|
||||
'any',
|
||||
'type 1234567890123456789012345678901234567890 file\n',
|
||||
[['any:1: separation does not match expectation (url#adding-packages-hash)',
|
||||
'type 1234567890123456789012345678901234567890 file\n']]),
|
||||
('3 spaces',
|
||||
'any',
|
||||
'type 1234567890123456789012345678901234567890 file\n',
|
||||
[['any:1: separation does not match expectation (url#adding-packages-hash)',
|
||||
'type 1234567890123456789012345678901234567890 file\n']]),
|
||||
('tabs',
|
||||
'any',
|
||||
'type\t1234567890123456789012345678901234567890\tfile\n',
|
||||
[['any:1: separation does not match expectation (url#adding-packages-hash)',
|
||||
'type\t1234567890123456789012345678901234567890\tfile\n']]),
|
||||
('mixed tabs and spaces',
|
||||
'any',
|
||||
'type\t 1234567890123456789012345678901234567890 \tfile\n',
|
||||
[['any:1: separation does not match expectation (url#adding-packages-hash)',
|
||||
'type\t 1234567890123456789012345678901234567890 \tfile\n']]),
|
||||
]
|
||||
|
||||
|
||||
@pytest.mark.parametrize('testname,filename,string,expected', HashSpaces)
|
||||
def test_HashSpaces(testname, filename, string, expected):
|
||||
warnings = util.check_file(m.HashSpaces, filename, string)
|
||||
assert warnings == expected
|
||||
18
utils/checkpackagelib/test_lib_ignore.py
Normal file
18
utils/checkpackagelib/test_lib_ignore.py
Normal file
@@ -0,0 +1,18 @@
|
||||
import pytest
|
||||
import checkpackagelib.test_util as util
|
||||
import checkpackagelib.lib_ignore as m
|
||||
|
||||
|
||||
IgnoreMissingFile = [
|
||||
('missing ignored file',
|
||||
'.checkpackageignore',
|
||||
'this-file-does-not-exist SomeTest',
|
||||
[['.checkpackageignore:1: ignored file this-file-does-not-exist is missing',
|
||||
'this-file-does-not-exist SomeTest']]),
|
||||
]
|
||||
|
||||
|
||||
@pytest.mark.parametrize('testname,filename,string,expected', IgnoreMissingFile)
|
||||
def test_IgnoreMissingFile(testname, filename, string, expected):
|
||||
warnings = util.check_file(m.IgnoreMissingFile, filename, string)
|
||||
assert warnings == expected
|
||||
699
utils/checkpackagelib/test_lib_mk.py
Normal file
699
utils/checkpackagelib/test_lib_mk.py
Normal file
@@ -0,0 +1,699 @@
|
||||
import pytest
|
||||
import checkpackagelib.test_util as util
|
||||
import checkpackagelib.lib_mk as m
|
||||
|
||||
|
||||
DoNotInstallToHostdirUsr = [
|
||||
('real case',
|
||||
'libapparmor.mk',
|
||||
'LIBAPPARMOR_CONF_OPTS += \\\n'
|
||||
'\t--with-python \\\n'
|
||||
'\tPYTHON=$(HOST_DIR)/usr/bin/python3 \\\n'
|
||||
'\tPYTHON_CONFIG=$(STAGING_DIR)/usr/bin/python3-config \\\n'
|
||||
'\tSWIG=$(SWIG)\n',
|
||||
[['libapparmor.mk:3: install files to $(HOST_DIR)/ instead of $(HOST_DIR)/usr/',
|
||||
'\tPYTHON=$(HOST_DIR)/usr/bin/python3 \\\n']]),
|
||||
('ignore comment',
|
||||
'any',
|
||||
'# following code do not install to $(HOST_DIR)/usr/\n',
|
||||
[]),
|
||||
]
|
||||
|
||||
|
||||
@pytest.mark.parametrize('testname,filename,string,expected', DoNotInstallToHostdirUsr)
|
||||
def test_DoNotInstallToHostdirUsr(testname, filename, string, expected):
|
||||
warnings = util.check_file(m.DoNotInstallToHostdirUsr, filename, string)
|
||||
assert warnings == expected
|
||||
|
||||
|
||||
Ifdef = [
|
||||
('ignore commented line',
|
||||
'any',
|
||||
'# ifdef\n',
|
||||
[]),
|
||||
('simple',
|
||||
'any',
|
||||
'\n'
|
||||
'ifdef BR2_PACKAGE_FWTS_EFI_RUNTIME_MODULE\n'
|
||||
'endif\n',
|
||||
[['any:2: use ifeq ($(SYMBOL),y) instead of ifdef SYMBOL',
|
||||
'ifdef BR2_PACKAGE_FWTS_EFI_RUNTIME_MODULE\n']]),
|
||||
('ignore indentation',
|
||||
'any',
|
||||
' ifdef FOO\n'
|
||||
' endif\n'
|
||||
'\tifdef BAR\n'
|
||||
'endif\n',
|
||||
[['any:1: use ifeq ($(SYMBOL),y) instead of ifdef SYMBOL',
|
||||
' ifdef FOO\n'],
|
||||
['any:3: use ifeq ($(SYMBOL),y) instead of ifdef SYMBOL',
|
||||
'\tifdef BAR\n']]),
|
||||
('typo',
|
||||
'any',
|
||||
'\n'
|
||||
'ifndef ($(BR2_ENABLE_LOCALE),y)\n'
|
||||
'endif\n',
|
||||
[['any:2: use ifneq ($(SYMBOL),y) instead of ifndef SYMBOL',
|
||||
'ifndef ($(BR2_ENABLE_LOCALE),y)\n']]),
|
||||
('else ifdef',
|
||||
'any',
|
||||
'else ifdef SYMBOL # comment\n',
|
||||
[['any:1: use ifeq ($(SYMBOL),y) instead of ifdef SYMBOL',
|
||||
'else ifdef SYMBOL # comment\n']]),
|
||||
('else ifndef',
|
||||
'any',
|
||||
'\t else ifndef\t($(SYMBOL),y) # comment\n',
|
||||
[['any:1: use ifneq ($(SYMBOL),y) instead of ifndef SYMBOL',
|
||||
'\t else ifndef\t($(SYMBOL),y) # comment\n']]),
|
||||
]
|
||||
|
||||
|
||||
@pytest.mark.parametrize('testname,filename,string,expected', Ifdef)
|
||||
def test_Ifdef(testname, filename, string, expected):
|
||||
warnings = util.check_file(m.Ifdef, filename, string)
|
||||
assert warnings == expected
|
||||
|
||||
|
||||
get_package_prefix_from_filename = [
|
||||
('linux tool',
|
||||
'package/linux-tools/linux-tool-gpio.mk.in',
|
||||
['gpio', 'GPIO']),
|
||||
('boot',
|
||||
'boot/binaries-marvell/binaries-marvell.mk',
|
||||
['binaries-marvell', 'BINARIES_MARVELL']),
|
||||
('toolchain',
|
||||
'toolchain/toolchain-external/toolchain-external-bootlin/toolchain-external-bootlin.mk',
|
||||
['toolchain-external-bootlin', 'TOOLCHAIN_EXTERNAL_BOOTLIN']),
|
||||
('package, underscore, subfolder',
|
||||
'package/x11r7/xapp_bitmap/xapp_bitmap.mk',
|
||||
['xapp_bitmap', 'XAPP_BITMAP']),
|
||||
('package, starting with number',
|
||||
'package/4th/4th.mk',
|
||||
['4th', '4TH']),
|
||||
('package, long name',
|
||||
'package/perl-mojolicious-plugin-authentication/perl-mojolicious-plugin-authentication.mk',
|
||||
['perl-mojolicious-plugin-authentication', 'PERL_MOJOLICIOUS_PLUGIN_AUTHENTICATION']),
|
||||
('package, case sensitive',
|
||||
'package/libeXosip2/libeXosip2.mk',
|
||||
['libeXosip2', 'LIBEXOSIP2']),
|
||||
]
|
||||
|
||||
|
||||
@pytest.mark.parametrize('testname,filename,expected', get_package_prefix_from_filename)
|
||||
def test_get_package_prefix_from_filename(testname, filename, expected):
|
||||
prefix_lower, prefix_upper = m.get_package_prefix_from_filename(filename)
|
||||
assert [prefix_lower, prefix_upper] == expected
|
||||
|
||||
|
||||
Indent = [
|
||||
('ignore comment at beginning of line',
|
||||
'any',
|
||||
'# very useful comment\n',
|
||||
[]),
|
||||
('ignore comment at end of line',
|
||||
'any',
|
||||
' # very useful comment\n',
|
||||
[]),
|
||||
('do not indent on conditional (good)',
|
||||
'any',
|
||||
'ifeq ($(BR2_TOOLCHAIN_HAS_THREADS),y)\n'
|
||||
'FOO_CONF_OPTS += something\n'
|
||||
'endef\n',
|
||||
[]),
|
||||
('do not indent on conditional (bad)',
|
||||
'any',
|
||||
'ifeq ($(BR2_TOOLCHAIN_HAS_THREADS),y)\n'
|
||||
'\tFOO_CONF_OPTS += something\n'
|
||||
'endef\n',
|
||||
[['any:2: unexpected indent with tabs',
|
||||
'\tFOO_CONF_OPTS += something\n']]),
|
||||
('indent after line that ends in backslash (good)',
|
||||
'any',
|
||||
'FOO_CONF_OPTS += \\\n'
|
||||
'\tsomething\n',
|
||||
[]),
|
||||
('indent after line that ends in backslash (bad)',
|
||||
'any',
|
||||
'FOO_CONF_OPTS += \\\n'
|
||||
'something\n',
|
||||
[['any:2: expected indent with tabs',
|
||||
'something\n']]),
|
||||
('indent after 2 lines that ends in backslash (good)',
|
||||
'any',
|
||||
'FOO_CONF_OPTS += \\\n'
|
||||
'\tsomething \\\n'
|
||||
'\tsomething_else\n',
|
||||
[]),
|
||||
('indent after 2 lines that ends in backslash (bad)',
|
||||
'any',
|
||||
'FOO_CONF_OPTS += \\\n'
|
||||
'\tsomething \\\n'
|
||||
'\tsomething_else \\\n'
|
||||
'FOO_CONF_OPTS += another_thing\n',
|
||||
[['any:4: expected indent with tabs',
|
||||
'FOO_CONF_OPTS += another_thing\n']]),
|
||||
('indent inside define (good)',
|
||||
'any',
|
||||
'define FOO_SOMETHING\n'
|
||||
'\tcommand\n'
|
||||
'\tcommand \\\n'
|
||||
'\t\targuments\n'
|
||||
'endef\n'
|
||||
'FOO_POST_PATCH_HOOKS += FOO_SOMETHING\n',
|
||||
[]),
|
||||
('indent inside define (bad, no indent)',
|
||||
'any',
|
||||
'define FOO_SOMETHING\n'
|
||||
'command\n'
|
||||
'endef\n',
|
||||
[['any:2: expected indent with tabs',
|
||||
'command\n']]),
|
||||
('indent inside define (bad, spaces)',
|
||||
'any',
|
||||
'define FOO_SOMETHING\n'
|
||||
' command\n'
|
||||
'endef\n',
|
||||
[['any:2: expected indent with tabs',
|
||||
' command\n']]),
|
||||
('indent make target (good)',
|
||||
'any',
|
||||
'make_target:\n'
|
||||
'\tcommand\n'
|
||||
'\n',
|
||||
[]),
|
||||
('indent make target (bad)',
|
||||
'any',
|
||||
'make_target:\n'
|
||||
' command\n'
|
||||
'\n',
|
||||
[['any:2: expected indent with tabs',
|
||||
' command\n']]),
|
||||
]
|
||||
|
||||
|
||||
@pytest.mark.parametrize('testname,filename,string,expected', Indent)
|
||||
def test_Indent(testname, filename, string, expected):
|
||||
warnings = util.check_file(m.Indent, filename, string)
|
||||
assert warnings == expected
|
||||
|
||||
|
||||
OverriddenVariable = [
|
||||
('simple assignment',
|
||||
'any.mk',
|
||||
'VAR_1 = VALUE1\n',
|
||||
[]),
|
||||
('unconditional override (variable without underscore)',
|
||||
'any.mk',
|
||||
'VAR1 = VALUE1\n'
|
||||
'VAR1 = VALUE1\n',
|
||||
[['any.mk:2: unconditional override of variable VAR1',
|
||||
'VAR1 = VALUE1\n']]),
|
||||
('unconditional override (variable with underscore, same value)',
|
||||
'any.mk',
|
||||
'VAR_1 = VALUE1\n'
|
||||
'VAR_1 = VALUE1\n',
|
||||
[['any.mk:2: unconditional override of variable VAR_1',
|
||||
'VAR_1 = VALUE1\n']]),
|
||||
('unconditional override (variable with underscore, different value)',
|
||||
'any.mk',
|
||||
'VAR_1 = VALUE1\n'
|
||||
'VAR_1 = VALUE2\n',
|
||||
[['any.mk:2: unconditional override of variable VAR_1',
|
||||
'VAR_1 = VALUE2\n']]),
|
||||
('warn for unconditional override even with wrong number of spaces',
|
||||
'any.mk',
|
||||
'VAR_1= VALUE1\n'
|
||||
'VAR_1 =VALUE2\n',
|
||||
[['any.mk:2: unconditional override of variable VAR_1',
|
||||
'VAR_1 =VALUE2\n']]),
|
||||
('warn for := override',
|
||||
'any.mk',
|
||||
'VAR_1 = VALUE1\n'
|
||||
'VAR_1 := VALUE2\n',
|
||||
[['any.mk:2: unconditional override of variable VAR_1',
|
||||
'VAR_1 := VALUE2\n']]),
|
||||
('append values outside conditional (good)',
|
||||
'any.mk',
|
||||
'VAR_1 = VALUE1\n'
|
||||
'VAR_1 += VALUE2\n',
|
||||
[]),
|
||||
('append values outside conditional (bad)',
|
||||
'any.mk',
|
||||
'VAR_1 = VALUE1\n'
|
||||
'VAR_1 := $(VAR_1), VALUE2\n',
|
||||
[['any.mk:2: unconditional override of variable VAR_1',
|
||||
'VAR_1 := $(VAR_1), VALUE2\n']]),
|
||||
('immediate assignment inside conditional',
|
||||
'any.mk',
|
||||
'VAR_1 = VALUE1\n'
|
||||
'ifeq (condition)\n'
|
||||
'VAR_1 := $(VAR_1), VALUE2\n',
|
||||
[['any.mk:3: immediate assignment to append to variable VAR_1',
|
||||
'VAR_1 := $(VAR_1), VALUE2\n']]),
|
||||
('immediate assignment inside conditional and unconditional override outside',
|
||||
'any.mk',
|
||||
'VAR_1 = VALUE1\n'
|
||||
'ifeq (condition)\n'
|
||||
'VAR_1 := $(VAR_1), VALUE2\n'
|
||||
'endif\n'
|
||||
'VAR_1 := $(VAR_1), VALUE2\n',
|
||||
[['any.mk:3: immediate assignment to append to variable VAR_1',
|
||||
'VAR_1 := $(VAR_1), VALUE2\n'],
|
||||
['any.mk:5: unconditional override of variable VAR_1',
|
||||
'VAR_1 := $(VAR_1), VALUE2\n']]),
|
||||
]
|
||||
|
||||
|
||||
@pytest.mark.parametrize('testname,filename,string,expected', OverriddenVariable)
|
||||
def test_OverriddenVariable(testname, filename, string, expected):
|
||||
warnings = util.check_file(m.OverriddenVariable, filename, string)
|
||||
assert warnings == expected
|
||||
|
||||
|
||||
PackageHeader = [
|
||||
('first line (good)',
|
||||
'any',
|
||||
80 * '#' + '\n',
|
||||
[]),
|
||||
('first line (bad)',
|
||||
'any',
|
||||
'# very useful comment\n',
|
||||
[['any:1: should be 80 hashes (url#writing-rules-mk)',
|
||||
'# very useful comment\n',
|
||||
80 * '#']]),
|
||||
('second line (bad)',
|
||||
'any',
|
||||
80 * '#' + '\n'
|
||||
'# package\n',
|
||||
[['any:2: should be 1 hash (url#writing-rules-mk)',
|
||||
'# package\n']]),
|
||||
('full header (good)',
|
||||
'any',
|
||||
80 * '#' + '\n'
|
||||
'#\n'
|
||||
'# package\n'
|
||||
'#\n' +
|
||||
80 * '#' + '\n'
|
||||
'\n',
|
||||
[]),
|
||||
('blank line after header (good)',
|
||||
'any',
|
||||
80 * '#' + '\n'
|
||||
'#\n'
|
||||
'# package\n'
|
||||
'#\n' +
|
||||
80 * '#' + '\n'
|
||||
'\n'
|
||||
'FOO_VERSION = 1\n',
|
||||
[]),
|
||||
('blank line after header (bad)',
|
||||
'any',
|
||||
80 * '#' + '\n'
|
||||
'#\n'
|
||||
'# package\n'
|
||||
'#\n' +
|
||||
80 * '#' + '\n'
|
||||
'FOO_VERSION = 1\n',
|
||||
[['any:6: should be a blank line (url#writing-rules-mk)',
|
||||
'FOO_VERSION = 1\n']]),
|
||||
('wrong number of hashes',
|
||||
'any',
|
||||
79 * '#' + '\n'
|
||||
'#\n'
|
||||
'# package\n'
|
||||
'#\n' +
|
||||
81 * '#' + '\n'
|
||||
'\n',
|
||||
[['any:1: should be 80 hashes (url#writing-rules-mk)',
|
||||
79 * '#' + '\n',
|
||||
80 * '#'],
|
||||
['any:5: should be 80 hashes (url#writing-rules-mk)',
|
||||
81 * '#' + '\n',
|
||||
80 * '#']]),
|
||||
('allow include without header',
|
||||
'any',
|
||||
'include $(sort $(wildcard package/foo/*/*.mk))\n',
|
||||
[]),
|
||||
]
|
||||
|
||||
|
||||
@pytest.mark.parametrize('testname,filename,string,expected', PackageHeader)
|
||||
def test_PackageHeader(testname, filename, string, expected):
|
||||
warnings = util.check_file(m.PackageHeader, filename, string)
|
||||
assert warnings == expected
|
||||
|
||||
|
||||
RemoveDefaultPackageSourceVariable = [
|
||||
('bad',
|
||||
'any.mk',
|
||||
'ANY_SOURCE = any-$(ANY_VERSION).tar.gz\n',
|
||||
[['any.mk:1: remove default value of _SOURCE variable (url#generic-package-reference)',
|
||||
'ANY_SOURCE = any-$(ANY_VERSION).tar.gz\n']]),
|
||||
('bad with path',
|
||||
'./any.mk',
|
||||
'ANY_SOURCE = any-$(ANY_VERSION).tar.gz\n',
|
||||
[['./any.mk:1: remove default value of _SOURCE variable (url#generic-package-reference)',
|
||||
'ANY_SOURCE = any-$(ANY_VERSION).tar.gz\n']]),
|
||||
('warn for correct line',
|
||||
'./any.mk',
|
||||
'\n'
|
||||
'\n'
|
||||
'\n'
|
||||
'ANY_SOURCE = any-$(ANY_VERSION).tar.gz\n',
|
||||
[['./any.mk:4: remove default value of _SOURCE variable (url#generic-package-reference)',
|
||||
'ANY_SOURCE = any-$(ANY_VERSION).tar.gz\n']]),
|
||||
('warn ignoring missing spaces',
|
||||
'./any.mk',
|
||||
'ANY_SOURCE=any-$(ANY_VERSION).tar.gz\n',
|
||||
[['./any.mk:1: remove default value of _SOURCE variable (url#generic-package-reference)',
|
||||
'ANY_SOURCE=any-$(ANY_VERSION).tar.gz\n']]),
|
||||
('good',
|
||||
'./any.mk',
|
||||
'ANY_SOURCE = aNy-$(ANY_VERSION).tar.gz\n',
|
||||
[]),
|
||||
('gcc exception',
|
||||
'gcc.mk',
|
||||
'GCC_SOURCE = gcc-$(GCC_VERSION).tar.gz\n',
|
||||
[]),
|
||||
('binutils exception',
|
||||
'./binutils.mk',
|
||||
'BINUTILS_SOURCE = binutils-$(BINUTILS_VERSION).tar.gz\n',
|
||||
[]),
|
||||
('gdb exception',
|
||||
'gdb/gdb.mk',
|
||||
'GDB_SOURCE = gdb-$(GDB_VERSION).tar.gz\n',
|
||||
[]),
|
||||
('package name with dash',
|
||||
'python-subprocess32.mk',
|
||||
'PYTHON_SUBPROCESS32_SOURCE = python-subprocess32-$(PYTHON_SUBPROCESS32_VERSION).tar.gz\n',
|
||||
[['python-subprocess32.mk:1: remove default value of _SOURCE variable (url#generic-package-reference)',
|
||||
'PYTHON_SUBPROCESS32_SOURCE = python-subprocess32-$(PYTHON_SUBPROCESS32_VERSION).tar.gz\n']]),
|
||||
]
|
||||
|
||||
|
||||
@pytest.mark.parametrize('testname,filename,string,expected', RemoveDefaultPackageSourceVariable)
|
||||
def test_RemoveDefaultPackageSourceVariable(testname, filename, string, expected):
|
||||
warnings = util.check_file(m.RemoveDefaultPackageSourceVariable, filename, string)
|
||||
assert warnings == expected
|
||||
|
||||
|
||||
SpaceBeforeBackslash = [
|
||||
('no backslash',
|
||||
'any.mk',
|
||||
'\n',
|
||||
[]),
|
||||
('ignore missing indent',
|
||||
'any.mk',
|
||||
'define ANY_SOME_FIXUP\n'
|
||||
'for i in $$(find $(STAGING_DIR)/usr/lib* -name "any*.la"); do \\\n',
|
||||
[]),
|
||||
('ignore missing space',
|
||||
'any.mk',
|
||||
'ANY_CONF_ENV= \\\n'
|
||||
'\tap_cv_void_ptr_lt_long=no \\\n',
|
||||
[]),
|
||||
('variable',
|
||||
'any.mk',
|
||||
'\n'
|
||||
'ANY = \\\n',
|
||||
[]),
|
||||
('2 spaces',
|
||||
'any.mk',
|
||||
'ANY = \\\n',
|
||||
[['any.mk:1: use only one space before backslash',
|
||||
'ANY = \\\n']]),
|
||||
('warn about correct line',
|
||||
'any.mk',
|
||||
'\n'
|
||||
'ANY = \\\n',
|
||||
[['any.mk:2: use only one space before backslash',
|
||||
'ANY = \\\n']]),
|
||||
('tab',
|
||||
'any.mk',
|
||||
'ANY =\t\\\n',
|
||||
[['any.mk:1: use only one space before backslash',
|
||||
'ANY =\t\\\n']]),
|
||||
('tabs',
|
||||
'any.mk',
|
||||
'ANY =\t\t\\\n',
|
||||
[['any.mk:1: use only one space before backslash',
|
||||
'ANY =\t\t\\\n']]),
|
||||
('spaces and tabs',
|
||||
'any.mk',
|
||||
'ANY = \t\t\\\n',
|
||||
[['any.mk:1: use only one space before backslash',
|
||||
'ANY = \t\t\\\n']]),
|
||||
('mixed spaces and tabs 1',
|
||||
'any.mk',
|
||||
'ANY = \t \t\\\n',
|
||||
[['any.mk:1: use only one space before backslash',
|
||||
'ANY = \t \t\\\n']]),
|
||||
('mixed spaces and tabs 2',
|
||||
'any.mk',
|
||||
'ANY = \t \\\n',
|
||||
[['any.mk:1: use only one space before backslash',
|
||||
'ANY = \t \\\n']]),
|
||||
]
|
||||
|
||||
|
||||
@pytest.mark.parametrize('testname,filename,string,expected', SpaceBeforeBackslash)
|
||||
def test_SpaceBeforeBackslash(testname, filename, string, expected):
|
||||
warnings = util.check_file(m.SpaceBeforeBackslash, filename, string)
|
||||
assert warnings == expected
|
||||
|
||||
|
||||
TrailingBackslash = [
|
||||
('no backslash',
|
||||
'any.mk',
|
||||
'ANY = \n',
|
||||
[]),
|
||||
('one line',
|
||||
'any.mk',
|
||||
'ANY = \\\n',
|
||||
[]),
|
||||
('2 lines',
|
||||
'any.mk',
|
||||
'ANY = \\\n'
|
||||
'\\\n',
|
||||
[]),
|
||||
('empty line after',
|
||||
'any.mk',
|
||||
'ANY = \\\n'
|
||||
'\n',
|
||||
[['any.mk:1: remove trailing backslash',
|
||||
'ANY = \\\n']]),
|
||||
('line with spaces after',
|
||||
'any.mk',
|
||||
'ANY = \\\n'
|
||||
' \n',
|
||||
[['any.mk:1: remove trailing backslash',
|
||||
'ANY = \\\n']]),
|
||||
('line with tabs after',
|
||||
'any.mk',
|
||||
'ANY = \\\n'
|
||||
'\t\n',
|
||||
[['any.mk:1: remove trailing backslash',
|
||||
'ANY = \\\n']]),
|
||||
('ignore if commented',
|
||||
'any.mk',
|
||||
'# ANY = \\\n'
|
||||
'\n',
|
||||
[]),
|
||||
('real example',
|
||||
'any.mk',
|
||||
'ANY_CONF_ENV= \t\\\n'
|
||||
'\tap_cv_void_ptr_lt_long=no \\\n'
|
||||
'\n',
|
||||
[['any.mk:2: remove trailing backslash',
|
||||
'\tap_cv_void_ptr_lt_long=no \\\n']]),
|
||||
('ignore whitespace 1',
|
||||
'any.mk',
|
||||
'ANY = \t\t\\\n',
|
||||
[]),
|
||||
('ignore whitespace 2',
|
||||
'any.mk',
|
||||
'ANY = \t \t\\\n',
|
||||
[]),
|
||||
('ignore whitespace 3',
|
||||
'any.mk',
|
||||
'ANY = \t \\\n',
|
||||
[]),
|
||||
]
|
||||
|
||||
|
||||
@pytest.mark.parametrize('testname,filename,string,expected', TrailingBackslash)
|
||||
def test_TrailingBackslash(testname, filename, string, expected):
|
||||
warnings = util.check_file(m.TrailingBackslash, filename, string)
|
||||
assert warnings == expected
|
||||
|
||||
|
||||
TypoInPackageVariable = [
|
||||
('good',
|
||||
'any.mk',
|
||||
'ANY_VAR = \n',
|
||||
[]),
|
||||
('good with path 1',
|
||||
'./any.mk',
|
||||
'ANY_VAR += \n',
|
||||
[]),
|
||||
('good with path 2',
|
||||
'any/any.mk',
|
||||
'ANY_VAR = \n',
|
||||
[]),
|
||||
('bad =',
|
||||
'any.mk',
|
||||
'OTHER_VAR = \n',
|
||||
[['any.mk:1: possible typo, variable not properly prefixed: OTHER_VAR -> *ANY_XXXX* (url#_tips_and_tricks)',
|
||||
'OTHER_VAR = \n']]),
|
||||
('bad +=',
|
||||
'any.mk',
|
||||
'OTHER_VAR += \n',
|
||||
[['any.mk:1: possible typo, variable not properly prefixed: OTHER_VAR -> *ANY_XXXX* (url#_tips_and_tricks)',
|
||||
'OTHER_VAR += \n']]),
|
||||
('ignore missing space',
|
||||
'any.mk',
|
||||
'OTHER_VAR= \n',
|
||||
[['any.mk:1: possible typo, variable not properly prefixed: OTHER_VAR -> *ANY_XXXX* (url#_tips_and_tricks)',
|
||||
'OTHER_VAR= \n']]),
|
||||
('use path in the warning',
|
||||
'./any.mk',
|
||||
'OTHER_VAR = \n',
|
||||
[['./any.mk:1: possible typo, variable not properly prefixed: OTHER_VAR -> *ANY_XXXX* (url#_tips_and_tricks)',
|
||||
'OTHER_VAR = \n']]),
|
||||
('another name',
|
||||
'other.mk',
|
||||
'ANY_VAR = \n',
|
||||
[['other.mk:1: possible typo, variable not properly prefixed: ANY_VAR -> *OTHER_XXXX* (url#_tips_and_tricks)',
|
||||
'ANY_VAR = \n']]),
|
||||
('libc exception',
|
||||
'./any.mk',
|
||||
'BR_LIBC = \n',
|
||||
[]),
|
||||
('rootfs exception',
|
||||
'any.mk',
|
||||
'ROOTFS_ANY_VAR += \n',
|
||||
[]),
|
||||
('host (good)',
|
||||
'any.mk',
|
||||
'HOST_ANY_VAR += \n',
|
||||
[]),
|
||||
('host (bad)',
|
||||
'any.mk',
|
||||
'HOST_OTHER_VAR = \n',
|
||||
[['any.mk:1: possible typo, variable not properly prefixed: HOST_OTHER_VAR -> *ANY_XXXX* (url#_tips_and_tricks)',
|
||||
'HOST_OTHER_VAR = \n']]),
|
||||
('provides',
|
||||
'any.mk',
|
||||
'ANY_PROVIDES = other thing\n'
|
||||
'OTHER_VAR = \n',
|
||||
[]),
|
||||
('ignore space',
|
||||
'any.mk',
|
||||
'ANY_PROVIDES = thing other \n'
|
||||
'OTHER_VAR = \n',
|
||||
[]),
|
||||
('wrong provides',
|
||||
'any.mk',
|
||||
'ANY_PROVIDES = other\n'
|
||||
'OTHERS_VAR = \n',
|
||||
[['any.mk:2: possible typo, variable not properly prefixed: OTHERS_VAR -> *ANY_XXXX* (url#_tips_and_tricks)',
|
||||
'OTHERS_VAR = \n']]),
|
||||
('linux tool',
|
||||
'package/linux-tools/linux-tool-cpupower.mk.in',
|
||||
'CPUPOWER_DEPENDENCIES =\n'
|
||||
'POWER_DEPENDENCIES +=\n',
|
||||
[['package/linux-tools/linux-tool-cpupower.mk.in:2: possible typo, variable not properly prefixed: '
|
||||
'POWER_DEPENDENCIES -> *CPUPOWER_XXXX* (url#_tips_and_tricks)',
|
||||
'POWER_DEPENDENCIES +=\n']]),
|
||||
]
|
||||
|
||||
|
||||
@pytest.mark.parametrize('testname,filename,string,expected', TypoInPackageVariable)
|
||||
def test_TypoInPackageVariable(testname, filename, string, expected):
|
||||
warnings = util.check_file(m.TypoInPackageVariable, filename, string)
|
||||
assert warnings == expected
|
||||
|
||||
|
||||
UselessFlag = [
|
||||
('autoreconf no',
|
||||
'any.mk',
|
||||
'ANY_AUTORECONF=NO\n',
|
||||
[['any.mk:1: useless default value (url#_infrastructure_for_autotools_based_packages)',
|
||||
'ANY_AUTORECONF=NO\n']]),
|
||||
('host autoreconf no',
|
||||
'any.mk',
|
||||
'HOST_ANY_AUTORECONF\n',
|
||||
[]),
|
||||
('autoreconf yes',
|
||||
'any.mk',
|
||||
'ANY_AUTORECONF=YES\n',
|
||||
[]),
|
||||
('libtool_patch yes',
|
||||
'any.mk',
|
||||
'ANY_LIBTOOL_PATCH\t= YES\n',
|
||||
[['any.mk:1: useless default value (url#_infrastructure_for_autotools_based_packages)',
|
||||
'ANY_LIBTOOL_PATCH\t= YES\n']]),
|
||||
('libtool_patch no',
|
||||
'any.mk',
|
||||
'ANY_LIBTOOL_PATCH= \t NO\n',
|
||||
[]),
|
||||
('generic',
|
||||
'any.mk',
|
||||
'ANY_INSTALL_IMAGES = NO\n'
|
||||
'ANY_REDISTRIBUTE = YES\n'
|
||||
'ANY_INSTALL_STAGING = NO\n'
|
||||
'ANY_INSTALL_TARGET = YES\n',
|
||||
[['any.mk:1: useless default value (url#_infrastructure_for_packages_with_specific_build_systems)',
|
||||
'ANY_INSTALL_IMAGES = NO\n'],
|
||||
['any.mk:2: useless default value (url#_infrastructure_for_packages_with_specific_build_systems)',
|
||||
'ANY_REDISTRIBUTE = YES\n'],
|
||||
['any.mk:3: useless default value (url#_infrastructure_for_packages_with_specific_build_systems)',
|
||||
'ANY_INSTALL_STAGING = NO\n'],
|
||||
['any.mk:4: useless default value (url#_infrastructure_for_packages_with_specific_build_systems)',
|
||||
'ANY_INSTALL_TARGET = YES\n']]),
|
||||
('conditional',
|
||||
'any.mk',
|
||||
'ifneq (condition)\n'
|
||||
'ANY_INSTALL_IMAGES = NO\n'
|
||||
'endif\n'
|
||||
'ANY_REDISTRIBUTE = YES\n',
|
||||
[['any.mk:4: useless default value (url#_infrastructure_for_packages_with_specific_build_systems)',
|
||||
'ANY_REDISTRIBUTE = YES\n']]),
|
||||
]
|
||||
|
||||
|
||||
@pytest.mark.parametrize('testname,filename,string,expected', UselessFlag)
|
||||
def test_UselessFlag(testname, filename, string, expected):
|
||||
warnings = util.check_file(m.UselessFlag, filename, string)
|
||||
assert warnings == expected
|
||||
|
||||
|
||||
VariableWithBraces = [
|
||||
('good',
|
||||
'xmlstarlet.mk',
|
||||
'XMLSTARLET_CONF_OPTS += \\\n'
|
||||
'\t--with-libxml-prefix=$(STAGING_DIR)/usr \\\n',
|
||||
[]),
|
||||
('bad',
|
||||
'xmlstarlet.mk',
|
||||
'XMLSTARLET_CONF_OPTS += \\\n'
|
||||
'\t--with-libxml-prefix=${STAGING_DIR}/usr \\\n',
|
||||
[['xmlstarlet.mk:2: use $() to delimit variables, not ${}',
|
||||
'\t--with-libxml-prefix=${STAGING_DIR}/usr \\\n']]),
|
||||
('expanded by the shell',
|
||||
'sg3_utils.mk',
|
||||
'\tfor prog in xcopy zone; do \\\n'
|
||||
'\t\t$(RM) $(TARGET_DIR)/usr/bin/sg_$${prog} ; \\\n'
|
||||
'\tdone\n',
|
||||
[]),
|
||||
('comments',
|
||||
'any.mk',
|
||||
'#\t--with-libxml-prefix=${STAGING_DIR}/usr \\\n',
|
||||
[]),
|
||||
]
|
||||
|
||||
|
||||
@pytest.mark.parametrize('testname,filename,string,expected', VariableWithBraces)
|
||||
def test_VariableWithBraces(testname, filename, string, expected):
|
||||
warnings = util.check_file(m.VariableWithBraces, filename, string)
|
||||
assert warnings == expected
|
||||
118
utils/checkpackagelib/test_lib_patch.py
Normal file
118
utils/checkpackagelib/test_lib_patch.py
Normal file
@@ -0,0 +1,118 @@
|
||||
import pytest
|
||||
import checkpackagelib.test_util as util
|
||||
import checkpackagelib.lib_patch as m
|
||||
|
||||
|
||||
ApplyOrder = [
|
||||
('standard', # catches https://bugs.busybox.net/show_bug.cgi?id=11271
|
||||
'0001-description.patch',
|
||||
'',
|
||||
[]),
|
||||
('standard with path',
|
||||
'path/0001-description.patch',
|
||||
'',
|
||||
[]),
|
||||
('acceptable format',
|
||||
'1-description.patch',
|
||||
'',
|
||||
[]),
|
||||
('acceptable format with path',
|
||||
'path/1-description.patch',
|
||||
'',
|
||||
[]),
|
||||
('old format',
|
||||
'package-0001-description.patch',
|
||||
'',
|
||||
[['package-0001-description.patch:0: use name <number>-<description>.patch (url#_providing_patches)']]),
|
||||
('old format with path',
|
||||
'path/package-0001-description.patch',
|
||||
'',
|
||||
[['path/package-0001-description.patch:0: use name <number>-<description>.patch (url#_providing_patches)']]),
|
||||
('missing number',
|
||||
'description.patch',
|
||||
'',
|
||||
[['description.patch:0: use name <number>-<description>.patch (url#_providing_patches)']]),
|
||||
('missing number with path',
|
||||
'path/description.patch',
|
||||
'',
|
||||
[['path/description.patch:0: use name <number>-<description>.patch (url#_providing_patches)']]),
|
||||
]
|
||||
|
||||
|
||||
@pytest.mark.parametrize('testname,filename,string,expected', ApplyOrder)
|
||||
def test_ApplyOrder(testname, filename, string, expected):
|
||||
warnings = util.check_file(m.ApplyOrder, filename, string)
|
||||
assert warnings == expected
|
||||
|
||||
|
||||
NumberedSubject = [
|
||||
('no subject',
|
||||
'patch',
|
||||
'',
|
||||
[]),
|
||||
('acceptable because it is not a git patch',
|
||||
'patch',
|
||||
'Subject: [PATCH 24/105] text\n',
|
||||
[]),
|
||||
('good',
|
||||
'patch',
|
||||
'Subject: [PATCH] text\n'
|
||||
'diff --git a/configure.ac b/configure.ac\n',
|
||||
[]),
|
||||
('bad',
|
||||
'patch',
|
||||
'Subject: [PATCH 24/105] text\n'
|
||||
'diff --git a/configure.ac b/configure.ac\n',
|
||||
[["patch:1: generate your patches with 'git format-patch -N'",
|
||||
'Subject: [PATCH 24/105] text\n']]),
|
||||
]
|
||||
|
||||
|
||||
@pytest.mark.parametrize('testname,filename,string,expected', NumberedSubject)
|
||||
def test_NumberedSubject(testname, filename, string, expected):
|
||||
warnings = util.check_file(m.NumberedSubject, filename, string)
|
||||
assert warnings == expected
|
||||
|
||||
|
||||
Sob = [
|
||||
('good',
|
||||
'patch',
|
||||
'Signed-off-by: John Doe <johndoe@example.com>\n',
|
||||
[]),
|
||||
('empty',
|
||||
'patch',
|
||||
'',
|
||||
[['patch:0: missing Signed-off-by in the header (url#_format_and_licensing_of_the_package_patches)']]),
|
||||
('bad',
|
||||
'patch',
|
||||
'Subject: [PATCH 24/105] text\n',
|
||||
[['patch:0: missing Signed-off-by in the header (url#_format_and_licensing_of_the_package_patches)']]),
|
||||
]
|
||||
|
||||
|
||||
@pytest.mark.parametrize('testname,filename,string,expected', Sob)
|
||||
def test_Sob(testname, filename, string, expected):
|
||||
warnings = util.check_file(m.Sob, filename, string)
|
||||
assert warnings == expected
|
||||
|
||||
|
||||
Upstream = [
|
||||
('good',
|
||||
'patch',
|
||||
'Upstream: https://some/amazing/patch/submission\n',
|
||||
[]),
|
||||
('empty',
|
||||
'patch',
|
||||
'',
|
||||
[['patch:0: missing Upstream in the header (url#_additional_patch_documentation)']]),
|
||||
('bad',
|
||||
'patch',
|
||||
'Subject: [PATCH 24/105] text\n',
|
||||
[['patch:0: missing Upstream in the header (url#_additional_patch_documentation)']]),
|
||||
]
|
||||
|
||||
|
||||
@pytest.mark.parametrize('testname,filename,string,expected', Upstream)
|
||||
def test_Upstream(testname, filename, string, expected):
|
||||
warnings = util.check_file(m.Upstream, filename, string)
|
||||
assert warnings == expected
|
||||
131
utils/checkpackagelib/test_lib_sysv.py
Normal file
131
utils/checkpackagelib/test_lib_sysv.py
Normal file
@@ -0,0 +1,131 @@
|
||||
import os
|
||||
import pytest
|
||||
import re
|
||||
import tempfile
|
||||
import checkpackagelib.test_util as util
|
||||
import checkpackagelib.lib_sysv as m
|
||||
from checkpackagelib.test_tool import check_file as tool_check_file
|
||||
|
||||
workdir = os.path.join(tempfile.mkdtemp(suffix='-checkpackagelib-test-sysv'))
|
||||
workdir_regex = re.compile(r'/tmp/tmp[^/]*-checkpackagelib-test-sysv')
|
||||
|
||||
|
||||
Indent = [
|
||||
('empty file',
|
||||
'any',
|
||||
'',
|
||||
[]),
|
||||
('empty line',
|
||||
'any',
|
||||
'\n',
|
||||
[]),
|
||||
('ignore whitespace',
|
||||
'any',
|
||||
' \n',
|
||||
[]),
|
||||
('spaces',
|
||||
'any',
|
||||
'case "$1" in\n'
|
||||
' start)',
|
||||
[['any:2: should be indented with tabs (url#adding-packages-start-script)',
|
||||
' start)']]),
|
||||
('tab',
|
||||
'any',
|
||||
'case "$1" in\n'
|
||||
'\tstart)',
|
||||
[]),
|
||||
('tabs and spaces',
|
||||
'any',
|
||||
'case "$1" in\n'
|
||||
'\t start)',
|
||||
[['any:2: should be indented with tabs (url#adding-packages-start-script)',
|
||||
'\t start)']]),
|
||||
('spaces and tabs',
|
||||
'any',
|
||||
'case "$1" in\n'
|
||||
' \tstart)',
|
||||
[['any:2: should be indented with tabs (url#adding-packages-start-script)',
|
||||
' \tstart)']]),
|
||||
]
|
||||
|
||||
|
||||
@pytest.mark.parametrize('testname,filename,string,expected', Indent)
|
||||
def test_Indent(testname, filename, string, expected):
|
||||
warnings = util.check_file(m.Indent, filename, string)
|
||||
assert warnings == expected
|
||||
|
||||
|
||||
NotExecutable = [
|
||||
('SysV',
|
||||
'sh-shebang.sh',
|
||||
0o775,
|
||||
'#!/bin/sh',
|
||||
["dir/sh-shebang.sh:0: This file does not need to be executable,"
|
||||
" just make sure you use '$(INSTALL) -D -m 0755' in the .mk file"]),
|
||||
]
|
||||
|
||||
|
||||
@pytest.mark.parametrize('testname,filename,permissions,string,expected', NotExecutable)
|
||||
def test_NotExecutable(testname, filename, permissions, string, expected):
|
||||
warnings = tool_check_file(m.NotExecutable, filename, string, permissions)
|
||||
assert warnings == expected
|
||||
|
||||
|
||||
Variables = [
|
||||
('empty file',
|
||||
'any',
|
||||
'',
|
||||
[['any:0: DAEMON variable not defined (url#adding-packages-start-script)']]),
|
||||
('daemon and pidfile ok',
|
||||
'package/busybox/S01syslogd',
|
||||
'DAEMON="syslogd"\n'
|
||||
'PIDFILE="/var/run/$DAEMON.pid"\n',
|
||||
[]),
|
||||
('wrong filename',
|
||||
'package/busybox/S01syslog',
|
||||
'DAEMON="syslogd"\n'
|
||||
'PIDFILE="/var/run/${DAEMON}.pid"\n',
|
||||
[['package/busybox/S01syslog:0: filename should be S<number><number><daemon name> (url#adding-packages-start-script)',
|
||||
'expecting S<number><number>syslogd']]),
|
||||
('no pidfile ok',
|
||||
'S99something',
|
||||
'DAEMON="something"\n',
|
||||
[]),
|
||||
('hardcoded pidfile',
|
||||
'S99something',
|
||||
'DAEMON="something"\n'
|
||||
'PIDFILE="/var/run/something.pid"\n',
|
||||
[['S99something:2: Incorrect PIDFILE value (url#adding-packages-start-script)',
|
||||
'PIDFILE="/var/run/something.pid"\n',
|
||||
'PIDFILE="/var/run/$DAEMON.pid"']]),
|
||||
('redefined daemon',
|
||||
'S50any',
|
||||
'DAEMON="any"\n'
|
||||
'DAEMON="other"\n',
|
||||
[['S50any:2: DAEMON variable redefined (url#adding-packages-start-script)',
|
||||
'DAEMON="other"\n']]),
|
||||
('daemon name with dash',
|
||||
'S82cups-browsed',
|
||||
'DAEMON="cups-browsed"',
|
||||
[]),
|
||||
('daemon with path',
|
||||
'S50avahi-daemon',
|
||||
'DAEMON=/usr/sbin/avahi-daemon',
|
||||
[['S50avahi-daemon:1: Do not include path in DAEMON (url#adding-packages-start-script)',
|
||||
'DAEMON=/usr/sbin/avahi-daemon',
|
||||
'DAEMON="avahi-daemon"']]),
|
||||
('daemon with path and wrong filename',
|
||||
'S50avahi',
|
||||
'DAEMON=/usr/sbin/avahi-daemon',
|
||||
[['S50avahi:1: Do not include path in DAEMON (url#adding-packages-start-script)',
|
||||
'DAEMON=/usr/sbin/avahi-daemon',
|
||||
'DAEMON="avahi-daemon"'],
|
||||
['S50avahi:0: filename should be S<number><number><daemon name> (url#adding-packages-start-script)',
|
||||
'expecting S<number><number>avahi-daemon']]),
|
||||
]
|
||||
|
||||
|
||||
@pytest.mark.parametrize('testname,filename,string,expected', Variables)
|
||||
def test_Variables(testname, filename, string, expected):
|
||||
warnings = util.check_file(m.Variables, filename, string)
|
||||
assert warnings == expected
|
||||
140
utils/checkpackagelib/test_tool.py
Normal file
140
utils/checkpackagelib/test_tool.py
Normal file
@@ -0,0 +1,140 @@
|
||||
import os
|
||||
import pytest
|
||||
import re
|
||||
import tempfile
|
||||
import checkpackagelib.tool as m
|
||||
|
||||
workdir_regex = re.compile(r'/tmp/tmp[^/]*-checkpackagelib-test-tool')
|
||||
|
||||
|
||||
def check_file(tool, filename, string, permissions=None):
|
||||
with tempfile.TemporaryDirectory(suffix='-checkpackagelib-test-tool') as workdir:
|
||||
script = os.path.join(workdir, filename)
|
||||
with open(script, 'wb') as f:
|
||||
f.write(string.encode())
|
||||
if permissions:
|
||||
os.chmod(script, permissions)
|
||||
obj = tool(script)
|
||||
result = obj.run()
|
||||
if result is None:
|
||||
return []
|
||||
return [workdir_regex.sub('dir', r) for r in result]
|
||||
|
||||
|
||||
NotExecutable = [
|
||||
('664',
|
||||
'package.mk',
|
||||
0o664,
|
||||
'',
|
||||
[]),
|
||||
('775',
|
||||
'package.mk',
|
||||
0o775,
|
||||
'',
|
||||
["dir/package.mk:0: This file does not need to be executable"]),
|
||||
]
|
||||
|
||||
|
||||
@pytest.mark.parametrize('testname,filename,permissions,string,expected', NotExecutable)
|
||||
def test_NotExecutable(testname, filename, permissions, string, expected):
|
||||
warnings = check_file(m.NotExecutable, filename, string, permissions)
|
||||
assert warnings == expected
|
||||
|
||||
|
||||
NotExecutable_hint = [
|
||||
('no hint',
|
||||
"",
|
||||
'sh-shebang.sh',
|
||||
0o775,
|
||||
'#!/bin/sh',
|
||||
["dir/sh-shebang.sh:0: This file does not need to be executable"]),
|
||||
('hint',
|
||||
", very special hint",
|
||||
'sh-shebang.sh',
|
||||
0o775,
|
||||
'#!/bin/sh',
|
||||
["dir/sh-shebang.sh:0: This file does not need to be executable, very special hint"]),
|
||||
]
|
||||
|
||||
|
||||
@pytest.mark.parametrize('testname,hint,filename,permissions,string,expected', NotExecutable_hint)
|
||||
def test_NotExecutable_hint(testname, hint, filename, permissions, string, expected):
|
||||
class NotExecutable(m.NotExecutable):
|
||||
def hint(self):
|
||||
return hint
|
||||
warnings = check_file(NotExecutable, filename, string, permissions)
|
||||
assert warnings == expected
|
||||
|
||||
|
||||
Flake8 = [
|
||||
('empty',
|
||||
'empty.py',
|
||||
'',
|
||||
[]),
|
||||
('W391',
|
||||
'blank-line.py',
|
||||
'\n',
|
||||
["dir/blank-line.py:0: run 'flake8' and fix the warnings",
|
||||
"dir/blank-line.py:1:1: W391 blank line at end of file"]),
|
||||
('more than one warning',
|
||||
'file',
|
||||
'import os\n'
|
||||
'import re\n'
|
||||
'\n',
|
||||
["dir/file:0: run 'flake8' and fix the warnings",
|
||||
"dir/file:1:1: F401 'os' imported but unused\n"
|
||||
"dir/file:2:1: F401 're' imported but unused\n"
|
||||
'dir/file:3:1: W391 blank line at end of file']),
|
||||
]
|
||||
|
||||
|
||||
@pytest.mark.parametrize('testname,filename,string,expected', Flake8)
|
||||
def test_Flake8(testname, filename, string, expected):
|
||||
warnings = check_file(m.Flake8, filename, string)
|
||||
assert warnings == expected
|
||||
|
||||
|
||||
Shellcheck = [
|
||||
('missing shebang',
|
||||
'empty.sh',
|
||||
'',
|
||||
["dir/empty.sh:0: run 'shellcheck' and fix the warnings",
|
||||
"In dir/empty.sh line 1:\n"
|
||||
"^-- SC2148 (error): Tips depend on target shell and yours is unknown. Add a shebang or a 'shell' directive.\n"
|
||||
"For more information:\n"
|
||||
" https://www.shellcheck.net/wiki/SC2148 -- Tips depend on target shell and y..."]),
|
||||
('sh shebang',
|
||||
'sh-shebang.sh',
|
||||
'#!/bin/sh',
|
||||
[]),
|
||||
('bash shebang',
|
||||
'bash-shebang.sh',
|
||||
'#!/bin/bash',
|
||||
[]),
|
||||
('2 warnings',
|
||||
'unused.sh',
|
||||
'unused=""',
|
||||
["dir/unused.sh:0: run 'shellcheck' and fix the warnings",
|
||||
"In dir/unused.sh line 1:\n"
|
||||
'unused=""\n'
|
||||
"^-- SC2148 (error): Tips depend on target shell and yours is unknown. Add a shebang or a 'shell' directive.\n"
|
||||
"^----^ SC2034 (warning): unused appears unused. Verify use (or export if used externally).\n"
|
||||
"For more information:\n"
|
||||
" https://www.shellcheck.net/wiki/SC2148 -- Tips depend on target shell and y...\n"
|
||||
" https://www.shellcheck.net/wiki/SC2034 -- unused appears unused. Verify use..."]),
|
||||
('tab',
|
||||
'tab.sh',
|
||||
'\t#!/bin/sh',
|
||||
["dir/tab.sh:0: run 'shellcheck' and fix the warnings",
|
||||
"In dir/tab.sh line 1:\n"
|
||||
'\t#!/bin/sh\n'
|
||||
"^-- SC1114 (error): Remove leading spaces before the shebang.\n"
|
||||
"For more information:\n"
|
||||
" https://www.shellcheck.net/wiki/SC1114 -- Remove leading spaces before the ..."]),
|
||||
]
|
||||
|
||||
|
||||
@pytest.mark.parametrize('testname,filename,string,expected', Shellcheck)
|
||||
def test_Shellcheck(testname, filename, string, expected):
|
||||
warnings = check_file(m.Shellcheck, filename, string)
|
||||
assert warnings == expected
|
||||
8
utils/checkpackagelib/test_util.py
Normal file
8
utils/checkpackagelib/test_util.py
Normal file
@@ -0,0 +1,8 @@
|
||||
def check_file(check_function, filename, string):
|
||||
obj = check_function(filename, 'url')
|
||||
result = []
|
||||
result.append(obj.before())
|
||||
for i, line in enumerate(string.splitlines(True)):
|
||||
result.append(obj.check_line(i + 1, line))
|
||||
result.append(obj.after())
|
||||
return [r for r in result if r is not None]
|
||||
44
utils/checkpackagelib/tool.py
Normal file
44
utils/checkpackagelib/tool.py
Normal file
@@ -0,0 +1,44 @@
|
||||
import flake8.main.application
|
||||
import os
|
||||
import subprocess
|
||||
import tempfile
|
||||
from checkpackagelib.base import _Tool
|
||||
|
||||
|
||||
class NotExecutable(_Tool):
|
||||
def ignore(self):
|
||||
return False
|
||||
|
||||
def run(self):
|
||||
if self.ignore():
|
||||
return
|
||||
if os.access(self.filename, os.X_OK):
|
||||
return ["{}:0: This file does not need to be executable{}".format(self.filename, self.hint())]
|
||||
|
||||
|
||||
class Flake8(_Tool):
|
||||
def run(self):
|
||||
with tempfile.NamedTemporaryFile() as output:
|
||||
app = flake8.main.application.Application()
|
||||
app.run(['--output-file={}'.format(output.name), self.filename])
|
||||
stdout = output.readlines()
|
||||
processed_output = [str(line.decode().rstrip()) for line in stdout if line]
|
||||
if len(stdout) == 0:
|
||||
return
|
||||
return ["{}:0: run 'flake8' and fix the warnings".format(self.filename),
|
||||
'\n'.join(processed_output)]
|
||||
|
||||
|
||||
class Shellcheck(_Tool):
|
||||
def run(self):
|
||||
cmd = ['shellcheck', "--external-sources", self.filename]
|
||||
try:
|
||||
p = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
||||
stdout = p.communicate()[0]
|
||||
processed_output = [str(line.decode().rstrip()) for line in stdout.splitlines() if line]
|
||||
if p.returncode == 0:
|
||||
return
|
||||
return ["{}:0: run 'shellcheck' and fix the warnings".format(self.filename),
|
||||
'\n'.join(processed_output)]
|
||||
except FileNotFoundError:
|
||||
return ["{}:0: failed to call 'shellcheck'".format(self.filename)]
|
||||
Reference in New Issue
Block a user