From d072ebc9554e5661419d6d75285bfee24dca743f Mon Sep 17 00:00:00 2001 From: Tristan Partin Date: Mon, 7 Mar 2022 13:20:59 -0600 Subject: [PATCH] Fix @typed_pos_args on java.generate_native_headers --- mesonbuild/modules/java.py | 11 ++++++----- test cases/java/9 jni/meson.build | 15 +++++++++++++-- .../src/com/mesonbuild/Configured.java.in | 5 +++++ .../java/9 jni/src/com/mesonbuild/JniTest.java | 2 +- .../java/9 jni/src/com/mesonbuild/meson.build | 10 +++++++++- test cases/java/9 jni/src/meson.build | 18 +++++------------- 6 files changed, 39 insertions(+), 22 deletions(-) create mode 100644 test cases/java/9 jni/src/com/mesonbuild/Configured.java.in diff --git a/mesonbuild/modules/java.py b/mesonbuild/modules/java.py index 6884a22fe..3806308dd 100644 --- a/mesonbuild/modules/java.py +++ b/mesonbuild/modules/java.py @@ -16,7 +16,7 @@ import os import pathlib import typing as T from mesonbuild import mesonlib -from mesonbuild.build import CustomTarget +from mesonbuild.build import CustomTarget, CustomTargetIndex, GeneratedList, Target from mesonbuild.compilers import detect_compiler_for, Compiler from mesonbuild.interpreter import Interpreter from mesonbuild.interpreterbase.decorators import ContainerTypeInfo, FeatureDeprecated, FeatureNew, KwargInfo, typed_pos_args, typed_kwargs @@ -80,12 +80,13 @@ class JavaModule(NewExtensionModule): return ModuleReturnValue(target, [target]) @FeatureNew('java.generate_native_headers', '0.62.0') - @typed_pos_args('java.generate_native_headers', (str, mesonlib.File), min_varargs=1) + @typed_pos_args('java.generate_native_headers', + varargs=(str, mesonlib.File, Target, CustomTargetIndex, GeneratedList)) @typed_kwargs('java.generate_native_headers', - KwargInfo('classes', (ContainerTypeInfo(list, str)), default=[], listify=True, + KwargInfo('classes', ContainerTypeInfo(list, str), default=[], listify=True, required=True), KwargInfo('package', str, default=None)) - def generate_native_headers(self, state: ModuleState, args: T.List[mesonlib.FileOrString], + def generate_native_headers(self, state: ModuleState, args: T.Tuple[T.List[mesonlib.FileOrString]], kwargs: T.Dict[str, T.Optional[str]]) -> ModuleReturnValue: classes = T.cast(T.List[str], kwargs.get('classes')) package = kwargs.get('package') @@ -112,7 +113,7 @@ class JavaModule(NewExtensionModule): prefix = classes[0] if not package else package target = CustomTarget(f'{prefix}-native-headers', state.subdir, state.subproject, command, - sources=list(args), outputs=headers, backend=state.backend) + sources=args[0], outputs=headers, backend=state.backend) # It is only known that 1.8.0 won't pre-create the directory. 11 and 16 # do not exhibit this behavior. diff --git a/test cases/java/9 jni/meson.build b/test cases/java/9 jni/meson.build index 1239e19e8..90a8485e5 100644 --- a/test cases/java/9 jni/meson.build +++ b/test cases/java/9 jni/meson.build @@ -16,6 +16,17 @@ java = find_program('java') jni_dep = dependency('jni', version : '>=1.8', modules: ['jvm', 'awt']) # generate native headers -subdir('src/com/mesonbuild') -subdir('lib') subdir('src') +subdir('lib') + +test( + 'jnitest', + java, + args: [ + '-Djava.library.path=@0@'.format(fs.parent(jnijava.full_path())), + '-jar', + jnijar, + ], + protocol : 'exitcode', + depends : [jnijava], +) diff --git a/test cases/java/9 jni/src/com/mesonbuild/Configured.java.in b/test cases/java/9 jni/src/com/mesonbuild/Configured.java.in new file mode 100644 index 000000000..fac6e0558 --- /dev/null +++ b/test cases/java/9 jni/src/com/mesonbuild/Configured.java.in @@ -0,0 +1,5 @@ +package com.mesonbuild; + +public final class Configured { + public static final int FINGERPRINT = @fingerprint@; +} diff --git a/test cases/java/9 jni/src/com/mesonbuild/JniTest.java b/test cases/java/9 jni/src/com/mesonbuild/JniTest.java index f80b326c1..4bfffe987 100644 --- a/test cases/java/9 jni/src/com/mesonbuild/JniTest.java +++ b/test cases/java/9 jni/src/com/mesonbuild/JniTest.java @@ -4,7 +4,7 @@ public final class JniTest { private static native int jni_test(); public static void main(String[] args) { - if (jni_test() != 0xdeadbeef) { + if (jni_test() != Configured.FINGERPRINT) { throw new RuntimeException("jdk_test() did not return 0"); } } diff --git a/test cases/java/9 jni/src/com/mesonbuild/meson.build b/test cases/java/9 jni/src/com/mesonbuild/meson.build index 3ee208326..2d88c5e62 100644 --- a/test cases/java/9 jni/src/com/mesonbuild/meson.build +++ b/test cases/java/9 jni/src/com/mesonbuild/meson.build @@ -1,3 +1,11 @@ +configured = configure_file( + input: files('Configured.java.in'), + output: 'Configured.java', + configuration: configuration_data({'fingerprint': '0xdeadbeef'}) +) + +sources += configured + native_headers = javamod.generate_native_headers( - 'JniTest.java', package: 'com.mesonbuild', classes: ['JdkTest']) + sources, package: 'com.mesonbuild', classes: ['JniTest']) native_header_includes = include_directories('.') diff --git a/test cases/java/9 jni/src/meson.build b/test cases/java/9 jni/src/meson.build index 07a0664b0..af443b517 100644 --- a/test cases/java/9 jni/src/meson.build +++ b/test cases/java/9 jni/src/meson.build @@ -1,17 +1,9 @@ +sources = [files('com/mesonbuild/JniTest.java')] + +subdir('com/mesonbuild') + jnijar = jar( 'jnijar', - 'com' / 'mesonbuild' / 'JniTest.java', + sources, 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], -)