Fix the typing around Compiler._get_compile_output()

This function says it returns a string, but was returning None in some
cases.
pull/11976/head
Tristan Partin 1 year ago
parent d4bcf05c39
commit 9e8a034ade
  1. 10
      mesonbuild/compilers/compilers.py
  2. 4
      mesonbuild/compilers/mixins/emscripten.py

@ -800,9 +800,7 @@ class Compiler(HoldableObject, metaclass=abc.ABCMeta):
return self.linker.has_multi_arguments(args, env)
def _get_compile_output(self, dirname: str, mode: CompileCheckMode) -> str:
# In pre-processor mode, the output is sent to stdout and discarded
if mode == CompileCheckMode.PREPROCESS:
return None
assert mode != CompileCheckMode.PREPROCESS, 'In pre-processor mode, the output is sent to stdout and discarded'
# Extension only matters if running results; '.exe' is
# guaranteed to be executable on every platform.
if mode == CompileCheckMode.LINK:
@ -832,6 +830,10 @@ class Compiler(HoldableObject, metaclass=abc.ABCMeta):
*, mode: CompileCheckMode = CompileCheckMode.LINK, want_output: bool = False,
temp_dir: T.Optional[str] = None) -> T.Iterator[T.Optional[CompileResult]]:
# TODO: there isn't really any reason for this to be a contextmanager
if mode == CompileCheckMode.PREPROCESS:
assert not want_output, 'In pre-processor mode, the output is sent to stdout and discarded'
if extra_args is None:
extra_args = []
@ -858,8 +860,8 @@ class Compiler(HoldableObject, metaclass=abc.ABCMeta):
commands.append(srcname)
# Preprocess mode outputs to stdout, so no output args
output = self._get_compile_output(tmpdirname, mode)
if mode != CompileCheckMode.PREPROCESS:
output = self._get_compile_output(tmpdirname, mode)
commands += self.get_output_args(output)
commands.extend(self.get_compiler_args_for_mode(CompileCheckMode(mode)))

@ -48,9 +48,7 @@ def wrap_js_includes(args: T.List[str]) -> T.List[str]:
class EmscriptenMixin(Compiler):
def _get_compile_output(self, dirname: str, mode: CompileCheckMode) -> str:
# In pre-processor mode, the output is sent to stdout and discarded
if mode == CompileCheckMode.PREPROCESS:
return None
assert mode != CompileCheckMode.PREPROCESS, 'In pre-processor mode, the output is sent to stdout and discarded'
# Unlike sane toolchains, emcc infers the kind of output from its name.
# This is the only reason why this method is overridden; compiler tests
# do not work well with the default exe/obj suffices.

Loading…
Cancel
Save