Psoserv now outputs its version when starting up.

This commit is contained in:
Daan Vanden Bosch 2021-08-15 16:24:47 +02:00
parent 2a510ec116
commit c11b84c950
3 changed files with 51 additions and 11 deletions

View File

@ -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)

View File

@ -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<KotlinCompile>().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<BuildNativeImageTask>().configureEach {
dependsOn(nativeAgentRun)
inputs.dir(agentOutputDir)
inputs.dir(nativeAgentOutputDir)
}
val serializationVersion: String by project.extra

View File

@ -28,7 +28,7 @@ private val LOGGER = KotlinLogging.logger("main")
fun main(args: Array<String>) {
try {
LOGGER.info { "Initializing." }
LOGGER.info { "Initializing psoserv version ${VersionInfo.version}." }
// Try to get config file location from arguments first.
var configFile: File? = null