aboutsummaryrefslogtreecommitdiff
path: root/mesonbuild/interpreter.py
diff options
context:
space:
mode:
authorTim-Philipp Müller <tim@centricular.com>2016-11-05 12:12:45 +0000
committerTim-Philipp Müller <tim@centricular.com>2016-11-05 16:56:02 +0000
commit627d859809f87feac758bcd2e52104548f147df4 (patch)
tree46f15dff499333e5818a18e20cab695d97088195 /mesonbuild/interpreter.py
parent5898fb094c9ad3b4d17c16fd151521c0bb52652f (diff)
downloadmeson-627d859809f87feac758bcd2e52104548f147df4.zip
meson-627d859809f87feac758bcd2e52104548f147df4.tar.gz
meson-627d859809f87feac758bcd2e52104548f147df4.tar.bz2
interpreter: copy mutable variables on assignment
All assignments in meson should be by value, so mutable objects (i.e. environment() and configuration_data()) should be copied automatically on assignment. Fixes #831.
Diffstat (limited to 'mesonbuild/interpreter.py')
-rw-r--r--mesonbuild/interpreter.py12
1 files changed, 10 insertions, 2 deletions
diff --git a/mesonbuild/interpreter.py b/mesonbuild/interpreter.py
index 8c6e2cd..3dc0c99 100644
--- a/mesonbuild/interpreter.py
+++ b/mesonbuild/interpreter.py
@@ -27,6 +27,7 @@ import os, sys, subprocess, shutil, uuid, re
from functools import wraps
import importlib
+import copy
run_depr_printed = False
@@ -91,6 +92,10 @@ class InterpreterObject():
return self.methods[method_name](args, kwargs)
raise InvalidCode('Unknown method "%s" in object.' % method_name)
+class MutableInterpreterObject(InterpreterObject):
+ def __init__(self):
+ super().__init__()
+
class TryRunResultHolder(InterpreterObject):
def __init__(self, res):
super().__init__()
@@ -181,7 +186,7 @@ class ConfigureFileHolder(InterpreterObject):
self.held_object = build.ConfigureFile(subdir, sourcename, targetname, configuration_data)
-class EnvironmentVariablesHolder(InterpreterObject):
+class EnvironmentVariablesHolder(MutableInterpreterObject):
def __init__(self):
super().__init__()
self.held_object = build.EnvironmentVariables()
@@ -211,7 +216,7 @@ class EnvironmentVariablesHolder(InterpreterObject):
self.add_var(self.held_object.prepend, args, kwargs)
-class ConfigurationDataHolder(InterpreterObject):
+class ConfigurationDataHolder(MutableInterpreterObject):
def __init__(self):
super().__init__()
self.used = False # These objects become immutable after use in configure_file.
@@ -2455,6 +2460,9 @@ requirements use the version keyword argument instead.''')
value = self.to_native(value)
if not self.is_assignable(value):
raise InvalidCode('Tried to assign an invalid value to variable.')
+ # For mutable objects we need to make a copy on assignment
+ if isinstance(value, MutableInterpreterObject):
+ value = copy.deepcopy(value)
self.set_variable(var_name, value)
return value