Can specify project options on the command line and the override defaults.

pull/15/head
Jussi Pakkanen 11 years ago
parent 4119859c3d
commit 55759e4aa9
  1. 1
      environment.py
  2. 3
      interpreter.py
  3. 2
      meson.py
  4. 20
      optinterpreter.py
  5. 4
      readme.txt

@ -1376,6 +1376,7 @@ class Environment():
self.cross_info = CrossBuildInfo(self.coredata.cross_file) self.cross_info = CrossBuildInfo(self.coredata.cross_file)
else: else:
self.cross_info = None self.cross_info = None
self.cmd_line_options = options.projectoptions
# List of potential compilers. # List of potential compilers.
if is_windows(): if is_windows():

@ -639,7 +639,8 @@ class Interpreter():
self.source_root = build.environment.get_source_dir() self.source_root = build.environment.get_source_dir()
option_file = os.path.join(self.source_root, self.subdir, 'meson_options.txt') option_file = os.path.join(self.source_root, self.subdir, 'meson_options.txt')
if os.path.exists(option_file): if os.path.exists(option_file):
oi = optinterpreter.OptionInterpreter(self.subproject) oi = optinterpreter.OptionInterpreter(self.subproject,\
self.build.environment.cmd_line_options)
oi.process(option_file) oi.process(option_file)
self.build.environment.merge_options(oi.options) self.build.environment.merge_options(oi.options)
mesonfile = os.path.join(self.source_root, self.subdir, environment.build_filename) mesonfile = os.path.join(self.source_root, self.subdir, environment.build_filename)

@ -70,6 +70,8 @@ parser.add_option('--werror', action='store_true', dest='werror', default=False,
help='Treat warnings as errors') help='Treat warnings as errors')
parser.add_option('--cross-file', default=None, dest='cross_file', parser.add_option('--cross-file', default=None, dest='cross_file',
help='file describing cross compilation environment') help='file describing cross compilation environment')
parser.add_option('-D', action='append', type='string', dest='projectoptions', default=[],
help='Set project options.')
class MesonApp(): class MesonApp():

@ -39,6 +39,9 @@ class UserOption:
super().__init__() super().__init__()
self.description = kwargs.get('description', '') self.description = kwargs.get('description', '')
def parse_string(self, valuestring):
return valuestring
class UserStringOption(UserOption): class UserStringOption(UserOption):
def __init__(self, kwargs): def __init__(self, kwargs):
super().__init__(kwargs) super().__init__(kwargs)
@ -59,6 +62,13 @@ class UserBooleanOption(UserOption):
raise OptionException('Value of boolean option is not boolean.') raise OptionException('Value of boolean option is not boolean.')
self.value = newvalue 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): class UserComboOption(UserOption):
def __init__(self, kwargs): def __init__(self, kwargs):
super().__init__(kwargs) super().__init__(kwargs)
@ -83,10 +93,14 @@ option_types = {'string' : UserStringOption,
} }
class OptionInterpreter: class OptionInterpreter:
def __init__(self, subproject): def __init__(self, subproject, command_line_options):
self.options = {} self.options = {}
self.subproject = subproject 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): def process(self, option_file):
try: try:
ast = mparser.Parser(open(option_file, 'r').read()).parse() ast = mparser.Parser(open(option_file, 'r').read()).parse()
@ -159,4 +173,6 @@ class OptionInterpreter:
opt = option_types[opt_type](kwargs) opt = option_types[opt_type](kwargs)
if opt.description == '': if opt.description == '':
opt.description = opt_name 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 self.options[opt_name] = opt

@ -4,8 +4,8 @@ build system.
Dependencies Dependencies
Python 3.3: http://python.org Python http://python.org (version 3.3 or newer)
Ninja: http://martine.github.com/ninja/ Ninja http://martine.github.com/ninja/
Installing from source Installing from source

Loading…
Cancel
Save