summaryrefslogtreecommitdiff
path: root/mesonbuild/coredata.py
diff options
context:
space:
mode:
authorDylan Baker <dylan@pnwbakers.com>2020-02-06 12:18:10 -0800
committerDylan Baker <dylan@pnwbakers.com>2020-08-01 22:00:06 -0700
commitbbba6a7f365f8b7dc7f2d4c3ce7f3e5f4c05fc5e (patch)
tree4391f82cb4f0264438c3b6fd74ef48f16d1836b8 /mesonbuild/coredata.py
parentaf763e093a8172536d96e24901b82edd2e5b2dc9 (diff)
downloadmeson-bbba6a7f365f8b7dc7f2d4c3ce7f3e5f4c05fc5e.tar.gz
Allow setting built-in options from cross/native files
This is like the project options, but for meson builtin options. The only real differences here have to do with the differences between meson builtin options and project options. Some meson options can be set on a per-machine basis (build.pkg_config_path vs pkg_config_path) others can be set on a per-subproject basis, but should inherit the parent setting.
Diffstat (limited to 'mesonbuild/coredata.py')
-rw-r--r--mesonbuild/coredata.py49
1 files changed, 41 insertions, 8 deletions
diff --git a/mesonbuild/coredata.py b/mesonbuild/coredata.py
index 3330ae52a..0cac02962 100644
--- a/mesonbuild/coredata.py
+++ b/mesonbuild/coredata.py
@@ -361,15 +361,15 @@ class CoreData:
self.install_guid = str(uuid.uuid4()).upper()
self.target_guids = {}
self.version = version
- self.builtins = {} # : OptionDictType
+ self.builtins = {} # type: OptionDictType
self.builtins_per_machine = PerMachine({}, {})
- self.backend_options = {} # : OptionDictType
- self.user_options = {} # : OptionDictType
+ self.backend_options = {} # type: OptionDictType
+ self.user_options = {} # type: OptionDictType
self.compiler_options = PerMachine(
defaultdict(dict),
defaultdict(dict),
) # : PerMachine[T.defaultdict[str, OptionDictType]]
- self.base_options = {} # : OptionDictType
+ self.base_options = {} # type: OptionDictType
self.cross_files = self.__load_config_files(options, scratch_dir, 'cross')
self.compilers = PerMachine(OrderedDict(), OrderedDict())
@@ -743,19 +743,28 @@ class CoreData:
mlog.warning('Recommend using either -Dbuildtype or -Doptimization + -Ddebug. '
'Using both is redundant since they override each other. '
'See: https://mesonbuild.com/Builtin-options.html#build-type-options')
+
cmd_line_options = OrderedDict()
- # Set project default_options as if they were passed to the cmdline.
+ # Set default options as if they were passed to the command line.
# Subprojects can only define default for user options and not yielding
# builtin option.
from . import optinterpreter
- for k, v in default_options.items():
+ for k, v in chain(default_options.items(), env.meson_options.host.get('', {}).items()):
if subproject:
if (k not in builtin_options or builtin_options[k].yielding) \
and optinterpreter.is_invalid_name(k, log=False):
continue
- k = subproject + ':' + k
cmd_line_options[k] = v
+ # IF the subproject options comes from a machine file, then we need to
+ # set the option as subproject:option
+ if subproject:
+ for k, v in env.meson_options.host.get(subproject, {}).items():
+ if (k not in builtin_options or builtin_options[k].yielding) \
+ and optinterpreter.is_invalid_name(k, log=False):
+ continue
+ cmd_line_options['{}:{}'.format(subproject, k)] = v
+
# load the values for user options out of the appropriate machine file,
# then overload the command line
for k, v in env.user_options.get(subproject, {}).items():
@@ -768,8 +777,32 @@ class CoreData:
if v is not None:
cmd_line_options[k] = v
+ from .compilers import all_languages
+ # Report that [properties]c_args
+ for lang in all_languages:
+ for args in ['{}_args'.format(lang), '{}_link_args'.format(lang)]:
+ msg = ('{} in the [properties] section of the machine file is deprecated, '
+ 'use the [built-in options] section.')
+ if args in env.properties.host or args in env.properties.build:
+ mlog.deprecation(msg.format(args))
+
+ # Currently we don't support any options that are both per-subproject
+ # and per-machine, but when we do this will need to account for that.
+ # For cross builds we need to get the build specifc options
+ if env.meson_options.host != env.meson_options.build and subproject in env.meson_options.build:
+ for k in builtin_options_per_machine.keys():
+ if k in env.meson_options.build[subproject]:
+ cmd_line_options['build.{}'.format(k)] = env.meson_options.build[subproject][k]
+
+ # compiler options are always per-machine
+ for lang in all_languages:
+ prefix = '{}_'.format(lang)
+ for k in env.meson_options.build[subproject]:
+ if k.startswith(prefix):
+ cmd_line_options['build.{}'.format(k)] = env.meson_options.build[subproject][k]
+
# Override all the above defaults using the command-line arguments
- # actually passed to us
+ # actually passed to use
cmd_line_options.update(env.cmd_line_options)
env.cmd_line_options = cmd_line_options