summaryrefslogtreecommitdiffstats
path: root/meta/classes/kernel-check.bbclass
blob: d202f4e32066bcefccf5c5a052b08d765f9c838a (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
91
92
93
94
95
96
97
# Provides a means of checking within a recipe if particular kernel
# config options are enabled
#
# Copyright (C) 2016 Intel Corporation
#
# Example usage (within a recipe):
#
# inherit kernel-check
# REQUIRED_KERNEL_OPTIONS = "CONFIG_CGROUPS CONFIG_NAMESPACES"
#
# If one or more of the options aren't in the built kernel configuration
# you will get a warning at do_configure time.
#
# You can also use the check_kernel_config_options() function to do
# explicit checks yourself (and perform a different action).

def check_kernel_config_options(options, d):
    """
    A function you can use to do explicit checks for kernel config
    options from python code
    """

    if isinstance(options, basestring):
        required = options.split()
    else:
        required = options[:]
    missing = []
    diffvalue = []
    if required:
        with open(d.expand('${STAGING_KERNEL_BUILDDIR}/.config'), 'r') as f:
            for line in f:
                if line.startswith('#'):
                    continue
                linesplit = line.rstrip().split('=', 1)
                if len(linesplit) < 2:
                    continue
                linevalue = linesplit[1]
                for req in required:
                    found = False
                    if '|' in req:
                        for reqitem in req.split('|'):
                            if reqitem == linesplit[0]:
                                if linevalue in ['y', 'm']:
                                    found = True
                                    break
                    else:
                        reqsplit = req.split('=', 1)
                        # Can check for CONFIG_OPTION or CONFIG_OPTION=value
                        if len(reqsplit) > 1:
                            reqvalue = reqsplit[1]
                        else:
                            reqvalue = None
                        if reqsplit[0] == linesplit[0]:
                            if reqvalue is None:
                                if linevalue not in ['y', 'm']:
                                    diffvalue.append((reqsplit[0], 'y or m', linevalue))
                            elif reqvalue.strip("'\"") != linevalue.strip("'\""):
                                diffvalue.append((reqsplit[0], reqvalue, linevalue))
                            found = True

                    if found:
                        required.remove(req)
                        break

        for req in required:
            reqsplit = req.split('=', 1)
            if len(reqsplit) > 1:
                if reqsplit[1] == 'n':
                    continue
                missing.append('%s=%s' % reqsplit)
            else:
                missing.append('%s' % req)

    return missing, diffvalue


python check_kernel_config() {
    pn = d.getVar('PN', True)
    required = d.getVar('REQUIRED_KERNEL_OPTIONS', True) or ''
    if ' | ' in required:
        bb.error('Invalid REQUIRED_KERNEL_OPTIONS value - cannot have spaces around |')
    if ' = ' in required:
        bb.error('Invalid REQUIRED_KERNEL_OPTIONS value - cannot have spaces around =')
    missing, diffvalue = check_kernel_config_options(required, d)
    if missing or diffvalue:
        reqstr = '\n  '.join(missing + ['%s=%s (actual value %s)' % item for item in diffvalue])
        # Just warn here for cases like linux-dummy where we don't actually
        # know the final config
        bb.warn('The kernel you are building against is missing the following required configuration options:\n  %s' % reqstr)
}

python() {
    if d.getVar('REQUIRED_KERNEL_OPTIONS', True):
        d.appendVar('DEPENDS', ' virtual/kernel')
        d.appendVarFlag('do_configure', 'prefuncs', ' check_kernel_config')
        d.appendVarFlag('do_configure', 'depends', ' virtual/kernel:do_shared_workdir')
}