Skip to content

Commit 12c09bf

Browse files
committed
Improve usages of providers.gradleProperty which will potentially allow to more frequently reuse Gradle CC
1 parent e345e59 commit 12c09bf

File tree

4 files changed

+54
-41
lines changed

4 files changed

+54
-41
lines changed

build-logic/src/main/kotlin/ckbuild.multiplatform-base.gradle.kts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
* Copyright (c) 2023-2025 Oleg Yukhnevich. Use of this source code is governed by the Apache 2.0 license.
33
*/
44

5+
import ckbuild.*
56
import org.jetbrains.kotlin.gradle.*
67
import org.jetbrains.kotlin.gradle.dsl.*
78
import org.jetbrains.kotlin.gradle.targets.jvm.*
@@ -11,8 +12,8 @@ plugins {
1112
kotlin("multiplatform")
1213
}
1314

14-
// true by default
15-
val warningsAsErrors = providers.gradleProperty("ckbuild.warningsAsErrors").orNull?.toBoolean() ?: true
15+
val warningsAsErrors = booleanProperty("ckbuild.warningsAsErrors", defaultValue = true)
16+
val skipLinkTasks = booleanProperty("ckbuild.skipLinkTasks", defaultValue = false)
1617

1718
@OptIn(ExperimentalKotlinGradlePluginApi::class)
1819
kotlin {
@@ -36,6 +37,7 @@ tasks.register("linkAll") {
3637
dependsOn(tasks.withType<KotlinNativeLink>())
3738
}
3839

39-
if (providers.gradleProperty("ckbuild.skipLinkTasks").map(String::toBoolean).getOrElse(false)) {
40-
tasks.withType<KotlinNativeLink>().configureEach { onlyIf { false } }
40+
tasks.withType<KotlinNativeLink>().configureEach {
41+
val skipLinkTasks = skipLinkTasks // for CC
42+
onlyIf { !skipLinkTasks.get() }
4143
}

build-logic/src/main/kotlin/ckbuild.multiplatform-tests.gradle.kts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
* Copyright (c) 2023-2025 Oleg Yukhnevich. Use of this source code is governed by the Apache 2.0 license.
33
*/
44

5+
import ckbuild.*
56
import ckbuild.tests.*
67
import com.android.build.gradle.internal.tasks.*
78
import org.jetbrains.kotlin.gradle.*
@@ -24,6 +25,8 @@ if (project.name != "cryptography-provider-jdk-android-tests") {
2425
tasks.register("koverVerify")
2526
}
2627

28+
val skipTestTasks = booleanProperty("ckbuild.skipTestTasks", defaultValue = false)
29+
2730
@OptIn(ExperimentalKotlinGradlePluginApi::class)
2831
kotlin {
2932
// just applying `kotlin-test` doesn't work for JVM if there are multiple test tasks (like when we test on different JDKs)
@@ -106,6 +109,7 @@ listOf("ios", "watchos", "tvos", "macos").forEach { targetGroup ->
106109
)
107110
}
108111

109-
if (providers.gradleProperty("ckbuild.skipTestTasks").map(String::toBoolean).getOrElse(false)) {
110-
tasks.matching { it is AbstractTestTask || it is AndroidTestTask || it.name == "koverVerify" }.configureEach { onlyIf { false } }
112+
tasks.matching { it is AbstractTestTask || it is AndroidTestTask || it.name == "koverVerify" }.configureEach {
113+
val skipTestTasks = skipTestTasks // for CC
114+
onlyIf { !skipTestTasks.get() }
111115
}

build-logic/src/main/kotlin/ckbuild/tests/TestFilters.kt

Lines changed: 36 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
/*
2-
* Copyright (c) 2024 Oleg Yukhnevich. Use of this source code is governed by the Apache 2.0 license.
2+
* Copyright (c) 2024-2025 Oleg Yukhnevich. Use of this source code is governed by the Apache 2.0 license.
33
*/
44

55
@file:Suppress("UnstableApiUsage")
66

77
package ckbuild.tests
88

9+
import ckbuild.*
910
import com.android.build.api.dsl.*
1011
import org.gradle.api.*
1112
import org.gradle.api.tasks.testing.*
@@ -19,52 +20,52 @@ class TestFilters(
1920
)
2021

2122
fun Project.applyProviderTestFilters() {
22-
val providerTestsStep = providers.gradleProperty("ckbuild.providerTests.step").orNull
23-
24-
val testFilters = when (providerTestsStep) {
25-
null -> TestFilters(
26-
androidTestRegex = "^((?!CompatibilityTest#(generateStep|generateStressStep|validateStep)).)*$",
27-
kotlinTestFilter = {
28-
setExcludePatterns(
29-
"*CompatibilityTest.generateStep",
30-
"*CompatibilityTest.generateStressStep",
31-
"*CompatibilityTest.validateStep"
32-
)
33-
}
34-
)
35-
"compatibility.generate" -> TestFilters(
36-
androidTestRegex = "^.*CompatibilityTest#generateStep$",
37-
kotlinTestFilter = {
38-
setIncludePatterns("*CompatibilityTest.generateStep")
39-
}
40-
)
41-
"compatibility.generateStress" -> TestFilters(
42-
androidTestRegex = "^.*CompatibilityTest#generateStressStep$",
43-
kotlinTestFilter = {
44-
setIncludePatterns("*CompatibilityTest.generateStressStep")
45-
}
46-
)
47-
"compatibility.validate" -> TestFilters(
48-
androidTestRegex = "^.*CompatibilityTest#validateStep$",
49-
kotlinTestFilter = {
50-
setIncludePatterns("*CompatibilityTest.validateStep")
51-
}
52-
)
53-
else -> error("wrong argument")
23+
val testFilters = stringProperty("ckbuild.providerTests.step", defaultValue = "compatibility.loop").map { providerTestsStep ->
24+
when (providerTestsStep) {
25+
"compatibility.loop" -> TestFilters(
26+
androidTestRegex = "^((?!CompatibilityTest#(generateStep|generateStressStep|validateStep)).)*$",
27+
kotlinTestFilter = {
28+
setExcludePatterns(
29+
"*CompatibilityTest.generateStep",
30+
"*CompatibilityTest.generateStressStep",
31+
"*CompatibilityTest.validateStep"
32+
)
33+
}
34+
)
35+
"compatibility.generate" -> TestFilters(
36+
androidTestRegex = "^.*CompatibilityTest#generateStep$",
37+
kotlinTestFilter = {
38+
setIncludePatterns("*CompatibilityTest.generateStep")
39+
}
40+
)
41+
"compatibility.generateStress" -> TestFilters(
42+
androidTestRegex = "^.*CompatibilityTest#generateStressStep$",
43+
kotlinTestFilter = {
44+
setIncludePatterns("*CompatibilityTest.generateStressStep")
45+
}
46+
)
47+
"compatibility.validate" -> TestFilters(
48+
androidTestRegex = "^.*CompatibilityTest#validateStep$",
49+
kotlinTestFilter = {
50+
setIncludePatterns("*CompatibilityTest.validateStep")
51+
}
52+
)
53+
else -> error("wrong argument")
54+
}
5455
}
5556

5657
plugins.withId("org.jetbrains.kotlin.multiplatform") {
5758
extensions.configure<KotlinMultiplatformExtension>("kotlin") {
5859
targets.withType<KotlinTargetWithTests<*, *>>().configureEach {
5960
testRuns.configureEach {
60-
filter(testFilters.kotlinTestFilter)
61+
filter(testFilters.get().kotlinTestFilter)
6162
}
6263
}
6364

6465
plugins.withId("com.android.kotlin.multiplatform.library") {
6566
androidLibrary {
6667
compilations.withType(KotlinMultiplatformAndroidDeviceTestCompilation::class).configureEach {
67-
instrumentationRunnerArguments["tests_regex"] = testFilters.androidTestRegex
68+
instrumentationRunnerArguments["tests_regex"] = testFilters.get().androidTestRegex
6869
}
6970
}
7071
}

build-logic/src/main/kotlin/ckbuild/utils.kt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,9 @@ import org.gradle.kotlin.dsl.*
1212
val Project.libsCatalog: VersionCatalog get() = extensions.getByName<VersionCatalogsExtension>("versionCatalogs").named("libs")
1313

1414
fun Project.versionCatalogLib(alias: String): Provider<MinimalExternalModuleDependency> = libsCatalog.findLibrary(alias).get()
15+
16+
fun Project.booleanProperty(name: String, defaultValue: Boolean): Provider<Boolean> =
17+
providers.gradleProperty(name).map(String::toBoolean).orElse(defaultValue)
18+
19+
fun Project.stringProperty(name: String, defaultValue: String): Provider<String> =
20+
providers.gradleProperty(name).orElse(defaultValue)

0 commit comments

Comments
 (0)