From 3673db3d0add70a28918dfeabc3810ffa82099f0 Mon Sep 17 00:00:00 2001 From: Suresh G Date: Sun, 8 Oct 2023 18:11:03 -0700 Subject: [PATCH] chore: fix for buildConfig configuration cache and disable k2 --- common/build.gradle.kts | 12 +++- .../commonMain/kotlin/dev/suresh/Platform.kt | 19 ++++++- .../desktopMain/kotlin/dev/suresh/Platform.kt | 4 +- .../src/jsMain/kotlin/dev/suresh/Platform.kt | 4 +- .../src/jvmMain/kotlin/dev/suresh/Platform.kt | 4 +- gradle.properties | 1 - .../main/kotlin/plugins/kotlin.mpp.gradle.kts | 10 +++- .../src/main/kotlin/tasks/BuildConfig.kt | 55 ++++++++----------- gradle/libs.versions.toml | 10 ++-- 9 files changed, 69 insertions(+), 50 deletions(-) diff --git a/common/build.gradle.kts b/common/build.gradle.kts index 17e6122ad62..5e64ea2ddb8 100644 --- a/common/build.gradle.kts +++ b/common/build.gradle.kts @@ -16,7 +16,13 @@ application { applicationDefaultJvmArgs += jvmArguments(forAppRun = true) } -buildConfig { catalogVersions = project.versionCatalogMapOf() } +buildConfig { + projectName = rootProject.name + projectVersion = project.version.toString() + projectDesc = rootProject.description + gitCommit = semver.commits.get().first() + catalogVersions = project.versionCatalogMapOf() +} dependencies { commonMainApi(libs.arrow.suspendapp) @@ -39,6 +45,10 @@ kotlin.sourceSets.jsMain { artifacts { add(commonJsResources.name, tasks.jsProcessResources) } } +// tasks.buildConfig { +// outputs.upToDateWhen { false } +// } + // configurations { // // Collects dependencies, constraints to be used by Consumable and Resolvable configurations. // val webResources by dependencyScope("webResources") diff --git a/common/src/commonMain/kotlin/dev/suresh/Platform.kt b/common/src/commonMain/kotlin/dev/suresh/Platform.kt index 2c9b29948de..e7a2715884d 100644 --- a/common/src/commonMain/kotlin/dev/suresh/Platform.kt +++ b/common/src/commonMain/kotlin/dev/suresh/Platform.kt @@ -4,16 +4,18 @@ package dev.suresh import BuildConfig import kotlin.jvm.JvmName +import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.Dispatchers +import kotlinx.coroutines.withContext import kotlinx.datetime.Clock import kotlinx.datetime.Instant import kotlinx.datetime.TimeZone import kotlinx.datetime.toLocalDateTime import kotlinx.serialization.json.Json -expect val platform: TargetPlatform +expect val platform: Platform -interface TargetPlatform { +interface Platform { val name: String @@ -58,7 +60,7 @@ interface TargetPlatform { mapOf( "java" to sysProp("java.runtime.version", "n/a"), "kotlin" to KotlinVersion.CURRENT.toString(), - "platform" to "Kotlin ${this@TargetPlatform.name}", + "platform" to "Kotlin ${this@Platform.name}", ), "git" to mapOf( @@ -96,3 +98,14 @@ val utcDateTimeNow /** Gets the current date and time in the system's default time zone. */ val localDateTimeNow get() = Clock.System.now().toLocalDateTime(TimeZone.currentSystemDefault()) + +/** + * Runs the given suspend block on a virtual thread, so that we can call blocking I/O APIs from + * coroutines + */ +suspend inline fun runOnVirtualThread(crossinline block: suspend CoroutineScope.() -> T): T = + withContext(platform.vtDispatcher) { block() } + +/** A coroutine scope that uses [Platform.vtDispatcher] as its dispatcher. */ +val virtualThreadScope + get() = CoroutineScope(platform.vtDispatcher) diff --git a/common/src/desktopMain/kotlin/dev/suresh/Platform.kt b/common/src/desktopMain/kotlin/dev/suresh/Platform.kt index 49c208aad07..63138924067 100644 --- a/common/src/desktopMain/kotlin/dev/suresh/Platform.kt +++ b/common/src/desktopMain/kotlin/dev/suresh/Platform.kt @@ -1,7 +1,7 @@ package dev.suresh -actual val platform: TargetPlatform = DesktopPlatform +actual val platform: Platform = DesktopPlatform -object DesktopPlatform : TargetPlatform { +object DesktopPlatform : Platform { override val name: String = "Desktop JVM" } diff --git a/common/src/jsMain/kotlin/dev/suresh/Platform.kt b/common/src/jsMain/kotlin/dev/suresh/Platform.kt index 5adab5289a8..1bf67af6aac 100644 --- a/common/src/jsMain/kotlin/dev/suresh/Platform.kt +++ b/common/src/jsMain/kotlin/dev/suresh/Platform.kt @@ -2,9 +2,9 @@ package dev.suresh import kotlinx.browser.window -actual val platform: TargetPlatform = JsPlatform +actual val platform: Platform = JsPlatform -object JsPlatform : TargetPlatform { +object JsPlatform : Platform { override val name: String = "JS" override val osInfo: Map diff --git a/common/src/jvmMain/kotlin/dev/suresh/Platform.kt b/common/src/jvmMain/kotlin/dev/suresh/Platform.kt index b47254f6d31..8a0b87f8c08 100644 --- a/common/src/jvmMain/kotlin/dev/suresh/Platform.kt +++ b/common/src/jvmMain/kotlin/dev/suresh/Platform.kt @@ -8,9 +8,9 @@ import java.util.concurrent.Executors import kotlinx.coroutines.asCoroutineDispatcher import org.slf4j.LoggerFactory -actual val platform: TargetPlatform = JvmPlatform +actual val platform: Platform = JvmPlatform -object JvmPlatform : TargetPlatform { +object JvmPlatform : Platform { private val log = LoggerFactory.getLogger(this::class.java) diff --git a/gradle.properties b/gradle.properties index 5b526d64902..24214ec3469 100644 --- a/gradle.properties +++ b/gradle.properties @@ -17,7 +17,6 @@ org.gradle.kotlin.dsl.allWarningsAsErrors=true ## Kotlin kotlin.code.style=official -kotlin.experimental.tryK2=true kotlin.daemon.jvmargs=--show-version --enable-preview -Xmx6g kotlin.jvm.target.validation.mode=warning kotlin.build.report.output=build_scan diff --git a/gradle/build-logic/common-plugins/src/main/kotlin/plugins/kotlin.mpp.gradle.kts b/gradle/build-logic/common-plugins/src/main/kotlin/plugins/kotlin.mpp.gradle.kts index ca4f09ecff6..cbc13f8729d 100644 --- a/gradle/build-logic/common-plugins/src/main/kotlin/plugins/kotlin.mpp.gradle.kts +++ b/gradle/build-logic/common-plugins/src/main/kotlin/plugins/kotlin.mpp.gradle.kts @@ -149,9 +149,13 @@ kotlin { // } // } // - // targets["metadata"].compilations["main"].defaultSourceSet { - // dependsOn(jvmCommon) - // } + + // val target = targets.first { it.platformType == KotlinPlatformType.common } + // val compilation = target.compilations["main"] + // // OR val compilation = targets["metadata"].compilations["main"] + // compilation.defaultSourceSet.kotlin.srcDir(buildConfig) + // // val newSourceSet = sourceSets.create("gen") + // // compilation.defaultSourceSet.dependsOn(newSourceSet) jvmMain { // dependsOn(jvmCommon) diff --git a/gradle/build-logic/common-plugins/src/main/kotlin/tasks/BuildConfig.kt b/gradle/build-logic/common-plugins/src/main/kotlin/tasks/BuildConfig.kt index 24fbec2b99a..141e4664554 100644 --- a/gradle/build-logic/common-plugins/src/main/kotlin/tasks/BuildConfig.kt +++ b/gradle/build-logic/common-plugins/src/main/kotlin/tasks/BuildConfig.kt @@ -1,12 +1,9 @@ package tasks import com.javiersc.semver.project.gradle.plugin.Commit -import gg.jte.ContentType -import gg.jte.TemplateEngine -import gg.jte.output.StringOutput +import gg.jte.generated.precompiled.StaticTemplates import javax.inject.Inject import org.gradle.api.DefaultTask -import org.gradle.api.file.DirectoryProperty import org.gradle.api.file.ProjectLayout import org.gradle.api.model.ObjectFactory import org.gradle.api.tasks.* @@ -14,16 +11,11 @@ import org.gradle.kotlin.dsl.* import org.gradle.language.base.plugins.LifecycleBasePlugin @CacheableTask -abstract class BuildConfig @Inject constructor(private val extn: BuildConfigExtension) : +abstract class BuildConfig @Inject constructor(@Nested val extn: BuildConfigExtension) : DefaultTask() { - @get:Input val version = extn.projectVersion - @get:Internal internal val templateName = "BuildConfig.kte" - @get:[OutputDirectory Optional] - val generatedOutputDir: DirectoryProperty = extn.outputDir - init { description = "Generate build config class" group = LifecycleBasePlugin.BUILD_TASK_NAME @@ -31,7 +23,7 @@ abstract class BuildConfig @Inject constructor(private val extn: BuildConfigExte @TaskAction fun execute() { - val dir = generatedOutputDir.asFile.get() + val dir = extn.outputDir.asFile.get() dir.deleteRecursively() dir.mkdirs() @@ -40,7 +32,7 @@ abstract class BuildConfig @Inject constructor(private val extn: BuildConfigExte val pkg = fqName.substringBeforeLast(".", "") val file = dir.resolve("$className.kt") - logger.quiet("Generated build config file: ${file.path}") + logger.quiet("Generated build config file: ${file.name}") // Get git commit info val gitCommit = run { @@ -59,38 +51,39 @@ abstract class BuildConfig @Inject constructor(private val extn: BuildConfigExte mapOf( "name" to extn.projectName.get(), "description" to extn.projectDesc.get(), - "version" to version.get(), + "version" to extn.projectVersion.get(), ) - // the().named("libs"). - val params = - mapOf( - "className" to className, - "pkg" to pkg, - "projectProps" to rootProjectProps, - "gitCommit" to gitCommit, - "catalogVersions" to extn.catalogVersions.get(), - "dependencies" to extn.dependencies.get(), - ) + // val content = StringOutput() + // val tmplEngine = TemplateEngine.createPrecompiled(ContentType.Plain).apply { + // setTrimControlStructures(true) } + // tmplEngine.render(templateName, params, content) - val content = StringOutput() - val tmplEngine = - TemplateEngine.createPrecompiled(ContentType.Plain).apply { setTrimControlStructures(true) } + val content = + StaticTemplates() + .BuildConfig( + className = className, + pkg = pkg, + projectProps = rootProjectProps, + gitCommit = gitCommit, + catalogVersions = extn.catalogVersions.get(), + dependencies = extn.dependencies.get()) + .render() - tmplEngine.render(templateName, params, content) - file.writeText(content.toString()) - // outputs.dirs(generatedOutputDir) + file.writeText(content) + // outputs.dirs(extn.outputDir) } } open class BuildConfigExtension @Inject constructor(layout: ProjectLayout, objects: ObjectFactory) { @get:Input val classFqName = objects.property().convention("BuildConfig") + @get:Input val projectVersion = objects.property() @get:Input val projectName = objects.property() @get:Input val projectDesc = objects.property() - @get:Input val gitCommit = objects.property() @get:Input val catalogVersions = objects.mapProperty().convention(emptyMap()) @get:Input val dependencies = objects.listProperty().convention(emptyList()) - val projectVersion = objects.property() + @Internal val gitCommit = objects.property() + @get:[OutputDirectory Optional] val outputDir = objects.directoryProperty().convention(layout.buildDirectory.dir("generated/buildconfig")) } diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index d7aba4609f3..2b8208b0fc7 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -5,7 +5,7 @@ kotlin-ksp = "1.9.20-Beta2-1.0.13" kotlin-jvmtarget = "21" kotlin-dsl-jvmtarget = "17" kotlin-api-version = "1.9" -kotlin-lang-version = "2.0" +kotlin-lang-version = "1.9" gradle = "8.4" node-version = "20.6.1" java-vendor = "Oracle" @@ -49,7 +49,7 @@ dokka = "1.9.0" intellij-coverage = "1.0.733" intellij-markdown = "0.5.2" jgit = "6.5.0.202303070854-r" -jte = "3.1.1" +jte = "3.1.2" jimfs = "1.3.0" junit = "5.10.0" koin = "3.4.1" @@ -81,7 +81,7 @@ uri-kmp = "0.0.15" cash-turbine = "1.0.0" kmp-store5 = "5.0.0-beta01" kmp-settings = "1.0.0" -parsus = "0.5.5" +parsus = "0.6.0" java-keyring = "1.0.3" java-keychain = "1.1.0" webjars-xterm = "5.1.0" @@ -114,7 +114,7 @@ npm-vega-lite = "5.13.0" npm-jsjoda-tz = "2.18.0" # Plugin versions -benmanes = "0.48.0" +benmanes = "0.49.0" foojay-resolver = "0.7.0" gradle-enterprise = "3.15.1" nexus-publish = "2.0.0-rc-1" @@ -122,7 +122,7 @@ shadow = "8.1.1" spotless = "6.22.0" semver-plugin = "0.5.0-rc.5" taskinfo = "2.1.0" -dependency-analysis = "1.24.0" +dependency-analysis = "1.25.0" best-practices-plugin = "0.10" graalvm-nativeimage = "0.9.27" github-depgraph = "0.1.0"