Skip to content

Commit 44e42ae

Browse files
build: cache R8 compatibility transformations (#1014)
The R8 compatibility fixture currently runs its expensive transformation on every test invocation. Declare the program jar, both ProGuard rule files, and JDK library directory as inputs, and the transformed jar and mapping as outputs, so Gradle can restore identical transformations from its build cache. JavaExec already tracks the tool classpath and arguments. Both executable compatibility smoke tests still run. Local JDK 21 experiments after deleting fixture outputs reduced the shrinker test command from **45s to 3s** with the R8 output restored. Changing a rule file changed the cache key and reran R8; restoring the rules restored the cached result. Both smoke tests passed in each case. Final independent-branch verification passed in 2s with Shadow, ProGuard, and R8 restored and both smoke tests executing. This is a one-file change with no dependency or optimizer-option changes. CI reuse needs a trusted main cache with matching inputs; #1012 enables retaining test preparation on main. SDK, rules, tool, or JDK changes still rebuild. Absolute argument paths conservatively restrict cache reuse to matching checkout/JDK paths. Validation: Kotlin/Java lint and 47 build-logic tests passed; cold execution, clean-output restoration, rule invalidation, and both shrinker smoke tests passed. Security-focused adversarial review checks cache input coverage and preserves existing cache trust boundaries. <!-- codex-thread: 01a0b068-1c07-70a1-b846-2ed907c8c512 -->
1 parent 7d2077c commit 44e42ae

1 file changed

Lines changed: 12 additions & 1 deletion

File tree

‎openai-java-proguard-test/build.gradle.kts‎

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,21 +75,32 @@ val testProGuard by tasks.registering(JavaExec::class) {
7575
}
7676

7777
val r8JarPath = "${layout.buildDirectory.get()}/libs/${project.name}-${project.version}-r8.jar"
78+
val r8MappingPath = "${layout.buildDirectory.get()}/r8-mapping.txt"
7879
val r8Jar by tasks.registering(JavaExec::class) {
7980
group = "verification"
8081
dependsOn(tasks.shadowJar)
8182

8283
mainClass.set("com.android.tools.r8.R8")
8384
classpath = buildscript.configurations["classpath"]
8485

86+
// JavaExec already tracks its tool classpath and arguments. Declare the files read through
87+
// those arguments so unchanged transformations can be restored without skipping the smoke test.
88+
inputs.files(shadowJarFile).withPropertyName("programJar").withNormalizer(ClasspathNormalizer::class)
89+
inputs.files("./test.pro", "../openai-java-core/src/main/resources/META-INF/proguard/openai-java-core.pro")
90+
.withPropertyName("proguardConfiguration").withPathSensitivity(PathSensitivity.RELATIVE)
91+
inputs.dir(System.getProperty("java.home"))
92+
.withPropertyName("libraryJavaHome").withPathSensitivity(PathSensitivity.RELATIVE)
93+
outputs.files(r8JarPath, r8MappingPath)
94+
outputs.cacheIf { true }
95+
8596
args = listOf(
8697
"--release",
8798
"--classfile",
8899
"--output", r8JarPath,
89100
"--lib", System.getProperty("java.home"),
90101
"--pg-conf", "./test.pro",
91102
"--pg-conf", "../openai-java-core/src/main/resources/META-INF/proguard/openai-java-core.pro",
92-
"--pg-map-output", "${layout.buildDirectory.get()}/r8-mapping.txt",
103+
"--pg-map-output", r8MappingPath,
93104
shadowJarFile.get().asFile.absolutePath,
94105
)
95106
}

0 commit comments

Comments
 (0)