Atlas - allnoconfig_walk.py

Home / ext / kconfiglib / examples Lines: 1 | Size: 1976 bytes [Download] [Show on GitHub] [Search similar files] [Raw] [Raw (proxy)]
[FILE BEGIN]
1# This is tree-walking version of allnoconfig.py, for demonstration purposes. 2# Verified by the test suite to generate identical output to 'make allnoconfig' 3# for all ARCHes. 4# 5# Note: A more practical version would use Kconfig.node_iter(). The manual tree 6# walking is for demonstration purposes. 7# 8# Usage for the Linux kernel: 9# 10# $ make [ARCH=<arch>] scriptconfig SCRIPT=Kconfiglib/examples/allnoconfig_walk.py 11 12import sys 13 14from kconfiglib import Kconfig, Symbol 15 16 17def do_allnoconfig(node): 18 global changed 19 20 # Walk the tree of menu nodes. You can imagine this as going down/into menu 21 # entries in the menuconfig interface, setting each to n (or the lowest 22 # assignable value). 23 24 while node: 25 if isinstance(node.item, Symbol): 26 sym = node.item 27 28 # Is the symbol a non-allnoconfig_y symbol that can be set to a 29 # lower value than its current value? 30 if (not sym.is_allnoconfig_y and 31 sym.assignable and 32 sym.assignable[0] < sym.tri_value): 33 34 # Yup, lower it 35 sym.set_value(sym.assignable[0]) 36 changed = True 37 38 # Recursively lower children 39 if node.list: 40 do_allnoconfig(node.list) 41 42 node = node.next 43 44 45# Parse the Kconfig files 46kconf = Kconfig(sys.argv[1]) 47 48# Do an initial pass to set 'option allnoconfig_y' symbols to y 49for sym in kconf.unique_defined_syms: 50 if sym.is_allnoconfig_y: 51 sym.set_value(2) 52 53while True: 54 # Changing later symbols in the configuration can sometimes allow earlier 55 # symbols to be lowered, e.g. if a later symbol 'select's an earlier 56 # symbol. To handle such situations, we do additional passes over the tree 57 # until we're no longer able to change the value of any symbol in a pass. 58 changed = False 59 60 do_allnoconfig(kconf.top_node) 61 62 # Did the pass change any symbols? 63 if not changed: 64 break 65 66print(kconf.write_config()) 67
[FILE END]
(C) 2025 0x4248 (C) 2025 4248 Media and 4248 Systems, All part of 0x4248 See LICENCE files for more information. Not all files are by 0x4248 always check Licencing.