lib_patch.py 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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. import os
  6. import re
  7. from checkpackagelib.base import _CheckFunction
  8. from checkpackagelib.lib import NewlineAtEof # noqa: F401
  9. class ApplyOrder(_CheckFunction):
  10. APPLY_ORDER = re.compile(r"\d{1,4}-[^/]*$")
  11. def before(self):
  12. if not self.APPLY_ORDER.match(os.path.basename(self.filename)):
  13. return ["{}:0: use name <number>-<description>.patch "
  14. "({}#_providing_patches)"
  15. .format(self.filename, self.url_to_manual)]
  16. class NumberedSubject(_CheckFunction):
  17. NUMBERED_PATCH = re.compile(r"Subject:\s*\[PATCH\s*\d+/\d+\]")
  18. def before(self):
  19. self.git_patch = False
  20. self.lineno = 0
  21. self.text = None
  22. def check_line(self, lineno, text):
  23. if text.startswith("diff --git"):
  24. self.git_patch = True
  25. return
  26. if self.NUMBERED_PATCH.search(text):
  27. self.lineno = lineno
  28. self.text = text
  29. def after(self):
  30. if self.git_patch and self.text:
  31. return ["{}:{}: generate your patches with 'git format-patch -N'"
  32. .format(self.filename, self.lineno),
  33. self.text]
  34. class Sob(_CheckFunction):
  35. SOB_ENTRY = re.compile(r"^Signed-off-by: .*$")
  36. def before(self):
  37. self.found = False
  38. def check_line(self, lineno, text):
  39. if self.found:
  40. return
  41. if self.SOB_ENTRY.search(text):
  42. self.found = True
  43. def after(self):
  44. if not self.found:
  45. return ["{}:0: missing Signed-off-by in the header "
  46. "({}#_format_and_licensing_of_the_package_patches)"
  47. .format(self.filename, self.url_to_manual)]