()
| 58 | |
| 59 | |
| 60 | def main(): |
| 61 | parser = argparse.ArgumentParser(description='Sming configuration management tool') |
| 62 | parser.add_argument('--to-kconfig', help="Convert Sming configuration to Kconfig format", action='store_true') |
| 63 | parser.add_argument('--from-kconfig', help="Convert Kconfig configuration to Sming format", action='store_true') |
| 64 | parser.add_argument('config_file', help='Source configuration file') |
| 65 | |
| 66 | args = parser.parse_args() |
| 67 | |
| 68 | if args.to_kconfig: |
| 69 | createComponentsFile() |
| 70 | |
| 71 | conf = kconfiglib.Kconfig(os.environ['KCONFIG']) |
| 72 | src = load_config_vars(args.config_file) |
| 73 | for k, v in src.items(): |
| 74 | c = conf.syms.get(k) |
| 75 | if c: |
| 76 | set_kconfig_value(c, v) |
| 77 | conf.write_config(os.environ['KCONFIG_CONFIG']) |
| 78 | elif args.from_kconfig: |
| 79 | conf = kconfiglib.Kconfig(os.environ['KCONFIG']) |
| 80 | conf.load_config(os.environ['KCONFIG_CONFIG']) |
| 81 | dst = load_config_vars(args.config_file) |
| 82 | varnames = set(dst.pop('CACHED_VAR_NAMES').split()) |
| 83 | |
| 84 | for k, sym in conf.syms.items(): |
| 85 | if sym.type is kconfiglib.UNKNOWN: |
| 86 | continue |
| 87 | if sym.env_var is not None: |
| 88 | continue |
| 89 | v = str(sym.user_value) if sym.user_value else "" |
| 90 | if sym.type is kconfiglib.BOOL: |
| 91 | v = "1" if v in ['y', '2'] else "0" |
| 92 | dst[sym.name] = v |
| 93 | varnames.add(sym.name) |
| 94 | with open(args.config_file, "w") as f: |
| 95 | for k, v in dst.items(): |
| 96 | f.write("%s=%s\n" % (k, v)) |
| 97 | f.write("\n") |
| 98 | varnames = list(varnames) |
| 99 | varnames.sort() |
| 100 | f.write("CACHED_VAR_NAMES := " + " ".join(varnames)) |
| 101 | else: |
| 102 | raise RuntimeError("No command specified") |
| 103 | |
| 104 | |
| 105 | if __name__ == '__main__': |
no test coverage detected