Skip to content

Commit

Permalink
Update cfgtool to handle choices and default values
Browse files Browse the repository at this point in the history
  • Loading branch information
mikee47 committed Sep 27, 2021
1 parent 19758ed commit 9bbea2c
Showing 1 changed file with 22 additions and 6 deletions.
28 changes: 22 additions & 6 deletions Tools/cfgtool.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,25 @@ def load_config_vars(filename):
return parser['config']


def set_kconfig_value(symbol, v):
"""Convert values from Sming format to Kconfig format.
Hidden variables are used to store choice selections and cannot be set directly.
Instead, locate the corresponding choice variable and set that.
"""
if symbol.visibility == 2:
if symbol.type is kconfiglib.BOOL:
v = 'y' if v == '1' else 'n'
elif symbol.type == kconfiglib._T_INT:
v = 0 if v == '' else v
symbol.set_value(v)
else:
for sym, cond in symbol.defaults:
if type(cond) is tuple:
cond = cond[1]
if v == sym.name and cond.type is kconfiglib.BOOL:
cond.set_value('y')
break

def main():
parser = argparse.ArgumentParser(description='Sming configuration management tool')
parser.add_argument('--to-kconfig', help="Convert Sming configuration to Kconfig format", action='store_true')
Expand All @@ -32,11 +51,8 @@ def main():
src = load_config_vars(args.config_file)
for k, v in src.items():
c = conf.syms.get(k)
if not c:
continue
if c.type is kconfiglib.BOOL:
v = 'y' if v == '1' else 'n'
c.set_value(v)
if c:
set_kconfig_value(c, v)
conf.write_config(os.environ['KCONFIG_CONFIG'])
elif args.from_kconfig:
conf.load_config(os.environ['KCONFIG_CONFIG'])
Expand All @@ -59,7 +75,7 @@ def main():
f.write("\n")
varnames = list(varnames)
varnames.sort()
f.write("CACHED_VARE_NAMES := " + " ".join(varnames))
f.write("CACHED_VAR_NAMES := " + " ".join(varnames))
else:
raise RuntimeError("No command specified")

Expand Down

0 comments on commit 9bbea2c

Please sign in to comment.