summaryrefslogtreecommitdiff
path: root/mesonbuild/compilers/d.py
diff options
context:
space:
mode:
authorDylan Baker <dylan@pnwbakers.com>2025-10-06 10:21:07 -0700
committerDylan Baker <dylan@pnwbakers.com>2025-10-06 10:22:41 -0700
commita6af0ad50373324ec9fe569e8315b03439491865 (patch)
treeed221189af614ce578190dfb51193e1efcb72b17 /mesonbuild/compilers/d.py
parent6c5a88632f1d3319124d03eab596d57416ef16c6 (diff)
downloadmeson-a6af0ad50373324ec9fe569e8315b03439491865.tar.gz
Revert "compilers: refactor sanity checking code"
This reverts commit 806289a5d27958a084bc6cba41b7cf9ccee4ecf4.
Diffstat (limited to 'mesonbuild/compilers/d.py')
-rw-r--r--mesonbuild/compilers/d.py22
1 files changed, 18 insertions, 4 deletions
diff --git a/mesonbuild/compilers/d.py b/mesonbuild/compilers/d.py
index 4df8f6570..9f662add3 100644
--- a/mesonbuild/compilers/d.py
+++ b/mesonbuild/compilers/d.py
@@ -5,6 +5,7 @@ from __future__ import annotations
import os.path
import re
+import subprocess
import typing as T
from .. import mesonlib
@@ -437,11 +438,24 @@ class DCompiler(Compiler):
full_version=full_version, is_cross=is_cross)
self.arch = arch
- def _sanity_check_source_code(self) -> str:
- return 'void main() { }'
+ 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_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]
+ 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 needs_static_linker(self) -> bool:
return True