diff options
Diffstat (limited to 'mesonbuild/backend/backends.py')
-rw-r--r-- | mesonbuild/backend/backends.py | 47 |
1 files changed, 34 insertions, 13 deletions
diff --git a/mesonbuild/backend/backends.py b/mesonbuild/backend/backends.py index 8d9796d..a6a42e9 100644 --- a/mesonbuild/backend/backends.py +++ b/mesonbuild/backend/backends.py @@ -26,7 +26,7 @@ from .. import mesonlib from .. import mlog from ..compilers import LANGUAGES_USING_LDFLAGS, detect, lang_suffixes from ..mesonlib import ( - File, MachineChoice, MesonException, OrderedSet, + File, MachineChoice, MesonException, MesonBugException, OrderedSet, ExecutableSerialisation, EnvironmentException, classify_unity_sources, get_compiler_for_source ) @@ -424,7 +424,7 @@ class Backend: abs_files: T.List[str] = [] result: T.List[mesonlib.File] = [] compsrcs = classify_unity_sources(target.compilers.values(), unity_src) - unity_size = target.get_option(OptionKey('unity_size')) + unity_size = self.get_target_option(target, 'unity_size') assert isinstance(unity_size, int), 'for mypy' def init_language_file(suffix: str, unity_file_number: int) -> T.TextIO: @@ -878,7 +878,8 @@ class Backend: object_suffix = machine.get_object_suffix() # For the TASKING compiler, in case of LTO or prelinking the object suffix has to be .mil if compiler.get_id() == 'tasking': - if target.get_option(OptionKey('b_lto')) or (isinstance(target, build.StaticLibrary) and target.prelink): + use_lto = self.get_target_option(target, 'b_lto') + if use_lto or (isinstance(target, build.StaticLibrary) and target.prelink): if not source.rsplit('.', 1)[1] in lang_suffixes['c']: if isinstance(target, build.StaticLibrary) and not target.prelink: raise EnvironmentException('Tried using MIL linking for a static library with a assembly file. This can only be done if the static library is prelinked or disable \'b_lto\'.') @@ -925,10 +926,10 @@ class Backend: # With unity builds, sources don't map directly to objects, # we only support extracting all the objects in this mode, # so just return all object files. - if extobj.target.is_unity: + if self.is_unity(extobj.target): compsrcs = classify_unity_sources(extobj.target.compilers.values(), sources) sources = [] - unity_size = extobj.target.get_option(OptionKey('unity_size')) + unity_size = self.get_target_option(extobj.target, 'unity_size') assert isinstance(unity_size, int), 'for mypy' for comp, srcs in compsrcs.items(): @@ -981,7 +982,7 @@ class Backend: def target_uses_pch(self, target: build.BuildTarget) -> bool: try: - return T.cast('bool', target.get_option(OptionKey('b_pch'))) + return T.cast('bool', self.get_target_option(target, 'b_pch')) except (KeyError, AttributeError): return False @@ -1007,7 +1008,6 @@ class Backend: # starting from hard-coded defaults followed by build options and so on. commands = compiler.compiler_args() - copt_proxy = target.get_options() # First, the trivial ones that are impossible to override. # # Add -nostdinc/-nostdinc++ if needed; can't be overridden @@ -1015,22 +1015,22 @@ class Backend: # Add things like /NOLOGO or -pipe; usually can't be overridden commands += compiler.get_always_args() # warning_level is a string, but mypy can't determine that - commands += compiler.get_warn_args(T.cast('str', target.get_option(OptionKey('warning_level')))) + commands += compiler.get_warn_args(T.cast('str', self.get_target_option(target, 'warning_level'))) # Add -Werror if werror=true is set in the build options set on the # command-line or default_options inside project(). This only sets the # action to be done for warnings if/when they are emitted, so it's ok # to set it after or get_warn_args(). - if target.get_option(OptionKey('werror')): + if self.get_target_option(target, 'werror'): commands += compiler.get_werror_args() # Add compile args for c_* or cpp_* build options set on the # command-line or default_options inside project(). - commands += compiler.get_option_compile_args(copt_proxy) + commands += compiler.get_option_compile_args(target, self.environment, target.subproject) - optimization = target.get_option(OptionKey('optimization')) + optimization = self.get_target_option(target, 'optimization') assert isinstance(optimization, str), 'for mypy' commands += compiler.get_optimization_args(optimization) - debug = target.get_option(OptionKey('debug')) + debug = self.get_target_option(target, 'debug') assert isinstance(debug, bool), 'for mypy' commands += compiler.get_debug_args(debug) @@ -1755,7 +1755,7 @@ class Backend: # TODO: Create GNUStrip/AppleStrip/etc. hierarchy for more # fine-grained stripping of static archives. can_strip = not isinstance(t, build.StaticLibrary) - should_strip = can_strip and t.get_option(OptionKey('strip')) + should_strip = can_strip and self.get_target_option(t, 'strip') assert isinstance(should_strip, bool), 'for mypy' # Install primary build output (library/executable/jar, etc) # Done separately because of strip/aliases/rpath @@ -2092,3 +2092,24 @@ class Backend: all_sources = T.cast('_ALL_SOURCES_TYPE', target.sources) + T.cast('_ALL_SOURCES_TYPE', target.generated) return self.compiler_to_generator(target, target.compiler, all_sources, target.output_templ, target.depends) + + def is_unity(self, target: build.BuildTarget) -> bool: + if isinstance(target, build.CompileTarget): + return False + val = self.get_target_option(target, 'unity') + if val == 'on': + return True + if val == 'off': + return False + if val == 'subprojects': + return target.subproject != '' + raise MesonException(f'Internal error: invalid option type for "unity": {val}') + + def get_target_option(self, target: build.BuildTarget, name: T.Union[str, OptionKey]) -> T.Union[str, int, bool, T.List[str]]: + if isinstance(name, str): + key = OptionKey(name, subproject=target.subproject) + elif isinstance(name, OptionKey): + key = name + else: + raise MesonBugException('Internal error: invalid option type.') + return self.environment.coredata.get_option_for_target(target, key) |