summaryrefslogtreecommitdiff
path: root/mesonbuild
diff options
context:
space:
mode:
Diffstat (limited to 'mesonbuild')
-rw-r--r--mesonbuild/coredata.py49
-rw-r--r--mesonbuild/environment.py28
-rw-r--r--mesonbuild/interpreter.py1
3 files changed, 65 insertions, 13 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
diff --git a/mesonbuild/environment.py b/mesonbuild/environment.py
index c872aeede..dc674fde1 100644
--- a/mesonbuild/environment.py
+++ b/mesonbuild/environment.py
@@ -556,6 +556,9 @@ class Environment:
# We only need one of these as project options are not per machine
user_options = {}
+ # meson builtin options, as passed through cross or native files
+ meson_options = PerMachineDefaultable()
+
## Setup build machine defaults
# Will be fully initialized later using compilers later.
@@ -568,14 +571,15 @@ class Environment:
## Read in native file(s) to override build machine configuration
- def load_user_options():
+ def load_options(tag: str, store: T.Dict[str, T.Any]) -> None:
for section in config.keys():
- if section.endswith('project options'):
+ if section.endswith(tag):
if ':' in section:
project = section.split(':')[0]
else:
project = ''
- user_options[project] = config.get(section, {})
+ store[project] = config.get(section, {})
+
if self.coredata.config_files is not None:
config = coredata.parse_machine_files(self.coredata.config_files)
@@ -586,7 +590,9 @@ class Environment:
# Don't run this if there are any cross files, we don't want to use
# the native values if we're doing a cross build
if not self.coredata.cross_files:
- load_user_options()
+ load_options('project options', user_options)
+ meson_options.build = {}
+ load_options('built-in options', meson_options.build)
## Read in cross file(s) to override host machine configuration
@@ -599,7 +605,9 @@ class Environment:
if 'target_machine' in config:
machines.target = MachineInfo.from_literal(config['target_machine'])
paths.host = Directories(**config.get('paths', {}))
- load_user_options()
+ load_options('project options', user_options)
+ meson_options.host = {}
+ load_options('built-in options', meson_options.host)
## "freeze" now initialized configuration, and "save" to the class.
@@ -608,6 +616,16 @@ class Environment:
self.properties = properties.default_missing()
self.paths = paths.default_missing()
self.user_options = user_options
+ self.meson_options = meson_options.default_missing()
+
+ # Ensure that no paths are passed via built-in options:
+ if '' in self.meson_options.host:
+ for each in coredata.BUILTIN_DIR_OPTIONS.keys():
+ # These are not per-subdirectory and probably never will be
+ if each in self.meson_options.host['']:
+ raise EnvironmentException(
+ 'Invalid entry {} in [built-in options] section. '
+ 'Use the [paths] section instead.'.format(each))
exe_wrapper = self.lookup_binary_entry(MachineChoice.HOST, 'exe_wrapper')
if exe_wrapper is not None:
diff --git a/mesonbuild/interpreter.py b/mesonbuild/interpreter.py
index 45813c1e1..317793db5 100644
--- a/mesonbuild/interpreter.py
+++ b/mesonbuild/interpreter.py
@@ -2791,6 +2791,7 @@ external dependencies (including libraries) must go to "dependencies".''')
default_options = mesonlib.stringlistify(kwargs.get('default_options', []))
default_options = coredata.create_options_dict(default_options)
+
if dirname == '':
raise InterpreterException('Subproject dir name must not be empty.')
if dirname[0] == '.':