From 929df93ba80be347bea5df850ebce280aed64be7 Mon Sep 17 00:00:00 2001 From: Dylan Baker Date: Fri, 1 Nov 2024 10:45:12 -0700 Subject: [PATCH] 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` --- mesonbuild/interpreter/interpreter.py | 4 ++-- mesonbuild/interpreterbase/interpreterbase.py | 3 +-- mesonbuild/modules/__init__.py | 2 +- 3 files changed, 4 insertions(+), 5 deletions(-) diff --git a/mesonbuild/interpreter/interpreter.py b/mesonbuild/interpreter/interpreter.py index 99530a8c8..2c277ea13 100644 --- a/mesonbuild/interpreter/interpreter.py +++ b/mesonbuild/interpreter/interpreter.py @@ -2701,11 +2701,11 @@ class Interpreter(InterpreterBase, HoldableObject): ofile_rpath = os.path.join(self.subdir, output) if ofile_rpath in self.configure_file_outputs: 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]) mlog.warning('Output file', mlog.bold(ofile_rpath, True), 'for configure_file() at', current_call, 'overwrites configure_file() output at', first_call) 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_abs = os.path.join(self.environment.build_dir, ofile_path, ofile_fname) diff --git a/mesonbuild/interpreterbase/interpreterbase.py b/mesonbuild/interpreterbase/interpreterbase.py index 525d5d6c5..5f9df4cb5 100644 --- a/mesonbuild/interpreterbase/interpreterbase.py +++ b/mesonbuild/interpreterbase/interpreterbase.py @@ -82,7 +82,7 @@ class InterpreterBase: self.current_lineno = -1 # Current node set during a function call. This can be used as location # 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: # meson.version().compare_version(version_string) # 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): cur = statements[i] try: - self.current_lineno = cur.lineno self.evaluate_statement(cur) except Exception as e: if getattr(e, 'lineno', None) is None: diff --git a/mesonbuild/modules/__init__.py b/mesonbuild/modules/__init__.py index 86dc8762e..f9374cc1d 100644 --- a/mesonbuild/modules/__init__.py +++ b/mesonbuild/modules/__init__.py @@ -38,7 +38,7 @@ class ModuleState: self.subproject = interpreter.subproject self.subdir = interpreter.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.project_name = interpreter.build.project_name self.project_version = interpreter.build.dep_manifest[interpreter.active_projectname].version