Report non-incremental annotation processors correctly
This commit fixes an issue when all APs would be reported as non-incremental, even if only a single one is non-incremental. Now, additional declared type is added that is used to denote processors that are incremental, but have been forced to run non-incrementally in presence of non-incremental APs. This means that only APs that do not support incremental annotation processing, or APs that are dynamic and are non-incremental at runtime will be reported.
This commit is contained in:
committed by
Yan Zhulanow
parent
ad352355de
commit
be3fe9495c
@@ -64,10 +64,15 @@ open class ProcessorLoader(private val options: KaptOptions, private val logger:
|
|||||||
val processorsInfo: Map<String, DeclaredProcType> = getIncrementalProcessorsFromClasspath(processorNames, classpath)
|
val processorsInfo: Map<String, DeclaredProcType> = getIncrementalProcessorsFromClasspath(processorNames, classpath)
|
||||||
|
|
||||||
val nonIncremental = processorNames.filter { !processorsInfo.containsKey(it) }
|
val nonIncremental = processorNames.filter { !processorsInfo.containsKey(it) }
|
||||||
return if (nonIncremental.isNotEmpty()) {
|
return processors.map {
|
||||||
processors.map { IncrementalProcessor(it, DeclaredProcType.NON_INCREMENTAL) }
|
val procType = processorsInfo[it.javaClass.name]?.let {
|
||||||
} else {
|
if (nonIncremental.isEmpty()) {
|
||||||
processors.map { IncrementalProcessor(it, processorsInfo.getValue(it.javaClass.name)) }
|
it
|
||||||
|
} else {
|
||||||
|
DeclaredProcType.INCREMENTAL_BUT_OTHER_APS_ARE_NOT
|
||||||
|
}
|
||||||
|
} ?: DeclaredProcType.NON_INCREMENTAL
|
||||||
|
IncrementalProcessor(it, procType)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+13
-9
@@ -13,7 +13,9 @@ import com.sun.tools.javac.processing.JavacFiler
|
|||||||
import com.sun.tools.javac.processing.JavacProcessingEnvironment
|
import com.sun.tools.javac.processing.JavacProcessingEnvironment
|
||||||
import com.sun.tools.javac.tree.JCTree
|
import com.sun.tools.javac.tree.JCTree
|
||||||
import org.jetbrains.kotlin.base.kapt3.KaptFlag
|
import org.jetbrains.kotlin.base.kapt3.KaptFlag
|
||||||
import org.jetbrains.kotlin.kapt3.base.incremental.*
|
import org.jetbrains.kotlin.kapt3.base.incremental.GeneratedTypesTaskListener
|
||||||
|
import org.jetbrains.kotlin.kapt3.base.incremental.IncrementalProcessor
|
||||||
|
import org.jetbrains.kotlin.kapt3.base.incremental.MentionedTypesTaskListener
|
||||||
import org.jetbrains.kotlin.kapt3.base.util.KaptBaseError
|
import org.jetbrains.kotlin.kapt3.base.util.KaptBaseError
|
||||||
import org.jetbrains.kotlin.kapt3.base.util.isJava9OrLater
|
import org.jetbrains.kotlin.kapt3.base.util.isJava9OrLater
|
||||||
import org.jetbrains.kotlin.kapt3.base.util.measureTimeMillisWithResult
|
import org.jetbrains.kotlin.kapt3.base.util.measureTimeMillisWithResult
|
||||||
@@ -51,7 +53,7 @@ fun KaptContext.doAnnotationProcessing(
|
|||||||
val parsedJavaFiles = parseJavaFiles(javaSourceFiles)
|
val parsedJavaFiles = parseJavaFiles(javaSourceFiles)
|
||||||
|
|
||||||
val sourcesStructureListener = cacheManager?.let {
|
val sourcesStructureListener = cacheManager?.let {
|
||||||
if (processors.any { it.kind == DeclaredProcType.NON_INCREMENTAL }) return@let null
|
if (processors.any { it.isUnableToRunIncrementally() }) return@let null
|
||||||
|
|
||||||
val recordTypesListener = MentionedTypesTaskListener(cacheManager.javaCache, processingEnvironment.elementUtils, Trees.instance(processingEnvironment))
|
val recordTypesListener = MentionedTypesTaskListener(cacheManager.javaCache, processingEnvironment.elementUtils, Trees.instance(processingEnvironment))
|
||||||
compiler.getTaskListeners().add(recordTypesListener)
|
compiler.getTaskListeners().add(recordTypesListener)
|
||||||
@@ -89,13 +91,15 @@ fun KaptContext.doAnnotationProcessing(
|
|||||||
logger.info("Analyzing sources structure took ${it.time}[ms].")
|
logger.info("Analyzing sources structure took ${it.time}[ms].")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (cacheManager != null && processors.any { it.getRuntimeType() == RuntimeProcType.NON_INCREMENTAL }) {
|
if (cacheManager != null) {
|
||||||
val nonIncremental =
|
val missingIncrementalSupport = processors.filter { it.isMissingIncrementalSupport() }
|
||||||
processors.filter { it.getRuntimeType() == RuntimeProcType.NON_INCREMENTAL }.map { it.processorName }
|
if (missingIncrementalSupport.isNotEmpty()) {
|
||||||
logger.warn(
|
val nonIncremental = missingIncrementalSupport.map { "${it.processorName} (${it.incrementalSupportType})" }
|
||||||
"Incremental annotation processing requested, but support is disabled because the following " +
|
logger.warn(
|
||||||
"processors are not incremental: ${nonIncremental.joinToString()}."
|
"Incremental annotation processing requested, but support is disabled because the following " +
|
||||||
)
|
"processors are not incremental: ${nonIncremental.joinToString()}."
|
||||||
|
)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
val log = compilerAfterAP.log
|
val log = compilerAfterAP.log
|
||||||
|
|||||||
+19
-8
@@ -19,14 +19,15 @@ import javax.tools.JavaFileObject
|
|||||||
|
|
||||||
private val ALLOWED_RUNTIME_TYPES = setOf(RuntimeProcType.AGGREGATING.name, RuntimeProcType.ISOLATING.name)
|
private val ALLOWED_RUNTIME_TYPES = setOf(RuntimeProcType.AGGREGATING.name, RuntimeProcType.ISOLATING.name)
|
||||||
|
|
||||||
class IncrementalProcessor(private val processor: Processor, val kind: DeclaredProcType) : Processor by processor {
|
class IncrementalProcessor(private val processor: Processor, private val kind: DeclaredProcType) : Processor by processor {
|
||||||
|
|
||||||
private var dependencyCollector = lazy { createDependencyCollector() }
|
private var dependencyCollector = lazy { createDependencyCollector() }
|
||||||
|
|
||||||
val processorName: String = processor.javaClass.name
|
val processorName: String = processor.javaClass.name
|
||||||
|
val incrementalSupportType: String = kind.name
|
||||||
|
|
||||||
override fun init(processingEnv: ProcessingEnvironment) {
|
override fun init(processingEnv: ProcessingEnvironment) {
|
||||||
if (kind == DeclaredProcType.NON_INCREMENTAL) {
|
if (!kind.canRunIncrementally) {
|
||||||
processor.init(processingEnv)
|
processor.init(processingEnv)
|
||||||
} else {
|
} else {
|
||||||
val originalFiler = processingEnv.filer
|
val originalFiler = processingEnv.filer
|
||||||
@@ -58,6 +59,12 @@ class IncrementalProcessor(private val processor: Processor, val kind: DeclaredP
|
|||||||
return AnnotationProcessorDependencyCollector(type)
|
return AnnotationProcessorDependencyCollector(type)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun isMissingIncrementalSupport(): Boolean {
|
||||||
|
if (kind == DeclaredProcType.NON_INCREMENTAL) return true
|
||||||
|
|
||||||
|
return kind == DeclaredProcType.DYNAMIC && getRuntimeType() == RuntimeProcType.NON_INCREMENTAL
|
||||||
|
}
|
||||||
|
fun isUnableToRunIncrementally() = !kind.canRunIncrementally
|
||||||
fun getGeneratedToSources() = dependencyCollector.value.getGeneratedToSources()
|
fun getGeneratedToSources() = dependencyCollector.value.getGeneratedToSources()
|
||||||
fun getRuntimeType(): RuntimeProcType = dependencyCollector.value.getRuntimeType()
|
fun getRuntimeType(): RuntimeProcType = dependencyCollector.value.getRuntimeType()
|
||||||
}
|
}
|
||||||
@@ -137,19 +144,23 @@ private fun getSrcFiles(elements: Array<out Element?>): Set<File> {
|
|||||||
}.toSet()
|
}.toSet()
|
||||||
}
|
}
|
||||||
|
|
||||||
enum class DeclaredProcType {
|
enum class DeclaredProcType(val canRunIncrementally: Boolean) {
|
||||||
AGGREGATING {
|
AGGREGATING(true) {
|
||||||
override fun toRuntimeType() = RuntimeProcType.AGGREGATING
|
override fun toRuntimeType() = RuntimeProcType.AGGREGATING
|
||||||
},
|
},
|
||||||
ISOLATING {
|
ISOLATING(true) {
|
||||||
override fun toRuntimeType() = RuntimeProcType.ISOLATING
|
override fun toRuntimeType() = RuntimeProcType.ISOLATING
|
||||||
},
|
},
|
||||||
DYNAMIC {
|
DYNAMIC(true) {
|
||||||
override fun toRuntimeType() = throw IllegalStateException("This should not be used")
|
override fun toRuntimeType() = throw IllegalStateException("This should not be used")
|
||||||
},
|
},
|
||||||
NON_INCREMENTAL {
|
NON_INCREMENTAL(false) {
|
||||||
override fun toRuntimeType() = RuntimeProcType.NON_INCREMENTAL
|
override fun toRuntimeType() = RuntimeProcType.NON_INCREMENTAL
|
||||||
};
|
},
|
||||||
|
INCREMENTAL_BUT_OTHER_APS_ARE_NOT(false) {
|
||||||
|
override fun toRuntimeType() = RuntimeProcType.NON_INCREMENTAL
|
||||||
|
},
|
||||||
|
;
|
||||||
|
|
||||||
abstract fun toRuntimeType(): RuntimeProcType
|
abstract fun toRuntimeType(): RuntimeProcType
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user