xref: /OK3568_Linux_fs/buildroot/utils/checkpackagelib/lib_patch.py (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1# See utils/checkpackagelib/readme.txt before editing this file.
2# The format of the patch files is tested during the build, so below check
3# functions don't need to check for things already checked by running
4# "make package-dirclean package-patch".
5
6import os
7import re
8
9from checkpackagelib.base import _CheckFunction
10from checkpackagelib.lib import NewlineAtEof           # noqa: F401
11
12
13class ApplyOrder(_CheckFunction):
14    APPLY_ORDER = re.compile(r"\d{1,4}-[^/]*$")
15
16    def before(self):
17        if not self.APPLY_ORDER.match(os.path.basename(self.filename)):
18            return ["{}:0: use name <number>-<description>.patch "
19                    "({}#_providing_patches)"
20                    .format(self.filename, self.url_to_manual)]
21
22
23class NumberedSubject(_CheckFunction):
24    NUMBERED_PATCH = re.compile(r"Subject:\s*\[PATCH\s*\d+/\d+\]")
25
26    def before(self):
27        self.git_patch = False
28        self.lineno = 0
29        self.text = None
30
31    def check_line(self, lineno, text):
32        if text.startswith("diff --git"):
33            self.git_patch = True
34            return
35        if self.NUMBERED_PATCH.search(text):
36            self.lineno = lineno
37            self.text = text
38
39    def after(self):
40        if self.git_patch and self.text:
41            return ["{}:{}: generate your patches with 'git format-patch -N'"
42                    .format(self.filename, self.lineno),
43                    self.text]
44
45
46class Sob(_CheckFunction):
47    SOB_ENTRY = re.compile(r"^Signed-off-by: .*$")
48
49    def before(self):
50        self.found = False
51
52    def check_line(self, lineno, text):
53        if self.found:
54            return
55        if self.SOB_ENTRY.search(text):
56            self.found = True
57
58    def after(self):
59        if not self.found:
60            return ["{}:0: missing Signed-off-by in the header "
61                    "({}#_format_and_licensing_of_the_package_patches)"
62                    .format(self.filename, self.url_to_manual)]
63