Add ability to debug Kotlin daemon in integration tests
^KT-53231 In progress
This commit is contained in:
+30
-15
@@ -127,6 +127,7 @@ 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,
|
||||||
|
kotlinDaemonDebugPort: Int? = this.kotlinDaemonDebugPort,
|
||||||
enableBuildCacheDebug: Boolean = false,
|
enableBuildCacheDebug: Boolean = false,
|
||||||
enableBuildScan: Boolean = this.enableBuildScan,
|
enableBuildScan: Boolean = this.enableBuildScan,
|
||||||
buildOptions: BuildOptions = this.buildOptions,
|
buildOptions: BuildOptions = this.buildOptions,
|
||||||
@@ -139,7 +140,8 @@ fun TestProject.build(
|
|||||||
buildOptions,
|
buildOptions,
|
||||||
enableBuildCacheDebug,
|
enableBuildCacheDebug,
|
||||||
enableBuildScan,
|
enableBuildScan,
|
||||||
gradleVersion
|
gradleVersion,
|
||||||
|
kotlinDaemonDebugPort
|
||||||
)
|
)
|
||||||
val gradleRunnerForBuild = gradleRunner
|
val gradleRunnerForBuild = gradleRunner
|
||||||
.also { if (forceOutput) it.forwardOutput() }
|
.also { if (forceOutput) it.forwardOutput() }
|
||||||
@@ -159,6 +161,7 @@ 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,
|
||||||
|
kotlinDaemonDebugPort: Int? = this.kotlinDaemonDebugPort,
|
||||||
enableBuildCacheDebug: Boolean = false,
|
enableBuildCacheDebug: Boolean = false,
|
||||||
enableBuildScan: Boolean = this.enableBuildScan,
|
enableBuildScan: Boolean = this.enableBuildScan,
|
||||||
buildOptions: BuildOptions = this.buildOptions,
|
buildOptions: BuildOptions = this.buildOptions,
|
||||||
@@ -171,7 +174,8 @@ fun TestProject.buildAndFail(
|
|||||||
buildOptions,
|
buildOptions,
|
||||||
enableBuildCacheDebug,
|
enableBuildCacheDebug,
|
||||||
enableBuildScan,
|
enableBuildScan,
|
||||||
gradleVersion
|
gradleVersion,
|
||||||
|
kotlinDaemonDebugPort
|
||||||
)
|
)
|
||||||
val gradleRunnerForBuild = gradleRunner
|
val gradleRunnerForBuild = gradleRunner
|
||||||
.also { if (forceOutput) it.forwardOutput() }
|
.also { if (forceOutput) it.forwardOutput() }
|
||||||
@@ -286,9 +290,18 @@ class TestProject(
|
|||||||
projectPath: Path,
|
projectPath: Path,
|
||||||
val buildOptions: BuildOptions,
|
val buildOptions: BuildOptions,
|
||||||
val gradleVersion: GradleVersion,
|
val gradleVersion: GradleVersion,
|
||||||
val enableGradleDebug: Boolean,
|
|
||||||
val forceOutput: Boolean,
|
val forceOutput: Boolean,
|
||||||
val enableBuildScan: Boolean
|
val enableBuildScan: Boolean,
|
||||||
|
/**
|
||||||
|
* Whether the test and the Gradle build launched by the test should be executed in the same process so that we can use the same
|
||||||
|
* debugger for both (see https://docs.gradle.org/current/javadoc/org/gradle/testkit/runner/GradleRunner.html#isDebug--).
|
||||||
|
*/
|
||||||
|
val enableGradleDebug: Boolean,
|
||||||
|
/**
|
||||||
|
* A port to debug the Kotlin daemon at.
|
||||||
|
* Note that we'll need to let the debugger start listening at this port first *before* the Kotlin daemon is launched.
|
||||||
|
*/
|
||||||
|
val kotlinDaemonDebugPort: Int? = null
|
||||||
) : GradleProject(projectName, projectPath) {
|
) : GradleProject(projectName, projectPath) {
|
||||||
fun subProject(name: String) = GradleProject(name, projectPath.resolve(name))
|
fun subProject(name: String) = GradleProject(name, projectPath.resolve(name))
|
||||||
|
|
||||||
@@ -330,18 +343,20 @@ private fun commonBuildSetup(
|
|||||||
buildOptions: BuildOptions,
|
buildOptions: BuildOptions,
|
||||||
enableBuildCacheDebug: Boolean,
|
enableBuildCacheDebug: Boolean,
|
||||||
enableBuildScan: Boolean,
|
enableBuildScan: Boolean,
|
||||||
gradleVersion: GradleVersion
|
gradleVersion: GradleVersion,
|
||||||
|
kotlinDaemonDebugPort: Int? = null
|
||||||
): List<String> {
|
): List<String> {
|
||||||
val buildOptionsArguments = buildOptions.toArguments(gradleVersion)
|
return buildOptions.toArguments(gradleVersion) + buildArguments + listOfNotNull(
|
||||||
val buildCacheDebugOption = if (enableBuildCacheDebug) "-Dorg.gradle.caching.debug=true" else null
|
"--full-stacktrace",
|
||||||
val buildScanOption = if (enableBuildScan) "--scan" else null
|
if (enableBuildCacheDebug) "-Dorg.gradle.caching.debug=true" else null,
|
||||||
return buildOptionsArguments +
|
if (enableBuildScan) "--scan" else null,
|
||||||
buildArguments +
|
kotlinDaemonDebugPort?.let {
|
||||||
listOfNotNull(
|
// Note that we pass "server=n", meaning that we'll need to let the debugger start listening at this port first *before* the
|
||||||
"--full-stacktrace",
|
// Kotlin daemon is launched. That is usually easier than trying to attach the debugger when the Kotlin daemon is launched
|
||||||
buildCacheDebugOption,
|
// (currently if we don't attach fast enough, the Kotlin daemon will fail to launch).
|
||||||
buildScanOption
|
"-Pkotlin.daemon.jvmargs=-agentlib:jdwp=transport=dt_socket,server=n,suspend=y,address=$it"
|
||||||
)
|
}
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun TestProject.withBuildSummary(
|
private fun TestProject.withBuildSummary(
|
||||||
|
|||||||
Reference in New Issue
Block a user