lib_patch.py 2.5 KB

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