backends: Stop separating base and compiler options

Since OptionKey is used we can mix all options together in a single
dictionary. That's already what we do in coredata.options.
pull/10165/head
Xavier Claessens 3 years ago committed by Xavier Claessens
parent 6c5a0f8332
commit 86aaac8e42
  1. 16
      mesonbuild/backend/backends.py
  2. 12
      mesonbuild/backend/ninjabackend.py
  3. 2
      mesonbuild/backend/vs2010backend.py
  4. 2
      mesonbuild/backend/xcodebackend.py
  5. 11
      mesonbuild/build.py

@ -32,7 +32,7 @@ from .. import mesonlib
from .. import mlog
from ..compilers import LANGUAGES_USING_LDFLAGS, detect
from ..mesonlib import (
File, MachineChoice, MesonException, OptionType, OrderedSet, OptionOverrideProxy,
File, MachineChoice, MesonException, OrderedSet, OptionOverrideProxy,
classify_unity_sources, OptionKey, join_args
)
@ -310,15 +310,9 @@ class Backend:
def get_target_filename_abs(self, target: T.Union[build.Target, build.CustomTargetIndex]) -> str:
return os.path.join(self.environment.get_build_dir(), self.get_target_filename(target))
def get_base_options_for_target(self, target: build.BuildTarget) -> OptionOverrideProxy:
return OptionOverrideProxy(target.option_overrides_base,
{k: v for k, v in self.environment.coredata.options.items()
if k.type in {OptionType.BASE, OptionType.BUILTIN}})
def get_compiler_options_for_target(self, target: build.BuildTarget) -> OptionOverrideProxy:
comp_reg = {k: v for k, v in self.environment.coredata.options.items() if k.is_compiler()}
comp_override = target.option_overrides_compiler
return OptionOverrideProxy(comp_override, comp_reg)
def get_options_for_target(self, target: build.BuildTarget) -> OptionOverrideProxy:
return OptionOverrideProxy(target.option_overrides,
self.environment.coredata.options)
def get_option_for_target(self, option_name: 'OptionKey', target: build.BuildTarget) -> T.Union[str, int, bool, 'WrapMode']:
if option_name in target.option_overrides_base:
@ -926,7 +920,7 @@ class Backend:
# starting from hard-coded defaults followed by build options and so on.
commands = compiler.compiler_args()
copt_proxy = self.get_compiler_options_for_target(target)
copt_proxy = self.get_options_for_target(target)
# First, the trivial ones that are impossible to override.
#
# Add -nostdinc/-nostdinc++ if needed; can't be overridden

@ -1605,7 +1605,7 @@ class NinjaBackend(backends.Backend):
cython = target.compilers['cython']
opt_proxy = self.get_compiler_options_for_target(target)
opt_proxy = self.get_options_for_target(target)
args: T.List[str] = []
args += cython.get_always_args()
@ -1692,7 +1692,7 @@ class NinjaBackend(backends.Backend):
# Rust compiler takes only the main file as input and
# figures out what other files are needed via import
# statements and magic.
base_proxy = self.get_base_options_for_target(target)
base_proxy = self.get_options_for_target(target)
args = rustc.compiler_args()
# Compiler args for compiling this target
args += compilers.get_base_compile_args(base_proxy, rustc)
@ -2463,7 +2463,7 @@ https://gcc.gnu.org/bugzilla/show_bug.cgi?id=47485'''))
return linker.get_link_debugfile_args(outname)
def generate_llvm_ir_compile(self, target, src):
base_proxy = self.get_base_options_for_target(target)
base_proxy = self.get_options_for_target(target)
compiler = get_compiler_for_source(target.compilers.values(), src)
commands = compiler.compiler_args()
# Compiler args for compiling this target
@ -2523,7 +2523,7 @@ https://gcc.gnu.org/bugzilla/show_bug.cgi?id=47485'''))
return commands
def _generate_single_compile_base_args(self, target: build.BuildTarget, compiler: 'Compiler') -> 'CompilerArgs':
base_proxy = self.get_base_options_for_target(target)
base_proxy = self.get_options_for_target(target)
# Create an empty commands list, and start adding arguments from
# various sources in the order in which they must override each other
commands = compiler.compiler_args()
@ -3025,9 +3025,9 @@ https://gcc.gnu.org/bugzilla/show_bug.cgi?id=47485'''))
# options passed on the command-line, in default_options, etc.
# These have the lowest priority.
if isinstance(target, build.StaticLibrary):
commands += linker.get_base_link_args(self.get_base_options_for_target(target))
commands += linker.get_base_link_args(self.get_options_for_target(target))
else:
commands += compilers.get_base_link_args(self.get_base_options_for_target(target),
commands += compilers.get_base_link_args(self.get_options_for_target(target),
linker,
isinstance(target, build.SharedModule))
# Add -nostdlib if needed; can't be overridden

@ -990,7 +990,7 @@ class Vs2010Backend(backends.Backend):
for l, comp in target.compilers.items():
if l in file_args:
file_args[l] += compilers.get_base_compile_args(
self.get_base_options_for_target(target), comp)
self.get_options_for_target(target), comp)
file_args[l] += comp.get_option_compile_args(
self.environment.coredata.options)

@ -1504,7 +1504,7 @@ class XCodeBackend(backends.Backend):
continue
# Start with warning args
warn_args = compiler.get_warn_args(self.get_option_for_target(OptionKey('warning_level'), target))
copt_proxy = self.get_compiler_options_for_target(target)
copt_proxy = self.get_options_for_target(target)
std_args = compiler.get_option_compile_args(copt_proxy)
# Add compile args added using add_project_arguments()
pargs = self.build.projects_args[target.for_machine].get(target.subproject, {}).get(lang, [])

@ -588,8 +588,7 @@ class Target(HoldableObject):
'''))
self.install = False
self.build_always_stale = False
self.option_overrides_base: T.Dict[OptionKey, str] = {}
self.option_overrides_compiler: T.Dict[OptionKey, str] = {}
self.option_overrides: T.Dict[OptionKey, str] = {}
self.extra_files = [] # type: T.List[File]
if not hasattr(self, 'typename'):
raise RuntimeError(f'Target type is not set for target class "{type(self).__name__}". This is a bug')
@ -697,9 +696,9 @@ class Target(HoldableObject):
for k, v in option_overrides.items():
if k.lang:
self.option_overrides_compiler[k.evolve(machine=self.for_machine)] = v
self.option_overrides[k.evolve(machine=self.for_machine)] = v
continue
self.option_overrides_base[k] = v
self.option_overrides[k] = v
@staticmethod
def parse_overrides(kwargs: T.Dict[str, T.Any]) -> T.Dict[OptionKey, str]:
@ -968,8 +967,8 @@ class BuildTarget(Target):
self.compilers['c'] = compilers['c']
if 'cython' in self.compilers:
key = OptionKey('language', machine=self.for_machine, lang='cython')
if key in self.option_overrides_compiler:
value = self.option_overrides_compiler[key]
if key in self.option_overrides:
value = self.option_overrides[key]
else:
value = self.environment.coredata.options[key].value

Loading…
Cancel
Save