Skip to content

Commit f1981cc

Browse files
committed
Add godot-coroutine-library to project
1 parent d9b7cb3 commit f1981cc

File tree

9 files changed

+139
-14
lines changed

9 files changed

+139
-14
lines changed

.clang-tidy

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
---
2+
Checks: 'clang-diagnostic-*,clang-analyzer-*,-*,cppcoreguidelines-pro-type-member-init,modernize-redundant-void-arg,modernize-use-bool-literals,modernize-use-default-member-init,modernize-use-nullptr,readability-braces-around-statements,readability-redundant-member-init'
3+
WarningsAsErrors: ''
4+
HeaderFilterRegex: ''
5+
AnalyzeTemporaryDtors: false
6+
FormatStyle: none
7+
CheckOptions:
8+
- key: cert-dcl16-c.NewSuffixes
9+
value: 'L;LL;LU;LLU'
10+
- key: cert-oop54-cpp.WarnOnlyIfThisHasSuspiciousField
11+
value: '0'
12+
- key: cppcoreguidelines-explicit-virtual-functions.IgnoreDestructors
13+
value: '1'
14+
- key: cppcoreguidelines-non-private-member-variables-in-classes.IgnoreClassesWithAllMemberVariablesBeingPublic
15+
value: '1'
16+
- key: cppcoreguidelines-pro-type-member-init.IgnoreArrays
17+
value: '1'
18+
- key: cppcoreguidelines-pro-type-member-init.UseAssignment
19+
value: '1'
20+
- key: google-readability-function-size.StatementThreshold
21+
value: '800'
22+
- key: google-readability-namespace-comments.ShortNamespaceLines
23+
value: '10'
24+
- key: google-readability-namespace-comments.SpacesBeforeComments
25+
value: '2'
26+
- key: modernize-loop-convert.MaxCopySize
27+
value: '16'
28+
- key: modernize-loop-convert.MinConfidence
29+
value: reasonable
30+
- key: modernize-loop-convert.NamingStyle
31+
value: CamelCase
32+
- key: modernize-pass-by-value.IncludeStyle
33+
value: llvm
34+
- key: modernize-replace-auto-ptr.IncludeStyle
35+
value: llvm
36+
- key: modernize-use-bool-literals.IgnoreMacros
37+
value: '0'
38+
- key: modernize-use-default-member-init.IgnoreMacros
39+
value: '0'
40+
- key: modernize-use-default-member-init.UseAssignment
41+
value: '1'
42+
- key: modernize-use-nullptr.NullMacros
43+
value: 'NULL'
44+
- key: readability-braces-around-statements.ShortStatementLines
45+
value: '0'
46+
...
47+

harness/tests/build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import org.jetbrains.kotlin.konan.target.HostManager
2-
import java.io.OutputStream
32

43
plugins {
54
// no need to apply kotlin jvm plugin. Our plugin already applies the correct version for you
@@ -14,6 +13,7 @@ repositories {
1413
godot {
1514
registrationFileBaseDir.set(projectDir.resolve("scripts").also { it.mkdirs() })
1615
isRegistrationFileHierarchyEnabled.set(true)
16+
enableGodotCoroutines.set(true)
1717

1818
//uncomment to test android
1919
// isAndroidExportEnabled.set(true)

harness/tests/settings.gradle.kts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ includeBuild("../../kt") {
1010
substitute(module("com.utopia-rise:godot-gradle-plugin")).using(project(":godot-gradle-plugin"))
1111
substitute(module("com.utopia-rise:godot-library-debug")).using(project(":godot-library"))
1212
substitute(module("com.utopia-rise:godot-library-release")).using(project(":godot-library"))
13+
substitute(module("com.utopia-rise:godot-coroutine-library-debug")).using(project(":godot-coroutine-library"))
14+
substitute(module("com.utopia-rise:godot-coroutine-library-release")).using(project(":godot-coroutine-library"))
1315
substitute(module("com.utopia-rise:godot-kotlin-symbol-processor")).using(project(":godot-kotlin-symbol-processor"))
1416
substitute(module("com.utopia-rise:godot-entry-generator")).using(project(":godot-entry-generator"))
1517
}

harness/tests/src/main/kotlin/godot/tests/Invocation.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ package godot.tests
33
import godot.Button
44
import godot.NavigationMesh
55
import godot.Node3D
6-
import godot.XRServer
76
import godot.Object
7+
import godot.XRServer
88
import godot.annotation.ColorNoAlpha
99
import godot.annotation.Dir
1010
import godot.annotation.DoubleRange
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
import versioninfo.fullGodotKotlinJvmVersion
2+
3+
plugins {
4+
alias(libs.plugins.kotlin.jvm)
5+
id("com.utopia-rise.godot-publish")
6+
id("com.utopia-rise.versioninfo")
7+
alias(libs.plugins.kotlinPreProcessors)
8+
}
9+
10+
val isRelease = project.hasProperty("release")
11+
12+
kotlinDefinitions {
13+
definitionsObjectName.set("GodotJvmBuildConfig")
14+
15+
define("DEBUG", !isRelease)
16+
}
17+
18+
19+
kotlin {
20+
jvmToolchain(11)
21+
}
22+
23+
java {
24+
withSourcesJar()
25+
withJavadocJar()
26+
}
27+
28+
dependencies {
29+
// added here as a transitive dependency so the user can use reflection
30+
// we need to add it here so reflection is available where the code is loaded (Bootstrap.kt) otherwise it will not work
31+
api(kotlin("reflect", version = libs.versions.kotlin.get()))
32+
implementation("com.utopia-rise:tools-common:$fullGodotKotlinJvmVersion")
33+
testImplementation("junit", "junit", "4.12")
34+
}
35+
36+
val targetSuffix = if (isRelease) "release" else "debug"
37+
38+
publishing {
39+
publications {
40+
@Suppress("UNUSED_VARIABLE")
41+
val godotCoroutineLibraryPublication by creating(MavenPublication::class) {
42+
pom {
43+
name.set("${project.name}-$targetSuffix")
44+
description.set("Godot library extension allowing the use of coroutines in a Godot context.")
45+
}
46+
artifactId = "godot-coroutine-library-$targetSuffix"
47+
description = "Godot library extension allowing the use of coroutines in a Godot context."
48+
artifact(tasks.jar)
49+
artifact(tasks.getByName("sourcesJar"))
50+
artifact(tasks.getByName("javadocJar"))
51+
}
52+
}
53+
}

kt/plugins/godot-gradle-plugin/src/main/kotlin/godot/gradle/GodotExtension.kt

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -159,12 +159,20 @@ open class GodotExtension(objects: ObjectFactory) {
159159
val additionalGraalResourceConfigurationFiles = objects.property(Array<String>::class.java)
160160

161161
/**
162-
* enable verbose mode on native image generation.
162+
* Enable verbose mode on native image generation.
163163
*
164-
* if set to true, native-image tool will be in verbose mode.
164+
* If set to true, native-image tool will be in verbose mode.
165165
*/
166166
val isGraalVmNativeImageGenerationVerbose: Property<Boolean> = objects.property(Boolean::class.java)
167167

168+
169+
/**
170+
* Enable the use of coroutines in the context of Godot lifecycle callbacks (signals)
171+
*
172+
* If set to true, import godot-coroutine-library
173+
*/
174+
val enableGodotCoroutines: Property<Boolean> = objects.property(Boolean::class.java)
175+
168176
internal fun configureExtensionDefaults(target: Project) {
169177
val androidSdkRoot = System.getenv("ANDROID_SDK_ROOT")?.let { androidSdkRoot ->
170178
File(androidSdkRoot)
@@ -218,6 +226,8 @@ open class GodotExtension(objects: ObjectFactory) {
218226
additionalGraalResourceConfigurationFiles.set(arrayOf())
219227
isGraalVmNativeImageGenerationVerbose.set(false)
220228

229+
enableGodotCoroutines.set(false)
230+
221231
System.getenv("VC_VARS_PATH")?.let {
222232
windowsDeveloperVCVarsPath.set(File(it))
223233
}

kt/plugins/godot-gradle-plugin/src/main/kotlin/godot/gradle/GodotPlugin.kt

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,13 @@ package godot.gradle
22

33
import godot.gradle.projectExt.checkKotlinVersionCompatibility
44
import godot.gradle.projectExt.configureThirdPartyPlugins
5+
import godot.gradle.projectExt.godotCoroutineLibraryArtifactName
6+
import godot.gradle.projectExt.godotJvmExtension
57
import godot.gradle.projectExt.setupConfigurationsAndCompilations
68
import godot.gradle.projectExt.setupTasks
79
import godot.gradle.properties.GodotKotlinJvmPropertiesFileImpl
810
import godot.plugins.common.GodotKotlinJvmPropertiesFile
11+
import godot.utils.GodotBuildProperties
912
import org.gradle.api.Plugin
1013
import org.gradle.api.Project
1114
import org.gradle.tooling.provider.model.ToolingModelBuilder
@@ -18,24 +21,30 @@ abstract class GodotPlugin : Plugin<Project> {
1821
@get:Inject
1922
abstract val registry: ToolingModelBuilderRegistry
2023

21-
override fun apply(target: Project) {
22-
target.checkKotlinVersionCompatibility()
24+
override fun apply(target: Project) = with(target) {
25+
checkKotlinVersionCompatibility()
2326

24-
val extension = target.extensions.create("godot", GodotExtension::class.java).also {
25-
it.configureExtensionDefaults(target)
27+
val extension = extensions.create("godot", GodotExtension::class.java).also {
28+
it.configureExtensionDefaults(this)
2629
}
2730

28-
target.configureThirdPartyPlugins()
29-
target.setupConfigurationsAndCompilations()
30-
target.setupTasks()
31+
configureThirdPartyPlugins()
32+
setupConfigurationsAndCompilations()
33+
setupTasks()
3134

3235
// registers the tooling model builder, so it can be used by the ide plugin
33-
target.afterEvaluate {
36+
afterEvaluate {
37+
if (godotJvmExtension.enableGodotCoroutines.get()) {
38+
dependencies.add(
39+
"implementation",
40+
dependencies.create("com.utopia-rise:${godotCoroutineLibraryArtifactName}:${GodotBuildProperties.assembledGodotKotlinJvmVersion}")
41+
)
42+
}
3443
registry.register(
3544
PropertiesModelBuilder(
3645
isFqNameRegistrationEnabled = extension.isFqNameRegistrationEnabled.get(),
3746
isRegistrationFileHierarchyEnabled = extension.isRegistrationFileHierarchyEnabled.get(),
38-
registrationFileBaseDir = extension.registrationFileBaseDir.get().asFile.relativeTo(target.projectDir).path
47+
registrationFileBaseDir = extension.registrationFileBaseDir.get().asFile.relativeTo(projectDir).path
3948
)
4049
)
4150
}
@@ -55,7 +64,7 @@ abstract class GodotPlugin : Plugin<Project> {
5564
private val isFqNameRegistrationEnabled: Boolean,
5665
private val isRegistrationFileHierarchyEnabled: Boolean,
5766
private val registrationFileBaseDir: String,
58-
): ToolingModelBuilder {
67+
) : ToolingModelBuilder {
5968
override fun canBuild(modelName: String): Boolean {
6069
return modelName == GodotKotlinJvmPropertiesFile::class.java.name
6170
}

kt/plugins/godot-gradle-plugin/src/main/kotlin/godot/gradle/projectExt/projectExtensions.kt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,3 +36,6 @@ val Project.isRelease: Boolean
3636

3737
val Project.godotLibraryArtifactName: String
3838
get() = "godot-library-${if (isRelease) "release" else "debug"}"
39+
40+
val Project.godotCoroutineLibraryArtifactName: String
41+
get() = "godot-coroutine-library-${if (isRelease) "release" else "debug"}"

kt/settings.gradle.kts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ includeBuild("api-generator") {
4242
}
4343

4444
include("godot-library")
45+
include("godot-coroutine-library")
4546

4647
subdir("entry-generation") {
4748
include("godot-kotlin-symbol-processor")

0 commit comments

Comments
 (0)