From c11b84c9509084381aaab25a7fb2e82ea50d9be8 Mon Sep 17 00:00:00 2001 From: Daan Vanden Bosch Date: Sun, 15 Aug 2021 16:24:47 +0200 Subject: [PATCH] Psoserv now outputs its version when starting up. --- psolib/build.gradle.kts | 9 ++-- psoserv/build.gradle.kts | 51 ++++++++++++++++--- .../kotlin/world/phantasmal/psoserv/Main.kt | 2 +- 3 files changed, 51 insertions(+), 11 deletions(-) diff --git a/psolib/build.gradle.kts b/psolib/build.gradle.kts index e2516f64..483977b3 100644 --- a/psolib/build.gradle.kts +++ b/psolib/build.gradle.kts @@ -14,12 +14,15 @@ buildscript { } } +/** Source code generated by the build script goes here. */ +val generatedCommonSrc = File(buildDir, "generated-src/commonMain/kotlin") + val serializationVersion: String by project.extra kotlin { sourceSets { commonMain { - kotlin.setSrcDirs(kotlin.srcDirs + file("build/generated-src/commonMain/kotlin")) + kotlin.setSrcDirs(kotlin.srcDirs + generatedCommonSrc) dependencies { api(project(":core")) api("org.jetbrains.kotlinx:kotlinx-serialization-core:$serializationVersion") @@ -39,9 +42,7 @@ val generateOpcodes = tasks.register("generateOpcodes") { val packageName = "world.phantasmal.psolib.asm" val opcodesFile = file("srcGeneration/asm/opcodes.yml") - val outputFile = file( - "build/generated-src/commonMain/kotlin/${packageName.replace('.', '/')}/Opcodes.kt" - ) + val outputFile = File(generatedCommonSrc, "${packageName.replace('.', '/')}/Opcodes.kt") inputs.file(opcodesFile) outputs.file(outputFile) diff --git a/psoserv/build.gradle.kts b/psoserv/build.gradle.kts index 1c7bb9c9..c760a964 100644 --- a/psoserv/build.gradle.kts +++ b/psoserv/build.gradle.kts @@ -1,4 +1,5 @@ import org.graalvm.buildtools.gradle.tasks.BuildNativeImageTask +import org.jetbrains.kotlin.gradle.tasks.KotlinCompile plugins { id("world.phantasmal.jvm") @@ -7,23 +8,61 @@ plugins { id("org.graalvm.buildtools.native") version "0.9.2" } +version = "0.0.1" + +/** Source code generated by the build script goes here. */ +val generatedSrc = File(buildDir, "generated-src/main/kotlin") + +kotlin { + sourceSets { + main { + kotlin.setSrcDirs(kotlin.srcDirs + generatedSrc) + } + } +} + +val generateVersionInfo by tasks.registering { + group = "code generation" + + val packageName = "world.phantasmal.psoserv" + val outputFile = File(generatedSrc, "${packageName.replace('.', '/')}/VersionInfo.kt") + + inputs.property("version", version) + outputs.file(outputFile) + + doLast { + outputFile.writeText(""" + package $packageName + + object VersionInfo { + val version: String = "$version" + } + """.trimIndent()) + } +} + +tasks.withType().configureEach { + dependsOn(generateVersionInfo) +} + val mainClassFqn = "world.phantasmal.psoserv.MainKt" -val agentOutputDir = File(buildDir, "agent-output") +val nativeAgentOutputDir = File(buildDir, "agent-output") application { mainClass.set(mainClassFqn) } val nativeAgentRun by tasks.registering(JavaExec::class) { - description = "Run with the GraalVM native-image-agent to produce reflection info etc. for the nativeBuild task." + description = + "Run with the GraalVM native-image-agent to produce reflection info etc. for the nativeBuild task." group = "application" dependsOn(tasks.build) - outputs.dir(agentOutputDir) + outputs.dir(nativeAgentOutputDir) mainClass.set(mainClassFqn) classpath = sourceSets.main.get().runtimeClasspath - jvmArgs = listOf("-agentlib:native-image-agent=config-output-dir=$agentOutputDir") + jvmArgs = listOf("-agentlib:native-image-agent=config-output-dir=$nativeAgentOutputDir") args = listOf( "--nostart", "--config=graalvm-agent.conf", @@ -35,13 +74,13 @@ nativeBuild { mainClass.set(mainClassFqn) buildArgs.addAll( "--allow-incomplete-classpath", - "-H:ConfigurationFileDirectories=$agentOutputDir", + "-H:ConfigurationFileDirectories=$nativeAgentOutputDir", ) } tasks.withType().configureEach { dependsOn(nativeAgentRun) - inputs.dir(agentOutputDir) + inputs.dir(nativeAgentOutputDir) } val serializationVersion: String by project.extra diff --git a/psoserv/src/main/kotlin/world/phantasmal/psoserv/Main.kt b/psoserv/src/main/kotlin/world/phantasmal/psoserv/Main.kt index 2eae7019..9e4fdc52 100644 --- a/psoserv/src/main/kotlin/world/phantasmal/psoserv/Main.kt +++ b/psoserv/src/main/kotlin/world/phantasmal/psoserv/Main.kt @@ -28,7 +28,7 @@ private val LOGGER = KotlinLogging.logger("main") fun main(args: Array) { try { - LOGGER.info { "Initializing." } + LOGGER.info { "Initializing psoserv version ${VersionInfo.version}." } // Try to get config file location from arguments first. var configFile: File? = null