mirror of
https://github.com/ReVanced/revanced-patcher.git
synced 2024-11-12 18:04:24 +01:00
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.
This commit is contained in:
parent
91cdfd53ef
commit
e11283744a
1 changed files with 9 additions and 9 deletions
|
@ -33,7 +33,7 @@ class PatchProcessor(
|
||||||
|
|
||||||
@Suppress("UNCHECKED_CAST")
|
@Suppress("UNCHECKED_CAST")
|
||||||
override fun process(resolver: Resolver): List<KSAnnotated> {
|
override fun process(resolver: Resolver): List<KSAnnotated> {
|
||||||
val executablePatches = buildMap {
|
val patches = buildMap {
|
||||||
resolver.getSymbolsWithAnnotation(Patch::class.qualifiedName!!).filter {
|
resolver.getSymbolsWithAnnotation(Patch::class.qualifiedName!!).filter {
|
||||||
// Do not check here if Patch is super of the class, because it is expensive.
|
// Do not check here if Patch is super of the class, because it is expensive.
|
||||||
// Check it later when processing.
|
// 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,
|
// 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.
|
// unlike the annotated patch.
|
||||||
val dependencyResolutionMap = buildMap {
|
val dependencyResolutionMap = buildMap {
|
||||||
executablePatches.values.filter { it.dependencies != null }.flatMap {
|
patches.values.filter { it.dependencies != null }.flatMap {
|
||||||
it.dependencies!!
|
it.dependencies!!
|
||||||
}.distinct().forEach { dependency ->
|
}.distinct().forEach { dependency ->
|
||||||
executablePatches.keys.find { it.qualifiedName?.asString() == dependency.toString() }
|
patches.keys.find { it.qualifiedName?.asString() == dependency.toString() }
|
||||||
?.let { patch ->
|
?.let { patch ->
|
||||||
this[dependency] = ClassName(
|
this[dependency] = ClassName(
|
||||||
patch.packageName.asString(),
|
patch.packageName.asString(),
|
||||||
|
@ -115,7 +115,7 @@ class PatchProcessor(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
executablePatches.forEach { (patchDeclaration, patchAnnotation) ->
|
patches.forEach { (patchDeclaration, patchAnnotation) ->
|
||||||
val isBytecodePatch = patchDeclaration.isSubclassOf(BytecodePatch::class)
|
val isBytecodePatch = patchDeclaration.isSubclassOf(BytecodePatch::class)
|
||||||
|
|
||||||
val superClass = if (isBytecodePatch) {
|
val superClass = if (isBytecodePatch) {
|
||||||
|
@ -156,14 +156,14 @@ class PatchProcessor(
|
||||||
|
|
||||||
patchAnnotation.dependencies?.let { dependencies ->
|
patchAnnotation.dependencies?.let { dependencies ->
|
||||||
addSuperclassConstructorParameter(
|
addSuperclassConstructorParameter(
|
||||||
"dependencies = setOf(%L)",
|
"dependencies = setOf(%L, %L)",
|
||||||
buildList {
|
buildList {
|
||||||
addAll(dependencies)
|
addAll(dependencies)
|
||||||
// Also add the source class of the generated class so that it is also executed.
|
|
||||||
add(patchDeclaration.toClassName())
|
|
||||||
}.joinToString(", ") { dependency ->
|
}.joinToString(", ") { dependency ->
|
||||||
"${(dependencyResolutionMap[dependency] ?: dependency)}::class"
|
"${(dependencyResolutionMap[dependency] ?: dependency)}::class"
|
||||||
}
|
},
|
||||||
|
// Also add the source class of the generated class so that it is also executed.
|
||||||
|
"${patchDeclaration.toClassName()}::class"
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
addSuperclassConstructorParameter(
|
addSuperclassConstructorParameter(
|
||||||
|
|
Loading…
Reference in a new issue