aboutsummaryrefslogtreecommitdiff
path: root/mesonbuild/compilers/compilers.py
diff options
context:
space:
mode:
authorJohn Ericson <git@JohnEricson.me>2019-02-26 00:55:43 -0500
committerDylan Baker <dylan@pnwbakers.com>2019-02-27 13:10:16 -0800
commit2d6d242aec2305cf60b4b743cdcc6de5b5d9d8ac (patch)
tree41806be9c0118b84f3d4972707f7ee898d4689b0 /mesonbuild/compilers/compilers.py
parentc2db7a9ceed3286683967768e6fcc1c170c24c42 (diff)
downloadmeson-2d6d242aec2305cf60b4b743cdcc6de5b5d9d8ac.zip
meson-2d6d242aec2305cf60b4b743cdcc6de5b5d9d8ac.tar.gz
meson-2d6d242aec2305cf60b4b743cdcc6de5b5d9d8ac.tar.bz2
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.
Diffstat (limited to 'mesonbuild/compilers/compilers.py')
-rw-r--r--mesonbuild/compilers/compilers.py38
1 files changed, 29 insertions, 9 deletions
diff --git a/mesonbuild/compilers/compilers.py b/mesonbuild/compilers/compilers.py
index 7955f3d..24dffa6 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 []