summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaolo Bonzini <pbonzini@redhat.com>2019-03-14 10:35:00 +0100
committerDylan Baker <dylan@pnwbakers.com>2019-03-18 10:51:44 -0700
commit7a02b76e70e219e5201e322c6c6c232d06601920 (patch)
tree55cfd1d4ad4f96f881659ae77b338d9896cc1618
parent222a973918fe01ae0c4051a821797dde96f018af (diff)
downloadmeson-7a02b76e70e219e5201e322c6c6c232d06601920.tar.gz
interpreterbase: protect string division with FeatureNew
Meson is not warning if you join paths with / but you are requesting a version older than 0.49.0; fix this before adding more features to the division operator. Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
-rw-r--r--mesonbuild/interpreterbase.py25
-rwxr-xr-xrun_project_tests.py8
-rw-r--r--test cases/warning/1 version for string div/a/b.c3
-rw-r--r--test cases/warning/1 version for string div/meson.build3
4 files changed, 31 insertions, 8 deletions
diff --git a/mesonbuild/interpreterbase.py b/mesonbuild/interpreterbase.py
index 9206d02d9..650d1e06c 100644
--- a/mesonbuild/interpreterbase.py
+++ b/mesonbuild/interpreterbase.py
@@ -606,6 +606,23 @@ The result of this is undefined and will become a hard error in a future Meson r
raise InterpreterException('Argument to negation is not an integer.')
return -v
+ @FeatureNew('/ with string arguments', '0.49.0')
+ def evaluate_path_join(self, l, r):
+ if not isinstance(l, str):
+ raise InvalidCode('The division operator can only append to a string.')
+ if not isinstance(r, str):
+ raise InvalidCode('The division operator can only append a string.')
+ return self.join_path_strings((l, r))
+
+ def evaluate_division(self, l, r):
+ if isinstance(l, str) or isinstance(r, str):
+ return self.evaluate_path_join(l, r)
+ if isinstance(l, int) and isinstance(r, int):
+ if r == 0:
+ raise InvalidCode('Division by zero.')
+ return l // r
+ raise InvalidCode('Division works only with strings or integers.')
+
def evaluate_arithmeticstatement(self, cur):
l = self.evaluate_statement(cur.left)
if is_disabler(l):
@@ -630,13 +647,7 @@ The result of this is undefined and will become a hard error in a future Meson r
raise InvalidCode('Multiplication works only with integers.')
return l * r
elif cur.operation == 'div':
- if isinstance(l, str) and isinstance(r, str):
- return self.join_path_strings((l, r))
- if isinstance(l, int) and isinstance(r, int):
- if r == 0:
- raise InvalidCode('Division by zero.')
- return l // r
- raise InvalidCode('Division works only with strings or integers.')
+ return self.evaluate_division(l, r)
elif cur.operation == 'mod':
if not isinstance(l, int) or not isinstance(r, int):
raise InvalidCode('Modulo works only with integers.')
diff --git a/run_project_tests.py b/run_project_tests.py
index 89f11d382..96fe99a89 100755
--- a/run_project_tests.py
+++ b/run_project_tests.py
@@ -547,6 +547,7 @@ def detect_tests_to_run():
# Name, subdirectory, skip condition.
all_tests = [
('common', 'common', False),
+ ('warning-meson', 'warning', False),
('failing-meson', 'failing', False),
('failing-build', 'failing build', False),
('failing-test', 'failing test', False),
@@ -623,9 +624,14 @@ def _run_tests(all_tests, log_name_base, failfast, extra_args):
(testnum, testbase) = t.name.split(' ', 1)
testname = '%.3d %s' % (int(testnum), testbase)
should_fail = False
+ suite_args = []
if name.startswith('failing'):
should_fail = name.split('failing-')[1]
- result = executor.submit(run_test, skipped, t.as_posix(), extra_args, system_compiler, backend, backend_flags, commands, should_fail)
+ if name.startswith('warning'):
+ suite_args = ['--fatal-meson-warnings']
+ should_fail = name.split('warning-')[1]
+ result = executor.submit(run_test, skipped, t.as_posix(), extra_args + suite_args,
+ system_compiler, backend, backend_flags, commands, should_fail)
futures.append((testname, t, result))
for (testname, t, result) in futures:
sys.stdout.flush()
diff --git a/test cases/warning/1 version for string div/a/b.c b/test cases/warning/1 version for string div/a/b.c
new file mode 100644
index 000000000..5047a34e3
--- /dev/null
+++ b/test cases/warning/1 version for string div/a/b.c
@@ -0,0 +1,3 @@
+int main()
+{
+}
diff --git a/test cases/warning/1 version for string div/meson.build b/test cases/warning/1 version for string div/meson.build
new file mode 100644
index 000000000..54e97088b
--- /dev/null
+++ b/test cases/warning/1 version for string div/meson.build
@@ -0,0 +1,3 @@
+project('warn on string division', 'c', meson_version: '>=0.48.0')
+
+executable('prog', 'a' / 'b.c')