Skip to content

Consider deprecating enableKotlinModuleRemapping flag #2066

Description

@Goooler

The flag was introduced due to #1874.

We can deprecate it and move

/**
* Applies remapping to the given kotlin module with the specified relocation path. The remapped
* module is then written to the zip file.
*/
@OptIn(UnstableMetadataApi::class)
private fun FileCopyDetails.remapKotlinModule() =
file.readBytes().let { bytes ->
val kmMetadata = KotlinModuleMetadata.read(bytes)
val newKmModule =
KmModule().apply {
// We don't need to relocate the nested properties in `optionalAnnotationClasses`, there
// is a very special use case for Kotlin Multiplatform.
optionalAnnotationClasses += kmMetadata.kmModule.optionalAnnotationClasses
packageParts +=
kmMetadata.kmModule.packageParts.map { (pkg, parts) ->
val relocatedPkg = relocators.relocateClass(pkg)
val relocatedParts =
KmPackageParts(
parts.fileFacades.mapTo(mutableListOf()) { relocators.relocatePath(it) },
parts.multiFileClassParts.entries.associateTo(mutableMapOf()) { (name, facade)
->
relocators.relocatePath(name) to relocators.relocatePath(facade)
},
)
relocatedPkg to relocatedParts
}
}
val newKmMetadata = KotlinModuleMetadata(newKmModule, kmMetadata.version)
val newBytes = newKmMetadata.write()
val relocatedPath = relocators.relocatePath(path)
val entryName =
when {
relocatedPath != path -> relocatedPath
// Nothing changed, so keep the original path.
newBytes.contentEquals(bytes) -> path
// Content changed but path didn't, so rename to avoid name clash. The filename does not
// matter to the compiler.
else -> path.replace(".kotlin_module", ".shadow.kotlin_module")
}
writeToZip(entryName = entryName, bytes = newBytes)
}
into a new ResourceTransformer in the next major version. Users who want to remap the module files will need to apply the new ResourceTransformer explicitly.

Metadata

Metadata

Assignees

No one assigned
    No fields configured for Feature.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions