savedefconfig.py 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. #!/usr/bin/env python3
  2. # Copyright (c) 2019, Ulf Magnusson
  3. # SPDX-License-Identifier: ISC
  4. """
  5. Saves a minimal configuration file that only lists symbols that differ in value
  6. from their defaults. Loading such a configuration file is equivalent to loading
  7. the "full" configuration file.
  8. Minimal configuration files are handy to start from when editing configuration
  9. files by hand.
  10. The default input configuration file is '.config'. A different input filename
  11. can be passed in the KCONFIG_CONFIG environment variable.
  12. Note: Minimal configurations can also be generated from within the menuconfig
  13. interface.
  14. """
  15. import argparse
  16. import kconfiglib
  17. def main():
  18. parser = argparse.ArgumentParser(
  19. formatter_class=argparse.RawDescriptionHelpFormatter,
  20. description=__doc__)
  21. parser.add_argument(
  22. "--kconfig",
  23. default="Kconfig",
  24. help="Top-level Kconfig file (default: Kconfig)")
  25. parser.add_argument(
  26. "--out",
  27. metavar="MINIMAL_CONFIGURATION",
  28. default="defconfig",
  29. help="Output filename for minimal configuration (default: defconfig)")
  30. args = parser.parse_args()
  31. kconf = kconfiglib.Kconfig(args.kconfig, suppress_traceback=True)
  32. print(kconf.load_config())
  33. print(kconf.write_min_config(args.out))
  34. if __name__ == "__main__":
  35. main()