|
|
@ -551,7 +551,7 @@ class CoreData: |
|
|
|
self.target_guids = {} |
|
|
|
self.target_guids = {} |
|
|
|
self.version = version |
|
|
|
self.version = version |
|
|
|
self.builtins = {} # type: OptionDictType |
|
|
|
self.builtins = {} # type: OptionDictType |
|
|
|
self.builtins_per_machine = PerMachine({}, {}) |
|
|
|
self.builtins_per_machine: PerMachine['OptionDictType'] = PerMachine({}, {}) |
|
|
|
self.backend_options = {} # type: OptionDictType |
|
|
|
self.backend_options = {} # type: OptionDictType |
|
|
|
self.user_options = {} # type: OptionDictType |
|
|
|
self.user_options = {} # type: OptionDictType |
|
|
|
self.compiler_options = PerMachine( |
|
|
|
self.compiler_options = PerMachine( |
|
|
@ -835,14 +835,10 @@ class CoreData: |
|
|
|
return k[:idx + 1] + 'build.' + k[idx + 1:] |
|
|
|
return k[:idx + 1] + 'build.' + k[idx + 1:] |
|
|
|
|
|
|
|
|
|
|
|
@classmethod |
|
|
|
@classmethod |
|
|
|
def is_per_machine_option(cls, optname): |
|
|
|
def is_per_machine_option(cls, optname: OptionKey) -> bool: |
|
|
|
if optname in BUILTIN_OPTIONS_PER_MACHINE: |
|
|
|
if optname.name in BUILTIN_OPTIONS_PER_MACHINE: |
|
|
|
return True |
|
|
|
return True |
|
|
|
from .compilers import compilers |
|
|
|
return optname.lang is not None |
|
|
|
for lang_prefix in [lang + '_' for lang in compilers.all_languages]: |
|
|
|
|
|
|
|
if optname.startswith(lang_prefix): |
|
|
|
|
|
|
|
return True |
|
|
|
|
|
|
|
return False |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def _get_all_nonbuiltin_options(self) -> T.Iterable[T.Dict[str, UserOption]]: |
|
|
|
def _get_all_nonbuiltin_options(self) -> T.Iterable[T.Dict[str, UserOption]]: |
|
|
|
yield self.backend_options |
|
|
|
yield self.backend_options |
|
|
@ -899,16 +895,6 @@ class CoreData: |
|
|
|
return False |
|
|
|
return False |
|
|
|
return len(self.cross_files) > 0 |
|
|
|
return len(self.cross_files) > 0 |
|
|
|
|
|
|
|
|
|
|
|
def strip_build_option_names(self, options): |
|
|
|
|
|
|
|
res = OrderedDict() |
|
|
|
|
|
|
|
for k, v in options.items(): |
|
|
|
|
|
|
|
if k.startswith('build.'): |
|
|
|
|
|
|
|
k = k.split('.', 1)[1] |
|
|
|
|
|
|
|
res.setdefault(k, v) |
|
|
|
|
|
|
|
else: |
|
|
|
|
|
|
|
res[k] = v |
|
|
|
|
|
|
|
return res |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def copy_build_options_from_regular_ones(self): |
|
|
|
def copy_build_options_from_regular_ones(self): |
|
|
|
assert(not self.is_cross_build()) |
|
|
|
assert(not self.is_cross_build()) |
|
|
|
for k, o in self.builtins_per_machine.host.items(): |
|
|
|
for k, o in self.builtins_per_machine.host.items(): |
|
|
@ -919,25 +905,26 @@ class CoreData: |
|
|
|
if k in build_opts: |
|
|
|
if k in build_opts: |
|
|
|
build_opts[k].set_value(o.value) |
|
|
|
build_opts[k].set_value(o.value) |
|
|
|
|
|
|
|
|
|
|
|
def set_options(self, options: T.Dict[str, T.Any], subproject: str = '', warn_unknown: bool = True) -> None: |
|
|
|
def set_options(self, options: T.Dict[OptionKey, T.Any], subproject: str = '', warn_unknown: bool = True) -> None: |
|
|
|
if not self.is_cross_build(): |
|
|
|
if not self.is_cross_build(): |
|
|
|
options = self.strip_build_option_names(options) |
|
|
|
options = {k: v for k, v in options.items() if k.machine is not MachineChoice.BUILD} |
|
|
|
# Set prefix first because it's needed to sanitize other options |
|
|
|
# Set prefix first because it's needed to sanitize other options |
|
|
|
if 'prefix' in options: |
|
|
|
pfk = OptionKey('prefix') |
|
|
|
prefix = self.sanitize_prefix(options['prefix']) |
|
|
|
if pfk in options: |
|
|
|
|
|
|
|
prefix = self.sanitize_prefix(options[pfk]) |
|
|
|
self.builtins['prefix'].set_value(prefix) |
|
|
|
self.builtins['prefix'].set_value(prefix) |
|
|
|
for key in builtin_dir_noprefix_options: |
|
|
|
for key in builtin_dir_noprefix_options: |
|
|
|
if key not in options: |
|
|
|
if key not in options: |
|
|
|
self.builtins[key].set_value(BUILTIN_OPTIONS[key].prefixed_default(key, prefix)) |
|
|
|
self.builtins[key].set_value(BUILTIN_OPTIONS[key].prefixed_default(key, prefix)) |
|
|
|
|
|
|
|
|
|
|
|
unknown_options = [] |
|
|
|
unknown_options: T.List[OptionKey] = [] |
|
|
|
for k, v in options.items(): |
|
|
|
for k, v in options.items(): |
|
|
|
if k == 'prefix': |
|
|
|
if k == pfk: |
|
|
|
continue |
|
|
|
continue |
|
|
|
if self._try_set_builtin_option(k, v): |
|
|
|
if self._try_set_builtin_option(str(k), v): |
|
|
|
continue |
|
|
|
continue |
|
|
|
for opts in self._get_all_nonbuiltin_options(): |
|
|
|
for opts in self._get_all_nonbuiltin_options(): |
|
|
|
tgt = opts.get(k) |
|
|
|
tgt = opts.get(str(k)) |
|
|
|
if tgt is None: |
|
|
|
if tgt is None: |
|
|
|
continue |
|
|
|
continue |
|
|
|
tgt.set_value(v) |
|
|
|
tgt.set_value(v) |
|
|
@ -945,59 +932,50 @@ class CoreData: |
|
|
|
else: |
|
|
|
else: |
|
|
|
unknown_options.append(k) |
|
|
|
unknown_options.append(k) |
|
|
|
if unknown_options and warn_unknown: |
|
|
|
if unknown_options and warn_unknown: |
|
|
|
unknown_options = ', '.join(sorted(unknown_options)) |
|
|
|
unknown_options_str = ', '.join(sorted(str(s) for s in unknown_options)) |
|
|
|
sub = 'In subproject {}: '.format(subproject) if subproject else '' |
|
|
|
sub = 'In subproject {}: '.format(subproject) if subproject else '' |
|
|
|
mlog.warning('{}Unknown options: "{}"'.format(sub, unknown_options)) |
|
|
|
mlog.warning('{}Unknown options: "{}"'.format(sub, unknown_options_str)) |
|
|
|
mlog.log('The value of new options can be set with:') |
|
|
|
mlog.log('The value of new options can be set with:') |
|
|
|
mlog.log(mlog.bold('meson setup <builddir> --reconfigure -Dnew_option=new_value ...')) |
|
|
|
mlog.log(mlog.bold('meson setup <builddir> --reconfigure -Dnew_option=new_value ...')) |
|
|
|
if not self.is_cross_build(): |
|
|
|
if not self.is_cross_build(): |
|
|
|
self.copy_build_options_from_regular_ones() |
|
|
|
self.copy_build_options_from_regular_ones() |
|
|
|
|
|
|
|
|
|
|
|
def set_default_options(self, default_options: 'T.OrderedDict[str, str]', subproject: str, env: 'Environment') -> None: |
|
|
|
def set_default_options(self, default_options: T.MutableMapping[OptionKey, str], subproject: str, env: 'Environment') -> None: |
|
|
|
# Preserve order: if env.raw_options has 'buildtype' it must come after |
|
|
|
# Preserve order: if env.options has 'buildtype' it must come after |
|
|
|
# 'optimization' if it is in default_options. |
|
|
|
# 'optimization' if it is in default_options. |
|
|
|
raw_options = OrderedDict() |
|
|
|
if not subproject: |
|
|
|
|
|
|
|
options: T.MutableMapping[OptionKey, T.Any] = OrderedDict() |
|
|
|
for k, v in default_options.items(): |
|
|
|
for k, v in default_options.items(): |
|
|
|
if subproject: |
|
|
|
options[k] = v |
|
|
|
k = subproject + ':' + k |
|
|
|
options.update(env.options) |
|
|
|
raw_options[k] = v |
|
|
|
env.options = options |
|
|
|
raw_options.update(env.raw_options) |
|
|
|
|
|
|
|
env.raw_options = raw_options |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Create a subset of raw_options, keeping only project and builtin |
|
|
|
# Create a subset of options, keeping only project and builtin |
|
|
|
# options for this subproject. |
|
|
|
# options for this subproject. |
|
|
|
# Language and backend specific options will be set later when adding |
|
|
|
# Language and backend specific options will be set later when adding |
|
|
|
# languages and setting the backend (builtin options must be set first |
|
|
|
# languages and setting the backend (builtin options must be set first |
|
|
|
# to know which backend we'll use). |
|
|
|
# to know which backend we'll use). |
|
|
|
options = OrderedDict() |
|
|
|
options: T.MutableMapping[OptionKey, T.Any] = OrderedDict() |
|
|
|
|
|
|
|
|
|
|
|
from . import optinterpreter |
|
|
|
from . import optinterpreter |
|
|
|
for k, v in env.raw_options.items(): |
|
|
|
for k, v in chain(default_options.items(), env.options.items()): |
|
|
|
raw_optname = k |
|
|
|
|
|
|
|
if subproject: |
|
|
|
|
|
|
|
# Subproject: skip options for other subprojects |
|
|
|
# Subproject: skip options for other subprojects |
|
|
|
if not k.startswith(subproject + ':'): |
|
|
|
if k.subproject and k.subproject != subproject: |
|
|
|
continue |
|
|
|
|
|
|
|
raw_optname = k.split(':')[1] |
|
|
|
|
|
|
|
elif ':' in k: |
|
|
|
|
|
|
|
# Main prject: skip options for subprojects |
|
|
|
|
|
|
|
continue |
|
|
|
continue |
|
|
|
# Skip base, compiler, and backend options, they are handled when |
|
|
|
# Skip base, compiler, and backend options, they are handled when |
|
|
|
# adding languages and setting backend. |
|
|
|
# adding languages and setting backend. |
|
|
|
if (k not in self.builtins and |
|
|
|
if (k.name not in self.builtins and k.name not in self.builtins_per_machine[k.machine] and |
|
|
|
k not in self.get_prefixed_options_per_machine(self.builtins_per_machine) and |
|
|
|
optinterpreter.is_invalid_name(str(k), log=False)): |
|
|
|
optinterpreter.is_invalid_name(raw_optname, log=False)): |
|
|
|
|
|
|
|
continue |
|
|
|
continue |
|
|
|
options[k] = v |
|
|
|
options[k] = v |
|
|
|
|
|
|
|
|
|
|
|
self.set_options(options, subproject=subproject) |
|
|
|
self.set_options(options, subproject=subproject) |
|
|
|
|
|
|
|
|
|
|
|
def add_compiler_options(self, options, lang, for_machine, env): |
|
|
|
def add_compiler_options(self, options: 'OptionDictType', lang: str, for_machine: MachineChoice, |
|
|
|
# prefixed compiler options affect just this machine |
|
|
|
env: 'Environment') -> None: |
|
|
|
opt_prefix = for_machine.get_prefix() |
|
|
|
|
|
|
|
for k, o in options.items(): |
|
|
|
for k, o in options.items(): |
|
|
|
optname = opt_prefix + lang + '_' + k |
|
|
|
key = OptionKey(k, lang=lang, machine=for_machine) |
|
|
|
value = env.raw_options.get(optname) |
|
|
|
value = env.options.get(key) |
|
|
|
if value is not None: |
|
|
|
if value is not None: |
|
|
|
o.set_value(value) |
|
|
|
o.set_value(value) |
|
|
|
self.compiler_options[for_machine][lang].setdefault(k, o) |
|
|
|
self.compiler_options[for_machine][lang].setdefault(k, o) |
|
|
@ -1006,8 +984,7 @@ class CoreData: |
|
|
|
for_machine: MachineChoice, env: 'Environment') -> None: |
|
|
|
for_machine: MachineChoice, env: 'Environment') -> None: |
|
|
|
"""Add global language arguments that are needed before compiler/linker detection.""" |
|
|
|
"""Add global language arguments that are needed before compiler/linker detection.""" |
|
|
|
from .compilers import compilers |
|
|
|
from .compilers import compilers |
|
|
|
options = compilers.get_global_options(lang, comp, for_machine, |
|
|
|
options = compilers.get_global_options(lang, comp, for_machine, env.is_cross_build()) |
|
|
|
env.is_cross_build()) |
|
|
|
|
|
|
|
self.add_compiler_options(options, lang, for_machine, env) |
|
|
|
self.add_compiler_options(options, lang, for_machine, env) |
|
|
|
|
|
|
|
|
|
|
|
def process_new_compiler(self, lang: str, comp: 'Compiler', env: 'Environment') -> None: |
|
|
|
def process_new_compiler(self, lang: str, comp: 'Compiler', env: 'Environment') -> None: |
|
|
@ -1021,8 +998,9 @@ class CoreData: |
|
|
|
if optname in self.base_options: |
|
|
|
if optname in self.base_options: |
|
|
|
continue |
|
|
|
continue |
|
|
|
oobj = compilers.base_options[optname] |
|
|
|
oobj = compilers.base_options[optname] |
|
|
|
if optname in env.raw_options: |
|
|
|
key = OptionKey(optname, machine=comp.for_machine) |
|
|
|
oobj.set_value(env.raw_options[optname]) |
|
|
|
if key in env.options: |
|
|
|
|
|
|
|
oobj.set_value(env.options[key]) |
|
|
|
enabled_opts.append(optname) |
|
|
|
enabled_opts.append(optname) |
|
|
|
self.base_options[optname] = oobj |
|
|
|
self.base_options[optname] = oobj |
|
|
|
self.emit_base_options_warnings(enabled_opts) |
|
|
|
self.emit_base_options_warnings(enabled_opts) |
|
|
@ -1118,7 +1096,7 @@ def read_cmd_line_file(build_dir: str, options: argparse.Namespace) -> None: |
|
|
|
|
|
|
|
|
|
|
|
# Do a copy because config is not really a dict. options.cmd_line_options |
|
|
|
# Do a copy because config is not really a dict. options.cmd_line_options |
|
|
|
# overrides values from the file. |
|
|
|
# overrides values from the file. |
|
|
|
d = dict(config['options']) |
|
|
|
d = {OptionKey.from_string(k): v for k, v in config['options'].items()} |
|
|
|
d.update(options.cmd_line_options) |
|
|
|
d.update(options.cmd_line_options) |
|
|
|
options.cmd_line_options = d |
|
|
|
options.cmd_line_options = d |
|
|
|
|
|
|
|
|
|
|
@ -1130,9 +1108,6 @@ def read_cmd_line_file(build_dir: str, options: argparse.Namespace) -> None: |
|
|
|
# literal_eval to get it into the list of strings. |
|
|
|
# literal_eval to get it into the list of strings. |
|
|
|
options.native_file = ast.literal_eval(properties.get('native_file', '[]')) |
|
|
|
options.native_file = ast.literal_eval(properties.get('native_file', '[]')) |
|
|
|
|
|
|
|
|
|
|
|
def cmd_line_options_to_string(options: argparse.Namespace) -> T.Dict[str, str]: |
|
|
|
|
|
|
|
return {k: str(v) for k, v in options.cmd_line_options.items()} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def write_cmd_line_file(build_dir: str, options: argparse.Namespace) -> None: |
|
|
|
def write_cmd_line_file(build_dir: str, options: argparse.Namespace) -> None: |
|
|
|
filename = get_cmd_line_file(build_dir) |
|
|
|
filename = get_cmd_line_file(build_dir) |
|
|
|
config = CmdLineFileParser() |
|
|
|
config = CmdLineFileParser() |
|
|
@ -1143,7 +1118,7 @@ def write_cmd_line_file(build_dir: str, options: argparse.Namespace) -> None: |
|
|
|
if options.native_file: |
|
|
|
if options.native_file: |
|
|
|
properties['native_file'] = [os.path.abspath(f) for f in options.native_file] |
|
|
|
properties['native_file'] = [os.path.abspath(f) for f in options.native_file] |
|
|
|
|
|
|
|
|
|
|
|
config['options'] = cmd_line_options_to_string(options) |
|
|
|
config['options'] = {str(k): str(v) for k, v in options.cmd_line_options.items()} |
|
|
|
config['properties'] = properties |
|
|
|
config['properties'] = properties |
|
|
|
with open(filename, 'w') as f: |
|
|
|
with open(filename, 'w') as f: |
|
|
|
config.write(f) |
|
|
|
config.write(f) |
|
|
@ -1152,14 +1127,14 @@ def update_cmd_line_file(build_dir: str, options: argparse.Namespace): |
|
|
|
filename = get_cmd_line_file(build_dir) |
|
|
|
filename = get_cmd_line_file(build_dir) |
|
|
|
config = CmdLineFileParser() |
|
|
|
config = CmdLineFileParser() |
|
|
|
config.read(filename) |
|
|
|
config.read(filename) |
|
|
|
config['options'].update(cmd_line_options_to_string(options)) |
|
|
|
config['options'].update({str(k): str(v) for k, v in options.cmd_line_options.items()}) |
|
|
|
with open(filename, 'w') as f: |
|
|
|
with open(filename, 'w') as f: |
|
|
|
config.write(f) |
|
|
|
config.write(f) |
|
|
|
|
|
|
|
|
|
|
|
def get_cmd_line_options(build_dir: str, options: argparse.Namespace) -> str: |
|
|
|
def get_cmd_line_options(build_dir: str, options: argparse.Namespace) -> str: |
|
|
|
copy = argparse.Namespace(**vars(options)) |
|
|
|
copy = argparse.Namespace(**vars(options)) |
|
|
|
read_cmd_line_file(build_dir, copy) |
|
|
|
read_cmd_line_file(build_dir, copy) |
|
|
|
cmdline = ['-D{}={}'.format(k, v) for k, v in copy.cmd_line_options.items()] |
|
|
|
cmdline = ['-D{}={}'.format(str(k), v) for k, v in copy.cmd_line_options.items()] |
|
|
|
if options.cross_file: |
|
|
|
if options.cross_file: |
|
|
|
cmdline += ['--cross-file {}'.format(f) for f in options.cross_file] |
|
|
|
cmdline += ['--cross-file {}'.format(f) for f in options.cross_file] |
|
|
|
if options.native_file: |
|
|
|
if options.native_file: |
|
|
@ -1214,14 +1189,17 @@ def register_builtin_arguments(parser: argparse.ArgumentParser) -> None: |
|
|
|
parser.add_argument('-D', action='append', dest='projectoptions', default=[], metavar="option", |
|
|
|
parser.add_argument('-D', action='append', dest='projectoptions', default=[], metavar="option", |
|
|
|
help='Set the value of an option, can be used several times to set multiple options.') |
|
|
|
help='Set the value of an option, can be used several times to set multiple options.') |
|
|
|
|
|
|
|
|
|
|
|
def create_options_dict(options: T.List[str]) -> T.Dict[str, str]: |
|
|
|
def create_options_dict(options: T.List[str], subproject: str = '') -> T.Dict[OptionKey, str]: |
|
|
|
result = OrderedDict() |
|
|
|
result: T.OrderedDict[OptionKey, str] = OrderedDict() |
|
|
|
for o in options: |
|
|
|
for o in options: |
|
|
|
try: |
|
|
|
try: |
|
|
|
(key, value) = o.split('=', 1) |
|
|
|
(key, value) = o.split('=', 1) |
|
|
|
except ValueError: |
|
|
|
except ValueError: |
|
|
|
raise MesonException('Option {!r} must have a value separated by equals sign.'.format(o)) |
|
|
|
raise MesonException('Option {!r} must have a value separated by equals sign.'.format(o)) |
|
|
|
result[key] = value |
|
|
|
k = OptionKey.from_string(key) |
|
|
|
|
|
|
|
if subproject: |
|
|
|
|
|
|
|
k = k.evolve(subproject=subproject) |
|
|
|
|
|
|
|
result[k] = value |
|
|
|
return result |
|
|
|
return result |
|
|
|
|
|
|
|
|
|
|
|
def parse_cmd_line_options(args: argparse.Namespace) -> None: |
|
|
|
def parse_cmd_line_options(args: argparse.Namespace) -> None: |
|
|
@ -1235,11 +1213,12 @@ def parse_cmd_line_options(args: argparse.Namespace) -> None: |
|
|
|
): |
|
|
|
): |
|
|
|
value = getattr(args, name, None) |
|
|
|
value = getattr(args, name, None) |
|
|
|
if value is not None: |
|
|
|
if value is not None: |
|
|
|
if name in args.cmd_line_options: |
|
|
|
key = OptionKey.from_string(name) |
|
|
|
|
|
|
|
if key in args.cmd_line_options: |
|
|
|
cmdline_name = BuiltinOption.argparse_name_to_arg(name) |
|
|
|
cmdline_name = BuiltinOption.argparse_name_to_arg(name) |
|
|
|
raise MesonException( |
|
|
|
raise MesonException( |
|
|
|
'Got argument {0} as both -D{0} and {1}. Pick one.'.format(name, cmdline_name)) |
|
|
|
'Got argument {0} as both -D{0} and {1}. Pick one.'.format(name, cmdline_name)) |
|
|
|
args.cmd_line_options[name] = value |
|
|
|
args.cmd_line_options[key] = value |
|
|
|
delattr(args, name) |
|
|
|
delattr(args, name) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|