Repository: mesonbuild/meson

Issue:
Meson 0.43 module java.py class JavaCompiler is missing needed methods
The JavaCompiler class appears to have fallen behind the times, so that some needed methods are missing. I have not done any kind of through review of what it would take to get JavaCompiler up to date. By simply working the failure symptoms, I found that for my project, adding the following methods,
along with the changes from Issue #2569 and Issue #2570, was sufficient to build a simple Java 9 project with Meson 0.43 and Ninja:

>     def get_warn_args(self, level):
>         return ['-Xlint:all']
>
>     def get_no_warn_args(self):
>         return ['-Xlint:none']
>
>     def depfile_for_object(self, objfile):
>         return objfile + '.' + self.get_depfile_suffix()
>
>     def get_depfile_suffix(self):
>         return 'd'



Discussion:
Could you please open a PR with these changes and also add some tests so this doesn't break again?
AFAICT, the depfile stuff is irrelevant since we don't try to call depfile methods for Java.

The warn_args thing seems reasonable.

@tristan957 you've been using Java recently, maybe you'd like to take a look?
I've not been using Java in recent years. If I recall correctly, my
original issue was that new prerelease versions of OpenJDK had unusual
version strings with no .*  minor version. For example "javac 11-ea", which
search_version() doesn't allow.  As a sanity check you might want to test
if meson's logic can at least handle those end cases without aborting.

Thanks for asking.

- Ron
Still retired and still enjoying it!

On Thu, Aug 25, 2022 at 1:28 AM Eli Schwartz ***@***.***>
wrote:

> AFAICT, the depfile stuff is irrelevant since we don't try to call depfile
> methods for Java.
>
> The warn_args thing seems reasonable.
>
> @tristan957 <https://github.com/tristan957> you've been using Java
> recently, maybe you'd like to take a look?
>
> —
> Reply to this email directly, view it on GitHub
> <https://github.com/mesonbuild/meson/issues/2571#issuecomment-1226831342>,
> or unsubscribe
> <https://github.com/notifications/unsubscribe-auth/AH3BRLOSSH76PYRHJ4MPML3V24HBZANCNFSM4EB7ZQKA>
> .
> You are receiving this because you authored the thread.Message ID:
> ***@***.***>
>


-- 
James Ronald Lovell ***@***.***>
Huntsville, AL, USA

I have this on my list of things to look at for 0.64. Obviously, the more Java can integrate with Meson, the better.
Enjoy retirement Ron :)

Resolving patch:
diff --git a/mesonbuild/compilers/java.py b/mesonbuild/compilers/java.py
--- a/mesonbuild/compilers/java.py
+++ b/mesonbuild/compilers/java.py
@@ -34,11 +34,21 @@ class JavaCompiler(BasicLinkerIsCompilerMixin, Compiler):
     language = 'java'
     id = 'unknown'
 
+    _WARNING_LEVELS: T.Dict[str, T.List[str]] = {
+        '0': ['-nowarn'],
+        '1': ['-Xlint:all'],
+        '2': ['-Xlint:all', '-Xdoclint:all'],
+        '3': ['-Xlint:all', '-Xdoclint:all'],
+    }
+
     def __init__(self, exelist: T.List[str], version: str, for_machine: MachineChoice,
                  info: 'MachineInfo', full_version: T.Optional[str] = None):
         super().__init__(exelist, version, for_machine, info, full_version=full_version)
         self.javarunner = 'java'
 
+    def get_warn_args(self, level: str) -> T.List[str]:
+        return self._WARNING_LEVELS[level]
+
     def get_werror_args(self) -> T.List[str]:
         return ['-Werror']
 
@@ -87,14 +97,14 @@ def sanity_check(self, work_dir: str, environment: 'Environment') -> None:
         pc = subprocess.Popen(self.exelist + [src], cwd=work_dir)
         pc.wait()
         if pc.returncode != 0:
-            raise EnvironmentException('Java compiler %s can not compile programs.' % self.name_string())
+            raise EnvironmentException(f'Java compiler {self.name_string()} can not compile programs.')
         runner = shutil.which(self.javarunner)
         if runner:
             cmdlist = [runner, obj]
             pe = subprocess.Popen(cmdlist, cwd=work_dir)
             pe.wait()
             if pe.returncode != 0:
-                raise EnvironmentException('Executables created by Java compiler %s are not runnable.' % self.name_string())
+                raise EnvironmentException(f'Executables created by Java compiler {self.name_string()} are not runnable.')
         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 " \
diff --git a/mesonbuild/compilers/mixins/islinker.py b/mesonbuild/compilers/mixins/islinker.py
--- a/mesonbuild/compilers/mixins/islinker.py
+++ b/mesonbuild/compilers/mixins/islinker.py
@@ -58,7 +58,7 @@ def can_linker_accept_rsp(self) -> bool:
     def get_linker_exelist(self) -> T.List[str]:
         return self.exelist.copy()
 
-    def get_linker_output_args(self, output: str) -> T.List[str]:
+    def get_linker_output_args(self, outputname: str) -> T.List[str]:
         return []
 
     def get_linker_always_args(self) -> T.List[str]:
@@ -119,7 +119,7 @@ def get_asneeded_args(self) -> T.List[str]:
     def get_buildtype_linker_args(self, buildtype: str) -> T.List[str]:
         return []
 
-    def get_link_debugfile_name(self, target: str) -> str:
+    def get_link_debugfile_name(self, targetfile: str) -> str:
         return ''
 
     def thread_flags(self, env: 'Environment') -> T.List[str]:


Test patch: