From 9c8dec53debdce0d8d07b66508e1705bbdc6f9e3 Mon Sep 17 00:00:00 2001 From: dunwen <1501000255@qq.com> Date: Thu, 24 Apr 2025 20:11:02 +0800 Subject: [PATCH 1/3] fix: increase build issue of vm injection --- .../java/tiktok/knit/plugin/element/ComponentClass.kt | 6 ++++++ .../src/main/java/tiktok/knit/plugin/writer/VMWriter.kt | 3 +++ .../src/main/java/tiktok/knit/bytex/KnitContextImpl.kt | 9 +++++++++ 3 files changed, 18 insertions(+) diff --git a/knit-asm/src/main/java/tiktok/knit/plugin/element/ComponentClass.kt b/knit-asm/src/main/java/tiktok/knit/plugin/element/ComponentClass.kt index 167ba84..ec13622 100644 --- a/knit-asm/src/main/java/tiktok/knit/plugin/element/ComponentClass.kt +++ b/knit-asm/src/main/java/tiktok/knit/plugin/element/ComponentClass.kt @@ -26,6 +26,7 @@ import tiktok.knit.plugin.knitVMAnnotationDesc import tiktok.knit.plugin.providesDesc import tiktok.knit.plugin.singletonDesc import tiktok.knit.plugin.toFieldAccess +import tiktok.knit.plugin.writer.VMProperty import kotlin.metadata.Visibility import kotlin.metadata.isSecondary import kotlin.metadata.jvm.signature @@ -56,6 +57,11 @@ data class ComponentClass( emptyMap(), emptyList(), emptyList(), false, ) + /** + * The internal name of all vm properties in this component class. + * */ + val vmPropertyInternalNames = hashSetOf() + companion object { fun from(container: MetadataContainer): ComponentClass { val classNode = container.node diff --git a/knit-asm/src/main/java/tiktok/knit/plugin/writer/VMWriter.kt b/knit-asm/src/main/java/tiktok/knit/plugin/writer/VMWriter.kt index a830957..e3b2947 100644 --- a/knit-asm/src/main/java/tiktok/knit/plugin/writer/VMWriter.kt +++ b/knit-asm/src/main/java/tiktok/knit/plugin/writer/VMWriter.kt @@ -64,6 +64,9 @@ fun generateVMLogic(context: KnitContext, classNode: ClassNode, thisComponent: B val allVMProperties = getVMProperties(context, classNode, thisComponent) if (allVMProperties.isEmpty()) return + val componentClass = context.componentMap[classNode.name] + componentClass?.vmPropertyInternalNames?.addAll(allVMProperties.map { it.type.internalName }) + // create vm prop provider functions for (vmProp in allVMProperties) { val backendFunctionName = vmProp.property.name + "\$knitVm" diff --git a/knit-bytex/src/main/java/tiktok/knit/bytex/KnitContextImpl.kt b/knit-bytex/src/main/java/tiktok/knit/bytex/KnitContextImpl.kt index 5d7a059..ee46321 100644 --- a/knit-bytex/src/main/java/tiktok/knit/bytex/KnitContextImpl.kt +++ b/knit-bytex/src/main/java/tiktok/knit/bytex/KnitContextImpl.kt @@ -158,10 +158,19 @@ class KnitContextImpl( depsMap[internalName]?.forEach { producer -> allNonIncrementalFiles += "$producer.class" } + allNonIncrementalFiles += calculateVMRelatedClasses(internalName).map { "$it.class" } } return allNonIncrementalFiles } + private fun calculateVMRelatedClasses(changedClass: String): Collection { + val componentMap = componentMap + return componentMap.filter { + val vmPropertyInterNames = it.value.vmPropertyInternalNames + return@filter vmPropertyInterNames.contains(changedClass) + }.keys + } + class Storage( val componentMap: Map, val backDepsMap: Map>, From 2e07c764ff20c75368c22985d859fb7b89c1845f Mon Sep 17 00:00:00 2001 From: zsub <49520432+zsqw123@users.noreply.github.com> Date: Thu, 24 Apr 2025 20:12:14 +0800 Subject: [PATCH 2/3] Update ComponentClass.kt --- .../main/java/tiktok/knit/plugin/element/ComponentClass.kt | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/knit-asm/src/main/java/tiktok/knit/plugin/element/ComponentClass.kt b/knit-asm/src/main/java/tiktok/knit/plugin/element/ComponentClass.kt index ec13622..9bf0514 100644 --- a/knit-asm/src/main/java/tiktok/knit/plugin/element/ComponentClass.kt +++ b/knit-asm/src/main/java/tiktok/knit/plugin/element/ComponentClass.kt @@ -57,9 +57,7 @@ data class ComponentClass( emptyMap(), emptyList(), emptyList(), false, ) - /** - * The internal name of all vm properties in this component class. - * */ + // Internal names of all vm properties in this component class, used for incremental build val vmPropertyInternalNames = hashSetOf() companion object { From b010949b8666a2dc05719c509e07341e746198b4 Mon Sep 17 00:00:00 2001 From: zsub <49520432+zsqw123@users.noreply.github.com> Date: Thu, 24 Apr 2025 20:13:36 +0800 Subject: [PATCH 3/3] Update KnitContextImpl.kt --- .../src/main/java/tiktok/knit/bytex/KnitContextImpl.kt | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/knit-bytex/src/main/java/tiktok/knit/bytex/KnitContextImpl.kt b/knit-bytex/src/main/java/tiktok/knit/bytex/KnitContextImpl.kt index ee46321..a901359 100644 --- a/knit-bytex/src/main/java/tiktok/knit/bytex/KnitContextImpl.kt +++ b/knit-bytex/src/main/java/tiktok/knit/bytex/KnitContextImpl.kt @@ -166,8 +166,7 @@ class KnitContextImpl( private fun calculateVMRelatedClasses(changedClass: String): Collection { val componentMap = componentMap return componentMap.filter { - val vmPropertyInterNames = it.value.vmPropertyInternalNames - return@filter vmPropertyInterNames.contains(changedClass) + changedClass in it.value.vmPropertyInternalNames }.keys } @@ -179,4 +178,4 @@ class KnitContextImpl( private val gson by lazy { Gson() } private const val cacheName = "knit-cache.json" -private val globalProvidesClass = "$globalProvidesInternalName.class" \ No newline at end of file +private val globalProvidesClass = "$globalProvidesInternalName.class"