Modern Apps git

← Modern-Apps.git

all: dedupe screenshot renders, sort buckets by preview number

Commit
76bf2227aabc22a9f2a5b49fdc2eef385d547b32
Author
vayun-mathur <[email protected]>
When
2026-10-25 18:24 UTC (1 month ago)
Parents
0b93570

Diff

build-logic/src/main/kotlin/common-conventions-preview-metadata.gradle.kts
diff --git a/build-logic/src/main/kotlin/common-conventions-preview-metadata.gradle.kts b/build-logic/src/main/kotlin/common-conventions-preview-metadata.gradle.ktsindex b0d0bf8579..d5f42e0009 100644--- a/build-logic/src/main/kotlin/common-conventions-preview-metadata.gradle.kts+++ b/build-logic/src/main/kotlin/common-conventions-preview-metadata.gradle.kts@@ -77,6 +77,11 @@ val previewSourcesDir = File(projectDir, "src/screenshotTest") // recording mode the images land in the reference dir; they are an intermediate for us (see // .gitignore), though keeping them is also what would let `validate…ScreenshotTest` act as // UI regression testing later.+//+// Order matters: `rendered/` is the fresh output of the `updateScreenshotTest` run this+// task just depended on; `reference/` accumulates across runs (and across plugin versions,+// whose filename hashes differ), so it is only a fallback. Reading reference first would+// publish stale duplicates alongside the fresh renders. val referenceDir = File(projectDir, "src/screenshotTestDev/reference") // Lazily derived from the build directory provider: no .get() at // configuration time, so merely configuring the project creates no tasks.@@ -112,9 +117,22 @@ abstract class CollectPreviewScreenshots : DefaultTask() {                     "\nDoes the module have @Preview functions under src/screenshotTest/?"             ) -        // Sorted by path so the listing order is the preview function order (Preview1…,-        // Preview2…). Anything else would silently shuffle the store listing.-        val images = source.walkTopDown().filter { it.extension == "png" }.sortedBy { it.invariantSeparatorsPath }.toList()+        // Sorted by file name so the listing order is the preview function order+        // (Preview1…, Preview2…) — the generated names embed the function name.+        // Deliberately NOT the full path: previews live in per-class directories+        // (e.g. maps' CarMetadataPreviews/ vs MetadataPreviews/), and sorting by+        // path would put every Car… shot before every Metadata… shot regardless of+        // number. Anything else would silently shuffle the store listing.+        // Deduplicated by content: the same preview can render more than once (e.g. a+        // stale reference image from an older plugin version sitting next to the fresh+        // render), and the store listing must not show the same shot twice.+        val seen = mutableSetOf<String>()+        val images = source.walkTopDown().filter { it.extension == "png" }.sortedBy { it.name }.filter { png ->+            seen.add(sha256Hex(png.readBytes()))+        }.toList()+        if (images.size < seen.size) {+            logger.lifecycle("Metadata screenshots: dropped ${seen.size - images.size} byte-identical duplicate(s)")+        }          val groups = readPreviewGroups(previewSources.get(), label.get()) @@ -127,7 +145,7 @@ abstract class CollectPreviewScreenshots : DefaultTask() {             }             val bucketDir = File(dest, bucket)             bucketDir.mkdirs()-            bucketImages.sortedBy { it.invariantSeparatorsPath }.forEachIndexed { index, png ->+            bucketImages.sortedBy { it.name }.forEachIndexed { index, png ->                 png.copyTo(File(bucketDir, "${index + 1}.png"), overwrite = true)             }         }@@ -138,6 +156,12 @@ abstract class CollectPreviewScreenshots : DefaultTask() {     /** Rendered filenames look like `Preview1Keypad_1-keypad_<hash>_0.png` — the leading segment is the function name. */     private fun functionNameOf(png: File): String = png.nameWithoutExtension.substringBefore('_') +    /** Content hash for duplicate detection (a few small PNGs per module — cheap). */+    private fun sha256Hex(bytes: ByteArray): String {+        val digest = java.security.MessageDigest.getInstance("SHA-256")+        return digest.digest(bytes).joinToString("") { "%02x".format(it) }+    }+     /**      * Maps preview function names (`Preview1Keypad`) to their `@Preview(group = ...)`      * bucket by scanning the module's `src/screenshotTest` sources. Only `@Preview(`@@ -180,7 +204,7 @@ tasks.register<CollectPreviewScreenshots>("metadata") {     // `update…` renders the previews and writes them out; `validate…` would additionally     // diff them against a committed baseline, which we do not keep.     dependsOn("updateScreenshotTest")-    sourceDirs.set(renderedDir.map { listOf(referenceDir, it) })+    sourceDirs.set(renderedDir.map { listOf(it, referenceDir) })     destination.set(screenshotsOut)     previewSources.set(previewSourcesDir)     buckets.set(screenshotBuckets)
metadata_data/photos/calculator/large-tablet/1.png
diff --git a/metadata_data/photos/calculator/5.png b/metadata_data/photos/calculator/large-tablet/1.pngsimilarity index 100%rename from metadata_data/photos/calculator/5.pngrename to metadata_data/photos/calculator/large-tablet/1.png
metadata_data/photos/calculator/large-tablet/2.png
diff --git a/metadata_data/photos/calculator/large-tablet/2.png b/metadata_data/photos/calculator/large-tablet/2.pngnew file mode 100644index 0000000000..7b647c6393Binary files /dev/null and b/metadata_data/photos/calculator/large-tablet/2.png differ
metadata_data/photos/calculator/phone/1.png
diff --git a/metadata_data/photos/calculator/1.png b/metadata_data/photos/calculator/phone/1.pngsimilarity index 100%rename from metadata_data/photos/calculator/1.pngrename to metadata_data/photos/calculator/phone/1.png
metadata_data/photos/calculator/phone/2.png
diff --git a/metadata_data/photos/calculator/phone/2.png b/metadata_data/photos/calculator/phone/2.pngnew file mode 100644index 0000000000..af6d14de95Binary files /dev/null and b/metadata_data/photos/calculator/phone/2.png differ
metadata_data/photos/calculator/phone/3.png
diff --git a/metadata_data/photos/calculator/2.png b/metadata_data/photos/calculator/phone/3.pngsimilarity index 100%rename from metadata_data/photos/calculator/2.pngrename to metadata_data/photos/calculator/phone/3.png
metadata_data/photos/calculator/phone/4.png
diff --git a/metadata_data/photos/calculator/phone/4.png b/metadata_data/photos/calculator/phone/4.pngnew file mode 100644index 0000000000..07310b2d28Binary files /dev/null and b/metadata_data/photos/calculator/phone/4.png differ
metadata_data/photos/calculator/phone/5.png
diff --git a/metadata_data/photos/calculator/3.png b/metadata_data/photos/calculator/phone/5.pngsimilarity index 100%rename from metadata_data/photos/calculator/3.pngrename to metadata_data/photos/calculator/phone/5.png
metadata_data/photos/calculator/phone/6.png
diff --git a/metadata_data/photos/calculator/phone/6.png b/metadata_data/photos/calculator/phone/6.pngnew file mode 100644index 0000000000..770ee46f3eBinary files /dev/null and b/metadata_data/photos/calculator/phone/6.png differ
metadata_data/photos/calculator/phone/7.png
diff --git a/metadata_data/photos/calculator/4.png b/metadata_data/photos/calculator/phone/7.pngsimilarity index 100%rename from metadata_data/photos/calculator/4.pngrename to metadata_data/photos/calculator/phone/7.png
metadata_data/photos/calculator/phone/8.png
diff --git a/metadata_data/photos/calculator/phone/8.png b/metadata_data/photos/calculator/phone/8.pngnew file mode 100644index 0000000000..5a4263f190Binary files /dev/null and b/metadata_data/photos/calculator/phone/8.png differ
metadata_data/photos/maps/large-tablet/1.png
diff --git a/metadata_data/photos/maps/6.png b/metadata_data/photos/maps/large-tablet/1.pngsimilarity index 100%rename from metadata_data/photos/maps/6.pngrename to metadata_data/photos/maps/large-tablet/1.png
metadata_data/photos/maps/large-tablet/2.png
diff --git a/metadata_data/photos/maps/7.png b/metadata_data/photos/maps/large-tablet/2.pngsimilarity index 100%rename from metadata_data/photos/maps/7.pngrename to metadata_data/photos/maps/large-tablet/2.png
metadata_data/photos/maps/phone/1.png
diff --git a/metadata_data/photos/maps/3.png b/metadata_data/photos/maps/phone/1.pngsimilarity index 100%rename from metadata_data/photos/maps/3.pngrename to metadata_data/photos/maps/phone/1.png
metadata_data/photos/maps/phone/2.png
diff --git a/metadata_data/photos/maps/4.png b/metadata_data/photos/maps/phone/2.pngsimilarity index 100%rename from metadata_data/photos/maps/4.pngrename to metadata_data/photos/maps/phone/2.png
metadata_data/photos/maps/phone/3.png
diff --git a/metadata_data/photos/maps/5.png b/metadata_data/photos/maps/phone/3.pngsimilarity index 66%rename from metadata_data/photos/maps/5.pngrename to metadata_data/photos/maps/phone/3.pngindex a081fd1184..f465a95564 100644Binary files a/metadata_data/photos/maps/5.png and b/metadata_data/photos/maps/phone/3.png differ
metadata_data/photos/maps/phone/4.png
diff --git a/metadata_data/photos/maps/1.png b/metadata_data/photos/maps/phone/4.pngsimilarity index 100%rename from metadata_data/photos/maps/1.pngrename to metadata_data/photos/maps/phone/4.png
metadata_data/photos/maps/phone/5.png
diff --git a/metadata_data/photos/maps/2.png b/metadata_data/photos/maps/phone/5.pngsimilarity index 100%rename from metadata_data/photos/maps/2.pngrename to metadata_data/photos/maps/phone/5.png