Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Workaround for issue during incremental processing for ksp #135

Merged
merged 2 commits into from
Oct 16, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ All notable changes to this project will be documented in this file.
---

## master
* Workaround issue where mock and spy cache was not invalidated properly
* Adding doc for `delegate` and removed return type where not needed

## 2.10.0
Expand Down
8 changes: 4 additions & 4 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ org.gradle.jvmargs=-Xmx1536m
# This option should only be used with decoupled projects. More details, visit
# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
org.gradle.parallel=true
# AndroidX package structure to make it clearer which packages are bundled with the
# Android operating system, and which are packaged with your app's APK
# https://developer.android.com/topic/libraries/support-library/androidx-rn
android.useAndroidX=true
org.gradle.caching=true

ksp.incremental=true
ksp.incremental.log=true

GROUP=com.careem.mockingbird
VERSION=2.11.0-SNAPSHOT
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package com.careem.mockingbird.processor

import com.google.devtools.ksp.processing.CodeGenerator
import com.google.devtools.ksp.processing.Dependencies
import com.google.devtools.ksp.processing.KSPLogger
import com.google.devtools.ksp.processing.Resolver
import com.google.devtools.ksp.processing.SymbolProcessor
Expand All @@ -39,39 +40,41 @@ class GenerateMocksSymbolProcessor(
mockGenerator = MockGenerator(resolver, logger, functionsMiner)
spyGenerator = SpyGenerator(resolver, logger, functionsMiner)

resolver.getSymbolsWithAnnotation(MOCK_ANNOTATION)
.map {
if (it !is KSPropertyDeclaration) error("$it is not a property declaration but is annotated with @Mock, not supported")
it.type
}
.distinctBy {
it.resolve().toClassName().canonicalName
}
.forEach {
logger.info(it.resolve().toClassName().canonicalName)
mockGenerator.createClass(it).writeTo(
codeGenerator = codeGenerator,
aggregating = false
)
}
resolver
.getSymbolsWithAnnotation(MOCK_ANNOTATION)
.generateCode(mockGenerator)

resolver.getSymbolsWithAnnotation(SPY_ANNOTATION)
resolver
.getSymbolsWithAnnotation(SPY_ANNOTATION)
.generateCode(spyGenerator)
return emptyList()
}

private fun Sequence<KSAnnotated>.generateCode(generator: Generator) {
this
.map {
if (it !is KSPropertyDeclaration) error("$it is not a property declaration but is annotated with @Mock, not supported")
if (it !is KSPropertyDeclaration) error("$it is not a property declaration but is annotated with @${generator.resolveSupertype()}, not supported")
logger.info("Process: ${it.type}")
it.type
}
.distinctBy {
it.resolve().toClassName().canonicalName
}
.forEach {
logger.info(it.resolve().toClassName().canonicalName)
spyGenerator.createClass(it).writeTo(
codeGenerator = codeGenerator,
aggregating = false
)
generator.createClass(it).apply {
try {
writeTo(
codeGenerator = codeGenerator,
// TODO remove this once ksp will be able to see `containingFiles` of class declared in common main ( required for incremental processing )
// TODO Dependencies.ALL_FILES is basically disabling incremental processing
dependencies = Dependencies.ALL_FILES
Comment on lines +69 to +71
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is the workaround

)
} catch (e: FileAlreadyExistsException) {
logger.info("${generator.resolveSupertype()} already generated by parsing another test")
}
}
}

return emptyList()
}

companion object {
Expand Down