aboutsummaryrefslogtreecommitdiff
path: root/mesonbuild/interpreterbase/interpreterbase.py
diff options
context:
space:
mode:
authorEli Schwartz <eschwartz@archlinux.org>2023-02-26 01:36:47 -0500
committerEli Schwartz <eschwartz@archlinux.org>2023-03-01 23:30:49 -0500
commit878c1604e6348f98602bbdd16d92fc63ed15ebea (patch)
treeb2d351ce888291cacb11dcce34178e69fd4c8891 /mesonbuild/interpreterbase/interpreterbase.py
parentcc23996266846890fea708a7eb5dcff66d44c8b6 (diff)
downloadmeson-878c1604e6348f98602bbdd16d92fc63ed15ebea.zip
meson-878c1604e6348f98602bbdd16d92fc63ed15ebea.tar.gz
meson-878c1604e6348f98602bbdd16d92fc63ed15ebea.tar.bz2
handle meson_version even when the build file fails to parse
If the meson.build file is sufficiently "broken", even attempting to lex and parse it will totally fail, and we error out without getting the opportunity to evalaute the project() function. This can fairly easily happen if we add new grammar to the syntax, which old versions of meson cannot understand. Setting a minimum meson_version doesn't help, because people with a too-old version of meson get parser errors instead of advice about upgrading meson. Examples of this include adding dict support to meson. There are two general approaches to solving this issue, one of which projects are empowered to do: - refactor the project to place too-new syntax in a subdir() loaded build file, so the root file can be interpreted - teach meson to catch errors in building the initial AST, and just load enough of the AST to check for meson_version advice This implements the latter, allowing to future-proof the build grammar.
Diffstat (limited to 'mesonbuild/interpreterbase/interpreterbase.py')
-rw-r--r--mesonbuild/interpreterbase/interpreterbase.py13
1 files changed, 10 insertions, 3 deletions
diff --git a/mesonbuild/interpreterbase/interpreterbase.py b/mesonbuild/interpreterbase/interpreterbase.py
index c8ef303..666045f 100644
--- a/mesonbuild/interpreterbase/interpreterbase.py
+++ b/mesonbuild/interpreterbase/interpreterbase.py
@@ -16,8 +16,7 @@
# or an interpreter-based tool.
from __future__ import annotations
-from .. import mparser, mesonlib
-from .. import environment
+from .. import environment, mparser, mesonlib
from .baseobjects import (
InterpreterObject,
@@ -103,6 +102,10 @@ class InterpreterBase:
# current meson version target within that if-block.
self.tmp_meson_version = None # type: T.Optional[str]
+ def handle_meson_version_from_ast(self, strict: bool = True) -> None:
+ # do nothing in an AST interpreter
+ return
+
def load_root_meson_file(self) -> None:
mesonfile = os.path.join(self.source_root, self.subdir, environment.build_filename)
if not os.path.isfile(mesonfile):
@@ -114,8 +117,12 @@ class InterpreterBase:
assert isinstance(code, str)
try:
self.ast = mparser.Parser(code, mesonfile).parse()
- except mesonlib.MesonException as me:
+ except mparser.ParseException as me:
me.file = mesonfile
+ # try to detect parser errors from new syntax added by future
+ # meson versions, and just tell the user to update meson
+ self.ast = me.ast
+ self.handle_meson_version_from_ast()
raise me
def parse_project(self) -> None: