summaryrefslogtreecommitdiff
path: root/mesonbuild/compilers/d.py
diff options
context:
space:
mode:
authorDylan Baker <dylan@pnwbakers.com>2025-07-03 15:38:32 -0700
committerDylan Baker <dylan@pnwbakers.com>2025-10-06 09:03:07 -0700
commit806289a5d27958a084bc6cba41b7cf9ccee4ecf4 (patch)
treed6193d9aa67a6fb26e539d8b936f58aea19f2958 /mesonbuild/compilers/d.py
parentbe50d0e23737dc0fc5f074a291644d7fde39ef7b (diff)
downloadmeson-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/d.py')
-rw-r--r--mesonbuild/compilers/d.py22
1 files changed, 4 insertions, 18 deletions
diff --git a/mesonbuild/compilers/d.py b/mesonbuild/compilers/d.py
index 9f662add3..4df8f6570 100644
--- a/mesonbuild/compilers/d.py
+++ b/mesonbuild/compilers/d.py
@@ -5,7 +5,6 @@ from __future__ import annotations
import os.path
import re
-import subprocess
import typing as T
from .. import mesonlib
@@ -438,24 +437,11 @@ class DCompiler(Compiler):
full_version=full_version, is_cross=is_cross)
self.arch = arch
- def sanity_check(self, work_dir: str, environment: 'Environment') -> None:
- source_name = os.path.join(work_dir, 'sanity.d')
- output_name = os.path.join(work_dir, 'dtest')
- with open(source_name, 'w', encoding='utf-8') as ofile:
- ofile.write('''void main() { }''')
+ def _sanity_check_source_code(self) -> str:
+ return 'void main() { }'
- compile_cmdlist = self.exelist + self.get_output_args(output_name) + self._get_target_arch_args() + [source_name]
-
- # If cross-compiling, we can't run the sanity check, only compile it.
- if self.is_cross and not environment.has_exe_wrapper():
- compile_cmdlist += self.get_compile_only_args()
-
- pc = subprocess.Popen(compile_cmdlist, cwd=work_dir)
- pc.wait()
- if pc.returncode != 0:
- raise EnvironmentException('D compiler %s cannot compile programs.' % self.name_string())
-
- stdo, stde = self.run_sanity_check(environment, [output_name], work_dir)
+ def _sanity_check_compile_args(self, env: Environment, sourcename: str, binname: str) -> T.List[str]:
+ return self.exelist + self.get_output_args(binname) + self._get_target_arch_args() + [sourcename]
def needs_static_linker(self) -> bool:
return True