提交 754a74ac 编写于 作者: I Ilya Matveev 提交者: Ilya Matveev

[Gradle, native] Allow parallel in-process compiler execution

This commit allows parallel in-process execution of the K/N compiler
that was prohibited by 254a978a.

Issue #KT-38991 fixed
上级 03bb9138
......@@ -14,45 +14,10 @@ class GeneralNativeIT : BaseGradleIT() {
get() = GradleVersionRequired.FOR_MPP_SUPPORT
@Test
fun testParallelExecutionDetection(): Unit = with(transformProjectWithPluginsDsl("native-parallel")) {
val compileTasks = arrayOf(":one:compileKotlinLinux", ":two:compileKotlinLinux")
// Check that parallel in-process execution fails with the corresponding message.
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()
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) {
fun testParallelExecutionSmoke(): Unit = with(transformProjectWithPluginsDsl("native-parallel")) {
// Check that the K/N compiler can be started in-process in parallel.
build(":one:compileKotlinLinux", ":two:compileKotlinLinux") {
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.")
}
}
......
......@@ -90,8 +90,7 @@ internal abstract class KotlinToolRunner(
}
}
// TODO: Make it private again once KT-37550 is fixed.
protected open fun runInProcess(args: List<String>) {
private fun runInProcess(args: List<String>) {
try {
val mainClass = getIsolatedClassLoader().loadClass(mainClass)
val entryPoint = mainClass.methods.single { it.name == daemonEntryPoint }
......
......@@ -83,50 +83,6 @@ internal abstract class KotlinNativeToolRunner(
override fun transformArgs(args: List<String>) = listOf(toolName) + args
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. */
......
......@@ -170,11 +170,7 @@ internal class PropertiesProvider private constructor(private val project: Proje
* Forces to run a compilation in a separate JVM.
*/
val nativeDisableCompilerDaemon: Boolean?
get() = booleanProperty(KOTLIN_NATIVE_DISABLE_COMPILER_DAEMON)
// TODO: Remove once KT-37550 is fixed
val nativeEnableParallelExecutionCheck: Boolean
get() = booleanProperty(KOTLIN_NATIVE_ENABLE_PARALLEL_EXECUTION_CHECK) ?: true
get() = booleanProperty("kotlin.native.disableCompilerDaemon")
/**
* 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"
internal const val KOTLIN_NATIVE_DISABLE_COMPILER_DAEMON = "kotlin.native.disableCompilerDaemon"
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 =
with(project.extensions.extraProperties) {
if (!has(CACHED_PROVIDER_EXT_NAME)) {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册