summaryrefslogtreecommitdiff
path: root/examples/allnoconfig.py
blob: edc473ded1b9f958f7bb23bcab7c6c45f7f72c08 (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
# Works like 'make allnoconfig'. Verified by the test suite to generate
# identical output to 'make allnoconfig' for all ARCHes.
#
# See allnoconfig_simpler.py for a much simpler version. This version
# demonstrates some tree walking and value processing.
#
# Usage:
#
#   $ make [ARCH=<arch>] scriptconfig SCRIPT=Kconfiglib/examples/allnoconfig.py

from kconfiglib import Config, Symbol, tri_less
import sys

def do_allnoconfig(node):
    global no_changes

    # Walk the tree of menu nodes. You can imagine this as going down/into menu
    # entries in the menuconfig interface, setting each to 'n' (or the lowest
    # assignable value).

    while node is not None:
        if isinstance(node.item, Symbol):
            sym = node.item

            # Is the symbol a non-choice symbol that can be set to a lower
            # value than its current value?
            if sym.choice is None and sym.assignable and \
               tri_less(sym.assignable[0], sym.value):

                # Yup, lower it
                sym.set_value(sym.assignable[0])
                no_changes = False

        # Recursively lower children
        if node.list is not None:
            do_allnoconfig(node.list)

        node = node.next

conf = Config(sys.argv[1])

while 1:
    # For tricky dependencies involving '!', setting later symbols to 'n' might
    # actually raise the value of earlier symbols. To be super safe, we do
    # additional passes until a pass no longer changes the value of any symbol.
    #
    # This isn't actually needed for any ARCH in the kernel as of 4.14. A
    # single pass gives the correct result.
    no_changes = True

    do_allnoconfig(conf.top_menu)

    # Did the pass change any symbols?
    if no_changes:
        break

conf.write_config(".config")