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/java.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/java.py')
| -rw-r--r-- | mesonbuild/compilers/java.py | 40 |
1 files changed, 19 insertions, 21 deletions
diff --git a/mesonbuild/compilers/java.py b/mesonbuild/compilers/java.py index 47d2ac9cd..13e48475c 100644 --- a/mesonbuild/compilers/java.py +++ b/mesonbuild/compilers/java.py @@ -6,7 +6,6 @@ from __future__ import annotations import os import os.path import shutil -import subprocess import textwrap import typing as T @@ -72,33 +71,32 @@ class JavaCompiler(BasicLinkerIsCompilerMixin, Compiler): return parameter_list - def sanity_check(self, work_dir: str, environment: 'Environment') -> None: - src = 'SanityCheck.java' - obj = 'SanityCheck' - source_name = os.path.join(work_dir, src) - with open(source_name, 'w', encoding='utf-8') as ofile: - ofile.write(textwrap.dedent( - '''class SanityCheck { - public static void main(String[] args) { - int i; - } - } - ''')) - pc = subprocess.Popen(self.exelist + [src], cwd=work_dir) - pc.wait() - if pc.returncode != 0: - raise EnvironmentException(f'Java compiler {self.name_string()} cannot compile programs.') + def _sanity_check_filenames(self) -> T.Tuple[str, str]: + sup = super()._sanity_check_filenames() + return sup[0], 'SanityCheck' + + def _sanity_check_compile_args(self, env: Environment, sourcename: str, binname: str) -> T.List[str]: + return self.exelist + self.get_always_args() + [sourcename] + + def _sanity_check_run_with_exe_wrapper(self, env: Environment, command: T.List[str]) -> T.List[str]: 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) - else: + if runner is None: m = "Java Virtual Machine wasn't found, but it's needed by Meson. " \ "Please install a JRE.\nIf you have specific needs where this " \ "requirement doesn't make sense, please open a bug at " \ "https://github.com/mesonbuild/meson/issues/new and tell us " \ "all about it." raise EnvironmentException(m) + return [runner, '-cp', '.', os.path.basename(command[0])] + + def _sanity_check_source_code(self) -> str: + return textwrap.dedent( + '''class SanityCheck { + public static void main(String[] args) { + int i; + } + } + ''') def needs_static_linker(self) -> bool: return False |
