Skip to content

Rework resource generation#881

Open
ExNDY wants to merge 19 commits into
icerockdev:developfrom
ExNDY:rework-resource-generation
Open

Rework resource generation#881
ExNDY wants to merge 19 commits into
icerockdev:developfrom
ExNDY:rework-resource-generation

Conversation

@ExNDY

@ExNDY ExNDY commented Jun 11, 2026

Copy link
Copy Markdown
Contributor

Summary

This PR reworks resource code generation to use batched accessors and a cleaner split between common generation logic and platform-specific initialization.

The main idea is that generated accessors are no longer emitted as one large monolithic block per resource type. Instead, resources are split into internal batches, while the public MR-facing API remains stable and aggregates those batches through values(). This reduces generated file size, simplifies platform-specific generators, and makes the generated structure easier to evolve.

The PR also includes:

What Changed

1. Batched generated accessors

  • ResourceTypeGenerator now chunks resources into batches and generates internal grouped accessor objects such as CommonMainStrings0, CommonMainStrings1, etc.
  • the public resource container still exposes the same logical API, but now aggregates batched groups through values();
  • common generation owns the accessor topology, while platform generators only provide platform-specific initialization and file emission.

This gives us a cleaner separation of responsibilities:

  • common layer: resource grouping, accessors, object layout;
  • platform layer: how a single resource instance is initialized on JVM/Apple/Android/etc.
object strings : ResourceContainer<StringResource> {
    override val __platformDetails: ResourcePlatformDetails
    override fun values(): List<StringResource> =
        listOf(CommonMainStrings0.values(), CommonMainStrings1.values()).flatten()
}

internal object CommonMainStrings0 {
    internal val title by lazy { init_title() }
    internal val subtitle by lazy { init_subtitle() }

    internal fun values(): List<StringResource> = listOf(title, subtitle)
}

val MR.strings.title: StringResource
    get() = CommonMainStrings0.title

2. Apple SVG opacity fix (#731)

  • Apple image generation now rewrites SVG colors with embedded alpha such as #RRGGBBAA and #RGBA;
  • alpha is extracted into SVG opacity attributes like fill-opacity and stroke-opacity before the file is written into the generated Apple asset catalog.

Example:

  • fill="#a3acb1a4" becomes fill="#a3acb1" fill-opacity="0.64"

This keeps the rendered appearance while producing SVG content that Apple handles more reliably, including in simulator runs.

3. Relocatable build cache fix

Fixed the relocatable build cache for GenerateMultiplatformResourcesTask: upperSourceSets is no longer included in the cache key as a regular @Input because it contained absolute paths to the source set resources. It is now marked as @Internal, so identical builds from different checkout paths can reuse the build cache.

Additionally, the generated MR contentHash is now a public const val, so resource changes become part of the public ABI and downstream Java/Gradle compilation can detect them more accurately.

Manual Verification

Tested manually:

  • :resources-generator:compileKotlin passes.
  • In compose-resources-gallery, modifying appleMain no longer invalidates commonMain/nativeMain, and only regenerates the necessary chain: appleMain -> iosMain -> iosSimulatorArm64Main.
  • A smoke test on two project copies under different /private/tmp/... paths showed FROM-CACHE for generateMR... tasks.

fixed issue: #731 , #810

@ExNDY

ExNDY commented Jun 14, 2026

Copy link
Copy Markdown
Contributor Author

on current time, i need ask about metadata.json files, after rework generation this structure little bit simple than generated files and i dont know what is next: its correct "info about resources" or need rework metadata for all generated objects

@Alex009 can i ask your help here

@ExNDY ExNDY requested a review from Alex009 June 19, 2026 09:06
@ExNDY ExNDY self-assigned this Jun 19, 2026
@ExNDY ExNDY added this to the 0.27.0 milestone Jun 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants