From 7dc5b74229e83876307082712162d48e3124e10b Mon Sep 17 00:00:00 2001 From: Ulf Magnusson Date: Wed, 17 Jan 2018 12:56:13 +0100 Subject: 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. --- kconfiglib.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'kconfiglib.py') 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) -- cgit v1.2.3