Skip to content

Commit

Permalink
Merge branch 'vnext'
Browse files Browse the repository at this point in the history
  • Loading branch information
gershnik committed May 3, 2024
2 parents 8e01034 + e5724e1 commit 80600b2
Show file tree
Hide file tree
Showing 51 changed files with 353 additions and 73 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@ jobs:
permissions: write-all
steps:
- name: Checkout
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: Get Release Name
shell: python
run: |
import os
#ref = os.environ['GITHUB_REF']
#name = ref[ref.rfind('/') + 2:]
#name = ref[ref.rfind('/') + 1:]
with open('VERSION', 'r') as verFile:
name = verFile.read().strip()
with open(os.environ['GITHUB_ENV'], 'w') as env:
Expand Down Expand Up @@ -47,7 +47,7 @@ jobs:
publishAllPublicationsToOssrhRepository
- name: Make release
uses: softprops/action-gh-release@v1
uses: softprops/action-gh-release@v2
with:
draft: true
prerelease: false
Expand Down
26 changes: 16 additions & 10 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,13 @@ jobs:
fail-fast: false
matrix:
include:
- os: macos-latest
- os: macos-13
java: '8'
- os: macos-latest
- os: macos-13
java: '11'
- os: macos-latest
- os: macos-13
java: '17'
- os: macos-latest
- os: macos-13
java: '21'
- os: windows-latest
java: '8'
Expand Down Expand Up @@ -98,7 +98,7 @@ jobs:
compiler: 'clang-15|clang++-15'

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4

- name: System Setup
shell: bash
Expand All @@ -121,7 +121,7 @@ jobs:
fi
- name: Set up JDK
uses: actions/setup-java@v3
uses: actions/setup-java@v4
with:
java-version: |
8
Expand All @@ -147,20 +147,26 @@ jobs:
run: cmake --build build --config $BUILD_TYPE --target test-jnigen

android:
runs-on: macos-latest
runs-on: ubuntu-latest

steps:
- name: Checkout
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: Enable KVM
run: |
echo 'KERNEL=="kvm", GROUP="kvm", MODE="0666", OPTIONS+="static_node=kvm"' | sudo tee /etc/udev/rules.d/99-kvm4all.rules
sudo udevadm control --reload-rules
sudo udevadm trigger --name-match=kvm
- name: Set up JDK
uses: actions/setup-java@v3
uses: actions/setup-java@v4
with:
java-version: 17
distribution: 'temurin'

- name: AVD cache
uses: actions/cache@v3
uses: actions/cache@v4
id: avd-cache
with:
path: |
Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
3.8
3.9
2 changes: 1 addition & 1 deletion jnigen/gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.4-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.7-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
Expand Down
25 changes: 25 additions & 0 deletions jnigen/kprocessor/src/smjni/jnigen/ksp/ClassContent.kt
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ internal class ClassContent(classInfo: JavaClassInfo,
is JavaClassInfo.Getter -> addJavaGetter(it, context)
is JavaClassInfo.Setter -> addJavaSetter(it, context)
is JavaClassInfo.Field -> addJavaField(it, context)
is JavaClassInfo.EnumEntry -> addJavaEnumEntry(it, context)
}
}

Expand Down Expand Up @@ -233,6 +234,30 @@ internal class ClassContent(classInfo: JavaClassInfo,
_javaEntities.add(field)
}

private fun addJavaEnumEntry(enumEntryInfo: JavaClassInfo.EnumEntry, context: Context) {
val fieldName = nameTable.allocateName(enumEntryInfo.jvmName)

val templateArguments = ArrayList<String>()
val argTypes = ArrayList<String>()
val argNames = ArrayList<String>()

val fieldType = enumEntryInfo.type
val fieldTypeName = context.typeMap.nativeNameOf(fieldType)
templateArguments.add(fieldTypeName)
val returnType = context.typeMap.wrapperNameOf(fieldTypeName, false)
templateArguments.add(cppName)

argTypes.add(context.typeMap.wrapperNameOf(fieldTypeName, true))

val field = JavaEntity(
JavaEntityType.StaticField,
true,
false, //meaningless for fields
fieldName, templateArguments, returnType, argTypes, argNames
)
_javaEntities.add(field)
}

private fun addJavaConstructor(constructorInfo: JavaClassInfo.Function, context: Context) {

addJavaCallable(constructorInfo.getCallableInfo(context), isConstructor = true, isStatic = false, isOpen = false, allowNonVirt = false, context)
Expand Down
5 changes: 3 additions & 2 deletions jnigen/kprocessor/src/smjni/jnigen/ksp/Generator.kt
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ internal class Generator(private val context: Context) {
generateTypeHeader()

val allHeaders = ArrayList<String>()
for (header in context.typeMap.classHeaders) {
for (header in context.typeMap.classHeaders.sorted()) {
if (generateClassHeader(header))
allHeaders.add(header)
}
Expand Down Expand Up @@ -101,7 +101,7 @@ internal class Generator(private val context: Context) {
classHeader.write("//THIS FILE IS AUTO-GENERATED. DO NOT EDIT\n\n")
classHeader.write("#include \"${context.headerName}\"\n\n")

context.typeMap.classesInHeader(header).forEach { classContent ->
context.typeMap.classesInHeader(header).sortedBy { it.cppName }.forEach { classContent ->
if (classContent.javaEntities.isNotEmpty() || classContent.nativeMethods.isNotEmpty())
generateClassDef(classHeader, classContent)
}
Expand Down Expand Up @@ -339,6 +339,7 @@ internal class Generator(private val context: Context) {
context.typeMap.classesInHeader(header)
.filter {it.hasCppClass }
.map { it.cppClassName }
.sorted()
.joinToString(separator = ", \\\n ")})

allHeader.write("\n\n#endif\n")
Expand Down
16 changes: 16 additions & 0 deletions jnigen/kprocessor/src/smjni/jnigen/ksp/JavaClassInfo.kt
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,11 @@ internal class JavaClassInfo private constructor(val qualifiedJavaClassName: Str
val jvmName : String get() = declaration.simpleName.asString()
}

class EnumEntry(private val declaration: KSClassDeclaration) : ExposedEntity(true) {
val type: KSType get() = (declaration.parentDeclaration!! as KSClassDeclaration).asStarProjectedType()
val jvmName : String get() = declaration.simpleName.asString()
}


companion object {
fun from(classDeclaration: KSClassDeclaration, context: Context) : JavaClassInfo {
Expand Down Expand Up @@ -186,6 +191,8 @@ internal class JavaClassInfo private constructor(val qualifiedJavaClassName: Str
is KSPropertyDeclaration -> yieldAll(handleProperty(context, companionDecl, isFileLevel = false, isFromCompanionObject = true))
}
}
} else if (decl.classKind == ClassKind.ENUM_ENTRY) {
yieldAll(handleEnumEntry(context, decl))
}
}
}
Expand Down Expand Up @@ -265,6 +272,15 @@ internal class JavaClassInfo private constructor(val qualifiedJavaClassName: Str
}
}

private fun handleEnumEntry(context: Context, decl: KSClassDeclaration) : Sequence<ExposedEntity> {
val annotations = collectAnnotations(decl.annotations, setOf(context.calledByNativeAnnotation))

return if (annotations[context.calledByNativeAnnotation] != null)
sequenceOf(EnumEntry(decl))
else
emptySequence()
}

private fun collectAnnotations(annotations: Sequence<KSAnnotation>, names: Set<String>) : Map<String, KSAnnotation> {
val ret = mutableMapOf<String, KSAnnotation>()
for (annotation in annotations) {
Expand Down
1 change: 1 addition & 0 deletions jnigen/kprocessor/test/src/KJniGenTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ class KJniGenTest {
fun generateOutput(name: String, dir: Path) {
val sources = Files.list(dir / "input")
.filter { setOf("kt", "java").contains(it.extension)}
.sorted(compareBy { it.fileName.toString() })
.map { SourceFile.fromPath(it.toFile()) }.toList()

val args = loadArguments(dir / "args.properties")
Expand Down
2 changes: 1 addition & 1 deletion jnigen/processor/src/smjni/jnigen/ClassContent.kt
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ internal class ClassContent(val classElement: TypeElement,

}
}
ElementKind.FIELD -> {
ElementKind.ENUM_CONSTANT, ElementKind.FIELD -> {

val fieldElement = childElement as VariableElement

Expand Down
14 changes: 9 additions & 5 deletions jnigen/processor/src/smjni/jnigen/Generator.kt
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ internal class Generator {
generateTypeHeader(typeMap, context)

val allHeaders = ArrayList<String>()
for (header in typeMap.classHeaders) {
for (header in typeMap.classHeaders.sorted()) {
if (generateClassHeader(header, typeMap, context))
allHeaders.add(header)
}
Expand All @@ -55,8 +55,7 @@ internal class Generator {
typeHeader.write("//THIS FILE IS AUTO-GENERATED. DO NOT EDIT\n\n")
typeHeader.write("#include <smjni/smjni.h>\n\n")

val exposedClasses = ArrayList(typeMap.exposedClasses.values)
exposedClasses.sortBy { it.cppName }
val exposedClasses = ArrayList(typeMap.exposedClasses.values).sortedBy { it.cppName }

for (classContent in exposedClasses) {
typeHeader.write("DEFINE_JAVA_TYPE(${classContent.cppName}, \"${classContent.binaryName}\")\n")
Expand Down Expand Up @@ -95,7 +94,7 @@ internal class Generator {
classHeader.write("//THIS FILE IS AUTO-GENERATED. DO NOT EDIT\n\n")
classHeader.write("#include \"${context.headerName}\"\n\n")

typeMap.classesInHeader(header).forEach { classContent ->
typeMap.classesInHeader(header).sortedBy { it.cppName }.forEach { classContent ->
if (classContent.javaEntities.isNotEmpty() || classContent.nativeMethods.isNotEmpty())
generateClassDef(classHeader, classContent)
}
Expand Down Expand Up @@ -329,7 +328,12 @@ internal class Generator {

allHeader.write("\n#define JNIGEN_ALL_GENERATED_CLASSES \\\n ")

allHeader.write(headers.joinToString(separator = ", \\\n ") { header -> typeMap.classesInHeader(header).filter {it.hasCppClass }.map { it.cppClassName }.joinToString(separator = ", \\\n ")})
allHeader.write(headers.joinToString(separator = ", \\\n ") { header ->
typeMap.classesInHeader(header)
.filter {it.hasCppClass }
.map { it.cppClassName }
.sorted()
.joinToString(separator = ", \\\n ")})

allHeader.write("\n\n#endif\n")
}
Expand Down
1 change: 1 addition & 0 deletions jnigen/processor/test/src/JniGenTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ class JniGenTest {
fun generateOutput(name: String, dir: Path) {
val sources = Files.list(dir / "input")
.filter { setOf("kt", "java").contains(it.extension)}
.sorted(compareBy { it.fileName.toString() })
.map { SourceFile.fromPath(it.toFile()) }.toList()

val args = loadArguments(dir / "args.properties")
Expand Down
6 changes: 3 additions & 3 deletions jnigen/settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@
pluginManagement {
plugins {
val gradleExtra = (gradle as ExtensionAware).extra
val kotlinVersion by gradleExtra("1.9.0")
val kspVersion by gradleExtra("1.0.13")
val junitVersion by gradleExtra("5.10.0")
val kotlinVersion by gradleExtra("1.9.23")
val kspVersion by gradleExtra("1.0.20")
val junitVersion by gradleExtra("5.10.2")
val kotlinCompileTestingVersion by gradleExtra("1.5.0")
val hamcrestVersion by gradleExtra("2.2")

Expand Down
8 changes: 8 additions & 0 deletions jnigen/test_data/sources/full/input/FileLevel.kt
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,12 @@ object ExposedObject {
@CalledByNative
@JvmField
val field = 1
}

@ExposeToNative
enum class SomeEnum {
@CalledByNative NORTH,
@CalledByNative SOUTH,
@CalledByNative WEST,
@CalledByNative EAST
}
10 changes: 6 additions & 4 deletions jnigen/test_data/sources/full/kapt-output.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ JNIGen: Discovered (command line) java.lang.Short
JNIGen: Discovered (command line) java.lang.Boolean
JNIGen: Discovered (command line) java.lang.Byte
JNIGen: Discovered (command line) java.lang.Integer
JNIGen: Discovered SomeEnum
JNIGen: Discovered Extension
JNIGen: Discovered Extension.Inner
JNIGen: Discovered FileLevelKt
Expand All @@ -17,12 +18,13 @@ JNIGen: Discovered sources.full_class.input.Types
JNIGen: Discovered Statics
JNIGen: Discovered Middle
JNIGen: Generating type_mapping.h: written
JNIGen: Generating ExposedObject_class.h: written
JNIGen: Generating ExtensionKt_class.h: written
JNIGen: Generating Extension_class.h: written
JNIGen: Generating FileLevelKt_class.h: written
JNIGen: Generating Statics_class.h: written
JNIGen: Generating FullClass_class.h: written
JNIGen: Generating ExtensionKt_class.h: written
JNIGen: Generating SomeEnum_class.h: written
JNIGen: Generating Statics_class.h: written
JNIGen: Generating Types_class.h: written
JNIGen: Generating ExposedObject_class.h: written
JNIGen: Generating Extension_class.h: written
JNIGen: Generating all_classes.h: written
JNIGen: Generating outputs.txt: written
39 changes: 39 additions & 0 deletions jnigen/test_data/sources/full/kapt-output/SomeEnum_class.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#ifndef HEADER_SOMEENUM_CLASS_H_INCLUDED
#define HEADER_SOMEENUM_CLASS_H_INCLUDED


//THIS FILE IS AUTO-GENERATED. DO NOT EDIT

#include "type_mapping.h"

class SomeEnum_class : public smjni::java_runtime::simple_java_class<jSomeEnum>
{
public:
SomeEnum_class(JNIEnv * env);

smjni::local_java_ref<jSomeEnum> get_NORTH(JNIEnv * env) const
{ return m_NORTH.get(env, *this); }
smjni::local_java_ref<jSomeEnum> get_SOUTH(JNIEnv * env) const
{ return m_SOUTH.get(env, *this); }
smjni::local_java_ref<jSomeEnum> get_WEST(JNIEnv * env) const
{ return m_WEST.get(env, *this); }
smjni::local_java_ref<jSomeEnum> get_EAST(JNIEnv * env) const
{ return m_EAST.get(env, *this); }
private:
const smjni::java_static_field<jSomeEnum, jSomeEnum> m_NORTH;
const smjni::java_static_field<jSomeEnum, jSomeEnum> m_SOUTH;
const smjni::java_static_field<jSomeEnum, jSomeEnum> m_WEST;
const smjni::java_static_field<jSomeEnum, jSomeEnum> m_EAST;

};


inline SomeEnum_class::SomeEnum_class(JNIEnv * env):
simple_java_class(env),
m_NORTH(env, *this, "NORTH"),
m_SOUTH(env, *this, "SOUTH"),
m_WEST(env, *this, "WEST"),
m_EAST(env, *this, "EAST")
{}

#endif
20 changes: 11 additions & 9 deletions jnigen/test_data/sources/full/kapt-output/all_classes.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,23 @@

//THIS FILE IS AUTO-GENERATED. DO NOT EDIT

#include "ExposedObject_class.h"
#include "ExtensionKt_class.h"
#include "Extension_class.h"
#include "FileLevelKt_class.h"
#include "Statics_class.h"
#include "FullClass_class.h"
#include "ExtensionKt_class.h"
#include "SomeEnum_class.h"
#include "Statics_class.h"
#include "Types_class.h"
#include "ExposedObject_class.h"
#include "Extension_class.h"

#define JNIGEN_ALL_GENERATED_CLASSES \
ExposedObject_class, \
ExtensionKt_class, \
Extension_class, \
FileLevelKt_class, \
Statics_class, \
FullClass_class, \
ExtensionKt_class, \
Types_class, \
ExposedObject_class, \
Extension_class
SomeEnum_class, \
Statics_class, \
Types_class

#endif
Loading

0 comments on commit 80600b2

Please sign in to comment.