Cleanup: remove deprecated methods from Kotlin daemon

This commit is contained in:
Andrey Uskov
2022-01-27 13:50:49 +03:00
committed by teamcity
parent c9e0100214
commit 1550a37b17
4 changed files with 33 additions and 327 deletions
@@ -18,6 +18,7 @@ package org.jetbrains.kotlin.daemon.client
import org.jetbrains.kotlin.cli.common.CompilerSystemProperties
import org.jetbrains.kotlin.cli.common.messages.CompilerMessageSeverity
import org.jetbrains.kotlin.cli.common.messages.CompilerMessageSourceLocation
import org.jetbrains.kotlin.cli.common.messages.MessageCollector
import org.jetbrains.kotlin.daemon.common.*
import org.jetbrains.kotlin.incremental.components.LookupTracker
@@ -144,48 +145,6 @@ object KotlinCompilerClient {
compilerService.releaseCompileSession(sessionId)
}
@Suppress("DEPRECATION")
@Deprecated("Use other compile method", ReplaceWith("compile"))
fun compile(compilerService: CompileService,
sessionId: Int,
targetPlatform: CompileService.TargetPlatform,
args: Array<out String>,
out: OutputStream,
port: Int = SOCKET_ANY_FREE_PORT,
operationsTracer: RemoteOperationsTracer? = null
): Int {
val outStrm = RemoteOutputStreamServer(out, port = port)
return compilerService.remoteCompile(sessionId, targetPlatform, args, CompilerCallbackServicesFacadeServer(port = port), outStrm, CompileService.OutputFormat.PLAIN, outStrm, operationsTracer).get()
}
@Suppress("DEPRECATION")
@Deprecated("Use non-deprecated compile method", ReplaceWith("compile"))
fun incrementalCompile(compileService: CompileService,
sessionId: Int,
targetPlatform: CompileService.TargetPlatform,
args: Array<out String>,
callbackServices: CompilationServices,
compilerOut: OutputStream,
daemonOut: OutputStream,
port: Int = SOCKET_ANY_FREE_PORT,
profiler: Profiler = DummyProfiler(),
operationsTracer: RemoteOperationsTracer? = null
): Int = profiler.withMeasure(this) {
compileService.remoteIncrementalCompile(
sessionId,
targetPlatform,
args,
CompilerCallbackServicesFacadeServer(incrementalCompilationComponents = callbackServices.incrementalCompilationComponents,
lookupTracker = callbackServices.lookupTracker,
compilationCanceledStatus = callbackServices.compilationCanceledStatus,
port = port),
RemoteOutputStreamServer(compilerOut, port),
CompileService.OutputFormat.XML,
RemoteOutputStreamServer(daemonOut, port),
operationsTracer).get()
}
fun compile(compilerService: CompileService,
sessionId: Int,
targetPlatform: CompileService.TargetPlatform,
@@ -274,14 +233,42 @@ object KotlinCompilerClient {
}
else -> {
println("Executing daemon compilation with args: " + filteredArgs.joinToString(" "))
val outStrm = RemoteOutputStreamServer(System.out)
val servicesFacade = CompilerCallbackServicesFacadeServer()
val messageCollector = object : MessageCollector {
var hasErrors = false
override fun clear() {}
override fun report(severity: CompilerMessageSeverity, message: String, location: CompilerMessageSourceLocation?) {
if (severity.isError) {
hasErrors = true
}
println("${severity.name}\t${location?.path ?: ""}:${location?.line ?: ""} \t$message")
}
override fun hasErrors() = hasErrors
}
val outputsCollector = { x: File, y: List<File> -> println("$x $y") }
val servicesFacade = BasicCompilerServicesWithResultsFacadeServer(messageCollector, outputsCollector)
try {
val memBefore = daemon.getUsedMemory().get() / 1024
val startTime = System.nanoTime()
@Suppress("DEPRECATION")
val res = daemon.remoteCompile(CompileService.NO_SESSION, CompileService.TargetPlatform.JVM, filteredArgs.toList().toTypedArray(), servicesFacade, outStrm, CompileService.OutputFormat.PLAIN, outStrm, null)
val compilationOptions = CompilationOptions(
CompilerMode.NON_INCREMENTAL_COMPILER,
CompileService.TargetPlatform.JVM,
arrayOf(ReportCategory.COMPILER_MESSAGE.code, ReportCategory.DAEMON_MESSAGE.code, ReportCategory.EXCEPTION.code, ReportCategory.OUTPUT_MESSAGE.code),
ReportSeverity.INFO.code,
emptyArray()
)
val res = daemon.compile(
CompileService.NO_SESSION,
filteredArgs.toList().toTypedArray(),
compilationOptions,
servicesFacade,
null
)
val endTime = System.nanoTime()
println("Compilation ${if (res.isGood) "succeeded" else "failed"}, result code: ${res.get()}")
@@ -292,7 +279,6 @@ object KotlinCompilerClient {
finally {
// forcing RMI to unregister all objects and stop
UnicastRemoteObject.unexportObject(servicesFacade, true)
UnicastRemoteObject.unexportObject(outStrm, true)
}
}
}
@@ -115,36 +115,6 @@ interface CompileService : Remote {
@Throws(RemoteException::class)
fun scheduleShutdown(graceful: Boolean): CallResult<Boolean>
// TODO: consider adding async version of shutdown and release
@Suppress("DEPRECATION")
@Deprecated("The usages should be replaced with `compile` method", ReplaceWith("compile"))
@Throws(RemoteException::class)
fun remoteCompile(
sessionId: Int,
targetPlatform: TargetPlatform,
args: Array<out String>,
servicesFacade: CompilerCallbackServicesFacade,
compilerOutputStream: RemoteOutputStream,
outputFormat: OutputFormat,
serviceOutputStream: RemoteOutputStream,
operationsTracer: RemoteOperationsTracer?
): CallResult<Int>
@Suppress("DEPRECATION")
@Deprecated("The usages should be replaced with `compile` method", ReplaceWith("compile"))
@Throws(RemoteException::class)
fun remoteIncrementalCompile(
sessionId: Int,
targetPlatform: TargetPlatform,
args: Array<out String>,
servicesFacade: CompilerCallbackServicesFacade,
compilerOutputStream: RemoteOutputStream,
compilerOutputFormat: OutputFormat,
serviceOutputStream: RemoteOutputStream,
operationsTracer: RemoteOperationsTracer?
): CallResult<Int>
@Throws(RemoteException::class)
fun compile(
sessionId: Int,
@@ -163,50 +133,9 @@ interface CompileService : Remote {
@Throws(RemoteException::class)
fun clearJarCache()
@Suppress("DEPRECATION")
@Deprecated("The usages should be replaced with other `leaseReplSession` method", ReplaceWith("leaseReplSession"))
@Throws(RemoteException::class)
fun leaseReplSession(
aliveFlagPath: String?,
targetPlatform: CompileService.TargetPlatform,
servicesFacade: CompilerCallbackServicesFacade,
templateClasspath: List<File>,
templateClassName: String,
scriptArgs: Array<out Any?>?,
scriptArgsTypes: Array<out Class<out Any>>?,
compilerMessagesOutputStream: RemoteOutputStream,
evalOutputStream: RemoteOutputStream?,
evalErrorStream: RemoteOutputStream?,
evalInputStream: RemoteInputStream?,
operationsTracer: RemoteOperationsTracer?
): CallResult<Int>
@Throws(RemoteException::class)
fun releaseReplSession(sessionId: Int): CallResult<Nothing>
@Deprecated("The usages should be replaced with `replCheck` method", ReplaceWith("replCheck"))
@Throws(RemoteException::class)
fun remoteReplLineCheck(
sessionId: Int,
codeLine: ReplCodeLine
): CallResult<ReplCheckResult>
@Deprecated("The usages should be replaced with `replCompile` method", ReplaceWith("replCompile"))
@Throws(RemoteException::class)
fun remoteReplLineCompile(
sessionId: Int,
codeLine: ReplCodeLine,
history: List<ReplCodeLine>?
): CallResult<ReplCompileResult>
@Deprecated("Evaluation on daemon is not supported")
@Throws(RemoteException::class)
fun remoteReplLineEval(
sessionId: Int,
codeLine: ReplCodeLine,
history: List<ReplCodeLine>?
): CallResult<ReplEvalResult>
@Throws(RemoteException::class)
fun leaseReplSession(
aliveFlagPath: String?,
@@ -723,51 +723,6 @@ class CompilerDaemonTest : KotlinIntegrationTestBase() {
}
}
fun testDaemonCallbackConnectionProblems() {
withFlagFile(getTestName(true), ".alive") { flagFile ->
val daemonOptions = makeTestDaemonOptions(getTestName(true))
withLogFile("kotlin-daemon-test") { logFile ->
val daemonJVMOptions = makeTestDaemonJvmOptions(logFile)
val daemon = KotlinCompilerClient.connectToCompileService(compilerId, flagFile, daemonJVMOptions, daemonOptions, DaemonReportingTargets(out = System.err), autostart = true)
assertNotNull("failed to connect daemon", daemon)
daemon?.registerClient(flagFile.absolutePath)
val file = File(testTempDir, "largeKotlinFile.kt")
file.writeText(generateLargeKotlinFile(10))
val jar = File(testTempDir, "largeKotlinFile.jar").absolutePath
var callbackServices: CompilerCallbackServicesFacadeServer? = null
callbackServices = CompilerCallbackServicesFacadeServer(compilationCanceledStatus = object : CompilationCanceledStatus {
override fun checkCanceled() {
thread {
Thread.sleep(10)
UnicastRemoteObject.unexportObject(callbackServices, true)
}
}
}, port = SOCKET_ANY_FREE_PORT)
val strm = ByteArrayOutputStream()
@Suppress("DEPRECATION")
val code = daemon!!.remoteCompile(CompileService.NO_SESSION,
CompileService.TargetPlatform.JVM,
arrayOf("-include-runtime", file.absolutePath, "-d", jar),
callbackServices,
RemoteOutputStreamServer(strm, SOCKET_ANY_FREE_PORT),
CompileService.OutputFormat.XML,
RemoteOutputStreamServer(strm, SOCKET_ANY_FREE_PORT),
null).get()
TestCase.assertEquals(0, code)
val compilerOutput = strm.toString()
assertTrue("Expecting cancellation message in:\n$compilerOutput", compilerOutput.contains("Compilation was canceled"))
logFile.assertLogContainsSequence("error communicating with host, assuming compilation canceled")
}
}
}
fun testDaemonReplScriptingNotInClasspathError() {
withDaemon(compilerId) { daemon ->
var repl: KotlinRemoteReplCompilerClient? = null
@@ -736,58 +736,6 @@ class CompileServiceImpl(
CompileService.CallResult.Good(res)
}
@Suppress("OverridingDeprecatedMember", "DEPRECATION", "OVERRIDE_DEPRECATION")
override fun remoteCompile(
sessionId: Int,
targetPlatform: CompileService.TargetPlatform,
args: Array<out String>,
servicesFacade: CompilerCallbackServicesFacade,
compilerOutputStream: RemoteOutputStream,
outputFormat: CompileService.OutputFormat,
serviceOutputStream: RemoteOutputStream,
operationsTracer: RemoteOperationsTracer?
): CompileService.CallResult<Int> =
doCompile(sessionId, args, compilerOutputStream, serviceOutputStream, operationsTracer) { printStream, eventManager, profiler ->
when (outputFormat) {
CompileService.OutputFormat.PLAIN -> compiler[targetPlatform].exec(printStream, *args)
CompileService.OutputFormat.XML -> compiler[targetPlatform].execAndOutputXml(
printStream,
createCompileServices(
servicesFacade,
eventManager,
profiler
),
*args
)
}
}
@Suppress("OverridingDeprecatedMember", "DEPRECATION", "OVERRIDE_DEPRECATION")
override fun remoteIncrementalCompile(
sessionId: Int,
targetPlatform: CompileService.TargetPlatform,
args: Array<out String>,
servicesFacade: CompilerCallbackServicesFacade,
compilerOutputStream: RemoteOutputStream,
compilerOutputFormat: CompileService.OutputFormat,
serviceOutputStream: RemoteOutputStream,
operationsTracer: RemoteOperationsTracer?
): CompileService.CallResult<Int> =
doCompile(sessionId, args, compilerOutputStream, serviceOutputStream, operationsTracer) { printStream, eventManager, profiler ->
when (compilerOutputFormat) {
CompileService.OutputFormat.PLAIN -> throw NotImplementedError("Only XML output is supported in remote incremental compilation")
CompileService.OutputFormat.XML -> compiler[targetPlatform].execAndOutputXml(
printStream,
createCompileServices(
servicesFacade,
eventManager,
profiler
),
*args
)
}
}
override fun classesFqNamesByFiles(
sessionId: Int, sourceFiles: Set<File>
): CompileService.CallResult<Set<String>> =
@@ -819,54 +767,9 @@ class CompileServiceImpl(
}
@Deprecated("The usages should be replaced with other `leaseReplSession` method", ReplaceWith("leaseReplSession"))
override fun leaseReplSession(
aliveFlagPath: String?,
targetPlatform: CompileService.TargetPlatform,
@Suppress("DEPRECATION") servicesFacade: CompilerCallbackServicesFacade,
templateClasspath: List<File>,
templateClassName: String,
scriptArgs: Array<out Any?>?,
scriptArgsTypes: Array<out Class<out Any>>?,
compilerMessagesOutputStream: RemoteOutputStream,
evalOutputStream: RemoteOutputStream?,
evalErrorStream: RemoteOutputStream?,
evalInputStream: RemoteInputStream?,
operationsTracer: RemoteOperationsTracer?
): CompileService.CallResult<Int> = ifAlive(minAliveness = Aliveness.Alive) {
if (targetPlatform != CompileService.TargetPlatform.JVM)
CompileService.CallResult.Error("Sorry, only JVM target platform is supported now")
else {
val disposable = Disposer.newDisposable()
val compilerMessagesStream = PrintStream(
BufferedOutputStream(
RemoteOutputStreamClient(compilerMessagesOutputStream, DummyProfiler()),
REMOTE_STREAM_BUFFER_SIZE
)
)
val messageCollector = KeepFirstErrorMessageCollector(compilerMessagesStream)
val repl = KotlinJvmReplService(
disposable, port, compilerId, templateClasspath, templateClassName,
messageCollector, operationsTracer
)
val sessionId = state.sessions.leaseSession(ClientOrSessionProxy(aliveFlagPath, repl, disposable))
CompileService.CallResult.Good(sessionId)
}
}
// TODO: add more checks (e.g. is it a repl session)
override fun releaseReplSession(sessionId: Int): CompileService.CallResult<Nothing> = releaseCompileSession(sessionId)
@Suppress("OverridingDeprecatedMember", "OVERRIDE_DEPRECATION")
override fun remoteReplLineCheck(sessionId: Int, codeLine: ReplCodeLine): CompileService.CallResult<ReplCheckResult> =
ifAlive(minAliveness = Aliveness.Alive) {
withValidRepl(sessionId) {
@Suppress("DEPRECATION")
CompileService.CallResult.Good(check(codeLine))
}
}
private fun createCompileServices(
@Suppress("DEPRECATION") facade: CompilerCallbackServicesFacade,
eventManager: EventManager,
@@ -904,29 +807,6 @@ class CompileServiceImpl(
return builder.build()
}
@Suppress("OverridingDeprecatedMember", "OVERRIDE_DEPRECATION")
override fun remoteReplLineCompile(
sessionId: Int,
codeLine: ReplCodeLine,
history: List<ReplCodeLine>?
): CompileService.CallResult<ReplCompileResult> =
ifAlive(minAliveness = Aliveness.Alive) {
withValidRepl(sessionId) {
@Suppress("DEPRECATION")
CompileService.CallResult.Good(compile(codeLine, history))
}
}
@Suppress("OverridingDeprecatedMember", "OVERRIDE_DEPRECATION")
override fun remoteReplLineEval(
sessionId: Int,
codeLine: ReplCodeLine,
history: List<ReplCodeLine>?
): CompileService.CallResult<ReplEvalResult> =
ifAlive(minAliveness = Aliveness.Alive) {
CompileService.CallResult.Error("Eval on daemon is not supported")
}
override fun leaseReplSession(
aliveFlagPath: String?,
compilerArguments: Array<out String>,
@@ -1171,50 +1051,6 @@ class CompileServiceImpl(
return true
}
// todo: remove after remoteIncrementalCompile is removed
private fun doCompile(
sessionId: Int,
args: Array<out String>,
compilerMessagesStreamProxy: RemoteOutputStream,
serviceOutputStreamProxy: RemoteOutputStream,
operationsTracer: RemoteOperationsTracer?,
body: (PrintStream, EventManager, Profiler) -> ExitCode
): CompileService.CallResult<Int> =
ifAlive {
withValidClientOrSessionProxy(sessionId) {
operationsTracer?.before("compile")
val rpcProfiler = if (daemonOptions.reportPerf) WallAndThreadTotalProfiler() else DummyProfiler()
val eventManger = EventManagerImpl()
val compilerMessagesStream = PrintStream(
BufferedOutputStream(
RemoteOutputStreamClient(compilerMessagesStreamProxy, rpcProfiler),
REMOTE_STREAM_BUFFER_SIZE
)
)
val serviceOutputStream = PrintStream(
BufferedOutputStream(
RemoteOutputStreamClient(serviceOutputStreamProxy, rpcProfiler),
REMOTE_STREAM_BUFFER_SIZE
)
)
try {
val compileServiceReporter = DaemonMessageReporterPrintStreamAdapter(serviceOutputStream)
if (args.none())
throw IllegalArgumentException("Error: empty arguments list.")
log.info("Starting compilation with args: " + args.joinToString(" "))
val exitCode = checkedCompile(compileServiceReporter, rpcProfiler) {
body(compilerMessagesStream, eventManger, rpcProfiler).code
}
CompileService.CallResult.Good(exitCode)
} finally {
serviceOutputStream.flush()
compilerMessagesStream.flush()
eventManger.fireCompilationFinished()
operationsTracer?.after("compile")
}
}
}
init {
// assuming logicaly synchronized
try {