diff options
| author | Xavier Claessens <xavier.claessens@collabora.com> | 2023-11-03 15:12:24 -0400 |
|---|---|---|
| committer | Xavier Claessens <xclaesse@gmail.com> | 2024-03-15 11:38:54 -0400 |
| commit | f41a95ddf28317abf9b58f913e1650a006c26c76 (patch) | |
| tree | 75a72d2e57986a043b36a1000253438d96a3f078 /mesonbuild/compilers/compilers.py | |
| parent | 3afbe042afbdd48d73853b2087bb1d88a2afa753 (diff) | |
| download | meson-f41a95ddf28317abf9b58f913e1650a006c26c76.tar.gz | |
compilers: Every compiler can run code
Compiling and linking code is part of the Compiler base class, there is
no reason it cannot also run executables.
Diffstat (limited to 'mesonbuild/compilers/compilers.py')
| -rw-r--r-- | mesonbuild/compilers/compilers.py | 25 |
1 files changed, 23 insertions, 2 deletions
diff --git a/mesonbuild/compilers/compilers.py b/mesonbuild/compilers/compilers.py index 8bc1294f8..faa147ad7 100644 --- a/mesonbuild/compilers/compilers.py +++ b/mesonbuild/compilers/compilers.py @@ -623,10 +623,31 @@ class Compiler(HoldableObject, metaclass=abc.ABCMeta): dependencies: T.Optional[T.List['Dependency']] = None) -> T.Tuple[bool, bool]: raise EnvironmentException('Language %s does not support header symbol checks.' % self.get_display_language()) - def run(self, code: 'mesonlib.FileOrString', env: 'Environment', *, + def run(self, code: 'mesonlib.FileOrString', env: 'Environment', extra_args: T.Union[T.List[str], T.Callable[[CompileCheckMode], T.List[str]], None] = None, dependencies: T.Optional[T.List['Dependency']] = None) -> RunResult: - raise EnvironmentException('Language %s does not support run checks.' % self.get_display_language()) + need_exe_wrapper = env.need_exe_wrapper(self.for_machine) + if need_exe_wrapper and self.exe_wrapper is None: + raise CrossNoRunException('Can not run test applications in this cross environment.') + with self._build_wrapper(code, env, extra_args, dependencies, mode=CompileCheckMode.LINK, want_output=True) as p: + if p.returncode != 0: + mlog.debug(f'Could not compile test file {p.input_name}: {p.returncode}\n') + return RunResult(False) + if need_exe_wrapper: + cmdlist = self.exe_wrapper.get_command() + [p.output_name] + else: + cmdlist = [p.output_name] + try: + pe, so, se = mesonlib.Popen_safe(cmdlist) + except Exception as e: + mlog.debug(f'Could not run: {cmdlist} (error: {e})\n') + return RunResult(False) + + mlog.debug('Program stdout:\n') + mlog.debug(so) + mlog.debug('Program stderr:\n') + mlog.debug(se) + return RunResult(True, pe.returncode, so, se) # Caching run() in general seems too risky (no way to know what the program # depends on), but some callers know more about the programs they intend to |
