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