interpreter: remove current_lineno

This was only used in a couple of places, and requires extra tracking to
ensure it is correct, while we already have `current_node.lineno`, which
is always accurate and up to date.

I have also fixed a potential strict-null issue by using a sentinel node
for `current_node`
pull/13908/head
Dylan Baker 4 weeks ago
parent b3f9b9dc06
commit 929df93ba8
  1. 4
      mesonbuild/interpreter/interpreter.py
  2. 3
      mesonbuild/interpreterbase/interpreterbase.py
  3. 2
      mesonbuild/modules/__init__.py

@ -2701,11 +2701,11 @@ class Interpreter(InterpreterBase, HoldableObject):
ofile_rpath = os.path.join(self.subdir, output) ofile_rpath = os.path.join(self.subdir, output)
if ofile_rpath in self.configure_file_outputs: if ofile_rpath in self.configure_file_outputs:
mesonbuildfile = os.path.join(self.subdir, 'meson.build') mesonbuildfile = os.path.join(self.subdir, 'meson.build')
current_call = f"{mesonbuildfile}:{self.current_lineno}" current_call = f"{mesonbuildfile}:{self.current_node.lineno}"
first_call = "{}:{}".format(mesonbuildfile, self.configure_file_outputs[ofile_rpath]) first_call = "{}:{}".format(mesonbuildfile, self.configure_file_outputs[ofile_rpath])
mlog.warning('Output file', mlog.bold(ofile_rpath, True), 'for configure_file() at', current_call, 'overwrites configure_file() output at', first_call) mlog.warning('Output file', mlog.bold(ofile_rpath, True), 'for configure_file() at', current_call, 'overwrites configure_file() output at', first_call)
else: else:
self.configure_file_outputs[ofile_rpath] = self.current_lineno self.configure_file_outputs[ofile_rpath] = self.current_node.lineno
(ofile_path, ofile_fname) = os.path.split(os.path.join(self.subdir, output)) (ofile_path, ofile_fname) = os.path.split(os.path.join(self.subdir, output))
ofile_abs = os.path.join(self.environment.build_dir, ofile_path, ofile_fname) ofile_abs = os.path.join(self.environment.build_dir, ofile_path, ofile_fname)

@ -82,7 +82,7 @@ class InterpreterBase:
self.current_lineno = -1 self.current_lineno = -1
# Current node set during a function call. This can be used as location # Current node set during a function call. This can be used as location
# when printing a warning message during a method call. # when printing a warning message during a method call.
self.current_node: mparser.BaseNode = None self.current_node = mparser.BaseNode(-1, -1, 'sentinel')
# This is set to `version_string` when this statement is evaluated: # This is set to `version_string` when this statement is evaluated:
# meson.version().compare_version(version_string) # meson.version().compare_version(version_string)
# If it was part of a if-clause, it is used to temporally override the # If it was part of a if-clause, it is used to temporally override the
@ -183,7 +183,6 @@ class InterpreterBase:
while i < len(statements): while i < len(statements):
cur = statements[i] cur = statements[i]
try: try:
self.current_lineno = cur.lineno
self.evaluate_statement(cur) self.evaluate_statement(cur)
except Exception as e: except Exception as e:
if getattr(e, 'lineno', None) is None: if getattr(e, 'lineno', None) is None:

@ -38,7 +38,7 @@ class ModuleState:
self.subproject = interpreter.subproject self.subproject = interpreter.subproject
self.subdir = interpreter.subdir self.subdir = interpreter.subdir
self.root_subdir = interpreter.root_subdir self.root_subdir = interpreter.root_subdir
self.current_lineno = interpreter.current_lineno self.current_lineno = interpreter.current_node.lineno
self.environment = interpreter.environment self.environment = interpreter.environment
self.project_name = interpreter.build.project_name self.project_name = interpreter.build.project_name
self.project_version = interpreter.build.dep_manifest[interpreter.active_projectname].version self.project_version = interpreter.build.dep_manifest[interpreter.active_projectname].version

Loading…
Cancel
Save