Fix the build

This commit is contained in:
Alexey Tsvetkov
2017-01-13 00:00:17 +03:00
parent 41c5568b74
commit bdae0b5efb
7 changed files with 78 additions and 29 deletions
@@ -23,10 +23,10 @@ import java.lang.reflect.Modifier
import java.util.*
fun <A : CommonCompilerArguments> parseArguments(args: Array<String>, arguments: A) {
val unparsedArgs = Args.parse(arguments, args, false).partition { it.startsWith("-X") }
arguments.unknownExtraFlags = unparsedArgs.first
arguments.freeArgs = unparsedArgs.second
val unparsedArgs = Args.parse(arguments, args, false)
val (unknownExtraArgs, unknownArgs) = unparsedArgs.partition { it.startsWith("-X") }
arguments.unknownExtraFlags = unknownExtraArgs
arguments.freeArgs = unknownArgs
for (argument in arguments.freeArgs) {
if (argument.startsWith("-")) {
@@ -132,7 +132,7 @@ interface CompileService : Remote {
@Throws(RemoteException::class)
fun compile(
sessionId: Int,
compilerArguments: CommonCompilerArguments,
compilerArguments: Array<String>,
compilationOptions: CompilationOptions,
servicesFacade: CompilerServicesFacadeBase,
compilationResultsSink: CompilationResultsSink?
@@ -23,10 +23,7 @@ import com.intellij.openapi.vfs.impl.jar.CoreJarFileSystem
import org.jetbrains.kotlin.cli.common.CLICompiler
import org.jetbrains.kotlin.cli.common.ExitCode
import org.jetbrains.kotlin.cli.common.KOTLIN_COMPILER_ENVIRONMENT_KEEPALIVE_PROPERTY
import org.jetbrains.kotlin.cli.common.arguments.CommonCompilerArguments
import org.jetbrains.kotlin.cli.common.arguments.K2JSCompilerArguments
import org.jetbrains.kotlin.cli.common.arguments.K2JVMCompilerArguments
import org.jetbrains.kotlin.cli.common.arguments.K2MetadataCompilerArguments
import org.jetbrains.kotlin.cli.common.arguments.*
import org.jetbrains.kotlin.cli.common.messages.*
import org.jetbrains.kotlin.cli.common.modules.ModuleXmlParser
import org.jetbrains.kotlin.cli.common.repl.ReplCheckResult
@@ -46,10 +43,8 @@ import org.jetbrains.kotlin.incremental.*
import org.jetbrains.kotlin.load.kotlin.incremental.components.IncrementalCompilationComponents
import org.jetbrains.kotlin.progress.CompilationCanceledStatus
import org.jetbrains.kotlin.utils.addToStdlib.check
import java.io.BufferedOutputStream
import java.io.ByteArrayOutputStream
import java.io.File
import java.io.PrintStream
import org.jetbrains.kotlin.utils.stackTraceStr
import java.io.*
import java.rmi.NoSuchObjectException
import java.rmi.registry.Registry
import java.rmi.server.UnicastRemoteObject
@@ -321,7 +316,7 @@ class CompileServiceImpl(
override fun compile(
sessionId: Int,
compilerArguments: CommonCompilerArguments,
compilerArguments: Array<String>,
compilationOptions: CompilationOptions,
servicesFacade: CompilerServicesFacadeBase,
compilationResultsSink: CompilationResultsSink?
@@ -330,6 +325,17 @@ class CompileServiceImpl(
val daemonReporter = DaemonMessageReporter(servicesFacade, compilationOptions)
val compilerMode = compilationOptions.compilerMode
val targetPlatform = compilationOptions.targetPlatform
val k2PlatformArgs = try {
when (targetPlatform) {
CompileService.TargetPlatform.JVM -> K2JVMCompilerArguments().apply { K2JVMCompiler().parseArguments(compilerArguments, this) }
CompileService.TargetPlatform.JS -> K2JSCompilerArguments().apply { K2JSCompiler().parseArguments(compilerArguments, this) }
CompileService.TargetPlatform.METADATA -> K2MetadataCompilerArguments().apply { K2MetadataCompiler().parseArguments(compilerArguments, this) }
}
}
catch (e: IllegalArgumentException) {
messageCollector.report(CompilerMessageSeverity.EXCEPTION, e.stackTraceStr, CompilerMessageLocation.NO_LOCATION)
return CompileService.CallResult.Error("Could not deserialize compiler arguments")
}
return when (compilerMode) {
CompilerMode.JPS_COMPILER -> {
@@ -337,12 +343,12 @@ class CompileServiceImpl(
doCompile(sessionId, daemonReporter, tracer = null) { eventManger, profiler ->
val services = createCompileServices(jpsServicesFacade, eventManger, profiler)
execCompiler(compilationOptions.targetPlatform, services, compilerArguments, messageCollector)
execCompiler(compilationOptions.targetPlatform, services, k2PlatformArgs, messageCollector)
}
}
CompilerMode.NON_INCREMENTAL_COMPILER -> {
doCompile(sessionId, daemonReporter, tracer = null) { eventManger, profiler ->
execCompiler(targetPlatform, Services.EMPTY, compilerArguments, messageCollector)
execCompiler(targetPlatform, Services.EMPTY, k2PlatformArgs, messageCollector)
}
}
CompilerMode.INCREMENTAL_COMPILER -> {
@@ -350,7 +356,7 @@ class CompileServiceImpl(
throw IllegalStateException("Incremental compilation is not supported for target platform: $targetPlatform")
}
val k2jvmArgs = compilerArguments as K2JVMCompilerArguments
val k2jvmArgs = k2PlatformArgs as K2JVMCompilerArguments
val gradleIncrementalArgs = compilationOptions as IncrementalCompilationOptions
val gradleIncrementalServicesFacade = servicesFacade as IncrementalCompilerServicesFacade
@@ -0,0 +1,27 @@
/*
* Copyright 2010-2017 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jetbrains.kotlin.utils
import java.io.PrintWriter
import java.io.StringWriter
val Exception.stackTraceStr: String
get() {
val sw = StringWriter()
PrintWriter(sw).use { printStackTrace(it) }
return sw.toString()
}
+1
View File
@@ -21,5 +21,6 @@
<orderEntry type="module" module-name="daemon-common" />
<orderEntry type="library" scope="TEST" name="kotlin-test" level="project" />
<orderEntry type="module" module-name="daemon" />
<orderEntry type="library" name="cli-parser" level="project" />
</component>
</module>
@@ -33,7 +33,20 @@ import java.rmi.server.UnicastRemoteObject
import java.util.*
class JpsKotlinCompilerRunner : KotlinCompilerRunner<JpsCompilerEnvironment>() {
override val log: KotlinLogger = JpsKotlinLogger(KotlinBuilder.LOG)
override val log: KotlinLogger = JpsKotlinLogger(KotlinBuilder.LOG)
private var compilerSettings: CompilerSettings? = null
private inline fun withCompilerSettings(settings: CompilerSettings, fn: ()->Unit) {
val old = compilerSettings
try {
compilerSettings = settings
fn()
}
finally {
compilerSettings = old
}
}
companion object {
private @Volatile var jpsDaemonConnection: DaemonConnection? = null
@@ -48,10 +61,9 @@ class JpsKotlinCompilerRunner : KotlinCompilerRunner<JpsCompilerEnvironment>() {
) {
val arguments = mergeBeans(commonArguments, k2jvmArguments)
setupK2JvmArguments(moduleFile, arguments)
val additionalArguments = compilerSettings.additionalArguments.split(" ").toTypedArray()
parseArguments(additionalArguments, arguments)
runCompiler(K2JVM_COMPILER, arguments, environment)
withCompilerSettings(compilerSettings) {
runCompiler(K2JVM_COMPILER, arguments, environment)
}
}
fun runK2JsCompiler(
@@ -65,10 +77,9 @@ class JpsKotlinCompilerRunner : KotlinCompilerRunner<JpsCompilerEnvironment>() {
) {
val arguments = mergeBeans(commonArguments, k2jsArguments)
setupK2JsArguments(outputFile, sourceFiles, libraryFiles, arguments)
val additionalArguments = compilerSettings.additionalArguments.split(" ").toTypedArray()
parseArguments(additionalArguments, arguments)
runCompiler(K2JS_COMPILER, arguments, environment)
withCompilerSettings(compilerSettings) {
runCompiler(K2JS_COMPILER, arguments, environment)
}
}
override fun compileWithDaemonOrFallback(
@@ -104,7 +115,9 @@ class JpsKotlinCompilerRunner : KotlinCompilerRunner<JpsCompilerEnvironment>() {
val compilerMode = CompilerMode.JPS_COMPILER
val verbose = compilerArgs.verbose
val options = CompilationOptions(compilerMode, targetPlatform, reportCategories(verbose), reportSeverity(verbose), requestedCompilationResults = emptyArray())
daemon.compile(sessionId, compilerArgs, options, JpsCompilerServicesFacadeImpl(environment), null)
val allArgs = ArgumentUtils.convertArgumentsToStringList(compilerArgs) +
(compilerSettings?.additionalArguments?.split(" ") ?: emptyList())
daemon.compile(sessionId, allArgs.toTypedArray(), options, JpsCompilerServicesFacadeImpl(environment), null)
}
return res?.get()?.let { exitCodeFromProcessExitCode(it) }
@@ -172,7 +172,8 @@ internal class GradleCompilerRunner(private val project: Project) : KotlinCompil
val servicesFacade = GradleCompilerServicesFacadeImpl(project, environment.messageCollector)
val res = withDaemon(environment, retryOnConnectionError = true) { daemon, sessionId ->
daemon.compile(sessionId, environment.compilerArgs, compilationOptions, servicesFacade, compilationResultsSink = null)
val argsArray = ArgumentUtils.convertArgumentsToStringList(environment.compilerArgs).toTypedArray()
daemon.compile(sessionId, argsArray, compilationOptions, servicesFacade, compilationResultsSink = null)
}
val exitCode = res?.get()?.let { exitCodeFromProcessExitCode(it) }
@@ -203,7 +204,8 @@ internal class GradleCompilerRunner(private val project: Project) : KotlinCompil
val servicesFacade = GradleIncrementalCompilerServicesFacadeImpl(project, environment)
val res = withDaemon(environment, retryOnConnectionError = true) { daemon, sessionId ->
daemon.compile(sessionId, environment.compilerArgs, compilationOptions, servicesFacade, GradleCompilationResultsSink(project))
val argsArray = ArgumentUtils.convertArgumentsToStringList(environment.compilerArgs).toTypedArray()
daemon.compile(sessionId, argsArray, compilationOptions, servicesFacade, GradleCompilationResultsSink(project))
}
val exitCode = res?.get()?.let { exitCodeFromProcessExitCode(it) }