compilers: Remove Environment parameter from Compiler.run_sanity_check

This commit is contained in:
Dylan Baker
2025-10-31 11:20:09 -07:00
parent ae56005bbd
commit fc97e4f395
8 changed files with 10 additions and 10 deletions

View File

@@ -1223,13 +1223,13 @@ class Compiler(HoldableObject, metaclass=abc.ABCMeta):
is good enough here.
"""
def run_sanity_check(self, environment: Environment, cmdlist: T.List[str], work_dir: str, use_exe_wrapper_for_cross: bool = True) -> T.Tuple[str, str]:
def run_sanity_check(self, cmdlist: T.List[str], work_dir: str, use_exe_wrapper_for_cross: bool = True) -> T.Tuple[str, str]:
# Run sanity check
if self.is_cross and use_exe_wrapper_for_cross:
if not environment.has_exe_wrapper():
if not self.environment.has_exe_wrapper():
# Can't check if the binaries run so we have to assume they do
return ('', '')
cmdlist = environment.exe_wrapper.get_command() + cmdlist
cmdlist = self.environment.exe_wrapper.get_command() + cmdlist
mlog.debug('Running test binary command: ', mesonlib.join_args(cmdlist))
try:
pe, stdo, stde = Popen_safe_logged(cmdlist, 'Sanity check', cwd=work_dir)

View File

@@ -101,7 +101,7 @@ class CsCompiler(BasicLinkerIsCompilerMixin, Compiler):
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)
self.run_sanity_check(cmdlist, work_dir, use_exe_wrapper_for_cross=False)
def needs_static_linker(self) -> bool:
return False

View File

@@ -580,7 +580,7 @@ class CudaCompiler(Compiler):
cmdlist = self.exelist + ['--run', f'"{binary_name}"']
try:
stdo, stde = self.run_sanity_check(env, cmdlist, work_dir)
stdo, stde = self.run_sanity_check(cmdlist, work_dir)
except EnvironmentException:
raise EnvironmentException(f'Executables created by {self.language} compiler {self.name_string()} are not runnable.')

View File

@@ -454,7 +454,7 @@ class DCompiler(Compiler):
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)
stdo, stde = self.run_sanity_check([output_name], work_dir)
def needs_static_linker(self) -> bool:
return True

View File

@@ -90,7 +90,7 @@ class JavaCompiler(BasicLinkerIsCompilerMixin, Compiler):
runner = shutil.which(self.javarunner)
if runner:
cmdlist = [runner, '-cp', '.', obj]
self.run_sanity_check(environment, cmdlist, work_dir, use_exe_wrapper_for_cross=False)
self.run_sanity_check(cmdlist, work_dir, use_exe_wrapper_for_cross=False)
else:
m = "Java Virtual Machine wasn't found, but it's needed by Meson. " \
"Please install a JRE.\nIf you have specific needs where this " \

View File

@@ -307,7 +307,7 @@ class CLikeCompiler(Compiler):
mlog.debug('-----')
if pc.returncode != 0:
raise mesonlib.EnvironmentException(f'Compiler {self.name_string()} cannot compile programs.')
self.run_sanity_check(environment, [binary_name], work_dir)
self.run_sanity_check([binary_name], work_dir)
def sanity_check(self, work_dir: str, environment: 'Environment') -> None:
code = 'int main(void) { int class=0; return class; }\n'

View File

@@ -149,7 +149,7 @@ class RustCompiler(Compiler):
if pc.returncode != 0:
raise EnvironmentException(f'Rust compiler {self.name_string()} cannot compile programs.')
self._native_static_libs(work_dir, source_name)
self.run_sanity_check(environment, [output_name], work_dir)
self.run_sanity_check([output_name], work_dir)
# Check if we are allowed to use nightly features.
# This is done here because it's the only place we have access to
# environment object, and sanity_check() is called after the compiler

View File

@@ -190,7 +190,7 @@ class SwiftCompiler(Compiler):
''')
pc = subprocess.Popen(self.exelist + extra_flags + ['-emit-executable', '-o', output_name, src], cwd=work_dir)
pc.wait()
self.run_sanity_check(environment, [output_name], work_dir)
self.run_sanity_check([output_name], work_dir)
def get_debug_args(self, is_debug: bool) -> T.List[str]:
return clike_debug_args[is_debug]