listnewconfig.py 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. #!/usr/bin/env python3
  2. # Copyright (c) 2018-2019, Ulf Magnusson
  3. # SPDX-License-Identifier: ISC
  4. """
  5. Lists all user-modifiable symbols that are not given a value in the
  6. configuration file. Usually, these are new symbols that have been added to the
  7. Kconfig files.
  8. The default configuration filename is '.config'. A different filename can be
  9. passed in the KCONFIG_CONFIG environment variable.
  10. """
  11. from __future__ import print_function
  12. import argparse
  13. import sys
  14. from kconfiglib import Kconfig, BOOL, TRISTATE, INT, HEX, STRING, TRI_TO_STR
  15. def main():
  16. parser = argparse.ArgumentParser(
  17. formatter_class=argparse.RawDescriptionHelpFormatter,
  18. description=__doc__)
  19. parser.add_argument(
  20. "--show-help", "-l",
  21. action="store_true",
  22. help="Show any help texts as well")
  23. parser.add_argument(
  24. "kconfig",
  25. metavar="KCONFIG",
  26. nargs="?",
  27. default="Kconfig",
  28. help="Top-level Kconfig file (default: Kconfig)")
  29. args = parser.parse_args()
  30. kconf = Kconfig(args.kconfig, suppress_traceback=True)
  31. # Make it possible to filter this message out
  32. print(kconf.load_config(), file=sys.stderr)
  33. for sym in kconf.unique_defined_syms:
  34. # Only show symbols that can be toggled. Choice symbols are a special
  35. # case in that sym.assignable will be (2,) (length 1) for visible
  36. # symbols in choices in y mode, but they can still be toggled by
  37. # selecting some other symbol.
  38. if sym.user_value is None and \
  39. (len(sym.assignable) > 1 or
  40. (sym.visibility and (sym.orig_type in (INT, HEX, STRING) or
  41. sym.choice))):
  42. # Don't reuse the 'config_string' format for bool/tristate symbols,
  43. # to show n-valued symbols as 'CONFIG_FOO=n' instead of
  44. # '# CONFIG_FOO is not set'. This matches the C tools.
  45. if sym.orig_type in (BOOL, TRISTATE):
  46. s = "{}{}={}\n".format(kconf.config_prefix, sym.name,
  47. TRI_TO_STR[sym.tri_value])
  48. else:
  49. s = sym.config_string
  50. print(s, end="")
  51. if args.show_help:
  52. for node in sym.nodes:
  53. if node.help is not None:
  54. # Indent by two spaces. textwrap.indent() is not
  55. # available in Python 2 (it's 3.3+).
  56. print("\n".join(" " + line
  57. for line in node.help.split("\n")))
  58. break
  59. if __name__ == "__main__":
  60. main()