diff options
| author | Dylan Baker <dylan@pnwbakers.com> | 2025-07-03 15:38:32 -0700 |
|---|---|---|
| committer | Dylan Baker <dylan@pnwbakers.com> | 2025-10-06 09:03:07 -0700 |
| commit | 806289a5d27958a084bc6cba41b7cf9ccee4ecf4 (patch) | |
| tree | d6193d9aa67a6fb26e539d8b936f58aea19f2958 /mesonbuild/compilers/cs.py | |
| parent | be50d0e23737dc0fc5f074a291644d7fde39ef7b (diff) | |
| download | meson-806289a5d27958a084bc6cba41b7cf9ccee4ecf4.tar.gz | |
compilers: refactor sanity checking code
The goal is to reduce code duplication, and allow each language to
implement as little as possible to get good checking. The main
motivation is that half of the checks are fragile, as they add the work
directory to the paths of the generated files they want to use. This
works when run inside mesonmain because we always have an absolute build
directory, but when put into run_project_tests.py it doesn't work
because that gives a relative build directory.
Diffstat (limited to 'mesonbuild/compilers/cs.py')
| -rw-r--r-- | mesonbuild/compilers/cs.py | 34 |
1 files changed, 14 insertions, 20 deletions
diff --git a/mesonbuild/compilers/cs.py b/mesonbuild/compilers/cs.py index 4bbddeb20..e515c338f 100644 --- a/mesonbuild/compilers/cs.py +++ b/mesonbuild/compilers/cs.py @@ -3,11 +3,10 @@ from __future__ import annotations -import os.path, subprocess +import os.path import textwrap import typing as T -from ..mesonlib import EnvironmentException from ..linkers import RSPFileSyntax from .compilers import Compiler @@ -83,26 +82,21 @@ class CsCompiler(BasicLinkerIsCompilerMixin, Compiler): def get_pch_name(self, header_name: str) -> str: return '' - def sanity_check(self, work_dir: str, environment: 'Environment') -> None: - src = 'sanity.cs' - obj = 'sanity.exe' - source_name = os.path.join(work_dir, src) - with open(source_name, 'w', encoding='utf-8') as ofile: - ofile.write(textwrap.dedent(''' - public class Sanity { - static public void Main () { - } + def _sanity_check_source_code(self) -> str: + return textwrap.dedent(''' + public class Sanity { + static public void Main () { } - ''')) - pc = subprocess.Popen(self.exelist + self.get_always_args() + [src], cwd=work_dir) - pc.wait() - if pc.returncode != 0: - raise EnvironmentException('C# compiler %s cannot compile programs.' % self.name_string()) + } + ''') + + def _sanity_check_compile_args(self, env: Environment, sourcename: str, binname: str) -> T.List[str]: + return self.exelist + self.get_always_args() + [sourcename] + self.get_output_args(binname) + + def _sanity_check_run_with_exe_wrapper(self, env: Environment, command: T.List[str]) -> T.List[str]: if self.runner: - cmdlist = [self.runner, obj] - else: - cmdlist = [os.path.join(work_dir, obj)] - self.run_sanity_check(environment, cmdlist, work_dir, use_exe_wrapper_for_cross=False) + return [self.runner] + command + return command def needs_static_linker(self) -> bool: return False |
