Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -428,7 +428,12 @@ class FfmProxyGenerator {
appendLine(" val target = cacheDir.resolve(fileName)")
appendLine(" stream.use { input ->")
appendLine(" val bytes = input.readAllBytes()")
appendLine(" if (!Files.exists(target) || Files.size(target) != bytes.size.toLong()) {")
appendLine(" // Size match alone is not enough: same-size builds can carry different")
appendLine(" // symbols (e.g. after an API rename), so compare content before trusting the cache.")
appendLine(" val stale = !Files.exists(target) ||")
appendLine(" Files.size(target) != bytes.size.toLong() ||")
appendLine(" !Files.readAllBytes(target).contentEquals(bytes)")
appendLine(" if (stale) {")
appendLine(" val tmp = Files.createTempFile(cacheDir, name, \".tmp\")")
appendLine(" Files.write(tmp, bytes)")
appendLine(" Files.move(tmp, target, StandardCopyOption.REPLACE_EXISTING, StandardCopyOption.ATOMIC_MOVE)")
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package dev.nucleusframework.nna.plugin.codegen

import dev.nucleusframework.nna.plugin.ir.KneModule
import org.junit.Assert.assertTrue
import org.junit.Test

class FfmProxyGeneratorRuntimeTest {

@Test
fun `cache staleness check compares content, not only size`() {
val runtime = generateRuntime()

// A same-size library with different symbols must refresh the cache (issue #29).
assertTrue(
"Generated runtime must compare cached bytes with resource bytes",
runtime.contains("!Files.readAllBytes(target).contentEquals(bytes)"),
)
}

private fun generateRuntime(): String {
val module = KneModule(
libName = "demo",
packages = setOf("demo"),
classes = emptyList(),
dataClasses = emptyList(),
enums = emptyList(),
functions = emptyList(),
)
return FfmProxyGenerator().generate(module, "demo").getValue("KneRuntime.kt")
}
}
Loading