From 4c4f184a3a648b8cb748ab35159a09ccd06b2ff7 Mon Sep 17 00:00:00 2001 From: Ulf Magnusson Date: Sun, 27 May 2018 20:37:59 +0200 Subject: allnoconfig: Move from examples/ to root Put to-be-packaged stuff in the root. Use allnoconfig_simpler.py, and rename allnoconfig.py to allnoconfig_walk.py and keep it as an example. --- examples/allnoconfig.py | 62 ----------------------------------------- examples/allnoconfig_simpler.py | 22 --------------- examples/allnoconfig_walk.py | 60 +++++++++++++++++++++++++++++++++++++++ testsuite.py | 16 +++++------ 4 files changed, 68 insertions(+), 92 deletions(-) delete mode 100644 examples/allnoconfig.py delete mode 100644 examples/allnoconfig_simpler.py create mode 100644 examples/allnoconfig_walk.py diff --git a/examples/allnoconfig.py b/examples/allnoconfig.py deleted file mode 100644 index e7f05f4..0000000 --- a/examples/allnoconfig.py +++ /dev/null @@ -1,62 +0,0 @@ -# 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 more roundabout -# version demonstrates some tree walking and value processing. -# -# Usage: -# -# $ make [ARCH=] scriptconfig SCRIPT=Kconfiglib/examples/allnoconfig.py - -from kconfiglib import Kconfig, Symbol -import sys - -def do_allnoconfig(node): - global changed - - # 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: - if isinstance(node.item, Symbol): - sym = node.item - - # Is the symbol a non-allnoconfig_y symbol that can be set to a - # lower value than its current value? - if (not sym.is_allnoconfig_y and - sym.assignable and - sym.assignable[0] < sym.tri_value): - - # Yup, lower it - sym.set_value(sym.assignable[0]) - changed = True - - # Recursively lower children - if node.list: - do_allnoconfig(node.list) - - node = node.next - -# Parse the Kconfig files -kconf = Kconfig(sys.argv[1]) - -# Do an initial pass to set 'option allnoconfig_y' symbols to y -for sym in kconf.defined_syms: - if sym.is_allnoconfig_y: - sym.set_value(2) - -while True: - # Changing later symbols in the configuration can sometimes allow earlier - # symbols to be lowered, e.g. if a later symbol 'select's an earlier - # symbol. To handle such situations, we do additional passes over the tree - # until we're no longer able to change the value of any symbol in a pass. - changed = False - - do_allnoconfig(kconf.top_node) - - # Did the pass change any symbols? - if not changed: - break - -kconf.write_config(".config") diff --git a/examples/allnoconfig_simpler.py b/examples/allnoconfig_simpler.py deleted file mode 100644 index 3babcab..0000000 --- a/examples/allnoconfig_simpler.py +++ /dev/null @@ -1,22 +0,0 @@ -# This is a simpler version of allnoconfig.py, corresponding to how the C -# implementation does it. Verified by the test suite to produce identical -# output to 'make allnoconfig' for all ARCHes. -# -# Usage: -# -# $ make [ARCH=] scriptconfig SCRIPT=Kconfiglib/examples/allnoconfig_simpler.py - -from kconfiglib import Kconfig, BOOL, TRISTATE -import sys - -kconf = Kconfig(sys.argv[1]) - -# Avoid warnings printed by Kconfiglib when assigning a value to a symbol that -# has no prompt. Such assignments never have an effect. -kconf.disable_warnings() - -for sym in kconf.defined_syms: - if sym.type in (BOOL, TRISTATE): - sym.set_value(2 if sym.is_allnoconfig_y else 0) - -kconf.write_config(".config") diff --git a/examples/allnoconfig_walk.py b/examples/allnoconfig_walk.py new file mode 100644 index 0000000..8e22cd9 --- /dev/null +++ b/examples/allnoconfig_walk.py @@ -0,0 +1,60 @@ +# This is tree-walking version of allnoconfig.py, for demonstration purposes. +# Verified by the test suite to generate identical output to 'make allnoconfig' +# for all ARCHes. +# +# Usage for the Linux kernel: +# +# $ make [ARCH=] scriptconfig SCRIPT=Kconfiglib/examples/allnoconfig_walk.py + +from kconfiglib import Kconfig, Symbol +import sys + +def do_allnoconfig(node): + global changed + + # 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: + if isinstance(node.item, Symbol): + sym = node.item + + # Is the symbol a non-allnoconfig_y symbol that can be set to a + # lower value than its current value? + if (not sym.is_allnoconfig_y and + sym.assignable and + sym.assignable[0] < sym.tri_value): + + # Yup, lower it + sym.set_value(sym.assignable[0]) + changed = True + + # Recursively lower children + if node.list: + do_allnoconfig(node.list) + + node = node.next + +# Parse the Kconfig files +kconf = Kconfig(sys.argv[1]) + +# Do an initial pass to set 'option allnoconfig_y' symbols to y +for sym in kconf.defined_syms: + if sym.is_allnoconfig_y: + sym.set_value(2) + +while True: + # Changing later symbols in the configuration can sometimes allow earlier + # symbols to be lowered, e.g. if a later symbol 'select's an earlier + # symbol. To handle such situations, we do additional passes over the tree + # until we're no longer able to change the value of any symbol in a pass. + changed = False + + do_allnoconfig(kconf.top_node) + + # Did the pass change any symbols? + if not changed: + break + +kconf.write_config(".config") diff --git a/testsuite.py b/testsuite.py index f157797..29d5860 100644 --- a/testsuite.py +++ b/testsuite.py @@ -1903,7 +1903,7 @@ def run_compatibility_tests(): #test_min_config, test_sanity, test_all_no, - test_all_no_simpler, + test_all_no_walk, test_all_yes) for test_fn in test_fns: @@ -1947,12 +1947,12 @@ def all_arch_srcarch_kconfigs(): def test_all_no(conf, arch, srcarch): """ - Verify that our examples/allnoconfig.py script generates the same .config - as 'make allnoconfig', for each architecture. Runs the script via - 'make scriptconfig', so kinda slow even in speedy mode. + Verify that allnoconfig.py script generates the same .config as 'make + allnoconfig', for each architecture. Runs the script via 'make + scriptconfig', so kinda slow even in speedy mode. """ # TODO: Support speedy mode for running the script - shell("make scriptconfig SCRIPT=Kconfiglib/examples/allnoconfig.py " + shell("make scriptconfig SCRIPT=Kconfiglib/allnoconfig.py " "PYTHONCMD='{}'".format(sys.executable)) shell("mv .config ._config") if speedy: @@ -1962,14 +1962,14 @@ def test_all_no(conf, arch, srcarch): compare_configs(arch) -def test_all_no_simpler(conf, arch, srcarch): +def test_all_no_walk(conf, arch, srcarch): """ - Verify that our examples/allnoconfig_simpler.py script generates the same + Verify that our examples/allnoconfig_walk.py script generates the same .config as 'make allnoconfig', for each architecture. Runs the script via 'make scriptconfig', so kinda slow even in speedy mode. """ # TODO: Support speedy mode for running the script - shell("make scriptconfig SCRIPT=Kconfiglib/examples/allnoconfig_simpler.py " + shell("make scriptconfig SCRIPT=Kconfiglib/examples/allnoconfig_walk.py " "PYTHONCMD='{}'".format(sys.executable)) shell("mv .config ._config") if speedy: -- cgit v1.2.3