summaryrefslogtreecommitdiff
path: root/kconfiglib.py
diff options
context:
space:
mode:
authorUlf Magnusson <ulfalizer@gmail.com>2018-01-17 12:56:13 +0100
committerUlf Magnusson <ulfalizer@gmail.com>2018-01-17 13:53:30 +0100
commit7dc5b74229e83876307082712162d48e3124e10b (patch)
tree63bff50cc694920ccc181092411bae2a7915ac43 /kconfiglib.py
parent67ef1d201644664afdfa2373e72495280a0c3fa0 (diff)
Detect recursive 'source' and print backtrace
Easier to debug than a RecursionError. Point out in the exception message that a common cause is environment variables not being set correctly.
Diffstat (limited to 'kconfiglib.py')
-rw-r--r--kconfiglib.py13
1 files changed, 13 insertions, 0 deletions
diff --git a/kconfiglib.py b/kconfiglib.py
index f111fe5..256c02c 100644
--- a/kconfiglib.py
+++ b/kconfiglib.py
@@ -1112,6 +1112,19 @@ class Kconfig(object):
Jumps to the beginning of a sourced Kconfig file, saving the previous
position and file object.
"""
+ # Check for recursive 'source'
+ for _, name, _ in self._filestack:
+ if name == filename:
+ # KconfigParseError might have been a better name, but too late
+ raise KconfigSyntaxError(
+ "\n{}:{}: Recursive 'source' of '{}' detected. Check that "
+ "environment variables are set correctly.\n"
+ "Backtrace:\n{}"
+ .format(self._filename, self._linenr, filename,
+ "\n".join("{}:{}".format(name, linenr)
+ for _, name, linenr
+ in reversed(self._filestack))))
+
self._filestack.append((self._file, self._filename, self._linenr))
try:
self._file = self._open(filename)