oelint.bbclass 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. addtask lint before do_build
  2. do_lint[nostamp] = "1"
  3. python do_lint() {
  4. pkgname = d.getVar("PN")
  5. ##############################
  6. # Test that DESCRIPTION exists
  7. #
  8. description = d.getVar("DESCRIPTION", False)
  9. if description[1:10] == '{SUMMARY}':
  10. bb.warn("%s: DESCRIPTION is not set" % pkgname)
  11. ##############################
  12. # Test that HOMEPAGE exists
  13. #
  14. homepage = d.getVar("HOMEPAGE", False)
  15. if homepage == '':
  16. bb.warn("%s: HOMEPAGE is not set" % pkgname)
  17. elif not homepage.startswith("http://") and not homepage.startswith("https://"):
  18. bb.warn("%s: HOMEPAGE doesn't start with http:// or https://" % pkgname)
  19. ##############################
  20. # Test for valid SECTION
  21. #
  22. section = d.getVar("SECTION", False)
  23. if section == '':
  24. bb.warn("%s: SECTION is not set" % pkgname)
  25. elif not section.islower():
  26. bb.warn("%s: SECTION should only use lower case" % pkgname)
  27. ##############################
  28. # Check that all patches have Signed-off-by and Upstream-Status
  29. #
  30. srcuri = d.getVar("SRC_URI", False).split()
  31. fpaths = (d.getVar('FILESPATH') or '').split(':')
  32. def findPatch(patchname):
  33. for dir in fpaths:
  34. patchpath = dir + patchname
  35. if os.path.exists(patchpath):
  36. return patchpath
  37. def findKey(path, key):
  38. ret = True
  39. f = open('%s' % path, mode = 'r')
  40. line = f.readline()
  41. while line:
  42. if line.find(key) != -1:
  43. ret = False
  44. line = f.readline()
  45. f.close()
  46. return ret
  47. def checkPN(pkgname, varname, str):
  48. if str.find("{PN}") != -1:
  49. bb.warn("%s: should use BPN instead of PN in %s" % (pkgname, varname))
  50. if str.find("{P}") != -1:
  51. bb.warn("%s: should use BP instead of P in %s" % (pkgname, varname))
  52. length = len("file://")
  53. for item in srcuri:
  54. if item.startswith("file://"):
  55. item = item[length:]
  56. if item.endswith(".patch") or item.endswith(".diff"):
  57. path = findPatch(item)
  58. if findKey(path, "Signed-off-by"):
  59. bb.warn("%s: %s doesn't have Signed-off-by" % (pkgname, item))
  60. if findKey(path, "Upstream-Status"):
  61. bb.warn("%s: %s doesn't have Upstream-Status" % (pkgname, item))
  62. ##############################
  63. # Check for ${PN} or ${P} usage in SRC_URI or S
  64. # Should use ${BPN} or ${BP} instead to avoid breaking multilib
  65. #
  66. for s in srcuri:
  67. if not s.startswith("file://"):
  68. checkPN(pkgname, 'SRC_URI', s)
  69. checkPN(pkgname, 'S', d.getVar('S', False))
  70. }