Rename JDK system dep to JNI

JNI is a more apt name because it currently only supports the JNI. I
also believe that CMake uses the terminology JNI here as well.

JNI is currently the only way to interact with the JVM through native
code, but there is a project called "Project Panama" which aims to be
another way for native code to interact with the JVM.
pull/10049/head
Tristan Partin 3 years ago committed by Eli Schwartz
parent f9bfeb2add
commit 96b2469544
  1. 26
      docs/markdown/Dependencies.md
  2. 4
      docs/markdown/Release-notes-for-0.58.0.md
  3. 6
      docs/markdown/snippets/jdk-renamed-to-jni.md
  4. 3
      mesonbuild/dependencies/__init__.py
  5. 21
      mesonbuild/dependencies/dev.py
  6. 9
      test cases/java/9 jdk/lib/com_mesonbuild_JdkTest.c
  7. 18
      test cases/java/9 jdk/lib/meson.build
  8. 17
      test cases/java/9 jdk/src/meson.build
  9. 9
      test cases/java/9 jni/lib/com_mesonbuild_JniTest.c
  10. 18
      test cases/java/9 jni/lib/meson.build
  11. 0
      test cases/java/9 jni/lib/native.c
  12. 6
      test cases/java/9 jni/meson.build
  13. 8
      test cases/java/9 jni/src/com/mesonbuild/JniTest.java
  14. 2
      test cases/java/9 jni/src/com/mesonbuild/meson.build
  15. 17
      test cases/java/9 jni/src/meson.build

@ -486,17 +486,31 @@ instead.
## JDK
*(added 0.58.0)*
*(deprecated 0.62.0)*
Provides access to compiling with the Java Native Interface (JNI). Lookup is
entirely dependent on the `target_machine` Java compiler. In a
cross-compilation, remember to override the Java compiler in order to add the
correct flags. The `version` keyword is compared against the version of the
Java compiler. No other `dependency()` keywords are respected.
Deprecated name for JNI. `dependency('jdk')` instead of `dependency('jni')`.
## JNI
*(added 0.62.0)*
Provides access to compiling with the Java Native Interface (JNI). The lookup
will first check if `JAVA_HOME` is set in the environment, and if not will use
the resolved path of `javac`. Systems will usually link your preferred JDK to
well known paths like `/usr/bin/javac` on Linux for instance. Using the path
from `JAVA_HOME` or the resolved `javac`, this dependency will place the JDK
installation's `include` directory and its platform-dependent subdirectory on
the compiler's include path.
```meson
dep = dependency('jdk', version: '>= 1.8.0')
dep = dependency('jni', version: '>= 1.8.0')
```
**Note**: Due to usage of a resolved path, upgrading the JDK may cause the
various headers to not be found. In that case, please reconfigure the build
directory. One workaround is to explicitly set `JAVA_HOME` instead of relying on
the fallback `javac` resolved path behavior.
## libgcrypt
*(added 0.49.0)*

@ -279,7 +279,7 @@ It is now allowed to pass libraries generated by a `custom_target()` to
pkg-config file generator. The output filename must have a known library extension
such as `.a`, `.so`, etc.
## JDK System Dependency
## JNI System Dependency
When building projects such as those interacting with the JNI, you need access
to a few header files located in a Java installation. This system dependency
@ -289,7 +289,7 @@ your system is a located in the `bin` directory of a Java installation. Note:
symlinks are resolved.
```meson
jdk = dependency('jdk', version : '>=1.8')
jni_dep = dependency('jni', version : '>=1.8')
```
Currently this system dependency only works on `linux`, `win32`, and `darwin`.

@ -0,0 +1,6 @@
## JDK System Dependency Renamed from `jdk` to `jni`
The JDK system dependency is useful for creating native Java modules using the
JNI. Since the purpose is to find the JNI, it has been decided that a better
name is in fact "jni". Use of `dependency('jdk')` should be replaced with
`dependency('jni')`.

@ -27,7 +27,7 @@ from .pkgconfig import PkgConfigDependency
from .factory import DependencyFactory
from .detect import find_external_dependency, get_dep_identifier, packages, _packages_accept_language
from .dev import (
ValgrindDependency, JDKSystemDependency, gmock_factory, gtest_factory,
ValgrindDependency, JNISystemDependency, JDKSystemDependency, gmock_factory, gtest_factory,
llvm_factory, zlib_factory)
from .coarrays import coarray_factory
from .mpi import mpi_factory
@ -229,6 +229,7 @@ packages.update({
'llvm': llvm_factory,
'valgrind': ValgrindDependency,
'zlib': zlib_factory,
'jni': JNISystemDependency,
'jdk': JDKSystemDependency,
'boost': BoostDependency,

@ -22,6 +22,8 @@ import pathlib
import shutil
import typing as T
from mesonbuild.interpreterbase.decorators import FeatureDeprecated
from .. import mesonlib, mlog
from ..compilers import AppleClangCCompiler, AppleClangCPPCompiler, detect_compiler_for
from ..environment import get_llvm_tool_names
@ -497,10 +499,11 @@ class ZlibSystemDependency(SystemDependency):
self.version = v.strip('"')
class JDKSystemDependency(SystemDependency):
class JNISystemDependency(SystemDependency):
def __init__(self, environment: 'Environment', kwargs: T.Dict[str, T.Any]):
super().__init__('jdk', environment, kwargs)
self.feature_since = ('0.59.0', '')
super().__init__('jni', environment, kwargs)
self.feature_since = ('0.62.0', '')
m = self.env.machines[self.for_machine]
@ -549,6 +552,18 @@ class JDKSystemDependency(SystemDependency):
return None
class JDKSystemDependency(JNISystemDependency):
def __init__(self, environment: 'Environment', kwargs: T.Dict[str, T.Any]):
super().__init__(environment, kwargs)
self.feature_since = ('0.59.0', '')
self.featurechecks.append(FeatureDeprecated(
'jdk system dependency',
'0.62.0',
'Use the jni system dependency instead'
))
llvm_factory = DependencyFactory(
'LLVM',
[DependencyMethods.CMAKE, DependencyMethods.CONFIG_TOOL],

@ -1,9 +0,0 @@
#include <jni.h>
#include "com_mesonbuild_JdkTest.h"
JNIEXPORT jint JNICALL Java_com_mesonbuild_JdkTest_jdk_1test
(JNIEnv *env, jclass clazz)
{
return (jint)0xdeadbeef;
}

@ -1,18 +0,0 @@
sources = [
files(
'native.c',
'com_mesonbuild_JdkTest.c',
),
native_headers
]
jdkjava = shared_module(
'jdkjava',
sources,
dependencies : [jdk],
include_directories : [native_header_includes]
)
jdkjava_dep = declare_dependency(
link_with : jdkjava,
)

@ -1,17 +0,0 @@
jdkjar = jar(
'jdkjar',
'com' / 'mesonbuild' / 'JdkTest.java',
main_class : 'com.mesonbuild.JdkTest',
)
test(
'jdktest',
java,
args: [
'-Djava.library.path=@0@'.format(fs.parent(jdkjava.full_path())),
'-jar',
jdkjar,
],
protocol : 'exitcode',
depends : [jdkjava],
)

@ -0,0 +1,9 @@
#include <jni.h>
#include "com_mesonbuild_JniTest.h"
JNIEXPORT jint JNICALL Java_com_mesonbuild_JniTest_jni_1test
(JNIEnv *env, jclass clazz)
{
return (jint)0xdeadbeef;
}

@ -0,0 +1,18 @@
sources = [
files(
'native.c',
'com_mesonbuild_JniTest.c',
),
native_headers
]
jnijava = shared_module(
'jnijava',
sources,
dependencies : [jni_dep],
include_directories : [native_header_includes]
)
jnijava_dep = declare_dependency(
link_with : jnijava
)

@ -1,11 +1,11 @@
project('jdkjava', ['c', 'java'])
project('jnijava', ['c', 'java'])
if build_machine.system() == 'cygwin'
error('MESON_SKIP_TEST: cygwin test failures')
endif
if build_machine.system() == 'windows' and build_machine.cpu_family() == 'x86'
error('MESON_SKIP_TEST: failing builds on 32bit Windows because a 32bit JDK isn not available in the Azure Pipelines Windows images')
error('MESON_SKIP_TEST: failing builds on 32bit Windows because a 32bit JDK is not available in the Azure Pipelines Windows images')
endif
fs = import('fs')
@ -13,7 +13,7 @@ javamod = import('java')
java = find_program('java')
jdk = dependency('jdk', version : '>=1.8')
jni_dep = dependency('jni', version : '>=1.8')
# generate native headers
subdir('src/com/mesonbuild')

@ -1,15 +1,15 @@
package com.mesonbuild;
public final class JdkTest {
private static native int jdk_test();
public final class JniTest {
private static native int jni_test();
public static void main(String[] args) {
if (jdk_test() != 0xdeadbeef) {
if (jni_test() != 0xdeadbeef) {
throw new RuntimeException("jdk_test() did not return 0");
}
}
static {
System.loadLibrary("jdkjava");
System.loadLibrary("jnijava");
}
}

@ -1,3 +1,3 @@
native_headers = javamod.generate_native_headers(
'JdkTest.java', package: 'com.mesonbuild', classes: ['JdkTest'])
'JniTest.java', package: 'com.mesonbuild', classes: ['JdkTest'])
native_header_includes = include_directories('.')

@ -0,0 +1,17 @@
jnijar = jar(
'jnijar',
'com' / 'mesonbuild' / 'JniTest.java',
main_class : 'com.mesonbuild.JniTest',
)
test(
'jnitest',
java,
args: [
'-Djava.library.path=@0@'.format(fs.parent(jnijava.full_path())),
'-jar',
jnijar,
],
protocol : 'exitcode',
depends : [jnijava],
)
Loading…
Cancel
Save