ulfalizer / Kconfiglib

A flexible Python 2/3 Kconfig implementation and library
ISC License
456 stars 161 forks source link

Mismatching if/endif handling is weak #56

Closed pfalcon closed 6 years ago

pfalcon commented 6 years ago

This report comes from Zephyr, with version of kconfiglib used there (Zephyr master e1e12ba0c6eeb41bea72ea242195306a69b8b013).

So, I was moving around/adding more "if" directives, and so happens that I added "endif", but (turned out) that missed to add corresponding "if". What I got is rather confusing error message:

$ zephyr-make menuconfig
mkdir -p outdir/qemu_x86 && cmake -DBOARD=qemu_x86 -Boutdir/qemu_x86 -H.
-- Selected BOARD qemu_x86
Zephyr version: 1.13.99
Parsing Kconfig tree in /home/pfalcon/projects-3rdparty/Embedded/Zephyr/zephyr/Kconfig
Traceback (most recent call last):
  File "/home/pfalcon/projects-3rdparty/Embedded/Zephyr/zephyr/scripts/kconfig/kconfig.py", line 210, in <module>
    main()
  File "/home/pfalcon/projects-3rdparty/Embedded/Zephyr/zephyr/scripts/kconfig/kconfig.py", line 44, in main
    kconf = Kconfig(args.kconfig_root, warn_to_stderr=False)
  File "/home/pfalcon/projects-3rdparty/Embedded/Zephyr/zephyr/scripts/kconfig/kconfiglib.py", line 836, in __init__
    self._parse_block(None, self.top_node, self.top_node)
  File "/home/pfalcon/projects-3rdparty/Embedded/Zephyr/zephyr/scripts/kconfig/kconfiglib.py", line 2377, in _parse_block
    prev = self._parse_block(None, parent, prev)
  File "/home/pfalcon/projects-3rdparty/Embedded/Zephyr/zephyr/scripts/kconfig/kconfiglib.py", line 2377, in _parse_block
    prev = self._parse_block(None, parent, prev)
  File "/home/pfalcon/projects-3rdparty/Embedded/Zephyr/zephyr/scripts/kconfig/kconfiglib.py", line 2416, in _parse_block
    self._parse_block(_T_ENDMENU, node, node)
  File "/home/pfalcon/projects-3rdparty/Embedded/Zephyr/zephyr/scripts/kconfig/kconfiglib.py", line 2377, in _parse_block
    prev = self._parse_block(None, parent, prev)
  File "/home/pfalcon/projects-3rdparty/Embedded/Zephyr/zephyr/scripts/kconfig/kconfiglib.py", line 2483, in _parse_block
    self._parse_error("unrecognized construct")
  File "/home/pfalcon/projects-3rdparty/Embedded/Zephyr/zephyr/scripts/kconfig/kconfiglib.py", line 3104, in _parse_error
    "{}couldn't parse '{}': {}".format(loc, self._line.rstrip(), msg))
kconfiglib.KconfigError: lib/posix/Kconfig:88: couldn't parse 'endif # POSIX_API': unrecognized construct
CMake Error at /home/pfalcon/projects-3rdparty/Embedded/Zephyr/zephyr/cmake/kconfig.cmake:158 (message):
  command failed with return code: 1
Call Stack (most recent call first):
  /home/pfalcon/projects-3rdparty/Embedded/Zephyr/zephyr/cmake/app/boilerplate.cmake:257 (include)
  CMakeLists.txt:2 (include)

As you may imagine, first motion is "huh, maybe it doesn't support comments on the same line after endif?". Grepping around Zephyr codebase shows they're used, and removing the comment still leads to the same couldn't parse 'endif': unrecognized construct error. That's pretty confusing if a standard keyword is "unrecognized". Would be nice if it reported "endif without corresponding if" of something.

ulfalizer commented 6 years ago

Yeah, that's a pretty bad error message. Fixed in https://github.com/ulfalizer/Kconfiglib/commit/c91e17c3f0b5410328b2d51c70224804e8b133cc.

I could push a new version to Zephyr as well.

pfalcon commented 6 years ago

Thanks!

I could push a new version to Zephyr as well.

Yes, that would be appreciated.

ulfalizer commented 6 years ago

Zephyr PR: https://github.com/zephyrproject-rtos/zephyr/pull/10266