Move CompilerMode and TargetPlatform to CompilationOptions

This commit is contained in:
Alexey Tsvetkov
2017-01-10 19:49:26 +03:00
parent c5a5463f50
commit e44cc43ada
5 changed files with 28 additions and 30 deletions
@@ -19,7 +19,11 @@ package org.jetbrains.kotlin.daemon.common
import java.io.File import java.io.File
import java.io.Serializable import java.io.Serializable
open class CompilationOptions(val reportingFilters: List<ReportingFilter>) : Serializable { open class CompilationOptions(
val compilerMode: CompileService.CompilerMode,
val targetPlatform: CompileService.TargetPlatform,
val reportingFilters: List<ReportingFilter>
) : Serializable {
companion object { companion object {
const val serialVersionUID: Long = 0 const val serialVersionUID: Long = 0
} }
@@ -32,8 +36,10 @@ class IncrementalCompilationOptions(
val workingDir: File, val workingDir: File,
val customCacheVersionFileName: String, val customCacheVersionFileName: String,
val customCacheVersion: Int, val customCacheVersion: Int,
compilerMode: CompileService.CompilerMode,
targetPlatform: CompileService.TargetPlatform,
reportingFilters: List<ReportingFilter> reportingFilters: List<ReportingFilter>
) : CompilationOptions(reportingFilters) { ) : CompilationOptions(compilerMode, targetPlatform, reportingFilters) {
companion object { companion object {
const val serialVersionUID: Long = 0 const val serialVersionUID: Long = 0
} }
@@ -136,8 +136,6 @@ interface CompileService : Remote {
@Throws(RemoteException::class) @Throws(RemoteException::class)
fun compile( fun compile(
sessionId: Int, sessionId: Int,
compilerMode: CompilerMode,
targetPlatform: TargetPlatform,
compilerArguments: CommonCompilerArguments, compilerArguments: CommonCompilerArguments,
compilationOptions: CompilationOptions, compilationOptions: CompilationOptions,
servicesFacade: CompilerServicesFacadeBase servicesFacade: CompilerServicesFacadeBase
@@ -323,14 +323,14 @@ class CompileServiceImpl(
override fun compile( override fun compile(
sessionId: Int, sessionId: Int,
compilerMode: CompileService.CompilerMode,
targetPlatform: CompileService.TargetPlatform,
compilerArguments: CommonCompilerArguments, compilerArguments: CommonCompilerArguments,
compilationOptions: CompilationOptions, compilationOptions: CompilationOptions,
servicesFacade: CompilerServicesFacadeBase servicesFacade: CompilerServicesFacadeBase
): CompileService.CallResult<Int> { ): CompileService.CallResult<Int> {
val messageCollector = CompileServicesFacadeMessageCollector(servicesFacade, compilationOptions) val messageCollector = CompileServicesFacadeMessageCollector(servicesFacade, compilationOptions)
val serviceReporter = CompileServiceReporterImpl(servicesFacade, compilationOptions) val serviceReporter = CompileServiceReporterImpl(servicesFacade, compilationOptions)
val compilerMode = compilationOptions.compilerMode
val targetPlatform = compilationOptions.targetPlatform
return when (compilerMode) { return when (compilerMode) {
CompileService.CompilerMode.JPS_COMPILER -> { CompileService.CompilerMode.JPS_COMPILER -> {
@@ -338,7 +338,7 @@ class CompileServiceImpl(
doCompile(sessionId, serviceReporter, tracer = null) { eventManger, profiler -> doCompile(sessionId, serviceReporter, tracer = null) { eventManger, profiler ->
val services = createCompileServices(jpsServicesFacade, eventManger, profiler) val services = createCompileServices(jpsServicesFacade, eventManger, profiler)
execCompiler(targetPlatform, services, compilerArguments, messageCollector) execCompiler(compilationOptions.targetPlatform, services, compilerArguments, messageCollector)
} }
} }
CompileService.CompilerMode.NON_INCREMENTAL_COMPILER -> { CompileService.CompilerMode.NON_INCREMENTAL_COMPILER -> {
@@ -99,13 +99,10 @@ class JpsKotlinCompilerRunner : KotlinCompilerRunner<JpsCompilerEnvironment>() {
} }
val res = withDaemon(environment, retryOnConnectionError = true) { daemon, sessionId -> val res = withDaemon(environment, retryOnConnectionError = true) { daemon, sessionId ->
daemon.compile( val options = CompilationOptions(CompileService.CompilerMode.JPS_COMPILER,
sessionId, targetPlatform,
CompileService.CompilerMode.JPS_COMPILER, reportingFilters = getReportingFilters(compilerArgs.verbose))
targetPlatform, daemon.compile(sessionId, compilerArgs, options, JpsCompilerServicesFacadeImpl(environment))
compilerArgs,
CompilationOptions(reportingFilters = getReportingFilters(compilerArgs.verbose)),
JpsCompilerServicesFacadeImpl(environment))
} }
return res?.get()?.let { exitCodeFromProcessExitCode(it) } return res?.get()?.let { exitCodeFromProcessExitCode(it) }
@@ -162,15 +162,14 @@ internal class GradleCompilerRunner(private val project: Project) : KotlinCompil
K2METADATA_COMPILER -> CompileService.TargetPlatform.METADATA K2METADATA_COMPILER -> CompileService.TargetPlatform.METADATA
else -> throw IllegalArgumentException("Unknown compiler type $compilerClassName") else -> throw IllegalArgumentException("Unknown compiler type $compilerClassName")
} }
val compilationOptions = CompilationOptions(
reportingFilters = getNonIncrementalReportingFilters(environment.compilerArgs.verbose),
compilerMode = CompileService.CompilerMode.NON_INCREMENTAL_COMPILER,
targetPlatform = targetPlatform)
val servicesFacade = GradleCompilerServicesFacadeImpl(project, environment.messageCollector)
val res = withDaemon(environment, retryOnConnectionError = true) { daemon, sessionId -> val res = withDaemon(environment, retryOnConnectionError = true) { daemon, sessionId ->
daemon.compile( daemon.compile(sessionId, environment.compilerArgs, compilationOptions, servicesFacade)
sessionId,
CompileService.CompilerMode.NON_INCREMENTAL_COMPILER,
targetPlatform,
environment.compilerArgs,
CompilationOptions(reportingFilters = getNonIncrementalReportingFilters(environment.compilerArgs.verbose)),
GradleCompilerServicesFacadeImpl(project, environment.messageCollector))
} }
val exitCode = res?.get()?.let { exitCodeFromProcessExitCode(it) } val exitCode = res?.get()?.let { exitCodeFromProcessExitCode(it) }
@@ -184,7 +183,7 @@ internal class GradleCompilerRunner(private val project: Project) : KotlinCompil
private fun incrementalCompilationWithDaemon(environment: GradleIncrementalCompilerEnvironment): ExitCode? { private fun incrementalCompilationWithDaemon(environment: GradleIncrementalCompilerEnvironment): ExitCode? {
val knownChangedFiles = environment.changedFiles as? ChangedFiles.Known val knownChangedFiles = environment.changedFiles as? ChangedFiles.Known
val additionalCompilerArguments = IncrementalCompilationOptions( val compilationOptions = IncrementalCompilationOptions(
areFileChangesKnown = knownChangedFiles != null, areFileChangesKnown = knownChangedFiles != null,
modifiedFiles = knownChangedFiles?.modified, modifiedFiles = knownChangedFiles?.modified,
deletedFiles = knownChangedFiles?.removed, deletedFiles = knownChangedFiles?.removed,
@@ -192,16 +191,14 @@ internal class GradleCompilerRunner(private val project: Project) : KotlinCompil
customCacheVersion = GRADLE_CACHE_VERSION, customCacheVersion = GRADLE_CACHE_VERSION,
customCacheVersionFileName = GRADLE_CACHE_VERSION_FILE_NAME, customCacheVersionFileName = GRADLE_CACHE_VERSION_FILE_NAME,
reportingFilters = getNonIncrementalReportingFilters(environment.compilerArgs.verbose) + reportingFilters = getNonIncrementalReportingFilters(environment.compilerArgs.verbose) +
getIncrementalReportingFilters(environment.compilerArgs.verbose) getIncrementalReportingFilters(environment.compilerArgs.verbose),
compilerMode = CompileService.CompilerMode.INCREMENTAL_COMPILER,
targetPlatform = CompileService.TargetPlatform.JVM
) )
val servicesFacade = GradleIncrementalCompilerServicesFacadeImpl(project, environment)
val res = withDaemon(environment, retryOnConnectionError = true) { daemon, sessionId -> val res = withDaemon(environment, retryOnConnectionError = true) { daemon, sessionId ->
daemon.compile( daemon.compile(sessionId, environment.compilerArgs, compilationOptions, servicesFacade)
sessionId,
CompileService.CompilerMode.INCREMENTAL_COMPILER,
CompileService.TargetPlatform.JVM,
environment.compilerArgs,
additionalCompilerArguments,
GradleIncrementalCompilerServicesFacadeImpl(project, environment))
} }
val exitCode = res?.get()?.let { exitCodeFromProcessExitCode(it) } val exitCode = res?.get()?.let { exitCodeFromProcessExitCode(it) }