aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xmesonconf.py42
-rw-r--r--optinterpreter.py11
2 files changed, 50 insertions, 3 deletions
diff --git a/mesonconf.py b/mesonconf.py
index 37aaede..02e9702 100755
--- a/mesonconf.py
+++ b/mesonconf.py
@@ -18,11 +18,15 @@ import sys, os
import pickle
from optparse import OptionParser
import coredata
+from meson import build_types
-usage_info = '%prog [build dir]'
+usage_info = '%prog [build dir] [set commands]'
parser = OptionParser(usage=usage_info, version=coredata.version)
+parser.add_option('-D', action='append', default=[], dest='sets',
+ help='Set an option to the given value.')
+
class ConfException(Exception):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
@@ -40,6 +44,10 @@ class Conf:
raise ConfException('Version mismatch (%s vs %s)' %
(coredata.version, self.coredata.version))
+ def save(self):
+ # Only called if something has changed so overwrite unconditionally.
+ pickle.dump(self.coredata, open(self.coredata_file, 'wb'))
+
def print_aligned(self, arr):
longest = max((len(x[0]) for x in arr))
for i in arr:
@@ -49,6 +57,32 @@ class Conf:
f = '%s:%s' % (name, padding)
print(f, value)
+ def tobool(self, thing):
+ if thing.lower() == 'true':
+ return True
+ if thing.lower() == 'false':
+ return False
+ raise ConfException('Value %s is not boolean (true or false)' % thing)
+
+ def set_options(self, options):
+ for o in options:
+ if '=' not in o:
+ raise ConfException('Value "%s" not of type "a=b"' % o)
+ (k, v) = o.split('=', 1)
+ if k == 'type':
+ if v not in build_types:
+ raise ConfException('Invalid build type %s' % v)
+ self.coredata.buildtype = v
+ elif k == 'strip':
+ self.coredata.strip = self.tobool(v)
+ elif k == 'coverage':
+ v = self.tobool(v)
+ self.coredata.coverage = self.tobool(v)
+ elif k == 'pch':
+ self.coredata.use_pch = self.tobool(v)
+ elif k == 'unity':
+ self.coredata.unity = self.tobool(v)
+
def print_conf(self):
print('Core properties\n')
print('Source dir:', self.build.environment.source_dir)
@@ -86,7 +120,11 @@ if __name__ == '__main__':
builddir = args[-1]
try:
c = Conf(builddir)
- c.print_conf()
+ if len(options.sets) > 0:
+ c.set_options(options.sets)
+ c.save()
+ else:
+ c.print_conf()
except ConfException as e:
print('Meson configurator encountered an error:\n')
print(e)
diff --git a/optinterpreter.py b/optinterpreter.py
index 756ec5f..8d42e1f 100644
--- a/optinterpreter.py
+++ b/optinterpreter.py
@@ -1,4 +1,4 @@
-# Copyright 2013 Jussi Pakkanen
+# Copyright 2013-2014 Jussi Pakkanen
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
@@ -17,6 +17,13 @@ import coredata
import nodes
import os
+forbidden_option_names = {'type': True,
+ 'strip': True,
+ 'coverage': True,
+ 'pch': True,
+ 'unity': True,
+ }
+
class OptionException(coredata.MesonException):
pass
@@ -138,6 +145,8 @@ class OptionInterpreter:
opt_name = posargs[0]
if not isinstance(opt_name, str):
raise OptionException('Positional argument must be a string.')
+ if opt_name in forbidden_option_names:
+ raise OptionException('Option name %s is reserved.' % opt_name)
if self.subproject != '':
opt_name = self.subproject + '-' + opt_name
opt = option_types[opt_type](kwargs)