https://kotlinlang.org logo
#ksp
Title
# ksp
m

mbonnin

10/10/2023, 12:53 PM
Trying to wrap my head around incremental processing. I'm currently in a situation where changing the KSP classpath processed sources classpath invokes my processor but somehow
resolver.getAllFiles()
return no files (not sure if expected?). The processed source files did not change but given my processor implementation did, shouldn't a full rebuild be done?. Is it expected that my processor is still called if nothing changed in the processed source files?
Comparing to another working project, the difference is that the working project has this line:
Copy code
The input changes require a full rebuild for incremental task
when the non-working one doesn't
Working:
Copy code
Input property '$1' file /Users/mbonnin/git/test-ksp/processor/build/libs/processor.jar has changed.
The input changes require a full rebuild for incremental task ':app:kspKotlin'.
Not working:
Copy code
Input property 'classpathSnapshotProperties.classpath' file /Users/mbonnin/git/apollo-kotlin/libraries/apollo-api/build/libs/apollo-api-jvm-4.0.0-beta.2-SNAPSHOT.jar has changed.
Alright, I was wrong, the KSP classpath didn't change, it's the classpath of the analyzed sources that did. That clears it up.
Still curious if calling the processor altogether could be avoided if nothing changed
t

Ting-Yuan Huang

10/10/2023, 6:23 PM
Processors can be called when there is no source change, when some of the outputs can possibly be based on classes in the compile classpath. The determination logic has to consider all possibilities and be conservative, so sometimes there are false positives. Setting the gradle property
ksp.incremental.log=true
and looking at
build/kspCaches/<target>/<source set>/logs
might give some hints on why the processors are called.
m

mbonnin

10/10/2023, 7:01 PM
It says this:
Copy code
All Files
  src/main/kotlin/com/apollographql/apollo/sample/server/Main.kt
  src/main/kotlin/com/apollographql/apollo/sample/server/SampleServer.kt
  src/main/kotlin/com/apollographql/apollo/sample/server/graphql/MutationRoot.kt
  src/main/kotlin/com/apollographql/apollo/sample/server/graphql/QueryRoot.kt
  src/main/kotlin/com/apollographql/apollo/sample/server/graphql/SubscriptionRoot.kt
Modified
Removed
Disappeared Outputs
Affected By CP
Affected By new syms
Affected By sealed
CP changes
Dirty:

Dirty / All: 0.00%
But it makes sense to give more control to the processor rather than not
t

Ting-Yuan Huang

10/10/2023, 7:06 PM
If your processor doesn't use
Resolver.getClassDeclarationByName
, then it is a false positive.
m

mbonnin

10/10/2023, 7:08 PM
It's ok though, was mostly curious, I don't mind at all 🙂
t

Ting-Yuan Huang

10/10/2023, 7:09 PM
It may be possible to optimize the call to processor away if KSP tracks the usage of getClassDeclarationByName. On the other hand, most of the processor would have very little overheads when there is no input source at all. The gain would be minimal.
m

mbonnin

10/10/2023, 7:10 PM
Does
getClassDeclarationByName
look into dependencies?
Copy code
Find a class in the compilation classpath for the given name
Ah, yes it does, gotcha 👍
Well it makes a ton of sense, thanks for the insight 🙏
👍 1
3 Views