]> rtime.felk.cvut.cz Git - coffee/buildroot.git/blob - support/scripts/checkpackagelib/lib_patch.py
check-package: move parts to subdirectory
[coffee/buildroot.git] / support / scripts / checkpackagelib / lib_patch.py
1 # See support/scripts/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
6 import re
7
8 from base import _CheckFunction
9 # Notice: ignore 'imported but unused' from pyflakes for check functions.
10 from lib import NewlineAtEof
11
12
13 class ApplyOrder(_CheckFunction):
14     APPLY_ORDER = re.compile("/\d{1,4}-[^/]*$")
15
16     def before(self):
17         if not self.APPLY_ORDER.search(self.filename):
18             return ["{}:0: use name <number>-<description>.patch "
19                     "({}#_providing_patches)"
20                     .format(self.filename, self.url_to_manual)]
21
22
23 class NumberedSubject(_CheckFunction):
24     NUMBERED_PATCH = re.compile("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
46 class Sob(_CheckFunction):
47     SOB_ENTRY = re.compile("^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)]