Stop using -Xbuild-file in Gradle Plugin

#KT-27640 fixed
    #KT-27778 fixed
    #KT-27638 fixed
This commit is contained in:
Alexey Tsvetkov
2018-11-02 05:08:48 +03:00
parent 9b5b0447fa
commit 5f54f67f70
12 changed files with 94 additions and 101 deletions
@@ -28,7 +28,8 @@ open class CompilationOptions(
/** @See [ReportSeverity] */
val reportSeverity: Int,
/** @See [CompilationResultCategory]] */
val requestedCompilationResults: Array<Int>
val requestedCompilationResults: Array<Int>,
val kotlinScriptExtensions: Array<String>? = null
) : Serializable {
companion object {
const val serialVersionUID: Long = 0
@@ -41,6 +42,7 @@ open class CompilationOptions(
"reportCategories=${Arrays.toString(reportCategories)}, " +
"reportSeverity=$reportSeverity, " +
"requestedCompilationResults=${Arrays.toString(requestedCompilationResults)}" +
"kotlinScriptExtensions=${Arrays.toString(kotlinScriptExtensions)}" +
")"
}
}
@@ -65,8 +67,16 @@ class IncrementalCompilationOptions(
val outputFiles: List<File>,
val multiModuleICSettings: MultiModuleICSettings,
val modulesInfo: IncrementalModuleInfo,
val classpathFqNamesHistory: File? = null
) : CompilationOptions(compilerMode, targetPlatform, reportCategories, reportSeverity, requestedCompilationResults) {
val classpathFqNamesHistory: File? = null,
kotlinScriptExtensions: Array<String>? = null
) : CompilationOptions(
compilerMode,
targetPlatform,
reportCategories,
reportSeverity,
requestedCompilationResults,
kotlinScriptExtensions
) {
companion object {
const val serialVersionUID: Long = 0
}
@@ -454,7 +454,7 @@ class CompileServiceImpl(
doCompile(sessionId, daemonReporter, tracer = null) { _, _ ->
execIncrementalCompiler(
k2jvmArgs, gradleIncrementalArgs, gradleIncrementalServicesFacade, compilationResults!!,
messageCollector, daemonReporter
messageCollector
)
}
}
@@ -525,44 +525,28 @@ class CompileServiceImpl(
}
}
// todo: non-IC non-KTS scripts?
private fun execIncrementalCompiler(
k2jvmArgs: K2JVMCompilerArguments,
incrementalCompilationOptions: IncrementalCompilationOptions,
servicesFacade: IncrementalCompilerServicesFacade,
compilationResults: CompilationResults,
compilerMessageCollector: MessageCollector,
daemonMessageReporter: DaemonMessageReporter
compilerMessageCollector: MessageCollector
): ExitCode {
val moduleFile = k2jvmArgs.buildFile?.let(::File)
assert(moduleFile?.exists() ?: false) { "Module does not exist ${k2jvmArgs.buildFile}" }
// todo: pass javaSourceRoots and allKotlinFiles using IncrementalCompilationOptions
val parsedModule = run {
val bytesOut = ByteArrayOutputStream()
val printStream = PrintStream(bytesOut)
val mc = PrintingMessageCollector(printStream, MessageRenderer.PLAIN_FULL_PATHS, false)
val parsedModule = ModuleXmlParser.parseModuleScript(k2jvmArgs.buildFile!!, mc)
if (mc.hasErrors()) {
daemonMessageReporter.report(ReportSeverity.ERROR, bytesOut.toString("UTF8"))
val allKotlinExtensions = (DEFAULT_KOTLIN_SOURCE_FILES_EXTENSIONS +
(incrementalCompilationOptions.kotlinScriptExtensions ?: emptyArray())).distinct()
val dotExtensions = allKotlinExtensions.map { ".$it" }
val freeArgs = arrayListOf<String>()
val allKotlinFiles = arrayListOf<File>()
for (arg in k2jvmArgs.freeArgs) {
val file = File(arg)
if (file.isFile && dotExtensions.any { ext -> file.path.endsWith(ext, ignoreCase = true) }) {
allKotlinFiles.add(file)
} else {
freeArgs.add(arg)
}
parsedModule
}
val javaSourceRoots = parsedModule.modules.flatMapTo(HashSet()) {
it.getJavaSourceRoots().map { JvmSourceRoot(File(it.path), it.packagePrefix) }
}
k2jvmArgs.commonSources = parsedModule.modules.flatMap { it.getCommonSourceFiles() }.toTypedArray().takeUnless { it.isEmpty() }
val allKotlinFiles = parsedModule.modules.flatMap { it.getSourceFiles().map(::File) }
val allKotlinExtensions = (
DEFAULT_KOTLIN_SOURCE_FILES_EXTENSIONS +
allKotlinFiles.asSequence()
.map { it.extension }
.filter { !it.equals("java", ignoreCase = true) }
.asIterable()
).distinct()
k2jvmArgs.friendPaths = parsedModule.modules.flatMap(Module::getFriendPaths).toTypedArray()
k2jvmArgs.freeArgs = freeArgs
val changedFiles = if (incrementalCompilationOptions.areFileChangesKnown) {
ChangedFiles.Known(incrementalCompilationOptions.modifiedFiles!!, incrementalCompilationOptions.deletedFiles!!)
@@ -588,7 +572,6 @@ class CompileServiceImpl(
val compiler = IncrementalJvmCompilerRunner(
workingDir,
javaSourceRoots,
reporter,
buildHistoryFile = incrementalCompilationOptions.multiModuleICSettings.buildHistoryFile,
outputFiles = outputFiles,