diff options
author | Jussi Pakkanen <jpakkane@gmail.com> | 2016-12-29 20:34:13 +0200 |
---|---|---|
committer | Jussi Pakkanen <jpakkane@gmail.com> | 2016-12-29 20:34:13 +0200 |
commit | d716d53b3204bab94894f26adab84840e4ba4a53 (patch) | |
tree | c5c71b40a0f3ff3291a5e4da81a5fd3f2b85098c /mesonbuild/interpreter.py | |
parent | 73042c79124f529eb8f08a25d2877b8ceebd4c22 (diff) | |
download | meson-d716d53b3204bab94894f26adab84840e4ba4a53.zip meson-d716d53b3204bab94894f26adab84840e4ba4a53.tar.gz meson-d716d53b3204bab94894f26adab84840e4ba4a53.tar.bz2 |
Can override project option default values in subproject().
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] |