Allow enabling build cache debug information.
^KT-45745 In Progress
This commit is contained in:
+29
-16
@@ -76,22 +76,24 @@ fun TestProject.build(
|
|||||||
vararg buildArguments: String,
|
vararg buildArguments: String,
|
||||||
forceOutput: Boolean = this.forceOutput,
|
forceOutput: Boolean = this.forceOutput,
|
||||||
enableGradleDebug: Boolean = this.enableGradleDebug,
|
enableGradleDebug: Boolean = this.enableGradleDebug,
|
||||||
|
enableBuildCacheDebug: Boolean = false,
|
||||||
buildOptions: KGPBaseTest.BuildOptions = this.buildOptions,
|
buildOptions: KGPBaseTest.BuildOptions = this.buildOptions,
|
||||||
assertions: BuildResult.() -> Unit = {}
|
assertions: BuildResult.() -> Unit = {}
|
||||||
) {
|
) {
|
||||||
val allBuildArguments = commonBuildSetup(
|
val allBuildArguments = commonBuildSetup(
|
||||||
buildArguments.toList(),
|
buildArguments.toList(),
|
||||||
buildOptions,
|
buildOptions,
|
||||||
|
enableBuildCacheDebug,
|
||||||
gradleVersion
|
gradleVersion
|
||||||
)
|
)
|
||||||
val gradleRunnerForBuild = gradleRunner
|
val gradleRunnerForBuild = gradleRunner
|
||||||
.also { if (forceOutput) it.forwardOutput() }
|
.also { if (forceOutput) it.forwardOutput() }
|
||||||
.withDebug(enableGradleDebug)
|
.withDebug(enableGradleDebug)
|
||||||
.withArguments(allBuildArguments)
|
.withArguments(allBuildArguments)
|
||||||
val buildResult = withBuildSummary(allBuildArguments) {
|
withBuildSummary(allBuildArguments) {
|
||||||
gradleRunnerForBuild.build()
|
val buildResult = gradleRunnerForBuild.build()
|
||||||
|
assertions(buildResult)
|
||||||
}
|
}
|
||||||
assertions(buildResult)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -101,23 +103,25 @@ fun TestProject.buildAndFail(
|
|||||||
vararg buildArguments: String,
|
vararg buildArguments: String,
|
||||||
forceOutput: Boolean = this.forceOutput,
|
forceOutput: Boolean = this.forceOutput,
|
||||||
enableGradleDebug: Boolean = this.enableGradleDebug,
|
enableGradleDebug: Boolean = this.enableGradleDebug,
|
||||||
|
enableBuildCacheDebug: Boolean = false,
|
||||||
buildOptions: KGPBaseTest.BuildOptions = this.buildOptions,
|
buildOptions: KGPBaseTest.BuildOptions = this.buildOptions,
|
||||||
assertions: BuildResult.() -> Unit = {}
|
assertions: BuildResult.() -> Unit = {}
|
||||||
) {
|
) {
|
||||||
val allBuildArguments = commonBuildSetup(
|
val allBuildArguments = commonBuildSetup(
|
||||||
buildArguments.toList(),
|
buildArguments.toList(),
|
||||||
buildOptions,
|
buildOptions,
|
||||||
|
enableBuildCacheDebug,
|
||||||
gradleVersion
|
gradleVersion
|
||||||
)
|
)
|
||||||
val gradleRunnerForBuild = gradleRunner
|
val gradleRunnerForBuild = gradleRunner
|
||||||
.also { if (forceOutput) it.forwardOutput() }
|
.also { if (forceOutput) it.forwardOutput() }
|
||||||
.withDebug(enableGradleDebug)
|
.withDebug(enableGradleDebug)
|
||||||
.withArguments(allBuildArguments)
|
.withArguments(allBuildArguments)
|
||||||
val buildResult = withBuildSummary(allBuildArguments) {
|
withBuildSummary(allBuildArguments) {
|
||||||
gradleRunnerForBuild.buildAndFail()
|
val buildResult = gradleRunnerForBuild.buildAndFail()
|
||||||
|
assertions(buildResult)
|
||||||
}
|
}
|
||||||
|
|
||||||
assertions(buildResult)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fun TestProject.enableLocalBuildCache(
|
fun TestProject.enableLocalBuildCache(
|
||||||
@@ -168,23 +172,32 @@ class TestProject(
|
|||||||
private fun commonBuildSetup(
|
private fun commonBuildSetup(
|
||||||
buildArguments: List<String>,
|
buildArguments: List<String>,
|
||||||
buildOptions: KGPBaseTest.BuildOptions,
|
buildOptions: KGPBaseTest.BuildOptions,
|
||||||
|
enableBuildCacheDebug: Boolean,
|
||||||
gradleVersion: GradleVersion
|
gradleVersion: GradleVersion
|
||||||
): List<String> {
|
): List<String> {
|
||||||
val buildOptionsArguments = buildOptions.toArguments(gradleVersion)
|
val buildOptionsArguments = buildOptions.toArguments(gradleVersion)
|
||||||
return buildOptionsArguments + buildArguments + "--full-stacktrace"
|
val buildCacheDebugOption = if (enableBuildCacheDebug) "-Dorg.gradle.caching.debug=true" else null
|
||||||
|
return buildOptionsArguments +
|
||||||
|
buildArguments +
|
||||||
|
listOfNotNull(
|
||||||
|
"--full-stacktrace",
|
||||||
|
buildCacheDebugOption
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun TestProject.withBuildSummary(
|
private fun TestProject.withBuildSummary(
|
||||||
buildArguments: List<String>,
|
buildArguments: List<String>,
|
||||||
run: () -> BuildResult
|
run: () -> Unit
|
||||||
): BuildResult = try {
|
) {
|
||||||
run()
|
try {
|
||||||
} catch (t: Throwable) {
|
run()
|
||||||
println("<=== Test build: $projectName ===>")
|
} catch (t: Throwable) {
|
||||||
println("<=== Using Gradle version: ${gradleVersion.version} ===>")
|
println("<=== Test build: $projectName ===>")
|
||||||
println("<=== Run arguments: ${buildArguments.joinToString()} ===>")
|
println("<=== Using Gradle version: ${gradleVersion.version} ===>")
|
||||||
println("<=== Project path: ${projectPath.toAbsolutePath()} ===>")
|
println("<=== Run arguments: ${buildArguments.joinToString()} ===>")
|
||||||
throw t
|
println("<=== Project path: ${projectPath.toAbsolutePath()} ===>")
|
||||||
|
throw t
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user