aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNirbheek Chauhan <nirbheek@centricular.com>2019-04-18 12:19:19 +0530
committerNirbheek Chauhan <nirbheek.chauhan@gmail.com>2019-04-18 19:18:21 +0000
commit2795f942bef680b0f050cc1f1001db26cab68bb9 (patch)
tree26f4ae38eb5e9b4f852f67fb2023259198835c1e
parent2e93ed58c30d63da8527ff16375ff9e0642e7533 (diff)
downloadmeson-2795f942bef680b0f050cc1f1001db26cab68bb9.zip
meson-2795f942bef680b0f050cc1f1001db26cab68bb9.tar.gz
meson-2795f942bef680b0f050cc1f1001db26cab68bb9.tar.bz2
interpreter: Check the meson version before parsing options
Also add a test for it so we don't regress this in the future. Closes https://github.com/mesonbuild/meson/issues/5281
-rw-r--r--mesonbuild/interpreter.py13
-rwxr-xr-xrun_unittests.py14
2 files changed, 21 insertions, 6 deletions
diff --git a/mesonbuild/interpreter.py b/mesonbuild/interpreter.py
index 993ebbd..8f33935 100644
--- a/mesonbuild/interpreter.py
+++ b/mesonbuild/interpreter.py
@@ -2575,6 +2575,12 @@ external dependencies (including libraries) must go to "dependencies".''')
if ':' in proj_name:
raise InvalidArguments("Project name {!r} must not contain ':'".format(proj_name))
+ if 'meson_version' in kwargs:
+ cv = coredata.version
+ pv = kwargs['meson_version']
+ if not mesonlib.version_compare(cv, pv):
+ raise InterpreterException('Meson version is %s but project requires %s' % (cv, pv))
+
if os.path.exists(self.option_file):
oi = optinterpreter.OptionInterpreter(self.subproject)
oi.process(self.option_file)
@@ -2621,11 +2627,8 @@ external dependencies (including libraries) must go to "dependencies".''')
mesonlib.project_meson_versions[self.subproject] = ''
if 'meson_version' in kwargs:
- cv = coredata.version
- pv = kwargs['meson_version']
- mesonlib.project_meson_versions[self.subproject] = pv
- if not mesonlib.version_compare(cv, pv):
- raise InterpreterException('Meson version is %s but project requires %s.' % (cv, pv))
+ mesonlib.project_meson_versions[self.subproject] = kwargs['meson_version']
+
self.build.projects[self.subproject] = proj_name
mlog.log('Project name:', mlog.bold(proj_name))
mlog.log('Project version:', mlog.bold(self.project_version))
diff --git a/run_unittests.py b/run_unittests.py
index 941280d..316525d 100755
--- a/run_unittests.py
+++ b/run_unittests.py
@@ -3644,12 +3644,13 @@ class FailureTests(BasePlatformTests):
super().setUp()
self.srcdir = os.path.realpath(tempfile.mkdtemp())
self.mbuild = os.path.join(self.srcdir, 'meson.build')
+ self.moptions = os.path.join(self.srcdir, 'meson_options.txt')
def tearDown(self):
super().tearDown()
windows_proof_rmtree(self.srcdir)
- def assertMesonRaises(self, contents, match, extra_args=None, langs=None, meson_version=None):
+ def assertMesonRaises(self, contents, match, extra_args=None, langs=None, meson_version=None, options=None):
'''
Assert that running meson configure on the specified @contents raises
a error message matching regex @match.
@@ -3664,6 +3665,9 @@ class FailureTests(BasePlatformTests):
for lang in langs:
f.write("add_languages('{}', required : false)\n".format(lang))
f.write(contents)
+ if options is not None:
+ with open(self.moptions, 'w') as f:
+ f.write(options)
# Force tracebacks so we can detect them properly
os.environ['MESON_FORCE_BACKTRACE'] = '1'
with self.assertRaisesRegex(MesonException, match, msg=contents):
@@ -3896,6 +3900,14 @@ class FailureTests(BasePlatformTests):
"sub1.get_variable('naaa')",
"""Subproject "subprojects/not-found-subproject" disabled can't get_variable on it.""")
+ def test_version_checked_before_parsing_options(self):
+ '''
+ https://github.com/mesonbuild/meson/issues/5281
+ '''
+ options = "option('some-option', type: 'foo', value: '')"
+ match = 'Meson version is.*but project requires >=2000'
+ self.assertMesonRaises("", match, meson_version='>=2000', options=options)
+
@unittest.skipUnless(is_windows() or is_cygwin(), "requires Windows (or Windows via Cygwin)")
class WindowsTests(BasePlatformTests):