summaryrefslogtreecommitdiffstats
path: root/meta/classes/oelint.bbclass
blob: 458a25ecc39cf1bba8ad8ae8f30c9fb92d0cbcfb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
#
# Copyright OpenEmbedded Contributors
#
# SPDX-License-Identifier: MIT
#

addtask lint before do_build
do_lint[nostamp] = "1"
python do_lint() {
    pkgname = d.getVar("PN")

    ##############################
    # Test that DESCRIPTION exists
    #
    description = d.getVar("DESCRIPTION", False)
    if description[1:10] == '{SUMMARY}':
        bb.warn("%s: DESCRIPTION is not set" % pkgname)


    ##############################
    # Test that HOMEPAGE exists
    #
    homepage = d.getVar("HOMEPAGE", False)
    if homepage == '':
        bb.warn("%s: HOMEPAGE is not set" % pkgname)
    elif not homepage.startswith("http://") and not homepage.startswith("https://"):
        bb.warn("%s: HOMEPAGE doesn't start with http:// or https://" % pkgname)


    ##############################
    # Test for valid SECTION
    #
    section = d.getVar("SECTION", False)
    if section == '':
        bb.warn("%s: SECTION is not set" % pkgname)
    elif not section.islower():
        bb.warn("%s: SECTION should only use lower case" % pkgname)


    ##############################
    # Check that all patches have Signed-off-by and Upstream-Status
    #
    srcuri = d.getVar("SRC_URI", False).split()
    fpaths = (d.getVar('FILESPATH') or '').split(':')

    def findPatch(patchname):
        for dir in fpaths:
            patchpath = dir + patchname
            if os.path.exists(patchpath):
                 return patchpath

    def findKey(path, key):
        ret = True
        f = open('%s' % path, mode = 'r')
        line = f.readline()
        while line:
            if line.find(key) != -1:
                ret = False
            line = f.readline()
        f.close()
        return ret

    def checkPN(pkgname, varname, str):
        if str.find("{PN}") != -1:
            bb.warn("%s: should use BPN instead of PN in %s" % (pkgname, varname))
        if str.find("{P}") != -1:
            bb.warn("%s: should use BP instead of P in %s" % (pkgname, varname))

    length = len("file://")
    for item in srcuri:
        if item.startswith("file://"):
            item = item[length:]
            if item.endswith(".patch") or item.endswith(".diff"):
                path = findPatch(item)
                if findKey(path, "Signed-off-by"):
                    bb.warn("%s: %s doesn't have Signed-off-by" % (pkgname, item))
                if findKey(path, "Upstream-Status"):
                    bb.warn("%s: %s doesn't have Upstream-Status" % (pkgname, item))


    ##############################
    # Check for ${PN} or ${P} usage in SRC_URI or S
    # Should use ${BPN} or ${BP} instead to avoid breaking multilib
    #
    for s in srcuri:
        if not s.startswith("file://"):
            checkPN(pkgname, 'SRC_URI', s)

    checkPN(pkgname, 'S', d.getVar('S', False))
}