kconfig: Refactor kconfig.py to use __main__ and argparse
Kconfig.py is not following the de-facto (real?) coding standards of Zephyr. This commit refactors kconfig.py with two changes: Use __main__ and def main(). Use argparse instead of sys.argv. Signed-off-by: Sebastian Bøe <sebastian.boe@nordicsemi.no>
This commit is contained in:
parent
4388f6f314
commit
60b01f3f54
1 changed files with 70 additions and 51 deletions
|
@ -2,14 +2,13 @@
|
|||
# Modified from: https://github.com/ulfalizer/Kconfiglib/blob/master/examples/merge_config.py
|
||||
from kconfiglib import Kconfig, Symbol, BOOL, STRING, TRISTATE, TRI_TO_STR
|
||||
import sys
|
||||
import argparse
|
||||
|
||||
if len(sys.argv) < 5:
|
||||
print('usage: {} Kconfig dotconfig autoconf conf1 [conf2 ...]'
|
||||
.format(sys.argv[0]))
|
||||
sys.exit(1)
|
||||
def main():
|
||||
parse_args()
|
||||
|
||||
print("Parsing Kconfig tree in {}".format(sys.argv[1]))
|
||||
kconf = Kconfig(sys.argv[1])
|
||||
print("Parsing Kconfig tree in {}".format(args.kconfig_root))
|
||||
kconf = Kconfig(args.kconfig_root)
|
||||
|
||||
# Enable warnings for assignments to undefined symbols
|
||||
kconf.enable_undef_warnings()
|
||||
|
@ -18,11 +17,11 @@ kconf.enable_undef_warnings()
|
|||
# up here as well. The approach in examples/allnoconfig_simpler.py could
|
||||
# provide an allnoconfig starting state for example.
|
||||
|
||||
print("Using {} as base".format(sys.argv[4]))
|
||||
for config in sys.argv[5:]:
|
||||
print("Using {} as base".format(args.conf_fragments[0]))
|
||||
for config in args.conf_fragments[1:]:
|
||||
print("Merging {}".format(config))
|
||||
# Create a merged configuration by loading the fragments with replace=False
|
||||
for config in sys.argv[4:]:
|
||||
for config in args.conf_fragments:
|
||||
kconf.load_config(config, replace=False)
|
||||
|
||||
|
||||
|
@ -66,7 +65,27 @@ for warning in kconf.warnings:
|
|||
|
||||
|
||||
# Write the merged configuration
|
||||
kconf.write_config(sys.argv[2])
|
||||
kconf.write_config(args.dotconfig)
|
||||
|
||||
# Write the C header
|
||||
kconf.write_autoconf(sys.argv[3])
|
||||
kconf.write_autoconf(args.autoconf)
|
||||
|
||||
|
||||
def parse_args():
|
||||
global args
|
||||
|
||||
parser = argparse.ArgumentParser(
|
||||
description=__doc__,
|
||||
formatter_class=argparse.RawDescriptionHelpFormatter
|
||||
)
|
||||
|
||||
parser.add_argument("kconfig_root")
|
||||
parser.add_argument("dotconfig")
|
||||
parser.add_argument("autoconf")
|
||||
parser.add_argument("conf_fragments", metavar='conf', type=str, nargs='+')
|
||||
|
||||
args = parser.parse_args()
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue