From f287cac862d0f55778d75800058994068b3b8627 Mon Sep 17 00:00:00 2001 From: Tristan Partin Date: Wed, 14 Dec 2022 18:49:00 -0600 Subject: Deduplicate code in JNISystemDependency conditional --- mesonbuild/dependencies/dev.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/mesonbuild/dependencies/dev.py b/mesonbuild/dependencies/dev.py index 0c4690b47..448d68291 100644 --- a/mesonbuild/dependencies/dev.py +++ b/mesonbuild/dependencies/dev.py @@ -574,10 +574,10 @@ class JNISystemDependency(SystemDependency): return java_cpus.get(cpu, cpu) java_home_lib = self.java_home / 'jre' / 'lib' / cpu_translate(m.cpu_family) - java_home_lib_server = java_home_lib / "server" else: java_home_lib = self.java_home / 'lib' - java_home_lib_server = java_home_lib / "server" + + java_home_lib_server = java_home_lib / 'server' if 'jvm' in modules: jvm = self.clib_compiler.find_library('jvm', environment, extra_dirs=[str(java_home_lib_server)]) -- cgit v1.2.3 From 7254db36a7adfa3f5e3e6cbce5dc1e3037893eb9 Mon Sep 17 00:00:00 2001 From: Tristan Partin Date: Wed, 14 Dec 2022 19:00:52 -0600 Subject: Try to find the jni dependency when javac is a Darwin stub Darwin-based systems, at least macOS, provide various JDK executable stubs in /System/Library/Frameworks/JavaVM.framework/Versions/*/Commands. These stubs are placed in such a way that they break the heuristics of the JNI system dependency. If a javac being analyzed to find a Java home is a stub, use /usr/libexec/java_home. See https://stackoverflow.com/a/15133344/7572728 for more details. Closes #11173 --- mesonbuild/dependencies/dev.py | 36 +++++++++++++++++++++++++----------- test cases/java/9 jni/meson.build | 6 ++++++ 2 files changed, 31 insertions(+), 11 deletions(-) diff --git a/mesonbuild/dependencies/dev.py b/mesonbuild/dependencies/dev.py index 448d68291..732ac8c7c 100644 --- a/mesonbuild/dependencies/dev.py +++ b/mesonbuild/dependencies/dev.py @@ -22,6 +22,7 @@ import os import re import pathlib import shutil +import subprocess import typing as T from mesonbuild.interpreterbase.decorators import FeatureDeprecated @@ -546,6 +547,17 @@ class JNISystemDependency(SystemDependency): self.java_home = environment.properties[self.for_machine].get_java_home() if not self.java_home: self.java_home = pathlib.Path(shutil.which(self.javac.exelist[0])).resolve().parents[1] + if m.is_darwin(): + problem_java_prefix = pathlib.Path('/System/Library/Frameworks/JavaVM.framework/Versions') + if problem_java_prefix in self.java_home.parents: + res = subprocess.run(['/usr/libexec/java_home', '--failfast', '--arch', m.cpu_family], + stdout=subprocess.PIPE) + if res.returncode != 0: + log = mlog.error if self.required else mlog.debug + log('JAVA_HOME could not be discovered on the system. Please set it explicitly.') + self.is_found = False + return + self.java_home = pathlib.Path(res.stdout.decode().strip()) platform_include_dir = self.__machine_info_to_platform_include_dir(m) if platform_include_dir is None: @@ -563,17 +575,7 @@ class JNISystemDependency(SystemDependency): java_home_lib_server = java_home_lib else: if version_compare(self.version, '<= 1.8.0'): - # The JDK and Meson have a disagreement here, so translate it - # over. In the event more translation needs to be done, add to - # following dict. - def cpu_translate(cpu: str) -> str: - java_cpus = { - 'x86_64': 'amd64', - } - - return java_cpus.get(cpu, cpu) - - java_home_lib = self.java_home / 'jre' / 'lib' / cpu_translate(m.cpu_family) + java_home_lib = self.java_home / 'jre' / 'lib' / self.__cpu_translate(m.cpu_family) else: java_home_lib = self.java_home / 'lib' @@ -596,6 +598,18 @@ class JNISystemDependency(SystemDependency): self.is_found = True + @staticmethod + def __cpu_translate(cpu: str) -> str: + ''' + The JDK and Meson have a disagreement here, so translate it over. In the event more + translation needs to be done, add to following dict. + ''' + java_cpus = { + 'x86_64': 'amd64', + } + + return java_cpus.get(cpu, cpu) + @staticmethod def __machine_info_to_platform_include_dir(m: 'MachineInfo') -> T.Optional[str]: """Translates the machine information to the platform-dependent include directory diff --git a/test cases/java/9 jni/meson.build b/test cases/java/9 jni/meson.build index 90a8485e5..7a6816591 100644 --- a/test cases/java/9 jni/meson.build +++ b/test cases/java/9 jni/meson.build @@ -11,10 +11,16 @@ endif fs = import('fs') javamod = import('java') +cc = meson.get_compiler('c') java = find_program('java') jni_dep = dependency('jni', version : '>=1.8', modules: ['jvm', 'awt']) +# Assert that the header can actually be found with the dependency. +cc.has_header('jni.h', dependencies: [jni_dep]) +# Assert that the platform-specific include directory is included in the compiler arguments. +cc.has_header('jni_md.h', dependencies: [jni_dep]) + # generate native headers subdir('src') subdir('lib') -- cgit v1.2.3 From fb6fda385391ac5d030b4e642fc426ada5d80488 Mon Sep 17 00:00:00 2001 From: Tristan Partin Date: Thu, 15 Dec 2022 12:54:56 -0600 Subject: Change double quote doc comment to sinqle quote --- mesonbuild/dependencies/dev.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/mesonbuild/dependencies/dev.py b/mesonbuild/dependencies/dev.py index 732ac8c7c..cc0284272 100644 --- a/mesonbuild/dependencies/dev.py +++ b/mesonbuild/dependencies/dev.py @@ -612,12 +612,12 @@ class JNISystemDependency(SystemDependency): @staticmethod def __machine_info_to_platform_include_dir(m: 'MachineInfo') -> T.Optional[str]: - """Translates the machine information to the platform-dependent include directory + '''Translates the machine information to the platform-dependent include directory When inspecting a JDK release tarball or $JAVA_HOME, inside the `include/` directory is a platform-dependent directory that must be on the target's include path in addition to the parent `include/` directory. - """ + ''' if m.is_linux(): return 'linux' elif m.is_windows(): -- cgit v1.2.3 From 71cddebf2c6093fe52de01329847926801f87f35 Mon Sep 17 00:00:00 2001 From: Tristan Partin Date: Thu, 15 Dec 2022 20:36:43 -0600 Subject: Enable Java project tests on Darwim --- run_project_tests.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/run_project_tests.py b/run_project_tests.py index 47acb2169..ce913f951 100755 --- a/run_project_tests.py +++ b/run_project_tests.py @@ -1091,7 +1091,7 @@ def detect_tests_to_run(only: T.Dict[str, T.List[str]], use_tmp: bool) -> T.List TestCategory('platform-osx', 'osx', not mesonlib.is_osx()), TestCategory('platform-windows', 'windows', not mesonlib.is_windows() and not mesonlib.is_cygwin()), TestCategory('platform-linux', 'linuxlike', mesonlib.is_osx() or mesonlib.is_windows()), - TestCategory('java', 'java', backend is not Backend.ninja or mesonlib.is_osx() or not have_java()), + TestCategory('java', 'java', backend is not Backend.ninja or not have_java()), TestCategory('C#', 'csharp', skip_csharp(backend)), TestCategory('vala', 'vala', backend is not Backend.ninja or not shutil.which(os.environ.get('VALAC', 'valac'))), TestCategory('cython', 'cython', backend is not Backend.ninja or not shutil.which(os.environ.get('CYTHON', 'cython'))), -- cgit v1.2.3