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 .. import mlog
from ..compilers import LANGUAGES_USING_LDFLAGS, detect from ..compilers import LANGUAGES_USING_LDFLAGS, detect
from ..mesonlib import ( from ..mesonlib import (
File, MachineChoice, MesonException, OptionType, OrderedSet, OptionOverrideProxy, File, MachineChoice, MesonException, OrderedSet, OptionOverrideProxy,
classify_unity_sources, OptionKey, join_args 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: 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)) 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: def get_options_for_target(self, target: build.BuildTarget) -> OptionOverrideProxy:
return OptionOverrideProxy(target.option_overrides_base, return OptionOverrideProxy(target.option_overrides,
{k: v for k, v in self.environment.coredata.options.items() self.environment.coredata.options)
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_option_for_target(self, option_name: 'OptionKey', target: build.BuildTarget) -> T.Union[str, int, bool, 'WrapMode']: 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: 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. # starting from hard-coded defaults followed by build options and so on.
commands = compiler.compiler_args() 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. # First, the trivial ones that are impossible to override.
# #
# Add -nostdinc/-nostdinc++ if needed; can't be overridden # Add -nostdinc/-nostdinc++ if needed; can't be overridden

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

@ -990,7 +990,7 @@ class Vs2010Backend(backends.Backend):
for l, comp in target.compilers.items(): for l, comp in target.compilers.items():
if l in file_args: if l in file_args:
file_args[l] += compilers.get_base_compile_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( file_args[l] += comp.get_option_compile_args(
self.environment.coredata.options) self.environment.coredata.options)

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

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

Loading…
Cancel
Save