From 2d6d242aec2305cf60b4b743cdcc6de5b5d9d8ac Mon Sep 17 00:00:00 2001 From: John Ericson Date: Tue, 26 Feb 2019 00:55:43 -0500 Subject: Feed compiler Properties to get its options defaulted Before, the logic initialization compiler options from environment variables vs config files was strewn about. Now, it is consolidated. We leverage the new `envconfig.py` module to expose the configuration data to `compilers.py` without creating an import cycle. --- mesonbuild/compilers/compilers.py | 38 +++++++++++++++++++++++++++++--------- mesonbuild/coredata.py | 9 +++------ 2 files changed, 32 insertions(+), 15 deletions(-) diff --git a/mesonbuild/compilers/compilers.py b/mesonbuild/compilers/compilers.py index 7955f3d4d..24dffa68b 100644 --- a/mesonbuild/compilers/compilers.py +++ b/mesonbuild/compilers/compilers.py @@ -24,6 +24,9 @@ from ..mesonlib import ( EnvironmentException, MesonException, OrderedSet, version_compare, Popen_safe ) +from ..envconfig import ( + Properties, +) """This file contains the data files of all compilers Meson knows about. To support a new compiler, add its information below. @@ -1009,27 +1012,44 @@ class Compiler: def get_options(self): opts = {} # build afresh every time - - # Take default values from env variables. - if not self.is_cross: - compile_args, link_args = self.get_args_from_envvars() - else: - compile_args = [] - link_args = [] description = 'Extra arguments passed to the {}'.format(self.get_display_language()) opts.update({ self.language + '_args': coredata.UserArrayOption( self.language + '_args', description + ' compiler', - compile_args, shlex_split=True, user_input=True, allow_dups=True), + [], shlex_split=True, user_input=True, allow_dups=True), self.language + '_link_args': coredata.UserArrayOption( self.language + '_link_args', description + ' linker', - link_args, shlex_split=True, user_input=True, allow_dups=True), + [], shlex_split=True, user_input=True, allow_dups=True), }) return opts + def get_and_default_options(self, properties: Properties): + """ + Take default values from env variables and/or config files. + """ + opts = self.get_options() + + if properties.fallback: + # Get from env vars. + compile_args, link_args = self.get_args_from_envvars() + else: + compile_args = [] + link_args = [] + + for k, o in opts.items(): + if k in properties: + # Get from configuration files. + o.set_value(properties[k]) + elif k == self.language + '_args': + o.set_value(compile_args) + elif k == self.language + '_link_args': + o.set_value(link_args) + + return opts + def get_option_compile_args(self, options): return [] diff --git a/mesonbuild/coredata.py b/mesonbuild/coredata.py index 0e11f5c01..28e78e5bd 100644 --- a/mesonbuild/coredata.py +++ b/mesonbuild/coredata.py @@ -569,13 +569,13 @@ class CoreData: self.cross_compilers[lang] = cross_comp # Native compiler always exist so always add its options. - new_options_for_build = comp.get_options() + new_options_for_build = comp.get_and_default_options(env.properties.build) preproc_flags_for_build = comp.get_preproc_flags() if cross_comp is not None: - new_options_for_host = cross_comp.get_options() + new_options_for_host = cross_comp.get_and_default_options(env.properties.host) preproc_flags_for_host = cross_comp.get_preproc_flags() else: - new_options_for_host = comp.get_options() + new_options_for_host = comp.get_and_default_options(env.properties.host) preproc_flags_for_host = comp.get_preproc_flags() opts_machines_list = [ @@ -588,9 +588,6 @@ class CoreData: for k, o in new_options.items(): if not k.startswith(optprefix): raise MesonException('Internal error, %s has incorrect prefix.' % k) - if k in env.properties[for_machine]: - # Get from configuration files. - o.set_value(env.properties[for_machine][k]) if (env.machines.matches_build_machine(for_machine) and k in env.cmd_line_options): # TODO think about cross and command-line interface. -- cgit v1.2.3