Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Experimental: Split core and api #718

Draft
wants to merge 16 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
2 changes: 1 addition & 1 deletion .gitattributes
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
kt/godot-library/src/main/kotlin/godot/gen/godot/*.kt linguist-generated=true
kt/godot-api-library/src/main/kotlin/godot/gen/godot/*.kt linguist-generated=true
harness/tests/.godot/**/* linguist-generated=true
4 changes: 2 additions & 2 deletions .github/workflows/build_jvm.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ jobs:
uses: actions/upload-artifact@v4
with:
name: jvm_godot-bootstrap_release
path: modules/kotlin_jvm/kt/godot-library/build/libs/godot-bootstrap.jar
path: modules/kotlin_jvm/kt/godot-library/godot-api-library/build/libs/godot-bootstrap.jar

- name: Upload entry-generator artifact
uses: actions/upload-artifact@v4
Expand Down Expand Up @@ -99,7 +99,7 @@ jobs:
uses: actions/upload-artifact@v4
with:
name: jvm_godot-bootstrap_debug
path: modules/kotlin_jvm/kt/godot-library/build/libs/godot-bootstrap.jar
path: modules/kotlin_jvm/kt/godot-library/godot-api-library/build/libs/godot-bootstrap.jar

- name: Verify ide plugin
run: |
Expand Down
18 changes: 14 additions & 4 deletions .github/workflows/deploy_jvm.yml
Original file line number Diff line number Diff line change
Expand Up @@ -67,15 +67,25 @@ jobs:
run: |
modules/kotlin_jvm/kt/gradlew -p modules/kotlin_jvm/kt/ :godot-kotlin-symbol-processor:publish

- name: Publish godot-library debug
- name: Publish godot-core-library debug
shell: sh
run: |
modules/kotlin_jvm/kt/gradlew -p modules/kotlin_jvm/kt/ :godot-library:publish -Pdebug
modules/kotlin_jvm/kt/gradlew -p modules/kotlin_jvm/kt/ :godot-core-library:publish -Pdebug

- name: Publish godot-library release
- name: Publish godot-core-library release
shell: sh
run: |
modules/kotlin_jvm/kt/gradlew -p modules/kotlin_jvm/kt/ :godot-library:publish -Prelease
modules/kotlin_jvm/kt/gradlew -p modules/kotlin_jvm/kt/ :godot-core-library:publish -Prelease

- name: Publish godot-api-library debug
shell: sh
run: |
modules/kotlin_jvm/kt/gradlew -p modules/kotlin_jvm/kt/ :godot-api-library:publish -Pdebug

- name: Publish godot-api-library release
shell: sh
run: |
modules/kotlin_jvm/kt/gradlew -p modules/kotlin_jvm/kt/ :godot-api-library:publish -Prelease

- name: Publish godot-coroutine-library debug
shell: sh
Expand Down
5 changes: 4 additions & 1 deletion harness/flattened-library-tests/settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@ includeBuild("../../kt/api-generator") {
includeBuild("../../kt") {
dependencySubstitution {
substitute(module("com.utopia-rise:godot-gradle-plugin")).using(project(":godot-gradle-plugin"))
substitute(module("com.utopia-rise:godot-library")).using(project(":godot-library"))
substitute(module("com.utopia-rise:godot-core-library-release")).using(project(":godot-core-library"))
substitute(module("com.utopia-rise:godot-api-library-release")).using(project(":godot-api-library"))
substitute(module("com.utopia-rise:godot-core-library-debug")).using(project(":godot-core-library"))
substitute(module("com.utopia-rise:godot-api-library-debug")).using(project(":godot-api-library"))
substitute(module("com.utopia-rise:godot-kotlin-symbol-processor")).using(project(":godot-kotlin-symbol-processor"))
substitute(module("com.utopia-rise:godot-entry-generator")).using(project(":godot-entry-generator"))
}
Expand Down
5 changes: 4 additions & 1 deletion harness/fqname-library-tests/settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@ includeBuild("../../kt/api-generator") {
includeBuild("../../kt") {
dependencySubstitution {
substitute(module("com.utopia-rise:godot-gradle-plugin")).using(project(":godot-gradle-plugin"))
substitute(module("com.utopia-rise:godot-library")).using(project(":godot-library"))
substitute(module("com.utopia-rise:godot-core-library-release")).using(project(":godot-core-library"))
substitute(module("com.utopia-rise:godot-api-library-release")).using(project(":godot-api-library"))
substitute(module("com.utopia-rise:godot-core-library-debug")).using(project(":godot-core-library"))
substitute(module("com.utopia-rise:godot-api-library-debug")).using(project(":godot-api-library"))
substitute(module("com.utopia-rise:godot-kotlin-symbol-processor")).using(project(":godot-kotlin-symbol-processor"))
substitute(module("com.utopia-rise:godot-entry-generator")).using(project(":godot-entry-generator"))
}
Expand Down
5 changes: 4 additions & 1 deletion harness/hierarchical-library-tests/settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@ includeBuild("../../kt/api-generator") {
includeBuild("../../kt") {
dependencySubstitution {
substitute(module("com.utopia-rise:godot-gradle-plugin")).using(project(":godot-gradle-plugin"))
substitute(module("com.utopia-rise:godot-library")).using(project(":godot-library"))
substitute(module("com.utopia-rise:godot-core-library-release")).using(project(":godot-core-library"))
substitute(module("com.utopia-rise:godot-api-library-release")).using(project(":godot-api-library"))
substitute(module("com.utopia-rise:godot-core-library-debug")).using(project(":godot-core-library"))
substitute(module("com.utopia-rise:godot-api-library-debug")).using(project(":godot-api-library"))
substitute(module("com.utopia-rise:godot-kotlin-symbol-processor")).using(project(":godot-kotlin-symbol-processor"))
substitute(module("com.utopia-rise:godot-entry-generator")).using(project(":godot-entry-generator"))
}
Expand Down
1 change: 1 addition & 0 deletions harness/tests/scripts/godot/tests/Invocation.gdj
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ properties = [
nav_meshes_dictionary,
nullable_dictionary,
color,
rid,
packed_byte_array,
packed_int32_array,
packed_float64_array,
Expand Down
3 changes: 2 additions & 1 deletion harness/tests/scripts/godot/tests/JavaTestClass.gdj
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ properties = [
dictionary
]
functions = [
greeting,
_ready,
greeting,
connect_and_trigger_signal,
signal_callback
]
6 changes: 4 additions & 2 deletions harness/tests/settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@ includeBuild("../../kt/api-generator") {
includeBuild("../../kt") {
dependencySubstitution {
substitute(module("com.utopia-rise:godot-gradle-plugin")).using(project(":godot-gradle-plugin"))
substitute(module("com.utopia-rise:godot-library-debug")).using(project(":godot-library"))
substitute(module("com.utopia-rise:godot-library-release")).using(project(":godot-library"))
substitute(module("com.utopia-rise:godot-core-library-release")).using(project(":godot-core-library"))
substitute(module("com.utopia-rise:godot-api-library-release")).using(project(":godot-api-library"))
substitute(module("com.utopia-rise:godot-core-library-debug")).using(project(":godot-core-library"))
substitute(module("com.utopia-rise:godot-api-library-debug")).using(project(":godot-api-library"))
substitute(module("com.utopia-rise:godot-coroutine-library-debug")).using(project(":godot-coroutine-library"))
substitute(module("com.utopia-rise:godot-coroutine-library-release")).using(project(":godot-coroutine-library"))
substitute(module("com.utopia-rise:godot-kotlin-symbol-processor")).using(project(":godot-kotlin-symbol-processor"))
Expand Down
4 changes: 2 additions & 2 deletions harness/tests/src/main/kotlin/godot/tests/FuncRefTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import godot.annotation.RegisterProperty
import godot.annotation.RegisterSignal
import godot.annotation.Rpc
import godot.core.signal0
import godot.extensions.call
import godot.extensions.callDeferred
import godot.extension.call
import godot.extension.callDeferred

@RegisterClass
class FuncRefTest : Node() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package godot.tests
import godot.Node
import godot.PackedScene
import godot.ResourceLoader
import godot.extensions.asStatic
import godot.extension.asStatic


object GodotStaticDelegateTest {
Expand Down
4 changes: 2 additions & 2 deletions harness/tests/src/main/kotlin/godot/tests/Invocation.kt
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import godot.annotation.IntRange
import godot.annotation.LongRange
import godot.annotation.MultilineText
import godot.annotation.PlaceHolderText
import godot.annotation.Range
import godot.annotation.RegisterClass
import godot.annotation.RegisterFunction
import godot.annotation.RegisterProperty
Expand All @@ -38,8 +39,7 @@ import godot.core.Vector2
import godot.core.Vector3
import godot.core.dictionaryOf
import godot.core.variantArrayOf
import godot.extensions.getNodeAs
import godot.registration.Range
import godot.extension.getNodeAs
import godot.tests.subpackage.OtherScript
import godot.util.RealT
import org.joda.time.DateTime
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ import godot.tools.common.constants.VARIANT_PARSER_PACKED_VECTOR2_ARRAY
import godot.tools.common.constants.VARIANT_PARSER_PACKED_VECTOR3_ARRAY
import godot.tools.common.constants.VARIANT_PARSER_STRING_NAME
import godot.tools.common.constants.VARIANT_PARSER__RID
import godot.tools.common.constants.godotApiPackage
import godot.tools.common.constants.godotPackage
import godot.tools.common.constants.godotCorePackage
import godot.tools.common.constants.variantParserPackage
import java.util.*
Expand Down Expand Up @@ -124,7 +124,7 @@ fun TypedTrait.getTypeClassName(): ClassTypeNameWrapper {
type == GodotTypes.variant -> ClassTypeNameWrapper(ANY)
type == GodotTypes.callable -> ClassTypeNameWrapper(GODOT_CALLABLE_BASE)
isCoreType() -> ClassTypeNameWrapper(ClassName(godotCorePackage, type!!))
else -> ClassTypeNameWrapper(ClassName(godotApiPackage, type!!))
else -> ClassTypeNameWrapper(ClassName(godotPackage, type!!))
}

if (this is NullableTrait) {
Expand Down
79 changes: 15 additions & 64 deletions kt/api-generator/src/main/kotlin/godot/codegen/generationEntry.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,8 @@ package godot.codegen

import com.fasterxml.jackson.core.type.TypeReference
import com.fasterxml.jackson.databind.ObjectMapper
import com.squareup.kotlinpoet.FileSpec
import godot.codegen.models.ApiDescription
import godot.codegen.models.enriched.toEnriched
import godot.codegen.poet.RegistrationFileSpec
import godot.codegen.repositories.ClassRepository
import godot.codegen.repositories.CoreTypeEnumRepository
import godot.codegen.repositories.GlobalEnumRepository
Expand All @@ -16,22 +14,18 @@ import godot.codegen.repositories.impl.JsonSingletonRepository
import godot.codegen.repositories.impl.KnownCoreTypeEnumRepository
import godot.codegen.repositories.impl.NativeStructureRepository
import godot.codegen.services.IClassGraphService
import godot.codegen.services.IClassService
import godot.codegen.services.IEnumService
import godot.codegen.services.IGenerationService
import godot.codegen.services.IApiService
import godot.codegen.services.IApiGenerationService
import godot.codegen.services.impl.AwaitGenerationService
import godot.codegen.services.impl.ClassGraphService
import godot.codegen.services.impl.ClassService
import godot.codegen.services.impl.EnumService
import godot.codegen.services.impl.GenerationService
import godot.codegen.services.impl.ApiService
import godot.codegen.services.impl.ApiGenerationService
import godot.codegen.services.impl.LambdaCallableGenerationService
import godot.codegen.services.impl.SignalGenerationService
import godot.tools.common.constants.Constraints
import godot.tools.common.constants.GENERATED_COMMENT
import godot.tools.common.constants.godotApiPackage
import java.io.File

fun File.generateApiFrom(jsonSource: File) {
fun generateApiFrom(jsonSource: File, coreDir: File, apiDir: File) {
val apiDescription = ObjectMapper().readValue(jsonSource, object : TypeReference<ApiDescription>() {})

val classRepository: ClassRepository = JsonClassRepository(apiDescription.classes.toEnriched())
Expand All @@ -41,65 +35,22 @@ fun File.generateApiFrom(jsonSource: File) {
val nativeStructureRepository = NativeStructureRepository(apiDescription.nativeStructures.toEnriched())

val classGraphService: IClassGraphService = ClassGraphService(classRepository)
val classService: IClassService = ClassService(
val apiService: IApiService = ApiService(
classRepository,
singletonRepository,
globalEnumRepository,
coreTypeEnumRepository,
classGraphService
)
val enumService: IEnumService = EnumService(globalEnumRepository, coreTypeEnumRepository, classService)
val generationService: IGenerationService = GenerationService(classGraphService, enumService, nativeStructureRepository)

classService.findGetSetMethodsAndUpdateProperties()
val generationService: IApiGenerationService = ApiGenerationService(classGraphService, apiService, nativeStructureRepository)
generationService.generateCore(coreDir)
generationService.generateApi(apiDir)

//TODO: generateEngineTypesRegistration

val engineIndexFile = FileSpec.builder(godotApiPackage, "EngineIndexes")
val registrationFileSpec = RegistrationFileSpec()

//We first generate singletons so that their index in engine types and engine singleton lists are same.
for (singleton in classService.getSingletons()) {
for (property in singleton.properties) {
classService.updatePropertyIfShouldUseSuper(singleton.name, property.name)
}

generationService.generateSingleton(singleton).writeTo(this)
generationService.generateEngineIndexesForClass(engineIndexFile, singleton)
generationService.generateEngineTypesRegistrationForSingleton(registrationFileSpec, singleton)
}

for (enrichedClass in classService.getClasses()) {
for (property in enrichedClass.properties) {
classService.updatePropertyIfShouldUseSuper(enrichedClass.name, property.name)
}

generationService.generateClass(enrichedClass).writeTo(this)
generationService.generateEngineIndexesForClass(engineIndexFile, enrichedClass)
generationService.generateEngineTypesRegistrationForClass(registrationFileSpec, enrichedClass)
}

engineIndexFile.build().writeTo(this)
registrationFileSpec.build().writeTo(this)

for (enum in enumService.getGlobalEnums()) {
val enumAndExtensions = generationService.generateEnum(enum)
val fileBuilder = FileSpec.builder(godotApiPackage, enum.name)
for (typeSpec in enumAndExtensions.first) {
fileBuilder.addType(typeSpec)
}
for (extension in enumAndExtensions.second) {
fileBuilder.addFunction(extension)
}

fileBuilder
.addFileComment(GENERATED_COMMENT)
.build()
.writeTo(this)
}

LambdaCallableGenerationService().generate(Constraints.MAX_FUNCTION_ARG_COUNT).writeTo(this)
SignalGenerationService().generate(Constraints.MAX_FUNCTION_ARG_COUNT).writeTo(this)
LambdaCallableGenerationService().generate(coreDir, apiDir)
SignalGenerationService().generate(coreDir, apiDir)
}

fun File.generateCoroutine() {
AwaitGenerationService.generate(Constraints.MAX_FUNCTION_ARG_COUNT).writeTo(this)
fun generateCoroutine(outputDir: File) {
AwaitGenerationService.generate(outputDir)
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class EnrichedClass(val internal: Class) : TypedTrait, IDocumented {
val signals = internal.signals?.toEnriched() ?: listOf()
val name = internal.name.escapeUnderscore()
val inherits = internal.inherits?.escapeUnderscore()
val engineClassDBIndexName = "ENGINECLASS_${internal.name.uppercase(Locale.US)}"
val engineClassDBIndexName = "ENGINE_CLASS_${internal.name.uppercase(Locale.US)}_INDEX"
val properties= internal.properties?.toEnriched() ?: listOf()
val methods = internal.methods?.toEnriched(engineClassDBIndexName) ?: listOf()
val apiType = ApiType.from(internal.apiType)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ package godot.codegen.poet
import com.squareup.kotlinpoet.FileSpec
import com.squareup.kotlinpoet.FunSpec
import godot.tools.common.constants.GENERATED_COMMENT
import godot.tools.common.constants.godotApiPackage
import godot.tools.common.constants.godotPackage

class RegistrationFileSpec {
val registrationFile = FileSpec.builder(godotApiPackage, "RegisterEngineTypes")
val registrationFile = FileSpec.builder(godotPackage, "RegisterEngineTypes")
val registerVariantMappingFunBuilder = FunSpec.builder("registerVariantMapping")
val registerMethodsFunBuilder = FunSpec.builder("registerEngineTypeMethods")
val registerTypesFunBuilder = FunSpec.builder("registerEngineTypes")
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package godot.codegen.services

import com.squareup.kotlinpoet.FileSpec
import com.squareup.kotlinpoet.FunSpec
import com.squareup.kotlinpoet.PropertySpec
import com.squareup.kotlinpoet.TypeSpec
import godot.codegen.models.enriched.*
import godot.codegen.poet.RegistrationFileSpec
import java.io.File

interface IApiGenerationService {
fun generateSingleton(singletonClass: EnrichedClass): FileSpec
fun generateClass(clazz: EnrichedClass): FileSpec
fun generateEnum(enum: EnrichedEnum, containingClassName: String? = null): Pair<List<TypeSpec>, List<FunSpec>>
fun generateConstant(constant: EnrichedConstant, containingClassName: String?): PropertySpec

fun generateEngineTypesRegistrationForClass(
registrationFileSpec: RegistrationFileSpec,
clazz: EnrichedClass
)
fun generateEngineTypesRegistrationForSingleton(
registrationFileSpec: RegistrationFileSpec,
singleton: EnrichedClass
)

fun generateCore(outputDir: File)
fun generateApi(outputDir: File)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package godot.codegen.services

import godot.codegen.models.custom.DefaultEnumValue
import godot.codegen.models.enriched.EnrichedClass
import godot.codegen.models.enriched.EnrichedEnum
import godot.codegen.poet.ClassTypeNameWrapper

interface IApiService {
fun getSingletons(): List<EnrichedClass>
fun getClasses(): List<EnrichedClass>
fun getGlobalEnums() : List<EnrichedEnum>


fun updatePropertyIfShouldUseSuper(className: String, propertyName: String)
fun findGetSetMethodsAndUpdateProperties()
fun findEnumValue(enumClassName: ClassTypeNameWrapper, enumValue: Long): DefaultEnumValue
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
package godot.codegen.services

import com.squareup.kotlinpoet.FileSpec
import java.io.File

interface IAwaitGenerationService {
fun generate(maxArgumentCount: Int): FileSpec
fun generate(output: File)
}

This file was deleted.

This file was deleted.

Loading
Loading