diff options
Diffstat (limited to 'mesonbuild/interpreter.py')
-rw-r--r-- | mesonbuild/interpreter.py | 31 |
1 files changed, 28 insertions, 3 deletions
diff --git a/mesonbuild/interpreter.py b/mesonbuild/interpreter.py index b889aa0..77145b1 100644 --- a/mesonbuild/interpreter.py +++ b/mesonbuild/interpreter.py @@ -1139,7 +1139,8 @@ class MesonMain(InterpreterObject): class Interpreter(InterpreterBase): - def __init__(self, build, backend, subproject='', subdir='', subproject_dir='subprojects'): + def __init__(self, build, backend, subproject='', subdir='', subproject_dir='subprojects', + default_project_options=[]): super().__init__(build.environment.get_source_dir(), subdir) self.build = build self.environment = build.environment @@ -1156,6 +1157,7 @@ class Interpreter(InterpreterBase): self.args_frozen = False self.subprojects = {} self.subproject_stack = [] + self.default_project_options = default_project_options[:] # Passed from the outside, only used in subprojects. self.build_func_dict() self.parse_project() self.builtin['build_machine'] = BuildMachine(self.coredata.compilers) @@ -1413,7 +1415,8 @@ class Interpreter(InterpreterBase): os.makedirs(os.path.join(self.build.environment.get_build_dir(), subdir), exist_ok=True) self.args_frozen = True mlog.log('\nExecuting subproject ', mlog.bold(dirname), '.\n', sep='') - subi = Interpreter(self.build, self.backend, dirname, subdir, self.subproject_dir) + subi = Interpreter(self.build, self.backend, dirname, subdir, self.subproject_dir, + mesonlib.stringlistify(kwargs.get('default_options', []))) subi.subprojects = self.subprojects subi.subproject_stack = self.subproject_stack + [dirname] @@ -1489,16 +1492,38 @@ class Interpreter(InterpreterBase): self.coredata.set_builtin_option(key, value) # If this was set on the command line, do not override. else: + # Option values set with subproject() default_options override those + # set in project() default_options. + pref = key + '=' + for i in self.default_project_options: + if i.startswith(pref): + option = i + break # 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 + # Add options that are only in default_options. + for defopt in self.default_project_options: + key, value = defopt.split('=') + pref = key + '=' + was_found = False + for i in default_options: + if i.startswith(pref): + was_found = True + break + if was_found: + break + defopt = self.subproject + ':' + defopt + newoptions = [defopt] + 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: + if self.environment.first_invocation and ('default_options' in kwargs or \ + len(self.default_project_options) > 0): self.parse_default_options(kwargs['default_options']) if not self.is_subproject(): self.build.project_name = args[0] |