diff options
author | Ting-Yuan Huang <laszio@google.com> | 2022-12-28 11:52:55 -0800 |
---|---|---|
committer | laszio <ting-yuan@users.noreply.github.com> | 2023-01-05 13:06:57 -0800 |
commit | 738bf176e5673a938b21d356012ec69620182ce0 (patch) | |
tree | f8140fc9bbcad5e526c5d33b2f034b7ea57c755b | |
parent | e81d01f80e8da40542f22e8cbeec724aa22d6062 (diff) | |
download | ksp-738bf176e5673a938b21d356012ec69620182ce0.tar.gz |
Exclude commonSources in processing
TODOs: AA
-rw-r--r-- | common-util/src/main/kotlin/com/google/devtools/ksp/KspOptions.kt | 14 | ||||
-rw-r--r-- | compiler-plugin/src/main/kotlin/com/google/devtools/ksp/KotlinSymbolProcessingExtension.kt | 5 |
2 files changed, 18 insertions, 1 deletions
diff --git a/common-util/src/main/kotlin/com/google/devtools/ksp/KspOptions.kt b/common-util/src/main/kotlin/com/google/devtools/ksp/KspOptions.kt index d0d34a4b..64aa0300 100644 --- a/common-util/src/main/kotlin/com/google/devtools/ksp/KspOptions.kt +++ b/common-util/src/main/kotlin/com/google/devtools/ksp/KspOptions.kt @@ -53,6 +53,8 @@ class KspOptions( val languageVersion: KotlinVersion, val apiVersion: KotlinVersion, val compilerVersion: KotlinVersion, + + val commonSources: List<File>, ) { class Builder { var projectBaseDir: File? = null @@ -86,6 +88,8 @@ class KspOptions( var apiVersion: KotlinVersion = ApiVersion.LATEST_STABLE.toKotlinVersion() var compilerVersion: KotlinVersion = KotlinVersion.CURRENT + var commonSources: MutableList<File> = mutableListOf() + fun build(): KspOptions { return KspOptions( requireNotNull(projectBaseDir) { "A non-null projectBaseDir must be provided" }, @@ -111,6 +115,7 @@ class KspOptions( languageVersion, apiVersion, compilerVersion, + commonSources, ) } } @@ -273,6 +278,14 @@ enum class KspCliOption( false, false ), + + COMMON_SOURCES_OPTION( + "commonSources", + "<commonSources>", + "common sources", + false, + true + ), } @Suppress("IMPLICIT_CAST_TO_ANY") @@ -300,4 +313,5 @@ fun KspOptions.Builder.processOption(option: KspCliOption, value: String) = when KspCliOption.WITH_COMPILATION_OPTION -> withCompilation = value.toBoolean() KspCliOption.CHANGED_CLASSES_OPTION -> changedClasses.addAll(value.split(':')) KspCliOption.RETURN_OK_ON_ERROR_OPTION -> returnOkOnError = value.toBoolean() + KspCliOption.COMMON_SOURCES_OPTION -> commonSources.addAll(value.split(File.pathSeparator).map { File(it) }) } diff --git a/compiler-plugin/src/main/kotlin/com/google/devtools/ksp/KotlinSymbolProcessingExtension.kt b/compiler-plugin/src/main/kotlin/com/google/devtools/ksp/KotlinSymbolProcessingExtension.kt index 4d43162d..60869e83 100644 --- a/compiler-plugin/src/main/kotlin/com/google/devtools/ksp/KotlinSymbolProcessingExtension.kt +++ b/compiler-plugin/src/main/kotlin/com/google/devtools/ksp/KotlinSymbolProcessingExtension.kt @@ -162,7 +162,9 @@ abstract class AbstractKotlinSymbolProcessingExtension( .mapNotNull { localFileSystem.findFileByPath(it.path)?.let { psiManager.findFile(it) } as? PsiJavaFile } val anyChangesWildcard = AnyChanges(options.projectBaseDir) - val ksFiles = files.map { KSFileImpl.getCached(it) } + javaFiles.map { KSFileJavaImpl.getCached(it) } + val commonSources: Set<String?> = options.commonSources.map { it.canonicalPath }.toSet() + val ksFiles = files.filterNot { it.virtualFile.canonicalPath in commonSources } + .map { KSFileImpl.getCached(it) } + javaFiles.map { KSFileJavaImpl.getCached(it) } lateinit var newFiles: List<KSFile> handleException(module, project) { @@ -175,6 +177,7 @@ abstract class AbstractKotlinSymbolProcessingExtension( dirtyFiles = incrementalContext.calcDirtyFiles(ksFiles).toSet() cleanFilenames = ksFiles.filterNot { it in dirtyFiles }.map { it.filePath }.toSet() newFiles = dirtyFiles.toList() + // DO NOT filter out common sources. files.forEach { fileClassProcessor.preprocessFile(it) } } else { newFiles = ksFiles.filter { |