summaryrefslogtreecommitdiff
path: root/kconfiglib.py
diff options
context:
space:
mode:
authorUlf Magnusson <ulfalizer@gmail.com>2017-09-24 13:09:11 +0200
committerUlf Magnusson <ulfalizer@gmail.com>2017-09-24 13:14:25 +0200
commit62c63e03ec968f0a38fb6d05222336c4e738dcd2 (patch)
tree63faca2c24ac85977ca22a28f6838b3ba494e268 /kconfiglib.py
parent0c3e0363d705be84f8cd06c1b4609927166d8b34 (diff)
Handle path cleanups in a cleaner way
_clean_up_path() was only ever passed filenames, so stripping trailing slashes was redundant. Better to strike at the root of the problem too, which is the os.path.join() with 'base_dir' defaulting to ".". The old hack gave incorrect results in obscure cases: Turning .//oops into /oops is wrong. The new version should be Windows-friendly as well.
Diffstat (limited to 'kconfiglib.py')
-rw-r--r--kconfiglib.py26
1 files changed, 15 insertions, 11 deletions
diff --git a/kconfiglib.py b/kconfiglib.py
index 7871651..fab1fb9 100644
--- a/kconfiglib.py
+++ b/kconfiglib.py
@@ -689,8 +689,17 @@ class Config(object):
elif t0 == T_SOURCE:
kconfig_file = tokens.get_next()
exp_kconfig_file = self._expand_sym_refs(kconfig_file)
- f = os.path.join(self.base_dir, exp_kconfig_file)
- if not os.path.exists(f):
+
+ # Hack: Avoid passing on a "./" prefix in the common case of
+ # 'base_dir' defaulting to ".", just to give less awkward
+ # results from e.g. get_def/ref_locations(). Maybe this could
+ # be handled in a nicer way.
+ if self.base_dir == ".":
+ filename = exp_kconfig_file
+ else:
+ filename = os.path.join(self.base_dir, exp_kconfig_file)
+
+ if not os.path.exists(filename):
raise IOError('{}:{}: sourced file "{}" (expands to "{}") '
"not found. Perhaps base_dir (argument to "
'Config.__init__(), currently "{}") is set '
@@ -700,7 +709,8 @@ class Config(object):
kconfig_file, exp_kconfig_file,
self.base_dir))
# Add items to the same block
- self._parse_file(f, parent, deps, visible_if_deps, block)
+ self._parse_file(filename, parent, deps, visible_if_deps,
+ block)
elif t0 == end_marker:
# We have reached the end of the block
@@ -3210,7 +3220,7 @@ class _FileFeed(object):
__slots__ = ['filename', 'lines', 'length', 'linenr']
def __init__(self, filename):
- self.filename = _clean_up_path(filename)
+ self.filename = filename
with open(filename) as f:
# No interleaving of I/O and processing yet. Don't know if it would
# help.
@@ -3424,15 +3434,9 @@ def _comment(s):
return res + "#"
return res
-def _clean_up_path(path):
- """Strips an initial "./" and any trailing slashes from 'path'."""
- if path.startswith("./"):
- path = path[2:]
- return path.rstrip("/")
-
def _stderr_msg(msg, filename, linenr):
if filename is not None:
- sys.stderr.write("{}:{}: ".format(_clean_up_path(filename), linenr))
+ sys.stderr.write("{}:{}: ".format(filename, linenr))
sys.stderr.write(msg + "\n")
def _tokenization_error(s, filename, linenr):