Use Workers API for NMPP tasks
This change enables parallel execution of compile tasks in NMPP projects
within a subproject.
#KT-28155 In Progress
Original commit: 37dfe2b608
This commit is contained in:
@@ -105,7 +105,7 @@ class JpsKotlinCompilerRunner : KotlinCompilerRunner<JpsCompilerEnvironment>() {
|
|||||||
arguments.destination = arguments.destination ?: destination
|
arguments.destination = arguments.destination ?: destination
|
||||||
|
|
||||||
withCompilerSettings(compilerSettings) {
|
withCompilerSettings(compilerSettings) {
|
||||||
runCompiler(K2METADATA_COMPILER, arguments, environment)
|
runCompiler(KotlinCompilerClass.METADATA, arguments, environment)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -119,7 +119,7 @@ class JpsKotlinCompilerRunner : KotlinCompilerRunner<JpsCompilerEnvironment>() {
|
|||||||
val arguments = mergeBeans(commonArguments, XmlSerializerUtil.createCopy(k2jvmArguments))
|
val arguments = mergeBeans(commonArguments, XmlSerializerUtil.createCopy(k2jvmArguments))
|
||||||
setupK2JvmArguments(moduleFile, arguments)
|
setupK2JvmArguments(moduleFile, arguments)
|
||||||
withCompilerSettings(compilerSettings) {
|
withCompilerSettings(compilerSettings) {
|
||||||
runCompiler(K2JVM_COMPILER, arguments, environment)
|
runCompiler(KotlinCompilerClass.JVM, arguments, environment)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -149,7 +149,7 @@ class JpsKotlinCompilerRunner : KotlinCompilerRunner<JpsCompilerEnvironment>() {
|
|||||||
log.debug("K2JS: arguments after setup" + ArgumentUtils.convertArgumentsToStringList(arguments))
|
log.debug("K2JS: arguments after setup" + ArgumentUtils.convertArgumentsToStringList(arguments))
|
||||||
|
|
||||||
withCompilerSettings(compilerSettings) {
|
withCompilerSettings(compilerSettings) {
|
||||||
runCompiler(K2JS_COMPILER, arguments, environment)
|
runCompiler(KotlinCompilerClass.JS, arguments, environment)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -157,24 +157,24 @@ class JpsKotlinCompilerRunner : KotlinCompilerRunner<JpsCompilerEnvironment>() {
|
|||||||
compilerClassName: String,
|
compilerClassName: String,
|
||||||
compilerArgs: CommonCompilerArguments,
|
compilerArgs: CommonCompilerArguments,
|
||||||
environment: JpsCompilerEnvironment
|
environment: JpsCompilerEnvironment
|
||||||
): ExitCode {
|
) {
|
||||||
log.debug("Using kotlin-home = " + environment.kotlinPaths.homePath)
|
log.debug("Using kotlin-home = " + environment.kotlinPaths.homePath)
|
||||||
|
|
||||||
return withDaemonOrFallback(
|
withDaemonOrFallback(
|
||||||
withDaemon = { compileWithDaemon(compilerClassName, compilerArgs, environment) },
|
withDaemon = { compileWithDaemon(compilerClassName, compilerArgs, environment) },
|
||||||
fallback = { fallbackCompileStrategy(compilerArgs, compilerClassName, environment) }
|
fallback = { fallbackCompileStrategy(compilerArgs, compilerClassName, environment) }
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun compileWithDaemon(
|
private fun compileWithDaemon(
|
||||||
compilerClassName: String,
|
compilerClassName: String,
|
||||||
compilerArgs: CommonCompilerArguments,
|
compilerArgs: CommonCompilerArguments,
|
||||||
environment: JpsCompilerEnvironment
|
environment: JpsCompilerEnvironment
|
||||||
): ExitCode? {
|
) {
|
||||||
val targetPlatform = when (compilerClassName) {
|
val targetPlatform = when (compilerClassName) {
|
||||||
K2JVM_COMPILER -> CompileService.TargetPlatform.JVM
|
KotlinCompilerClass.JVM -> CompileService.TargetPlatform.JVM
|
||||||
K2JS_COMPILER -> CompileService.TargetPlatform.JS
|
KotlinCompilerClass.JS -> CompileService.TargetPlatform.JS
|
||||||
K2METADATA_COMPILER -> CompileService.TargetPlatform.METADATA
|
KotlinCompilerClass.METADATA -> CompileService.TargetPlatform.METADATA
|
||||||
else -> throw IllegalArgumentException("Unknown compiler type $compilerClassName")
|
else -> throw IllegalArgumentException("Unknown compiler type $compilerClassName")
|
||||||
}
|
}
|
||||||
val compilerMode = CompilerMode.JPS_COMPILER
|
val compilerMode = CompilerMode.JPS_COMPILER
|
||||||
@@ -186,7 +186,7 @@ class JpsKotlinCompilerRunner : KotlinCompilerRunner<JpsCompilerEnvironment>() {
|
|||||||
reportSeverity(verbose),
|
reportSeverity(verbose),
|
||||||
requestedCompilationResults = emptyArray()
|
requestedCompilationResults = emptyArray()
|
||||||
)
|
)
|
||||||
return doWithDaemon(environment) { sessionId, daemon ->
|
doWithDaemon(environment) { sessionId, daemon ->
|
||||||
environment.withProgressReporter { progress ->
|
environment.withProgressReporter { progress ->
|
||||||
progress.compilationStarted()
|
progress.compilationStarted()
|
||||||
daemon.compile(
|
daemon.compile(
|
||||||
@@ -197,7 +197,7 @@ class JpsKotlinCompilerRunner : KotlinCompilerRunner<JpsCompilerEnvironment>() {
|
|||||||
null
|
null
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}?.let { exitCodeFromProcessExitCode(it) }
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun <T> withDaemonOrFallback(withDaemon: () -> T?, fallback: () -> T): T =
|
private fun <T> withDaemonOrFallback(withDaemon: () -> T?, fallback: () -> T): T =
|
||||||
@@ -253,7 +253,7 @@ class JpsKotlinCompilerRunner : KotlinCompilerRunner<JpsCompilerEnvironment>() {
|
|||||||
compilerArgs: CommonCompilerArguments,
|
compilerArgs: CommonCompilerArguments,
|
||||||
compilerClassName: String,
|
compilerClassName: String,
|
||||||
environment: JpsCompilerEnvironment
|
environment: JpsCompilerEnvironment
|
||||||
): ExitCode {
|
) {
|
||||||
if ("true" == System.getProperty("kotlin.jps.tests") && "true" == System.getProperty(FAIL_ON_FALLBACK_PROPERTY)) {
|
if ("true" == System.getProperty("kotlin.jps.tests") && "true" == System.getProperty(FAIL_ON_FALLBACK_PROPERTY)) {
|
||||||
error("Fallback strategy is disabled in tests!")
|
error("Fallback strategy is disabled in tests!")
|
||||||
}
|
}
|
||||||
@@ -278,8 +278,7 @@ class JpsKotlinCompilerRunner : KotlinCompilerRunner<JpsCompilerEnvironment>() {
|
|||||||
// exec() returns an ExitCode object, class of which is loaded with a different class loader,
|
// exec() returns an ExitCode object, class of which is loaded with a different class loader,
|
||||||
// so we take it's contents through reflection
|
// so we take it's contents through reflection
|
||||||
val exitCode = ExitCode.valueOf(getReturnCodeFromObject(rc))
|
val exitCode = ExitCode.valueOf(getReturnCodeFromObject(rc))
|
||||||
processCompilerOutput(environment, stream, exitCode)
|
processCompilerOutput(environment.messageCollector, environment.outputItemsCollector, stream, exitCode)
|
||||||
return exitCode
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun setupK2JvmArguments(moduleFile: File, settings: K2JVMCompilerArguments) {
|
private fun setupK2JvmArguments(moduleFile: File, settings: K2JVMCompilerArguments) {
|
||||||
@@ -317,7 +316,7 @@ class JpsKotlinCompilerRunner : KotlinCompilerRunner<JpsCompilerEnvironment>() {
|
|||||||
else -> throw IllegalStateException("Unexpected return: " + rc)
|
else -> throw IllegalStateException("Unexpected return: " + rc)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun getDaemonConnection(environment: JpsCompilerEnvironment): CompileServiceSession? =
|
private fun getDaemonConnection(environment: JpsCompilerEnvironment): CompileServiceSession? =
|
||||||
getOrCreateDaemonConnection {
|
getOrCreateDaemonConnection {
|
||||||
environment.progressReporter.progress("connecting to daemon")
|
environment.progressReporter.progress("connecting to daemon")
|
||||||
val libPath = CompilerRunnerUtil.getLibPath(environment.kotlinPaths, environment.messageCollector)
|
val libPath = CompilerRunnerUtil.getLibPath(environment.kotlinPaths, environment.messageCollector)
|
||||||
@@ -334,7 +333,15 @@ class JpsKotlinCompilerRunner : KotlinCompilerRunner<JpsCompilerEnvironment>() {
|
|||||||
|
|
||||||
environment.withProgressReporter { progress ->
|
environment.withProgressReporter { progress ->
|
||||||
progress.progress("connecting to daemon")
|
progress.progress("connecting to daemon")
|
||||||
newDaemonConnection(compilerId, clientFlagFile, sessionFlagFile, environment, daemonOptions, additionalJvmParams.toTypedArray())
|
newDaemonConnection(
|
||||||
|
compilerId,
|
||||||
|
clientFlagFile,
|
||||||
|
sessionFlagFile,
|
||||||
|
environment.messageCollector,
|
||||||
|
log.isDebugEnabled,
|
||||||
|
daemonOptions,
|
||||||
|
additionalJvmParams.toTypedArray()
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user