From e11283744a21fe2d09435e99d6924462b6aac3b8 Mon Sep 17 00:00:00 2001 From: oSumAtrIX Date: Wed, 13 Sep 2023 03:05:06 +0200 Subject: [PATCH] fix: Do not resolve the proxied patch to the proxy in the dependency list If a patch is used as a dependency, it would be present in `dependencyResolutionMap`. If that patch would also be annotated, then the generated patch would depend on itself. --- .../annotation/processor/PatchProcessor.kt | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/revanced-patch-annotation-processor/src/main/kotlin/app/revanced/patcher/patch/annotation/processor/PatchProcessor.kt b/revanced-patch-annotation-processor/src/main/kotlin/app/revanced/patcher/patch/annotation/processor/PatchProcessor.kt index ae55c1e0..ae09d7c6 100644 --- a/revanced-patch-annotation-processor/src/main/kotlin/app/revanced/patcher/patch/annotation/processor/PatchProcessor.kt +++ b/revanced-patch-annotation-processor/src/main/kotlin/app/revanced/patcher/patch/annotation/processor/PatchProcessor.kt @@ -33,7 +33,7 @@ class PatchProcessor( @Suppress("UNCHECKED_CAST") override fun process(resolver: Resolver): List { - val executablePatches = buildMap { + val patches = buildMap { resolver.getSymbolsWithAnnotation(Patch::class.qualifiedName!!).filter { // Do not check here if Patch is super of the class, because it is expensive. // Check it later when processing. @@ -99,13 +99,13 @@ class PatchProcessor( } // If a patch depends on another, that is annotated, the dependency should be replaced with the generated patch, - // because the generated patch has all the necessary properties to invoke the super constructor, + // because the generated patch has all the necessary properties to invoke the super constructor with, // unlike the annotated patch. val dependencyResolutionMap = buildMap { - executablePatches.values.filter { it.dependencies != null }.flatMap { + patches.values.filter { it.dependencies != null }.flatMap { it.dependencies!! }.distinct().forEach { dependency -> - executablePatches.keys.find { it.qualifiedName?.asString() == dependency.toString() } + patches.keys.find { it.qualifiedName?.asString() == dependency.toString() } ?.let { patch -> this[dependency] = ClassName( patch.packageName.asString(), @@ -115,7 +115,7 @@ class PatchProcessor( } } - executablePatches.forEach { (patchDeclaration, patchAnnotation) -> + patches.forEach { (patchDeclaration, patchAnnotation) -> val isBytecodePatch = patchDeclaration.isSubclassOf(BytecodePatch::class) val superClass = if (isBytecodePatch) { @@ -156,14 +156,14 @@ class PatchProcessor( patchAnnotation.dependencies?.let { dependencies -> addSuperclassConstructorParameter( - "dependencies = setOf(%L)", + "dependencies = setOf(%L, %L)", buildList { addAll(dependencies) - // Also add the source class of the generated class so that it is also executed. - add(patchDeclaration.toClassName()) }.joinToString(", ") { dependency -> "${(dependencyResolutionMap[dependency] ?: dependency)}::class" - } + }, + // Also add the source class of the generated class so that it is also executed. + "${patchDeclaration.toClassName()}::class" ) } addSuperclassConstructorParameter(