Can set project options (but not global options) in subproject default options.

pull/1260/head
Jussi Pakkanen 8 years ago
parent f85c348b94
commit 73042c7912
  1. 10
      mesonbuild/interpreter.py
  2. 7
      mesonbuild/optinterpreter.py
  3. 2
      test cases/unit/3 subproject defaults/meson.build
  4. 9
      test cases/unit/3 subproject defaults/subprojects/foob/meson.build
  5. 3
      test cases/unit/3 subproject defaults/subprojects/foob/meson_options.txt

@ -1483,19 +1483,25 @@ class Interpreter(InterpreterBase):
raise InterpreterException('All default options must be of type key=value.')
key, value = option.split('=', 1)
if coredata.is_builtin_option(key):
if self.subproject != '':
continue # Only the master project is allowed to set global options.
if not self.environment.had_argument_for(key):
self.coredata.set_builtin_option(key, value)
# If this was set on the command line, do not override.
else:
# If we are in a subproject, add the subproject prefix to option
# name.
if self.subproject != '':
option = self.subproject + ':' + option
newoptions = [option] + self.environment.cmd_line_options.projectoptions
self.environment.cmd_line_options.projectoptions = newoptions
@stringArgs
def func_project(self, node, args, kwargs):
if self.environment.first_invocation and 'default_options' in kwargs:
self.parse_default_options(kwargs['default_options'])
if not self.is_subproject():
self.build.project_name = args[0]
if self.environment.first_invocation and 'default_options' in kwargs:
self.parse_default_options(kwargs['default_options'])
if os.path.exists(self.option_file):
oi = optinterpreter.OptionInterpreter(self.subproject, \
self.build.environment.cmd_line_options.projectoptions,

@ -71,8 +71,15 @@ class OptionInterpreter:
def __init__(self, subproject, command_line_options):
self.options = {}
self.subproject = subproject
self.sbprefix = subproject + ':'
self.cmd_line_options = {}
for o in command_line_options:
if self.subproject != '': # Strip the beginning.
if not o.startswith(self.sbprefix):
continue
else:
if ':' in o:
continue
try:
(key, value) = o.split('=', 1)
except ValueError:

@ -3,6 +3,8 @@ project('subproject defaults', 'c',
'fromcmdline=defopt'] # This should get the value set in command line.
)
subproject('foob')
assert(get_option('fromcmdline') == 'cmdline', 'Default option defined in cmd line is incorrect: ' + get_option('fromcmdline'))
assert(get_option('defopoverride') == 'defopt', 'Default option without cmd line override is incorrect: ' + get_option('defopoverride'))
assert(get_option('fromoptfile') == 'optfile', 'Default value from option file is incorrect: ' + get_option('fromoptfile'))

@ -0,0 +1,9 @@
project('foob', 'c',
default_options : ['defopoverride=s_defopt', # This should be overridden.
'fromcmdline=s_defopt'] # This should get the value set in command line.
)
assert(get_option('fromcmdline') == 's_cmdline', 'Default option defined in cmd line is incorrect: ' + get_option('fromcmdline'))
assert(get_option('defopoverride') == 's_defopt', 'Default option without cmd line override is incorrect: ' + get_option('defopoverride'))
assert(get_option('fromoptfile') == 's_optfile', 'Default value from option file is incorrect: ' + get_option('fromoptfile'))

@ -0,0 +1,3 @@
option('defopoverride', type : 'string', value : 's_optfile', description : 'A value for overriding.')
option('fromcmdline', type : 'string', value : 's_optfile', description : 'A value for overriding.')
option('fromoptfile', type : 'string', value : 's_optfile', description : 'A value for not overriding.')
Loading…
Cancel
Save