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 11from checkpackagelib.tool import NotExecutable # noqa: F401 12 13 14class ApplyOrder(_CheckFunction): 15 APPLY_ORDER = re.compile(r"\d{1,4}-[^/]*$") 16 17 def before(self): 18 if not self.APPLY_ORDER.match(os.path.basename(self.filename)): 19 return ["{}:0: use name <number>-<description>.patch " 20 "({}#_providing_patches)" 21 .format(self.filename, self.url_to_manual)] 22 23 24class NumberedSubject(_CheckFunction): 25 NUMBERED_PATCH = re.compile(r"Subject:\s*\[PATCH\s*\d+/\d+\]") 26 27 def before(self): 28 self.git_patch = False 29 self.lineno = 0 30 self.text = None 31 32 def check_line(self, lineno, text): 33 if text.startswith("diff --git"): 34 self.git_patch = True 35 return 36 if self.NUMBERED_PATCH.search(text): 37 self.lineno = lineno 38 self.text = text 39 40 def after(self): 41 if self.git_patch and self.text: 42 return ["{}:{}: generate your patches with 'git format-patch -N'" 43 .format(self.filename, self.lineno), 44 self.text] 45 46 47class Sob(_CheckFunction): 48 SOB_ENTRY = re.compile(r"^Signed-off-by: .*$") 49 50 def before(self): 51 self.found = False 52 53 def check_line(self, lineno, text): 54 if self.found: 55 return 56 if self.SOB_ENTRY.search(text): 57 self.found = True 58 59 def after(self): 60 if not self.found: 61 return ["{}:0: missing Signed-off-by in the header " 62 "({}#_format_and_licensing_of_the_package_patches)" 63 .format(self.filename, self.url_to_manual)] 64 65 66class Upstream(_CheckFunction): 67 UPSTREAM_ENTRY = re.compile(r"^Upstream: .*$") 68 69 def before(self): 70 self.found = False 71 72 def check_line(self, lineno, text): 73 if self.found: 74 return 75 if self.UPSTREAM_ENTRY.search(text): 76 self.found = True 77 78 def after(self): 79 if not self.found: 80 return ["{}:0: missing Upstream in the header " 81 "({}#_additional_patch_documentation)" 82 .format(self.filename, self.url_to_manual)] 83