cashapp / paparazzi

Render your Android screens without a physical device or emulator
https://cashapp.github.io/paparazzi/
Apache License 2.0
2.29k stars 214 forks source link

Switch library resource paths from exploded aar to artifact cache dir #851

Open jrodbx opened 1 year ago

jrodbx commented 1 year ago

As part of the new resource rewriting mechanism, Paparazzi needs to be informed of where external AAR libraries reside to crawl them for potential Android resources.

In efforts to be efficient, the current implementation looks at the exploded aar directory for the artifact, e.g.,

caches/transforms-3/b300a7e5a3fc4e2b007ed112e3603d73/transformed/material-1.3.1/res

But that hash seems to change too often. Recently Gradle version bumps, changes to internal Paparazzi plugin code, etc., have all resulted in tests that reference this path (for the purposes of asserting that the new resource rewriting mechanism is working as expected) to be updated, which is silly.

If we instead use the original aar artifact path, e.g.,

caches/modules-2/files-2.1/androidx.compose.material/material/1.3.1/2c9bd8fc68163a260e999d9c1603b40ad7982134/material-1.3.1.aar

my guess is that hash will never change, since it's under the group:artifact:version directory subtree, which would only change if a new binary mapped to that triple were pushed to Maven Central (unlikely?)

Pros:

Cons:

seems like pros outweigh the cons here.

cc: @kevinzheng-ap @JakeWharton

TWiStErRob commented 1 year ago

I think the transform folder includes Jetifier (and potentially other transformations as well), not just "explosion", so as a Con it might be simply incorrect to look in modules: a resource might reference something (e.g. a support lib class/resource) which is replaced (e.g. with a Jetpack class/resource).

Quick investigation of where the directory name comes from * it's calculated in one of the `org.gradle.internal.execution.UnitOfWork#identify` implementations (there are many, debug would reveal exact values I think, but didn't go as far) * that is propagated to transformations in `org.gradle.internal.execution.steps.IdentifyStep#createIdentityContext` * which gets used at `org.gradle.internal.execution.steps.AssignWorkspaceStep#execute` to create the directory * and that is used as the base of the parameter in `org.gradle.api.artifacts.transform.TransformAction#transform`