[Gradle, native] Allow parallel in-process compiler execution
This commit allows parallel in-process execution of the K/N compiler
that was prohibited by 254a978a06.
Issue #KT-38991 fixed
This commit is contained in:
committed by
Ilya Matveev
parent
03bb9138ad
commit
754a74ac4a
+3
-38
@@ -14,45 +14,10 @@ class GeneralNativeIT : BaseGradleIT() {
|
|||||||
get() = GradleVersionRequired.FOR_MPP_SUPPORT
|
get() = GradleVersionRequired.FOR_MPP_SUPPORT
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun testParallelExecutionDetection(): Unit = with(transformProjectWithPluginsDsl("native-parallel")) {
|
fun testParallelExecutionSmoke(): Unit = with(transformProjectWithPluginsDsl("native-parallel")) {
|
||||||
val compileTasks = arrayOf(":one:compileKotlinLinux", ":two:compileKotlinLinux")
|
// Check that the K/N compiler can be started in-process in parallel.
|
||||||
// Check that parallel in-process execution fails with the corresponding message.
|
build(":one:compileKotlinLinux", ":two:compileKotlinLinux") {
|
||||||
build(*compileTasks) {
|
|
||||||
assertFailed()
|
|
||||||
assertContains("Parallel in-process execution of the Kotlin/Native compiler detected.")
|
|
||||||
}
|
|
||||||
|
|
||||||
// Parallel execution without daemon => ok.
|
|
||||||
build("clean", *compileTasks, "-Pkotlin.native.disableCompilerDaemon=true") {
|
|
||||||
assertSuccessful()
|
assertSuccessful()
|
||||||
assertTasksExecuted(*compileTasks)
|
|
||||||
}
|
|
||||||
|
|
||||||
// org.gradle.parallel must be set in the properties file (not in command line).
|
|
||||||
projectDir.resolve("gradle.properties").modify {
|
|
||||||
it.replace("org.gradle.parallel=true", "org.gradle.parallel=false")
|
|
||||||
}
|
|
||||||
|
|
||||||
// Sequential execution => ok.
|
|
||||||
build("clean", *compileTasks) {
|
|
||||||
assertSuccessful()
|
|
||||||
assertTasksExecuted(*compileTasks)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Check for KT-37696.
|
|
||||||
// Add an incorrect code to trigger compilation failure.
|
|
||||||
projectDir.resolve("one/src/linuxMain/kotlin/main.kt").appendText("\nfun incorrect")
|
|
||||||
gradleBuildScript("two").appendText("""
|
|
||||||
|
|
||||||
val compileKotlinLinux by tasks.getting
|
|
||||||
compileKotlinLinux.mustRunAfter(":one:compileKotlinLinux")
|
|
||||||
""".trimIndent())
|
|
||||||
|
|
||||||
build("clean", *compileTasks, "--continue") {
|
|
||||||
assertFailed()
|
|
||||||
assertTasksFailed(":one:compileKotlinLinux")
|
|
||||||
assertTasksExecuted(":two:compileKotlinLinux")
|
|
||||||
assertNotContains("Parallel in-process execution of the Kotlin/Native compiler detected.")
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+1
-2
@@ -90,8 +90,7 @@ internal abstract class KotlinToolRunner(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Make it private again once KT-37550 is fixed.
|
private fun runInProcess(args: List<String>) {
|
||||||
protected open fun runInProcess(args: List<String>) {
|
|
||||||
try {
|
try {
|
||||||
val mainClass = getIsolatedClassLoader().loadClass(mainClass)
|
val mainClass = getIsolatedClassLoader().loadClass(mainClass)
|
||||||
val entryPoint = mainClass.methods.single { it.name == daemonEntryPoint }
|
val entryPoint = mainClass.methods.single { it.name == daemonEntryPoint }
|
||||||
|
|||||||
-44
@@ -83,50 +83,6 @@ internal abstract class KotlinNativeToolRunner(
|
|||||||
override fun transformArgs(args: List<String>) = listOf(toolName) + args
|
override fun transformArgs(args: List<String>) = listOf(toolName) + args
|
||||||
|
|
||||||
final override fun getCustomJvmArgs() = project.jvmArgs
|
final override fun getCustomJvmArgs() = project.jvmArgs
|
||||||
|
|
||||||
final override fun runInProcess(args: List<String>) {
|
|
||||||
withParallelExecutionGuard {
|
|
||||||
super.runInProcess(args)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// TODO: Remove once KT-37550 is fixed
|
|
||||||
private inline fun withParallelExecutionGuard(action: () -> Unit) {
|
|
||||||
try {
|
|
||||||
if (PropertiesProvider(project).nativeEnableParallelExecutionCheck) {
|
|
||||||
System.getProperties().compute(PARALLEL_EXECUTION_GUARD_PROPERTY) { _, value ->
|
|
||||||
check(value == null) { PARALLEL_EXECUTION_ERROR_MESSAGE }
|
|
||||||
"true"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
action()
|
|
||||||
|
|
||||||
} finally {
|
|
||||||
if (PropertiesProvider(project).nativeEnableParallelExecutionCheck) {
|
|
||||||
System.clearProperty(PARALLEL_EXECUTION_GUARD_PROPERTY)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
companion object {
|
|
||||||
private const val PARALLEL_EXECUTION_GUARD_PROPERTY = "org.jetbrains.kotlin.native.compiler.running"
|
|
||||||
|
|
||||||
private val PARALLEL_EXECUTION_ERROR_MESSAGE = """
|
|
||||||
Parallel in-process execution of the Kotlin/Native compiler detected.
|
|
||||||
|
|
||||||
At this moment the parallel execution of several compiler instances in the same process is not supported.
|
|
||||||
To fix this, you can do one of the following things:
|
|
||||||
|
|
||||||
- Disable in-process execution. To do this, set '${PropertiesProvider.KOTLIN_NATIVE_DISABLE_COMPILER_DAEMON}=true' project property.
|
|
||||||
|
|
||||||
- Disable parallel task execution. To do this, set 'org.gradle.parallel=false' project property.
|
|
||||||
|
|
||||||
If you still want to run the compiler in-process in parallel, you may disable this check by setting project
|
|
||||||
property '${PropertiesProvider.KOTLIN_NATIVE_ENABLE_PARALLEL_EXECUTION_CHECK}=false'. Note that in this case the compiler may fail.
|
|
||||||
|
|
||||||
""".trimIndent()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/** A common ancestor for all runners that run the cinterop tool. */
|
/** A common ancestor for all runners that run the cinterop tool. */
|
||||||
|
|||||||
+1
-9
@@ -170,11 +170,7 @@ internal class PropertiesProvider private constructor(private val project: Proje
|
|||||||
* Forces to run a compilation in a separate JVM.
|
* Forces to run a compilation in a separate JVM.
|
||||||
*/
|
*/
|
||||||
val nativeDisableCompilerDaemon: Boolean?
|
val nativeDisableCompilerDaemon: Boolean?
|
||||||
get() = booleanProperty(KOTLIN_NATIVE_DISABLE_COMPILER_DAEMON)
|
get() = booleanProperty("kotlin.native.disableCompilerDaemon")
|
||||||
|
|
||||||
// TODO: Remove once KT-37550 is fixed
|
|
||||||
val nativeEnableParallelExecutionCheck: Boolean
|
|
||||||
get() = booleanProperty(KOTLIN_NATIVE_ENABLE_PARALLEL_EXECUTION_CHECK) ?: true
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Allows a user to specify additional arguments of a JVM executing KLIB commonizer.
|
* Allows a user to specify additional arguments of a JVM executing KLIB commonizer.
|
||||||
@@ -229,12 +225,8 @@ internal class PropertiesProvider private constructor(private val project: Proje
|
|||||||
|
|
||||||
private const val CACHED_PROVIDER_EXT_NAME = "kotlin.properties.provider"
|
private const val CACHED_PROVIDER_EXT_NAME = "kotlin.properties.provider"
|
||||||
|
|
||||||
internal const val KOTLIN_NATIVE_DISABLE_COMPILER_DAEMON = "kotlin.native.disableCompilerDaemon"
|
|
||||||
internal const val KOTLIN_NATIVE_IGNORE_INCORRECT_DEPENDENCIES = "kotlin.native.ignoreIncorrectDependencies"
|
internal const val KOTLIN_NATIVE_IGNORE_INCORRECT_DEPENDENCIES = "kotlin.native.ignoreIncorrectDependencies"
|
||||||
|
|
||||||
// TODO: Remove once KT-37550 is fixed
|
|
||||||
internal const val KOTLIN_NATIVE_ENABLE_PARALLEL_EXECUTION_CHECK = "kotlin.native.enableParallelExecutionCheck"
|
|
||||||
|
|
||||||
operator fun invoke(project: Project): PropertiesProvider =
|
operator fun invoke(project: Project): PropertiesProvider =
|
||||||
with(project.extensions.extraProperties) {
|
with(project.extensions.extraProperties) {
|
||||||
if (!has(CACHED_PROVIDER_EXT_NAME)) {
|
if (!has(CACHED_PROVIDER_EXT_NAME)) {
|
||||||
|
|||||||
Reference in New Issue
Block a user