Skip to content

Commit 24022eb

Browse files
committed
Updated targets setup
1 parent 8e58235 commit 24022eb

File tree

5 files changed

+58
-42
lines changed

5 files changed

+58
-42
lines changed

gradle-conventions/common/src/main/kotlin/util/OptionalProperty.kt

Lines changed: 30 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,24 +6,43 @@ package util
66

77
import org.gradle.api.Project
88
import kotlin.reflect.KProperty
9+
import kotlin.text.replaceFirstChar
10+
11+
class OptionalProperty(private val target: Project, private val subpaths: Array<out String>) {
12+
private var cachedValue: Boolean? = null
913

10-
class OptionalProperty(private val target: Project) {
1114
operator fun getValue(thisRef: Any?, property: KProperty<*>): Boolean {
12-
return getValue("kotlinx.rpc.${property.name}")
15+
return cachedValue ?: target.getValue(property.name, subpaths).also { cachedValue = it }
1316
}
17+
}
18+
19+
private fun Project.getValue(propertyName: String, subpaths: Array<out String>): Boolean {
20+
val subpathProperty = subpaths
21+
.joinToString(".", postfix = ".")
22+
.takeIf { it != "." && it.isNotEmpty() }
23+
?: ""
24+
25+
val subpathCamelCase = subpaths
26+
.joinToString("") { it.replaceFirstChar(Char::titlecase) }
27+
.replaceFirstChar { it.lowercase() }
28+
29+
val name = propertyName
30+
.removePrefix(subpathCamelCase)
31+
.replaceFirstChar { it.lowercase() }
32+
33+
val fullName = "kotlinx.rpc.$subpathProperty$name"
1434

15-
fun getValue(propName: String): Boolean {
16-
return when {
17-
target.hasProperty(propName) -> (target.properties[propName] as String).toBoolean()
18-
else -> false
19-
}
35+
return when {
36+
hasProperty(fullName) -> (properties[fullName] as? String)?.toBooleanStrictOrNull()
37+
?: error("Invalid value for '$fullName' property: ${properties[fullName]}")
38+
else -> false
2039
}
2140
}
2241

23-
fun Project.optionalProperty(): OptionalProperty {
24-
return OptionalProperty(this)
42+
fun Project.optionalProperty(vararg subpaths: String): OptionalProperty {
43+
return OptionalProperty(this, subpaths)
2544
}
2645

27-
fun Project.optionalProperty(name: String): Boolean {
28-
return OptionalProperty(this).getValue(name)
46+
fun Project.optionalPropertyValue(name: String, vararg subpaths: String): Boolean {
47+
return getValue(name, subpaths)
2948
}

gradle-conventions/common/src/main/kotlin/util/ProjectKotlinConfig.kt

Lines changed: 14 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,6 @@ private fun loadTargetsSinceKotlinLookupTable(rootDir: String): Map<String, Stri
3535
class ProjectKotlinConfig(
3636
project: Project,
3737
val kotlinVersion: KotlinVersion,
38-
jvm: Boolean = true,
39-
js: Boolean = true,
40-
wasmJs: Boolean = true,
41-
wasmJsD8: Boolean = true,
42-
wasmWasi: Boolean = true,
43-
val native: Boolean = true,
4438
) : Project by project {
4539
private val targetsLookup by lazy {
4640
val globalRootDir: String by extra
@@ -56,11 +50,19 @@ class ProjectKotlinConfig(
5650
} ?: false
5751
}
5852

59-
val jvm: Boolean by lazy { jvm && isIncluded("jvm") }
60-
val js: Boolean by lazy { js && isIncluded("js") }
61-
val wasmJs: Boolean by lazy { wasmJs && isIncluded("wasmJs") }
62-
val wasmJsD8: Boolean by lazy { wasmJsD8 && wasmJs }
63-
val wasmWasi: Boolean by lazy { wasmWasi && isIncluded("wasmWasi") }
53+
private val excludeJvm: Boolean by optionalProperty("exclude")
54+
private val excludeJs: Boolean by optionalProperty("exclude")
55+
private val excludeWasmJs: Boolean by optionalProperty("exclude")
56+
private val excludeWasmJsD8: Boolean by optionalProperty("exclude")
57+
private val excludeWasmWasi: Boolean by optionalProperty("exclude")
58+
val excludeNative: Boolean by optionalProperty("exclude")
59+
60+
val jvm: Boolean by lazy { !excludeJvm && isIncluded("jvm") }
61+
val js: Boolean by lazy { !excludeJs && isIncluded("js") }
62+
val wasmJs: Boolean by lazy { !excludeWasmJs && isIncluded("wasmJs") }
63+
val wasmJsD8: Boolean by lazy { !excludeWasmJsD8 && wasmJs }
64+
val wasmWasi: Boolean by lazy { !excludeWasmWasi && isIncluded("wasmWasi") }
65+
val native = !excludeNative
6466

6567
private val nativeLookup by lazy {
6668
targetsLookup.filterKeys { key ->
@@ -75,29 +77,17 @@ class ProjectKotlinConfig(
7577
!kotlinMasterBuild && targetFunction.parameters.size == 1 && isIncluded(
7678
targetName = targetFunction.name,
7779
lookupTable = nativeLookup,
78-
)
80+
) && !optionalPropertyValue(targetFunction.name, "exclude")
7981
}.map { function ->
8082
function.call(kmp) as KotlinTarget
8183
}
8284
}
8385

8486
fun Project.withKotlinConfig(configure: ProjectKotlinConfig.() -> Unit) {
8587
val kotlinVersion: KotlinVersion by extra
86-
val excludeJvm: Boolean by optionalProperty()
87-
val excludeJs: Boolean by optionalProperty()
88-
val excludeWasmJs: Boolean by optionalProperty()
89-
val excludeWasmJsD8: Boolean by optionalProperty()
90-
val excludeWasmWasi: Boolean by optionalProperty()
91-
val excludeNative: Boolean by optionalProperty()
9288

9389
ProjectKotlinConfig(
9490
project = project,
9591
kotlinVersion = kotlinVersion,
96-
jvm = !excludeJvm,
97-
js = !excludeJs,
98-
wasmJs = !excludeWasmJs,
99-
wasmJsD8 = !excludeWasmJsD8,
100-
wasmWasi = !excludeWasmWasi,
101-
native = !excludeNative,
10292
).configure()
10393
}

krpc/gradle.properties

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,6 @@
33
#
44

55
# https://github.com/oshai/kotlin-logging/issues/433
6-
kotlinx.rpc.excludeWasmWasi=true
6+
kotlinx.rpc.exclude.wasmWasi=true
7+
kotlinx.rpc.exclude.watchosArm32=true
8+
kotlinx.rpc.exclude.watchosDeviceArm64=true

krpc/krpc-test/gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@
33
#
44

55
# tests fail with some obscure reason
6-
kotlinx.rpc.excludeWasmJsD8=true
6+
kotlinx.rpc.exclude.wasmJsD8=true

versions-root/targets-since-kotlin-lookup.json

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"wasmJs": "*",
66
"wasmWasi": "*",
77

8-
"mingwX64": "-",
8+
"mingwX64": "*",
99

1010
"linuxX64": "*",
1111
"linuxArm64": "*",
@@ -15,15 +15,20 @@
1515
"iosSimulatorArm64": "*",
1616

1717
"watchosX64": "*",
18-
"watchosArm32": "-",
18+
"watchosArm32": "*",
1919
"watchosArm64": "*",
2020
"watchosSimulatorArm64": "*",
21-
"watchosDeviceArm64": "-",
21+
"watchosDeviceArm64": "*",
2222

2323
"tvosX64": "*",
2424
"tvosArm64": "*",
25-
"tvosSimulatorArm64": "-",
25+
"tvosSimulatorArm64": "*",
2626

2727
"macosX64": "*",
28-
"macosArm64": "*"
28+
"macosArm64": "*",
29+
30+
"androidNativeArm32": "-",
31+
"androidNativeArm64": "-",
32+
"androidNativeX86": "-",
33+
"androidNativeX64": "-"
2934
}

0 commit comments

Comments
 (0)