Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Implement boilerplate code required to support Kotlin generator #1649

Merged
merged 9 commits into from
Feb 7, 2025

Conversation

pwrobeldev
Copy link
Contributor

@pwrobeldev pwrobeldev commented Feb 5, 2025

This change is intended to bring the boilerplate code, which is required
to support generation of the new output language: Kotlin.

The CLI interface has been extended by the new Kotlin-specific parameters:

  • kotlinpackage - Kotlin package name
  • kotlinintpackage - Kotlin package name to append to kotlinpackage for internal types
  • kotlinnamerules - Kotlin name rules property file

CMake scripts have been adjusted to allow the users to generate the code for Kotlin and properly
build it. Moreover, CMake parameters, which correspond to new CLI options have been added as well:

  • GLUECODIUM_KOTLIN_PACKAGE
  • GLUECODIUM_KOTLIN_INTERNAL_PACKAGE
  • GLUECODIUM_KOTLIN_NAMERULES

The required classes for Kotlin have been created in gluecodium/generator/ directory.
Furthermore, new mustache templates were added to generate Kotlin files.

To provide some basic level of validation new smoke and functional tests were created.
The CI workflow file for functional tests has been also adjusted to execute the tests on CI.

This change extends parsing of command line arguments
to honor three new flags:
 - 'kotlinpackage' - Kotlin package name
 - 'kotlinintpackage' - Kotlin package name to append to
                        'kotlinpackage' for internal types
 - 'kotlinnamerules' - Kotlin name rules property file

Signed-off-by: Patryk Wrobel <183546751+pwrobeldev@users.noreply.github.com>
This commit introduces new generator type in CMake
scripts as well as parameters, which are Kotlin-specific:
 - 'GLUECODIUM_KOTLIN_PACKAGE'
 - 'GLUECODIUM_KOTLIN_INTERNAL_PACKAGE'
 - 'GLUECODIUM_KOTLIN_NAMERULES'

The scripts have been adjusted to ensure that the generated
files are properly listed and included.

Signed-off-by: Patryk Wrobel <183546751+pwrobeldev@users.noreply.github.com>
'spotless.gradle' was adjusted to avoid checking formatting
in generated Kotlin files from smoke tests directory.

Signed-off-by: Patryk Wrobel <183546751+pwrobeldev@users.noreply.github.com>
This change is intended to prepare LIME loader and runtime
for processing of Kotlin. Therefore, the following changes
are introduced:
 - LimeAttributeType.KOTLIN is added
 - LimeExternalDescriptor provides Kotlin specific descriptor
 - AntlrLimeConverter is able to correctly convert Kotlin
   annotation

Signed-off-by: Patryk Wrobel <183546751+pwrobeldev@users.noreply.github.com>
This change brings the boilerplate code required to
run generation of Kotlin code. This is still WIP
and therefore, certain classes may not support all
required functionalities.

Note: this change does not implements comments
processing.

Signed-off-by: Patryk Wrobel <183546751+pwrobeldev@users.noreply.github.com>
This commit introduces smoke tests for basic input files
including generation of simple classes, structures,
enumerations, errors, properties etc.

Signed-off-by: Patryk Wrobel <183546751+pwrobeldev@users.noreply.github.com>
This change brings basic functional tests of
generated Kotlin code including creating and calling
methods of classes, structures and interfaces.

Signed-off-by: Patryk Wrobel <183546751+pwrobeldev@users.noreply.github.com>
This change adds a new workflow, which runs Kotlin
functional tests on CI.

Signed-off-by: Patryk Wrobel <183546751+pwrobeldev@users.noreply.github.com>
@pwrobeldev pwrobeldev changed the title Pwrobeldev/initial kotlin support Kotlin: implement boilerplate code required to support Kotlin generator Feb 5, 2025
@pwrobeldev pwrobeldev changed the title Kotlin: implement boilerplate code required to support Kotlin generator Implement boilerplate code required to support Kotlin generator Feb 5, 2025
@pwrobeldev pwrobeldev marked this pull request as ready for review February 5, 2025 10:11
@@ -74,6 +74,11 @@ function(gluecodium_get_target_include_directories _target)
"$<BUILD_INTERFACE:${_output_${_source_set_lower}_dir}/android/jni>")
endif()

if(android-kotlin IN_LIST _generators)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here and other similar places we should consider the case when we generate both Java and Kotlin. In such cases when packages (com.here.sdk.etc) are the same we can't include both generated JNI sources. Even when packages are not the same and generated functions name in MAIN sources should be unique, the code in COMMON source set still might somehow clash. And the last problem which came to my mind: in case of different packages even if we don't have problems with name conflicts (i.e. functions name are unique, namespace in COMMON sources is also unique, etc.) there is still problem with passing types in weird scenarios like Java -> C++ -> Kotlin and vice versa. But may be last scenario is not possible.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As per offline discussion: for now I will implement a check to prevent generation of both Java and Kotlin in one pass. I will also create a task to look for a viable solution.

@@ -59,6 +59,10 @@ function(gluecodium_list_generated_files _target)
list(APPEND _android_generated_files "${_unity_dir}/${GLUECODIUM_GENERATED_jni_${_group}}")
endif()

if(android-kotlin IN_LIST _generators)
list(APPEND _android_kotlin_generated_files "${_unity_dir}/${GLUECODIUM_GENERATED_jni_kotlin_${_group}}")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same...

if(android-kotlin IN_LIST GLUECODIUM_GENERATORS)
# Include all conversion headers first, so all later generic conversions relying on
# specialization have all these defined
_include_all(jni_kotlin "android-kotlin/jni/*_Conversion.h" "android-kotlin/jni/*.cpp")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same...

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Taking into account our plans it would be nice to have mixed tests. I.e. existing tests on Java which run over Kotlin generated code.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good idea 👍

As per offline discussion:

  • currently the generated Kotlin code does not support many required features
  • some small adjustments may be required in the case of Java functional tests -- some of them do not obey preconditions related to nullability of parameters. For instance InterfacesTest.java -> setSelfInterfaceNull() passes null to a function, which does not accept nullable types.

Therefore, I will write it down as a task and I will proceed with it in the near future.

Usage of both generators in one pass could cause
symbols clash for JNI bindings. At the moment
running both generators in one pass is disallowed.

Signed-off-by: Patryk Wrobel <183546751+pwrobeldev@users.noreply.github.com>
@pwrobeldev pwrobeldev merged commit aec3ed0 into master Feb 7, 2025
19 checks passed
@pwrobeldev pwrobeldev deleted the pwrobeldev/initial-kotlin-support branch February 7, 2025 16:11
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants