ulfalizer / Kconfiglib

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

Failure to parse Kconfig.include on kernels with version >=5.12.1 #109

Open oddlama opened 3 years ago

oddlama commented 3 years ago

Kconfiglib fails to correctly parse the "newer" Kconfig.include files that are used from kernel 5.12.1 and upwards. To reproduce, simply download a recent kernel, and run something like this:

import kconfiglib
kconfig = kconfiglib.Kconfig("/usr/src/linux/Kconfig")

You will be getting an error, stating that there seems to be a linker support error, although running make works just fine with the same environment. For reference, this was tested on a clean gentoo installation (on 2021-08-09) with kernel 5.13.8-gentoo.

Traceback (most recent call last):
  File "/root/.local/lib/python3.9/site-packages/kconfiglib.py", line 2783, in _expand_macro
    res += args[int(new_args[0])]
ValueError: invalid literal for int() with base 10: 'error-if'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/root/.local/lib/python3.9/site-packages/autokernel/kconfig.py", line 127, in load_kconfig
    kconfig = kconfiglib.Kconfig(os.path.realpath(kconfig_file), warn_to_stderr=False)
  File "/root/.local/lib/python3.9/site-packages/kconfiglib.py", line 947, in __init__
    self._init(filename, warn, warn_to_stderr, encoding)
  File "/root/.local/lib/python3.9/site-packages/kconfiglib.py", line 1085, in _init
    self._parse_block(None, self.top_node, self.top_node).next = None
  File "/root/.local/lib/python3.9/site-packages/kconfiglib.py", line 2989, in _parse_block
    prev = self._parse_block(None, parent, prev)
  File "/root/.local/lib/python3.9/site-packages/kconfiglib.py", line 2914, in _parse_block
    while self._next_line():
  File "/root/.local/lib/python3.9/site-packages/kconfiglib.py", line 2236, in _next_line
    self._tokens = self._tokenize(line)
  File "/root/.local/lib/python3.9/site-packages/kconfiglib.py", line 2371, in _tokenize
    self._parse_assignment(s)
  File "/root/.local/lib/python3.9/site-packages/kconfiglib.py", line 2611, in _parse_assignment
    s, i = self._expand_macro(s, i, ())
  File "/root/.local/lib/python3.9/site-packages/kconfiglib.py", line 2787, in _expand_macro
    res += self._fn_val(new_args)
  File "/root/.local/lib/python3.9/site-packages/kconfiglib.py", line 2850, in _fn_val
    return py_fn(self, *args)
  File "/root/.local/lib/python3.9/site-packages/kconfiglib.py", line 6776, in _error_if_fn
    raise KconfigError("{}:{}: {}".format(
kconfiglib.KconfigError: scripts/Kconfig.include:56: Sorry, this linker is not supported.