diff options
| author | Dylan Baker <dylan@pnwbakers.com> | 2025-10-31 11:27:53 -0700 |
|---|---|---|
| committer | Dylan Baker <dylan@pnwbakers.com> | 2025-11-19 10:48:48 -0800 |
| commit | 8938f5efad47364da9e6234660562ae5a05f1c06 (patch) | |
| tree | 0f242235ed9c95f94be0605ef16273d256ce98cd | |
| parent | fc97e4f395e6ad551eb71b97b85df24302bcb7a4 (diff) | |
| download | meson-8938f5efad47364da9e6234660562ae5a05f1c06.tar.gz | |
compilers: Remove Environment parameter from Compiler.sanity_check
| -rw-r--r-- | mesonbuild/compilers/asm.py | 2 | ||||
| -rw-r--r-- | mesonbuild/compilers/c.py | 4 | ||||
| -rw-r--r-- | mesonbuild/compilers/compilers.py | 2 | ||||
| -rw-r--r-- | mesonbuild/compilers/cpp.py | 4 | ||||
| -rw-r--r-- | mesonbuild/compilers/cs.py | 2 | ||||
| -rw-r--r-- | mesonbuild/compilers/cuda.py | 6 | ||||
| -rw-r--r-- | mesonbuild/compilers/cython.py | 4 | ||||
| -rw-r--r-- | mesonbuild/compilers/d.py | 4 | ||||
| -rw-r--r-- | mesonbuild/compilers/detect.py | 2 | ||||
| -rw-r--r-- | mesonbuild/compilers/fortran.py | 4 | ||||
| -rw-r--r-- | mesonbuild/compilers/java.py | 2 | ||||
| -rw-r--r-- | mesonbuild/compilers/mixins/clike.py | 11 | ||||
| -rw-r--r-- | mesonbuild/compilers/objc.py | 4 | ||||
| -rw-r--r-- | mesonbuild/compilers/objcpp.py | 4 | ||||
| -rw-r--r-- | mesonbuild/compilers/rust.py | 2 | ||||
| -rw-r--r-- | mesonbuild/compilers/swift.py | 6 | ||||
| -rw-r--r-- | mesonbuild/compilers/vala.py | 8 | ||||
| -rw-r--r-- | mesonbuild/dependencies/base.py | 2 | ||||
| -rwxr-xr-x | run_project_tests.py | 2 | ||||
| -rw-r--r-- | unittests/allplatformstests.py | 2 |
20 files changed, 38 insertions, 39 deletions
diff --git a/mesonbuild/compilers/asm.py b/mesonbuild/compilers/asm.py index 54218eb0a..c298933a1 100644 --- a/mesonbuild/compilers/asm.py +++ b/mesonbuild/compilers/asm.py @@ -41,7 +41,7 @@ class ASMCompiler(Compiler): raise EnvironmentException(f'ASM Compiler {self.id} does not support building for {info.cpu_family} CPU family.') super().__init__(ccache, exelist, version, for_machine, env, linker, full_version) - def sanity_check(self, work_dir: str, environment: Environment) -> None: + def sanity_check(self, work_dir: str) -> None: return None diff --git a/mesonbuild/compilers/c.py b/mesonbuild/compilers/c.py index 51db061ae..8e084e62c 100644 --- a/mesonbuild/compilers/c.py +++ b/mesonbuild/compilers/c.py @@ -74,9 +74,9 @@ class CCompiler(CLikeCompiler, Compiler): def get_no_stdinc_args(self) -> T.List[str]: return ['-nostdinc'] - def sanity_check(self, work_dir: str, environment: 'Environment') -> None: + def sanity_check(self, work_dir: str) -> None: code = 'int main(void) { int class=0; return class; }\n' - return self._sanity_check_impl(work_dir, environment, 'sanitycheckc.c', code) + return self._sanity_check_impl(work_dir, 'sanitycheckc.c', code) def has_header_symbol(self, hname: str, symbol: str, prefix: str, env: 'Environment', *, diff --git a/mesonbuild/compilers/compilers.py b/mesonbuild/compilers/compilers.py index 73a623c9a..5dc53a86a 100644 --- a/mesonbuild/compilers/compilers.py +++ b/mesonbuild/compilers/compilers.py @@ -1213,7 +1213,7 @@ class Compiler(HoldableObject, metaclass=abc.ABCMeta): return ' '.join(self.exelist) @abc.abstractmethod - def sanity_check(self, work_dir: str, environment: 'Environment') -> None: + def sanity_check(self, work_dir: str) -> None: """Check that this compiler actually works. This should provide a simple compile/link test. Something as simple as: diff --git a/mesonbuild/compilers/cpp.py b/mesonbuild/compilers/cpp.py index f3301a963..eef39a75d 100644 --- a/mesonbuild/compilers/cpp.py +++ b/mesonbuild/compilers/cpp.py @@ -84,9 +84,9 @@ class CPPCompiler(CLikeCompiler, Compiler): def get_no_stdlib_link_args(self) -> T.List[str]: return ['-nostdlib++'] - def sanity_check(self, work_dir: str, environment: 'Environment') -> None: + def sanity_check(self, work_dir: str) -> None: code = 'class breakCCompiler;int main(void) { return 0; }\n' - return self._sanity_check_impl(work_dir, environment, 'sanitycheckcpp.cc', code) + return self._sanity_check_impl(work_dir, 'sanitycheckcpp.cc', code) def get_compiler_check_args(self, mode: CompileCheckMode) -> T.List[str]: # -fpermissive allows non-conforming code to compile which is necessary diff --git a/mesonbuild/compilers/cs.py b/mesonbuild/compilers/cs.py index ef3dd62cf..cacd9ee47 100644 --- a/mesonbuild/compilers/cs.py +++ b/mesonbuild/compilers/cs.py @@ -82,7 +82,7 @@ class CsCompiler(BasicLinkerIsCompilerMixin, Compiler): def get_pch_name(self, header_name: str) -> str: return '' - def sanity_check(self, work_dir: str, environment: 'Environment') -> None: + def sanity_check(self, work_dir: str) -> None: src = 'sanity.cs' obj = 'sanity.exe' source_name = os.path.join(work_dir, src) diff --git a/mesonbuild/compilers/cuda.py b/mesonbuild/compilers/cuda.py index 68df39bc3..129b2ee14 100644 --- a/mesonbuild/compilers/cuda.py +++ b/mesonbuild/compilers/cuda.py @@ -497,7 +497,7 @@ class CudaCompiler(Compiler): def thread_link_flags(self, environment: 'Environment') -> T.List[str]: return self._to_host_flags(self.host_compiler.thread_link_flags(environment), Phase.LINKER) - def sanity_check(self, work_dir: str, env: 'Environment') -> None: + def sanity_check(self, work_dir: str) -> None: mlog.debug('Sanity testing ' + self.get_display_language() + ' compiler:', ' '.join(self.exelist)) mlog.debug('Is cross compiler: %s.' % str(self.is_cross)) @@ -550,10 +550,10 @@ class CudaCompiler(Compiler): # Use the -ccbin option, if available, even during sanity checking. # Otherwise, on systems where CUDA does not support the default compiler, # NVCC becomes unusable. - flags += self.get_ccbin_args(None, env, '') + flags += self.get_ccbin_args(None, self.environment, '') # If cross-compiling, we can't run the sanity check, only compile it. - if self.is_cross and not env.has_exe_wrapper(): + if self.is_cross and not self.environment.has_exe_wrapper(): # Linking cross built apps is painful. You can't really # tell if you should use -nostdlib or not and for example # on OSX the compiler binary is the same but you need diff --git a/mesonbuild/compilers/cython.py b/mesonbuild/compilers/cython.py index 2eced65f9..960944846 100644 --- a/mesonbuild/compilers/cython.py +++ b/mesonbuild/compilers/cython.py @@ -49,9 +49,9 @@ class CythonCompiler(Compiler): def get_depfile_suffix(self) -> str: return 'dep' - def sanity_check(self, work_dir: str, environment: 'Environment') -> None: + def sanity_check(self, work_dir: str) -> None: code = 'print("hello world")' - with self.cached_compile(code, environment.coredata) as p: + with self.cached_compile(code, self.environment.coredata) as p: if p.returncode != 0: raise EnvironmentException(f'Cython compiler {self.id!r} cannot compile programs') diff --git a/mesonbuild/compilers/d.py b/mesonbuild/compilers/d.py index 761ed5fc3..cfb1120a5 100644 --- a/mesonbuild/compilers/d.py +++ b/mesonbuild/compilers/d.py @@ -437,7 +437,7 @@ class DCompiler(Compiler): full_version=full_version) self.arch = arch - def sanity_check(self, work_dir: str, environment: 'Environment') -> None: + def sanity_check(self, work_dir: str) -> 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: @@ -446,7 +446,7 @@ class DCompiler(Compiler): 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(): + if self.is_cross and not self.environment.has_exe_wrapper(): compile_cmdlist += self.get_compile_only_args() pc = subprocess.Popen(compile_cmdlist, cwd=work_dir) diff --git a/mesonbuild/compilers/detect.py b/mesonbuild/compilers/detect.py index d005b6817..db2bdf6ab 100644 --- a/mesonbuild/compilers/detect.py +++ b/mesonbuild/compilers/detect.py @@ -112,7 +112,7 @@ def detect_compiler_for(env: 'Environment', lang: str, for_machine: MachineChoic assert comp.for_machine == for_machine env.coredata.process_compiler_options(lang, comp, subproject) if not skip_sanity_check: - comp.sanity_check(env.get_scratch_dir(), env) + comp.sanity_check(env.get_scratch_dir()) env.coredata.compilers[comp.for_machine][lang] = comp return comp diff --git a/mesonbuild/compilers/fortran.py b/mesonbuild/compilers/fortran.py index 2a3521f35..c5e8dc549 100644 --- a/mesonbuild/compilers/fortran.py +++ b/mesonbuild/compilers/fortran.py @@ -59,10 +59,10 @@ class FortranCompiler(CLikeCompiler, Compiler): largs = env.coredata.get_external_link_args(self.for_machine, self.language) return cargs, largs - def sanity_check(self, work_dir: str, environment: 'Environment') -> None: + def sanity_check(self, work_dir: str) -> None: source_name = 'sanitycheckf.f' code = ' PROGRAM MAIN\n PRINT *, "Fortran compilation is working."\n END\n' - return self._sanity_check_impl(work_dir, environment, source_name, code) + return self._sanity_check_impl(work_dir, source_name, code) def get_optimization_args(self, optimization_level: str) -> T.List[str]: return gnu_optimization_args[optimization_level] diff --git a/mesonbuild/compilers/java.py b/mesonbuild/compilers/java.py index f1b84cd85..f60bc6bbb 100644 --- a/mesonbuild/compilers/java.py +++ b/mesonbuild/compilers/java.py @@ -71,7 +71,7 @@ class JavaCompiler(BasicLinkerIsCompilerMixin, Compiler): return parameter_list - def sanity_check(self, work_dir: str, environment: 'Environment') -> None: + def sanity_check(self, work_dir: str) -> None: src = 'SanityCheck.java' obj = 'SanityCheck' source_name = os.path.join(work_dir, src) diff --git a/mesonbuild/compilers/mixins/clike.py b/mesonbuild/compilers/mixins/clike.py index b70ba8324..17da834fa 100644 --- a/mesonbuild/compilers/mixins/clike.py +++ b/mesonbuild/compilers/mixins/clike.py @@ -268,8 +268,7 @@ class CLikeCompiler(Compiler): def gen_import_library_args(self, implibname: str) -> T.List[str]: return self.linker.import_library_args(implibname) - def _sanity_check_impl(self, work_dir: str, environment: 'Environment', - sname: str, code: str) -> None: + def _sanity_check_impl(self, work_dir: str, sname: str, code: str) -> None: mlog.debug('Sanity testing ' + self.get_display_language() + ' compiler:', mesonlib.join_args(self.exelist)) mlog.debug(f'Is cross compiler: {self.is_cross!s}.') @@ -278,14 +277,14 @@ class CLikeCompiler(Compiler): mode = CompileCheckMode.LINK if self.is_cross: binname += '_cross' - if not environment.has_exe_wrapper(): + if not self.environment.has_exe_wrapper(): # Linking cross built C/C++ apps is painful. You can't really # tell if you should use -nostdlib or not and for example # on OSX the compiler binary is the same but you need # a ton of compiler flags to differentiate between # arm and x86_64. So just compile. mode = CompileCheckMode.COMPILE - cargs, largs = self._get_basic_compiler_args(environment, mode) + cargs, largs = self._get_basic_compiler_args(self.environment, mode) extra_flags = cargs + self.linker_to_compiler_args(largs) # Is a valid executable output for all toolchains and platforms @@ -309,9 +308,9 @@ class CLikeCompiler(Compiler): raise mesonlib.EnvironmentException(f'Compiler {self.name_string()} cannot compile programs.') self.run_sanity_check([binary_name], work_dir) - def sanity_check(self, work_dir: str, environment: 'Environment') -> None: + def sanity_check(self, work_dir: str) -> None: code = 'int main(void) { int class=0; return class; }\n' - return self._sanity_check_impl(work_dir, environment, 'sanitycheckc.c', code) + return self._sanity_check_impl(work_dir, 'sanitycheckc.c', code) def check_header(self, hname: str, prefix: str, env: 'Environment', *, extra_args: T.Union[None, T.List[str], T.Callable[['CompileCheckMode'], T.List[str]]] = None, diff --git a/mesonbuild/compilers/objc.py b/mesonbuild/compilers/objc.py index 9de945728..e32b71d60 100644 --- a/mesonbuild/compilers/objc.py +++ b/mesonbuild/compilers/objc.py @@ -47,9 +47,9 @@ class ObjCCompiler(CLikeCompiler, Compiler): def get_display_language() -> str: return 'Objective-C' - def sanity_check(self, work_dir: str, environment: 'Environment') -> None: + def sanity_check(self, work_dir: str) -> None: code = '#import<stddef.h>\nint main(void) { return 0; }\n' - return self._sanity_check_impl(work_dir, environment, 'sanitycheckobjc.m', code) + return self._sanity_check_impl(work_dir, 'sanitycheckobjc.m', code) def form_compileropt_key(self, basename: str) -> OptionKey: if basename == 'std': diff --git a/mesonbuild/compilers/objcpp.py b/mesonbuild/compilers/objcpp.py index 6a4f45e25..ae3750335 100644 --- a/mesonbuild/compilers/objcpp.py +++ b/mesonbuild/compilers/objcpp.py @@ -48,9 +48,9 @@ class ObjCPPCompiler(CLikeCompiler, Compiler): def get_display_language() -> str: return 'Objective-C++' - def sanity_check(self, work_dir: str, environment: 'Environment') -> None: + def sanity_check(self, work_dir: str) -> None: code = '#import<stdio.h>\nclass MyClass;int main(void) { return 0; }\n' - return self._sanity_check_impl(work_dir, environment, 'sanitycheckobjcpp.mm', code) + return self._sanity_check_impl(work_dir, 'sanitycheckobjcpp.mm', code) def get_options(self) -> MutableKeyedOptionDictType: opts = super().get_options() diff --git a/mesonbuild/compilers/rust.py b/mesonbuild/compilers/rust.py index 8068865e2..f7e392a57 100644 --- a/mesonbuild/compilers/rust.py +++ b/mesonbuild/compilers/rust.py @@ -115,7 +115,7 @@ class RustCompiler(Compiler): def needs_static_linker(self) -> bool: return False - def sanity_check(self, work_dir: str, environment: Environment) -> None: + def sanity_check(self, work_dir: str) -> None: source_name = os.path.join(work_dir, 'sanity.rs') output_name = os.path.join(work_dir, 'rusttest.exe') cmdlist = self.exelist.copy() diff --git a/mesonbuild/compilers/swift.py b/mesonbuild/compilers/swift.py index 26e2daf19..ee908a8d7 100644 --- a/mesonbuild/compilers/swift.py +++ b/mesonbuild/compilers/swift.py @@ -175,16 +175,16 @@ class SwiftCompiler(Compiler): return parameter_list - def sanity_check(self, work_dir: str, environment: 'Environment') -> None: + def sanity_check(self, work_dir: str) -> None: src = 'swifttest.swift' source_name = os.path.join(work_dir, src) output_name = os.path.join(work_dir, 'swifttest') extra_flags: T.List[str] = [] - extra_flags += environment.coredata.get_external_args(self.for_machine, self.language) + extra_flags += self.environment.coredata.get_external_args(self.for_machine, self.language) if self.is_cross: extra_flags += self.get_compile_only_args() else: - extra_flags += environment.coredata.get_external_link_args(self.for_machine, self.language) + extra_flags += self.environment.coredata.get_external_link_args(self.for_machine, self.language) with open(source_name, 'w', encoding='utf-8') as ofile: ofile.write('''print("Swift compilation is working.") ''') diff --git a/mesonbuild/compilers/vala.py b/mesonbuild/compilers/vala.py index ccdd77a3f..6968cb9d5 100644 --- a/mesonbuild/compilers/vala.py +++ b/mesonbuild/compilers/vala.py @@ -106,15 +106,15 @@ class ValaCompiler(Compiler): return parameter_list - def sanity_check(self, work_dir: str, environment: 'Environment') -> None: + def sanity_check(self, work_dir: str) -> None: code = 'class MesonSanityCheck : Object { }' extra_flags: T.List[str] = [] - extra_flags += environment.coredata.get_external_args(self.for_machine, self.language) + extra_flags += self.environment.coredata.get_external_args(self.for_machine, self.language) if self.is_cross: extra_flags += self.get_compile_only_args() else: - extra_flags += environment.coredata.get_external_link_args(self.for_machine, self.language) - with self.cached_compile(code, environment.coredata, extra_args=extra_flags, mode=CompileCheckMode.COMPILE) as p: + extra_flags += self.environment.coredata.get_external_link_args(self.for_machine, self.language) + with self.cached_compile(code, self.environment.coredata, extra_args=extra_flags, mode=CompileCheckMode.COMPILE) as p: if p.returncode != 0: msg = f'Vala compiler {self.name_string()!r} cannot compile programs' raise EnvironmentException(msg) diff --git a/mesonbuild/dependencies/base.py b/mesonbuild/dependencies/base.py index c515e364c..4536746d9 100644 --- a/mesonbuild/dependencies/base.py +++ b/mesonbuild/dependencies/base.py @@ -93,7 +93,7 @@ class MissingCompiler(_MissingCompilerBase): def get_output_args(self, outputname: str) -> T.List[str]: return [] - def sanity_check(self, work_dir: str, environment: 'Environment') -> None: + def sanity_check(self, work_dir: str) -> None: return None def __getattr__(self, item: str) -> T.Any: diff --git a/run_project_tests.py b/run_project_tests.py index c92df2b9f..62fe73ac3 100755 --- a/run_project_tests.py +++ b/run_project_tests.py @@ -999,7 +999,7 @@ def have_working_compiler(lang: str, use_tmp: bool) -> bool: return False env.coredata.process_compiler_options(lang, compiler, '') try: - compiler.sanity_check(env.get_scratch_dir(), env) + compiler.sanity_check(env.get_scratch_dir()) except mesonlib.MesonException: return False return True diff --git a/unittests/allplatformstests.py b/unittests/allplatformstests.py index d1e5a554d..3f78c72b4 100644 --- a/unittests/allplatformstests.py +++ b/unittests/allplatformstests.py @@ -2513,7 +2513,7 @@ class AllPlatformTests(BasePlatformTests): try: comp = detect_compiler_for(env, l, MachineChoice.HOST, True, '') with tempfile.TemporaryDirectory() as d: - comp.sanity_check(d, env) + comp.sanity_check(d) langs.append(l) except EnvironmentException: pass |
