Store filename in node location

Warnings have a location node object (with subdir and lineno
attributes), which is passed as a location: kwarg to mlog.warning() and
formatted in _log_error().

Re-purpose the subdir attribute (path relative to the source root dir,
with an implied filename of 'meson.build'), which is stored into the
node by parser(), to contain a pathname.

(Properly I should rename 'subdir' -> 'file' everywhere, but that's a
lot of churn just to see if this works)

Notes:
The warning location node may also have a colno attribute, which is
currently ignored by _log_error().

We can't currently issue warnings with locations in meson_options.txt
because the filename isn't part of the location (as it's assumed to be
'meson.build).
pull/6627/head
Jon Turney 5 years ago
parent 534a974da7
commit 346b5c4be7
No known key found for this signature in database
GPG Key ID: C7C86F0370285C81
  1. 2
      mesonbuild/ast/interpreter.py
  2. 2
      mesonbuild/interpreter.py
  3. 2
      mesonbuild/interpreterbase.py
  4. 2
      mesonbuild/mlog.py
  5. 2
      mesonbuild/optinterpreter.py

@ -154,7 +154,7 @@ class AstInterpreter(interpreterbase.InterpreterBase):
code = f.read()
assert(isinstance(code, str))
try:
codeblock = mparser.Parser(code, subdir).parse()
codeblock = mparser.Parser(code, absname).parse()
except mesonlib.MesonException as me:
me.file = absname
raise me

@ -3748,7 +3748,7 @@ This will become a hard error in the future.''' % kwargs['input'], location=self
code = f.read()
assert(isinstance(code, str))
try:
codeblock = mparser.Parser(code, self.subdir).parse()
codeblock = mparser.Parser(code, absname).parse()
except mesonlib.MesonException as me:
me.file = absname
raise me

@ -381,7 +381,7 @@ class InterpreterBase:
raise InvalidCode('Builder file is empty.')
assert(isinstance(code, str))
try:
self.ast = mparser.Parser(code, self.subdir).parse()
self.ast = mparser.Parser(code, mesonfile).parse()
except mesonlib.MesonException as me:
me.file = mesonfile
raise me

@ -251,7 +251,7 @@ def _log_error(severity: str, *rargs: T.Union[str, AnsiDecorator],
location = kwargs.pop('location', None)
if location is not None:
location_file = os.path.join(location.subdir, build_filename)
location_file = location.subdir
location_str = get_error_location_string(location_file, location.lineno)
# Unions are frankly awful, and we have to T.cast here to get mypy
# to understand that the list concatenation is safe

@ -140,7 +140,7 @@ class OptionInterpreter:
def process(self, option_file):
try:
with open(option_file, 'r', encoding='utf8') as f:
ast = mparser.Parser(f.read(), '').parse()
ast = mparser.Parser(f.read(), option_file).parse()
except mesonlib.MesonException as me:
me.file = option_file
raise me

Loading…
Cancel
Save