From 38cca3bdeca7d91044e11ddf2193e07c5d223ad3 Mon Sep 17 00:00:00 2001 From: Ulf Magnusson Date: Wed, 30 May 2018 18:05:04 +0200 Subject: allyesconfig: Prepare for packaging Move to the root, simplify a bit, provide an entry point function (for setuptools's entry_points). --- allyesconfig.py | 79 ++++++++++++++++++++++++++++++++++++++++++++++++ examples/allyesconfig.py | 69 ------------------------------------------ testsuite.py | 14 ++++----- 3 files changed, 86 insertions(+), 76 deletions(-) create mode 100755 allyesconfig.py delete mode 100644 examples/allyesconfig.py diff --git a/allyesconfig.py b/allyesconfig.py new file mode 100755 index 0000000..e405e3d --- /dev/null +++ b/allyesconfig.py @@ -0,0 +1,79 @@ +#!/usr/bin/env python + +# Works like 'make allyesconfig'. Verified by the test suite to generate output +# identical to 'make allyesconfig', for all ARCHES. +# +# In theory, we need to handle choices in two different modes: +# +# y: One symbol is y, the rest are n +# m: Any number of symbols are m, the rest are n +# +# Only tristate choices can be in m mode. +# +# Here's a convoluted example of how you might get an m-mode choice even during +# allyesconfig: +# +# choice +# tristate "weird choice" +# depends on m +# +# ... +# +# endchoice +# +# +# Usage for the Linux kernel: +# +# $ make [ARCH=] scriptconfig SCRIPT=Kconfiglib/examples/allyesconfig.py + +import os +import sys + +import kconfiglib + +def main(): + if len(sys.argv) > 2: + sys.exit("usage: {} [Kconfig]".format(sys.argv[0])) + + kconf = kconfiglib.Kconfig("Kconfig" if len(sys.argv) < 2 else 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() + + # Small optimization + BOOL_TRI = (kconfiglib.BOOL, kconfiglib.TRISTATE) + + for sym in kconf.defined_syms: + if sym.orig_type in BOOL_TRI and not sym.choice: + sym.set_value(2) + + # This might be slightly more robust than what the C tools do for choices, + # as raising one choice might allow other choices to be raised. It + # currently produces the same output for all ARCHes though. + + while True: + changed = False + + for choice in kconf.choices: + if choice.assignable and choice.tri_value < choice.assignable[-1]: + choice.set_value(choice.assignable[-1]) + + # For y-mode choices, we just let the choice get its default + # selection. For m-mode choices, we set all choice symbols to + # m. + if choice.tri_value == 1: + for sym in choice.syms: + sym.set_value(1) + + changed = True + + # Do multiple passes until we longer manage to raise any choices, like + # in allnoconfig_walk.py + if not changed: + break + + kconf.write_config(".config") + +if __name__ == "__main__": + main() diff --git a/examples/allyesconfig.py b/examples/allyesconfig.py deleted file mode 100644 index e27374e..0000000 --- a/examples/allyesconfig.py +++ /dev/null @@ -1,69 +0,0 @@ -# Works like 'make allyesconfig'. Verified by the test suite to generate output -# identical to 'make allyesconfig', for all ARCHES. -# -# This example is implemented a bit differently from allnoconfig.py to -# demonstrate some other possibilities. A variant similar to -# allnoconfig_simpler.py could be constructed too. -# -# In theory, we need to handle choices in two different modes: -# -# y: One symbol is y, the rest are n -# m: Any number of symbols are m, the rest are n -# -# Only tristate choices can be in m mode. -# -# In practice, no m mode choices appear for allyesconfig as of 4.14, as -# expected, but we still handle them here for completeness. Here's a convoluted -# example of how you might get an m-mode choice even during allyesconfig: -# -# choice -# tristate "weird choice" -# depends on m -# -# ... -# -# endchoice -# -# -# Usage: -# -# $ make [ARCH=] scriptconfig SCRIPT=Kconfiglib/examples/allyesconfig.py - -from kconfiglib import Kconfig, Choice -import sys - -kconf = Kconfig(sys.argv[1]) - -while True: - changed = False - - for sym in kconf.defined_syms: - # Choices are handled separately below - if sym.choice: - continue - - # Set the symbol to the highest assignable value, unless it already has - # that value. sym.assignable[-1] gives the last element in assignable. - if sym.assignable and sym.tri_value < sym.assignable[-1]: - sym.set_value(sym.assignable[-1]) - changed = True - - for choice in kconf.choices: - # Same logic as above for choices - if choice.assignable and choice.tri_value < choice.assignable[-1]: - choice.set_value(choice.assignable[-1]) - - # For y-mode choices, we just let the choice get its default - # selection. For m-mode choices, we set all choice symbols to m. - if choice.tri_value == 1: - for sym in choice.syms: - sym.set_value(1) - - changed = True - - # Do multiple passes until we longer manage to raise any symbols or - # choices, like in allnoconfig.py - if not changed: - break - -kconf.write_config(".config") diff --git a/testsuite.py b/testsuite.py index 1f0ef64..8bf9502 100644 --- a/testsuite.py +++ b/testsuite.py @@ -1985,9 +1985,9 @@ def test_all_no(conf, arch, srcarch): def test_all_no_walk(conf, arch, srcarch): """ - 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. + Verify that examples/allnoconfig_walk.py 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_walk.py " @@ -2002,12 +2002,12 @@ def test_all_no_walk(conf, arch, srcarch): def test_all_yes(conf, arch, srcarch): """ - Verify that our examples/allyesconfig.py script generates the same .config - as 'make allyesconfig', for each architecture. Runs the script via - 'make scriptconfig', so kinda slow even in speedy mode. + Verify that allyesconfig.py generates the same .config as + 'make allyesconfig', 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/allyesconfig.py " + shell("make scriptconfig SCRIPT=Kconfiglib/allyesconfig.py " "PYTHONCMD='{}'".format(sys.executable)) shell("mv .config ._config") if speedy: -- cgit v1.2.3