Skip to content

Commit 3673db3

Browse files
committed
chore: fix for buildConfig configuration cache and disable k2
1 parent 2633025 commit 3673db3

File tree

9 files changed

+69
-50
lines changed

9 files changed

+69
-50
lines changed

common/build.gradle.kts

+11-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,13 @@ application {
1616
applicationDefaultJvmArgs += jvmArguments(forAppRun = true)
1717
}
1818

19-
buildConfig { catalogVersions = project.versionCatalogMapOf() }
19+
buildConfig {
20+
projectName = rootProject.name
21+
projectVersion = project.version.toString()
22+
projectDesc = rootProject.description
23+
gitCommit = semver.commits.get().first()
24+
catalogVersions = project.versionCatalogMapOf()
25+
}
2026

2127
dependencies {
2228
commonMainApi(libs.arrow.suspendapp)
@@ -39,6 +45,10 @@ kotlin.sourceSets.jsMain {
3945
artifacts { add(commonJsResources.name, tasks.jsProcessResources) }
4046
}
4147

48+
// tasks.buildConfig {
49+
// outputs.upToDateWhen { false }
50+
// }
51+
4252
// configurations {
4353
// // Collects dependencies, constraints to be used by Consumable and Resolvable configurations.
4454
// val webResources by dependencyScope("webResources")

common/src/commonMain/kotlin/dev/suresh/Platform.kt

+16-3
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,18 @@ package dev.suresh
44

55
import BuildConfig
66
import kotlin.jvm.JvmName
7+
import kotlinx.coroutines.CoroutineScope
78
import kotlinx.coroutines.Dispatchers
9+
import kotlinx.coroutines.withContext
810
import kotlinx.datetime.Clock
911
import kotlinx.datetime.Instant
1012
import kotlinx.datetime.TimeZone
1113
import kotlinx.datetime.toLocalDateTime
1214
import kotlinx.serialization.json.Json
1315

14-
expect val platform: TargetPlatform
16+
expect val platform: Platform
1517

16-
interface TargetPlatform {
18+
interface Platform {
1719

1820
val name: String
1921

@@ -58,7 +60,7 @@ interface TargetPlatform {
5860
mapOf(
5961
"java" to sysProp("java.runtime.version", "n/a"),
6062
"kotlin" to KotlinVersion.CURRENT.toString(),
61-
"platform" to "Kotlin ${this@TargetPlatform.name}",
63+
"platform" to "Kotlin ${this@Platform.name}",
6264
),
6365
"git" to
6466
mapOf(
@@ -96,3 +98,14 @@ val utcDateTimeNow
9698
/** Gets the current date and time in the system's default time zone. */
9799
val localDateTimeNow
98100
get() = Clock.System.now().toLocalDateTime(TimeZone.currentSystemDefault())
101+
102+
/**
103+
* Runs the given suspend block on a virtual thread, so that we can call blocking I/O APIs from
104+
* coroutines
105+
*/
106+
suspend inline fun <T> runOnVirtualThread(crossinline block: suspend CoroutineScope.() -> T): T =
107+
withContext(platform.vtDispatcher) { block() }
108+
109+
/** A coroutine scope that uses [Platform.vtDispatcher] as its dispatcher. */
110+
val virtualThreadScope
111+
get() = CoroutineScope(platform.vtDispatcher)
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package dev.suresh
22

3-
actual val platform: TargetPlatform = DesktopPlatform
3+
actual val platform: Platform = DesktopPlatform
44

5-
object DesktopPlatform : TargetPlatform {
5+
object DesktopPlatform : Platform {
66
override val name: String = "Desktop JVM"
77
}

common/src/jsMain/kotlin/dev/suresh/Platform.kt

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ package dev.suresh
22

33
import kotlinx.browser.window
44

5-
actual val platform: TargetPlatform = JsPlatform
5+
actual val platform: Platform = JsPlatform
66

7-
object JsPlatform : TargetPlatform {
7+
object JsPlatform : Platform {
88
override val name: String = "JS"
99

1010
override val osInfo: Map<String, String?>

common/src/jvmMain/kotlin/dev/suresh/Platform.kt

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@ import java.util.concurrent.Executors
88
import kotlinx.coroutines.asCoroutineDispatcher
99
import org.slf4j.LoggerFactory
1010

11-
actual val platform: TargetPlatform = JvmPlatform
11+
actual val platform: Platform = JvmPlatform
1212

13-
object JvmPlatform : TargetPlatform {
13+
object JvmPlatform : Platform {
1414

1515
private val log = LoggerFactory.getLogger(this::class.java)
1616

gradle.properties

-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ org.gradle.kotlin.dsl.allWarningsAsErrors=true
1717

1818
## Kotlin
1919
kotlin.code.style=official
20-
kotlin.experimental.tryK2=true
2120
kotlin.daemon.jvmargs=--show-version --enable-preview -Xmx6g
2221
kotlin.jvm.target.validation.mode=warning
2322
kotlin.build.report.output=build_scan

gradle/build-logic/common-plugins/src/main/kotlin/plugins/kotlin.mpp.gradle.kts

+7-3
Original file line numberDiff line numberDiff line change
@@ -149,9 +149,13 @@ kotlin {
149149
// }
150150
// }
151151
//
152-
// targets["metadata"].compilations["main"].defaultSourceSet {
153-
// dependsOn(jvmCommon)
154-
// }
152+
153+
// val target = targets.first { it.platformType == KotlinPlatformType.common }
154+
// val compilation = target.compilations["main"]
155+
// // OR val compilation = targets["metadata"].compilations["main"]
156+
// compilation.defaultSourceSet.kotlin.srcDir(buildConfig)
157+
// // val newSourceSet = sourceSets.create("gen")
158+
// // compilation.defaultSourceSet.dependsOn(newSourceSet)
155159

156160
jvmMain {
157161
// dependsOn(jvmCommon)
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,29 @@
11
package tasks
22

33
import com.javiersc.semver.project.gradle.plugin.Commit
4-
import gg.jte.ContentType
5-
import gg.jte.TemplateEngine
6-
import gg.jte.output.StringOutput
4+
import gg.jte.generated.precompiled.StaticTemplates
75
import javax.inject.Inject
86
import org.gradle.api.DefaultTask
9-
import org.gradle.api.file.DirectoryProperty
107
import org.gradle.api.file.ProjectLayout
118
import org.gradle.api.model.ObjectFactory
129
import org.gradle.api.tasks.*
1310
import org.gradle.kotlin.dsl.*
1411
import org.gradle.language.base.plugins.LifecycleBasePlugin
1512

1613
@CacheableTask
17-
abstract class BuildConfig @Inject constructor(private val extn: BuildConfigExtension) :
14+
abstract class BuildConfig @Inject constructor(@Nested val extn: BuildConfigExtension) :
1815
DefaultTask() {
1916

20-
@get:Input val version = extn.projectVersion
21-
2217
@get:Internal internal val templateName = "BuildConfig.kte"
2318

24-
@get:[OutputDirectory Optional]
25-
val generatedOutputDir: DirectoryProperty = extn.outputDir
26-
2719
init {
2820
description = "Generate build config class"
2921
group = LifecycleBasePlugin.BUILD_TASK_NAME
3022
}
3123

3224
@TaskAction
3325
fun execute() {
34-
val dir = generatedOutputDir.asFile.get()
26+
val dir = extn.outputDir.asFile.get()
3527
dir.deleteRecursively()
3628
dir.mkdirs()
3729

@@ -40,7 +32,7 @@ abstract class BuildConfig @Inject constructor(private val extn: BuildConfigExte
4032
val pkg = fqName.substringBeforeLast(".", "")
4133

4234
val file = dir.resolve("$className.kt")
43-
logger.quiet("Generated build config file: ${file.path}")
35+
logger.quiet("Generated build config file: ${file.name}")
4436

4537
// Get git commit info
4638
val gitCommit = run {
@@ -59,38 +51,39 @@ abstract class BuildConfig @Inject constructor(private val extn: BuildConfigExte
5951
mapOf(
6052
"name" to extn.projectName.get(),
6153
"description" to extn.projectDesc.get(),
62-
"version" to version.get(),
54+
"version" to extn.projectVersion.get(),
6355
)
6456

65-
// the<VersionCatalogsExtension>().named("libs").
66-
val params =
67-
mapOf(
68-
"className" to className,
69-
"pkg" to pkg,
70-
"projectProps" to rootProjectProps,
71-
"gitCommit" to gitCommit,
72-
"catalogVersions" to extn.catalogVersions.get(),
73-
"dependencies" to extn.dependencies.get(),
74-
)
57+
// val content = StringOutput()
58+
// val tmplEngine = TemplateEngine.createPrecompiled(ContentType.Plain).apply {
59+
// setTrimControlStructures(true) }
60+
// tmplEngine.render(templateName, params, content)
7561

76-
val content = StringOutput()
77-
val tmplEngine =
78-
TemplateEngine.createPrecompiled(ContentType.Plain).apply { setTrimControlStructures(true) }
62+
val content =
63+
StaticTemplates()
64+
.BuildConfig(
65+
className = className,
66+
pkg = pkg,
67+
projectProps = rootProjectProps,
68+
gitCommit = gitCommit,
69+
catalogVersions = extn.catalogVersions.get(),
70+
dependencies = extn.dependencies.get())
71+
.render()
7972

80-
tmplEngine.render(templateName, params, content)
81-
file.writeText(content.toString())
82-
// outputs.dirs(generatedOutputDir)
73+
file.writeText(content)
74+
// outputs.dirs(extn.outputDir)
8375
}
8476
}
8577

8678
open class BuildConfigExtension @Inject constructor(layout: ProjectLayout, objects: ObjectFactory) {
8779
@get:Input val classFqName = objects.property<String>().convention("BuildConfig")
80+
@get:Input val projectVersion = objects.property<String>()
8881
@get:Input val projectName = objects.property<String>()
8982
@get:Input val projectDesc = objects.property<String>()
90-
@get:Input val gitCommit = objects.property<Commit>()
9183
@get:Input val catalogVersions = objects.mapProperty<String, String>().convention(emptyMap())
9284
@get:Input val dependencies = objects.listProperty<String>().convention(emptyList())
93-
val projectVersion = objects.property<String>()
85+
@Internal val gitCommit = objects.property<Commit>()
86+
@get:[OutputDirectory Optional]
9487
val outputDir =
9588
objects.directoryProperty().convention(layout.buildDirectory.dir("generated/buildconfig"))
9689
}

gradle/libs.versions.toml

+5-5
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ kotlin-ksp = "1.9.20-Beta2-1.0.13"
55
kotlin-jvmtarget = "21"
66
kotlin-dsl-jvmtarget = "17"
77
kotlin-api-version = "1.9"
8-
kotlin-lang-version = "2.0"
8+
kotlin-lang-version = "1.9"
99
gradle = "8.4"
1010
node-version = "20.6.1"
1111
java-vendor = "Oracle"
@@ -49,7 +49,7 @@ dokka = "1.9.0"
4949
intellij-coverage = "1.0.733"
5050
intellij-markdown = "0.5.2"
5151
jgit = "6.5.0.202303070854-r"
52-
jte = "3.1.1"
52+
jte = "3.1.2"
5353
jimfs = "1.3.0"
5454
junit = "5.10.0"
5555
koin = "3.4.1"
@@ -81,7 +81,7 @@ uri-kmp = "0.0.15"
8181
cash-turbine = "1.0.0"
8282
kmp-store5 = "5.0.0-beta01"
8383
kmp-settings = "1.0.0"
84-
parsus = "0.5.5"
84+
parsus = "0.6.0"
8585
java-keyring = "1.0.3"
8686
java-keychain = "1.1.0"
8787
webjars-xterm = "5.1.0"
@@ -114,15 +114,15 @@ npm-vega-lite = "5.13.0"
114114
npm-jsjoda-tz = "2.18.0"
115115

116116
# Plugin versions
117-
benmanes = "0.48.0"
117+
benmanes = "0.49.0"
118118
foojay-resolver = "0.7.0"
119119
gradle-enterprise = "3.15.1"
120120
nexus-publish = "2.0.0-rc-1"
121121
shadow = "8.1.1"
122122
spotless = "6.22.0"
123123
semver-plugin = "0.5.0-rc.5"
124124
taskinfo = "2.1.0"
125-
dependency-analysis = "1.24.0"
125+
dependency-analysis = "1.25.0"
126126
best-practices-plugin = "0.10"
127127
graalvm-nativeimage = "0.9.27"
128128
github-depgraph = "0.1.0"

0 commit comments

Comments
 (0)