Fix hook metadata emission when class deps are unresolved#189
Conversation
|
This PR contains changes that modified the public API. To update the reference ABI dumps: ./gradlew updateLegacyAbi
git add **/api/**
git commit -m "Update ABI reference"
git pushAfter updating, the CI will pass. Make sure the changes are backward compatible. |
There was a problem hiding this comment.
Pull request overview
This PR fixes an issue where hook metadata could be incomplete when @DependsOnClass annotation references are unresolved during symbol processing. The change ensures that hooks with unresolved class dependencies are properly deferred for later processing rather than being partially emitted to the generated surf-hooks.json file.
Changes:
- Added a
hasUnresolvedClassDependencyflag to track when any@DependsOnClassannotation has an unresolved reference - Added early return logic after processing all class dependencies to skip hooks with unresolved dependencies
- Ensured unresolved hooks are added to the deferred list for reprocessing in subsequent rounds
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| deferred += hookClass | ||
| hasUnresolvedClassDependency = true | ||
| return@mapNotNull null | ||
| } | ||
|
|
||
| val closestClass = clazzValue.declaration.closestClassDeclaration() | ||
| if (closestClass == null) { | ||
| deferred += hookClass |
There was a problem hiding this comment.
If a hook class has multiple @DependsOnClass annotations with unresolved dependencies, hookClass will be added to the deferred list multiple times (lines 57 and 64). This could lead to duplicate entries in the deferred list and potentially reprocessing the same hook multiple times in subsequent rounds.
Consider adding the hook to deferred only once, either by checking if it's already in the list before adding, or by deferring the addition until after all annotations are processed (e.g., moving it to lines 71-73 where the flag is checked).
Motivation
@DependsOnClassreferences are unresolved so generatedsurf-hooks.jsondoes not contain entries missing class dependencies.Description
surf-api-gradle-plugin/surf-api-processor/src/main/kotlin/.../HookSymbolProcessor.kttrack unresolved class dependencies with ahasUnresolvedClassDependencyflag and short-circuitmapNotNulltoreturn@mapNotNull nullwhen anyDependsOnClassreference is unresolved or itsclosestClassDeclaration()is missing, preventing partialPluginHookMeta.Hookentries.Testing
Codex Task