Compile using -module xml
KT-8487
This commit is contained in:
@@ -46,6 +46,26 @@ fun Iterable<File>.javaSourceRoots(roots: Iterable<File>): Iterable<File> =
|
|||||||
.map { findSrcDirRoot(it, roots) }
|
.map { findSrcDirRoot(it, roots) }
|
||||||
.filterNotNull()
|
.filterNotNull()
|
||||||
|
|
||||||
|
fun makeModuleFile(name: String, isTest: Boolean, outputDir: File, sourcesToCompile: List<File>, javaSourceRoots: Iterable<File>, classpath: Iterable<File>, friendDirs: Iterable<File>): File {
|
||||||
|
val builder = KotlinModuleXmlBuilder()
|
||||||
|
builder.addModule(
|
||||||
|
name,
|
||||||
|
outputDir.absolutePath,
|
||||||
|
sourcesToCompile,
|
||||||
|
javaSourceRoots.map { JvmSourceRoot(it) },
|
||||||
|
classpath,
|
||||||
|
"java-production",
|
||||||
|
isTest,
|
||||||
|
// this excludes the output directories from the class path, to be removed for true incremental compilation
|
||||||
|
setOf(outputDir),
|
||||||
|
friendDirs
|
||||||
|
)
|
||||||
|
|
||||||
|
val scriptFile = File.createTempFile("kjps", StringUtil.sanitizeJavaIdentifier(name) + ".script.xml")
|
||||||
|
FileUtil.writeToFile(scriptFile, builder.asText().toString())
|
||||||
|
return scriptFile
|
||||||
|
}
|
||||||
|
|
||||||
fun makeCompileServices(
|
fun makeCompileServices(
|
||||||
incrementalCaches: Map<TargetId, IncrementalCache>,
|
incrementalCaches: Map<TargetId, IncrementalCache>,
|
||||||
lookupTracker: LookupTracker,
|
lookupTracker: LookupTracker,
|
||||||
|
|||||||
+43
-42
@@ -467,58 +467,59 @@ open class KotlinCompile() : AbstractKotlinCompile<K2JVMCompilerArguments>() {
|
|||||||
|
|
||||||
private data class CompileChangedResults(val exitCode: ExitCode, val generatedFiles: List<GeneratedFile<TargetId>>)
|
private data class CompileChangedResults(val exitCode: ExitCode, val generatedFiles: List<GeneratedFile<TargetId>>)
|
||||||
|
|
||||||
private fun compileChanged(targets: List<TargetId>,
|
private fun compileChanged(
|
||||||
sourcesToCompile: List<File>,
|
targets: List<TargetId>,
|
||||||
outputDir: File,
|
sourcesToCompile: List<File>,
|
||||||
args: K2JVMCompilerArguments,
|
outputDir: File,
|
||||||
getIncrementalCache: (TargetId) -> GradleIncrementalCacheImpl,
|
args: K2JVMCompilerArguments,
|
||||||
lookupTracker: LookupTracker)
|
getIncrementalCache: (TargetId)->GradleIncrementalCacheImpl,
|
||||||
: CompileChangedResults
|
lookupTracker: LookupTracker
|
||||||
{
|
): CompileChangedResults {
|
||||||
// show kotlin compiler where to look for java source files
|
val moduleFile = makeModuleFile(args.moduleName, isTest = false, outputDir = outputDir, sourcesToCompile = sourcesToCompile, javaSourceRoots = getJavaSourceRoots(), classpath = classpath, friendDirs = listOf())
|
||||||
args.freeArgs = (sourcesToCompile.map { it.absolutePath } + getJavaSourceRoots().map { it.absolutePath }).distinct()
|
args.module = moduleFile.absolutePath
|
||||||
args.destination = outputDir.absolutePath
|
|
||||||
|
|
||||||
logger.kotlinDebug("compiling with args ${ArgumentUtils.convertArgumentsToStringList(args)}")
|
|
||||||
|
|
||||||
val outputItemCollector = OutputItemsCollectorImpl()
|
val outputItemCollector = OutputItemsCollectorImpl()
|
||||||
|
|
||||||
val messageCollector = GradleMessageCollector(logger, outputItemCollector)
|
val messageCollector = GradleMessageCollector(logger, outputItemCollector)
|
||||||
|
|
||||||
val incrementalCaches = makeIncrementalCachesMap(targets, { listOf<TargetId>() }, getIncrementalCache, { this })
|
try {
|
||||||
|
val incrementalCaches = makeIncrementalCachesMap(targets, { listOf<TargetId>() }, getIncrementalCache, { this })
|
||||||
|
val compilationCanceledStatus = object : CompilationCanceledStatus {
|
||||||
|
override fun checkCanceled() {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
val compilationCanceledStatus = object : CompilationCanceledStatus {
|
logger.kotlinDebug("compiling with args ${ArgumentUtils.convertArgumentsToStringList(args)}")
|
||||||
override fun checkCanceled() {}
|
val exitCode = compiler.exec(messageCollector, makeCompileServices(incrementalCaches, lookupTracker, compilationCanceledStatus), args)
|
||||||
|
return CompileChangedResults(
|
||||||
|
exitCode,
|
||||||
|
outputItemCollector.generatedFiles(
|
||||||
|
targets = targets,
|
||||||
|
representativeTarget = targets.first(),
|
||||||
|
getSources = { sourcesToCompile },
|
||||||
|
getOutputDir = { outputDir }))
|
||||||
|
}
|
||||||
|
finally {
|
||||||
|
moduleFile.delete()
|
||||||
}
|
}
|
||||||
|
|
||||||
logger.kotlinDebug("compiling with args ${ArgumentUtils.convertArgumentsToStringList(args)}")
|
|
||||||
|
|
||||||
val exitCode = compiler.exec(messageCollector, makeCompileServices(incrementalCaches, lookupTracker, compilationCanceledStatus), args)
|
|
||||||
|
|
||||||
return CompileChangedResults(
|
|
||||||
exitCode,
|
|
||||||
outputItemCollector.generatedFiles(
|
|
||||||
targets = targets,
|
|
||||||
representativeTarget = targets.first(),
|
|
||||||
getSources = { sourcesToCompile },
|
|
||||||
getOutputDir = { outputDir }))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun compileNotIncremental(sourcesToCompile: List<File>,
|
private fun compileNotIncremental(
|
||||||
outputDir: File,
|
sourcesToCompile: List<File>,
|
||||||
args: K2JVMCompilerArguments)
|
outputDir: File,
|
||||||
: ExitCode
|
args: K2JVMCompilerArguments
|
||||||
{
|
): ExitCode {
|
||||||
// show kotlin compiler where to look for java source files
|
val moduleFile = makeModuleFile(args.moduleName, isTest = false, outputDir = outputDir, sourcesToCompile = sourcesToCompile, javaSourceRoots = getJavaSourceRoots(), classpath = classpath, friendDirs = listOf())
|
||||||
args.freeArgs = (sourcesToCompile.map { it.absolutePath } + getJavaSourceRoots().map { it.absolutePath }).distinct()
|
args.module = moduleFile.absolutePath
|
||||||
args.destination = outputDir.absolutePath
|
val messageCollector = GradleMessageCollector(logger)
|
||||||
|
|
||||||
logger.kotlinDebug("compiling with args ${ArgumentUtils.convertArgumentsToStringList(args)}")
|
try {
|
||||||
|
logger.kotlinDebug("compiling with args ${ArgumentUtils.convertArgumentsToStringList(args)}")
|
||||||
return compiler.exec(GradleMessageCollector(logger), Services.EMPTY, args)
|
return compiler.exec(messageCollector, Services.EMPTY, args)
|
||||||
|
}
|
||||||
|
finally {
|
||||||
|
moduleFile.delete()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private fun handleKaptProperties(extraProperties: ExtraPropertiesExtension, pluginOptions: MutableList<String>) {
|
private fun handleKaptProperties(extraProperties: ExtraPropertiesExtension, pluginOptions: MutableList<String>) {
|
||||||
val kaptAnnotationsFile = extraProperties.getOrNull<File>("kaptAnnotationsFile")
|
val kaptAnnotationsFile = extraProperties.getOrNull<File>("kaptAnnotationsFile")
|
||||||
if (kaptAnnotationsFile != null) {
|
if (kaptAnnotationsFile != null) {
|
||||||
|
|||||||
Reference in New Issue
Block a user