diff options
-rw-r--r-- | mesonbuild/interpreter.py | 10 | ||||
-rw-r--r-- | mesonbuild/optinterpreter.py | 7 | ||||
-rw-r--r-- | test cases/unit/3 subproject defaults/meson.build | 2 | ||||
-rw-r--r-- | test cases/unit/3 subproject defaults/subprojects/foob/meson.build | 9 | ||||
-rw-r--r-- | test cases/unit/3 subproject defaults/subprojects/foob/meson_options.txt | 3 |
5 files changed, 29 insertions, 2 deletions
diff --git a/mesonbuild/interpreter.py b/mesonbuild/interpreter.py index 4f3f81a..b889aa0 100644 --- a/mesonbuild/interpreter.py +++ b/mesonbuild/interpreter.py @@ -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, diff --git a/mesonbuild/optinterpreter.py b/mesonbuild/optinterpreter.py index 81f3177..2ba7b99 100644 --- a/mesonbuild/optinterpreter.py +++ b/mesonbuild/optinterpreter.py @@ -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: diff --git a/test cases/unit/3 subproject defaults/meson.build b/test cases/unit/3 subproject defaults/meson.build index 1616006..0f64c9b 100644 --- a/test cases/unit/3 subproject defaults/meson.build +++ b/test cases/unit/3 subproject defaults/meson.build @@ -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')) diff --git a/test cases/unit/3 subproject defaults/subprojects/foob/meson.build b/test cases/unit/3 subproject defaults/subprojects/foob/meson.build new file mode 100644 index 0000000..48d0210 --- /dev/null +++ b/test cases/unit/3 subproject defaults/subprojects/foob/meson.build @@ -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')) + diff --git a/test cases/unit/3 subproject defaults/subprojects/foob/meson_options.txt b/test cases/unit/3 subproject defaults/subprojects/foob/meson_options.txt new file mode 100644 index 0000000..7a1f6c0 --- /dev/null +++ b/test cases/unit/3 subproject defaults/subprojects/foob/meson_options.txt @@ -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.') |