aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJussi Pakkanen <jpakkane@gmail.com>2015-02-21 02:31:34 +0200
committerJussi Pakkanen <jpakkane@gmail.com>2015-02-21 02:31:34 +0200
commit75a0bc835051daa5ca6a202cff57e40912d7979d (patch)
tree6f70feca1a4dd9878c5f9a81f039b4430b528614
parent1ab5b850ef2b9e59d1b88331a19688e0fcfa3bef (diff)
downloadmeson-75a0bc835051daa5ca6a202cff57e40912d7979d.zip
meson-75a0bc835051daa5ca6a202cff57e40912d7979d.tar.gz
meson-75a0bc835051daa5ca6a202cff57e40912d7979d.tar.bz2
Created a set_variable command.
-rw-r--r--interpreter.py16
-rw-r--r--test cases/common/17 if/meson.build2
2 files changed, 15 insertions, 3 deletions
diff --git a/interpreter.py b/interpreter.py
index 92a2b92..c1e4547 100644
--- a/interpreter.py
+++ b/interpreter.py
@@ -731,6 +731,7 @@ class Interpreter():
'subproject' : self.func_subproject,
'pkgconfig_gen' : self.func_pkgconfig_gen,
'vcs_tag' : self.func_vcs_tag,
+ 'set_variable' : self.func_set_variable,
}
def get_build_def_files(self):
@@ -781,7 +782,20 @@ class Interpreter():
return self.variables[varname]
raise InvalidCode('Unknown variable "%s".' % varname)
+ def func_set_variable(self, node, args, kwargs):
+ if len(args) != 2:
+ raise InvalidCode('Set_variable takes two arguments.')
+ varname = args[0]
+ if not isinstance(varname, str):
+ raise InvalidCode('First argument to set_variable must be a string.')
+ value = self.to_native(args[1])
+ self.set_variable(varname, value)
+
def set_variable(self, varname, variable):
+ if variable is None:
+ raise InvalidCode('Can not assign None to variable.')
+ if not self.is_assignable(variable):
+ raise InvalidCode('Assigned value not of assignable type.')
if varname in self.builtin:
raise InvalidCode('Tried to overwrite internal variable "%s"' % varname)
self.variables[varname] = variable
@@ -1433,8 +1447,6 @@ class Interpreter():
if not isinstance(var_name, str):
raise InvalidArguments('Tried to assign value to a non-variable.')
value = self.evaluate_statement(node.value)
- if value is None:
- raise InvalidCode('Can not assign None to variable.')
value = self.to_native(value)
if not self.is_assignable(value):
raise InvalidCode('Tried to assign an invalid value to variable.')
diff --git a/test cases/common/17 if/meson.build b/test cases/common/17 if/meson.build
index 5d6a005..b77f93a 100644
--- a/test cases/common/17 if/meson.build
+++ b/test cases/common/17 if/meson.build
@@ -1,7 +1,7 @@
project('if test', 'c')
var1 = true
-var2 = false
+set_variable('var2', false)
if var1
exe = executable('prog', 'prog.c')