aboutsummaryrefslogtreecommitdiff
path: root/optinterpreter.py
diff options
context:
space:
mode:
authorJussi Pakkanen <jpakkane@gmail.com>2014-08-06 21:40:09 +0300
committerJussi Pakkanen <jpakkane@gmail.com>2014-08-06 21:40:23 +0300
commit55759e4aa990a9755e29f35a4aec6c0a6e89c7d7 (patch)
tree81baca8d69769e95ad3486c3f67f71b0ca506cc6 /optinterpreter.py
parent4119859c3d20231a5a2592e5d0be756cf978cdc9 (diff)
downloadmeson-55759e4aa990a9755e29f35a4aec6c0a6e89c7d7.zip
meson-55759e4aa990a9755e29f35a4aec6c0a6e89c7d7.tar.gz
meson-55759e4aa990a9755e29f35a4aec6c0a6e89c7d7.tar.bz2
Can specify project options on the command line and the override defaults.
Diffstat (limited to 'optinterpreter.py')
-rw-r--r--optinterpreter.py20
1 files changed, 18 insertions, 2 deletions
diff --git a/optinterpreter.py b/optinterpreter.py
index 812b6f4..900ecbf 100644
--- a/optinterpreter.py
+++ b/optinterpreter.py
@@ -39,6 +39,9 @@ class UserOption:
super().__init__()
self.description = kwargs.get('description', '')
+ def parse_string(self, valuestring):
+ return valuestring
+
class UserStringOption(UserOption):
def __init__(self, kwargs):
super().__init__(kwargs)
@@ -59,6 +62,13 @@ class UserBooleanOption(UserOption):
raise OptionException('Value of boolean option is not boolean.')
self.value = newvalue
+ def parse_string(self, valuestring):
+ if valuestring == 'false':
+ return False
+ if valuestring == 'true':
+ return True
+ raise OptionException('Value %s is not a boolean.' % valuestring)
+
class UserComboOption(UserOption):
def __init__(self, kwargs):
super().__init__(kwargs)
@@ -83,10 +93,14 @@ option_types = {'string' : UserStringOption,
}
class OptionInterpreter:
- def __init__(self, subproject):
+ def __init__(self, subproject, command_line_options):
self.options = {}
self.subproject = subproject
-
+ self.cmd_line_options = {}
+ for o in command_line_options:
+ (key, value) = o.split('=', 1)
+ self.cmd_line_options[key] = value
+
def process(self, option_file):
try:
ast = mparser.Parser(open(option_file, 'r').read()).parse()
@@ -159,4 +173,6 @@ class OptionInterpreter:
opt = option_types[opt_type](kwargs)
if opt.description == '':
opt.description = opt_name
+ if opt_name in self.cmd_line_options:
+ opt.set_value(opt.parse_string(self.cmd_line_options[opt_name]))
self.options[opt_name] = opt