Skip to content

Commit fc09aa3

Browse files
ALikhachevqurbonzoda
authored andcommitted
Declare system properties reads to be compatible w/ configuration cache
Gradle reports direct system properties reads as configuration cache problems as system properties are potential build configuration inputs. See https://docs.gradle.org/7.0/userguide/configuration_cache.html for more details
1 parent ba68c66 commit fc09aa3

File tree

5 files changed

+31
-10
lines changed

5 files changed

+31
-10
lines changed

plugin/main/src/kotlinx/benchmark/gradle/BenchmarksPlugin.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ class BenchmarksPlugin : Plugin<Project> {
5858
task<DefaultTask>(it.prefixName(RUN_BENCHMARKS_TASKNAME)) {
5959
group = BENCHMARKS_TASK_GROUP
6060
description = "Execute all benchmarks in a project"
61-
extensions.extraProperties.set("idea.internal.test", System.getProperty("idea.active"))
61+
extensions.extraProperties.set("idea.internal.test", getSystemProperty("idea.active"))
6262

6363
// Force all benchmarks runner to first build all benchmarks to ensure it won't spend time
6464
// running some benchmarks when other will fail to compile

plugin/main/src/kotlinx/benchmark/gradle/JsNodeTasks.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ fun Project.createJsBenchmarkExecTask(
1717

1818
group = BenchmarksPlugin.BENCHMARKS_TASK_GROUP
1919
description = "Executes benchmark for '${target.name}'"
20-
extensions.extraProperties.set("idea.internal.test", System.getProperty("idea.active"))
20+
extensions.extraProperties.set("idea.internal.test", project.getSystemProperty("idea.active"))
2121

2222
val reportsDir = benchmarkReportsDir(config, target)
2323
val reportFile = reportsDir.resolve("${target.name}.${config.reportFileExt()}")

plugin/main/src/kotlinx/benchmark/gradle/JvmTasks.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ fun Project.createJvmBenchmarkExecTask(
9595
) {
9696
group = BenchmarksPlugin.BENCHMARKS_TASK_GROUP
9797
description = "Execute benchmark for '${target.name}'"
98-
extensions.extraProperties.set("idea.internal.test", System.getProperty("idea.active"))
98+
extensions.extraProperties.set("idea.internal.test", project.getSystemProperty("idea.active"))
9999

100100
val benchmarkBuildDir = benchmarkBuildDir(target)
101101
val reportsDir = benchmarkReportsDir(config, target)

plugin/main/src/kotlinx/benchmark/gradle/NativeMultiplatformTasks.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ fun Project.createNativeBenchmarkExecTask(
106106
) {
107107
group = BenchmarksPlugin.BENCHMARKS_TASK_GROUP
108108
description = "Executes benchmark for '${target.name}'"
109-
extensions.extraProperties.set("idea.internal.test", System.getProperty("idea.active"))
109+
extensions.extraProperties.set("idea.internal.test", project.getSystemProperty("idea.active"))
110110

111111
val binary =
112112
benchmarkCompilation.target.binaries.getExecutable(benchmarkCompilation.name, NativeBuildType.RELEASE)

plugin/main/src/kotlinx/benchmark/gradle/Utils.kt

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
11
package kotlinx.benchmark.gradle
22

3-
import groovy.lang.*
4-
import org.gradle.api.*
5-
import org.gradle.api.tasks.*
6-
import java.io.*
7-
import java.time.*
8-
import java.time.format.*
3+
import groovy.lang.Closure
4+
import org.gradle.api.Action
5+
import org.gradle.api.Project
6+
import org.gradle.api.Task
7+
import org.gradle.api.invocation.Gradle
8+
import org.gradle.api.tasks.TaskProvider
9+
import org.gradle.util.GradleVersion
10+
import java.io.File
11+
import java.time.LocalDateTime
12+
import java.time.format.DateTimeFormatter
913

1014
fun cleanup(file: File) {
1115
if (file.exists()) {
@@ -115,3 +119,20 @@ private fun validateConfig(config: BenchmarkConfiguration) {
115119
}
116120

117121
}
122+
123+
internal val Gradle.isConfigurationCacheAvailable
124+
get() = try {
125+
val startParameters = gradle.startParameter
126+
startParameters.javaClass.getMethod("isConfigurationCache")
127+
.invoke(startParameters) as? Boolean
128+
} catch (_: Exception) {
129+
null
130+
} ?: false
131+
132+
internal fun Project.getSystemProperty(key: String): String? {
133+
return if (gradle.isConfigurationCacheAvailable) {
134+
providers.systemProperty(key).forUseAtConfigurationTime().orNull
135+
} else {
136+
System.getProperty(key)
137+
}
138+
}

0 commit comments

Comments
 (0)