[gradle, mpp] Clean-up dead code around metadata klib manifest handling

See the added source comment for details. This commit shouldn't change
any behavior of KGP

^KT-64525
This commit is contained in:
Dmitry Savvinov
2023-12-21 16:32:43 +01:00
committed by Space Team
parent 5c28e63608
commit 8236fc245b
@@ -271,16 +271,6 @@ abstract class AbstractKotlinNativeCompile<
compilation.languageSettings
}
@get:Input
@get:Optional
internal val konanTargetsForManifest: String by project.provider {
@Suppress("CAST_NEVER_SUCCEEDS") // TODO: this warning looks very suspicious, as if the code never works as intended.
(compilation as? KotlinSharedNativeCompilation)
?.konanTargets
?.joinToString(separator = " ") { it.visibleName }
.orEmpty()
}
@get:Internal
internal val manifestFile: Provider<RegularFile> get() = projectLayout.buildDirectory.file("tmp/$name/inputManifest")
@@ -504,7 +494,25 @@ internal constructor(
val manifestFile: File = manifestFile.get().asFile
manifestFile.ensureParentDirsCreated()
val properties = java.util.Properties()
properties[KLIB_PROPERTY_NATIVE_TARGETS] = konanTargetsForManifest
/**
* We're overwriting the native_targets field in the klib manifest, because otherwise it will contain
* only one passed `-target` or host-target, if nothing is passed. Both options are wrong for shared-native
* compilations.
*
* If the native_targets manifest will contain too few targets, IDE and compilation will not work properly (e.g., it will forbid
* dependencies on such metadata-klibs from shared native source sets, because it will consider that a source set with targets
* like (iosArm64, iosSimulatorArm64) can't depend on a klib with native_targets=iosArm64)
*
* Now, overwriting it to empty value is entirely unintended behavior that appeared long time ago (~Kotlin 1.4) due to some
* unfortunate merges. Surprisingly, it gives the desired behavior.
*
* While we could change this code to contain the proper set of KonanTargets (the ones that are actually the targets of shared-native
* compilation), that would introduce one new "flavour" of manifests/binaries, which complicates a bit further work in this area.
*
* So, for now we're leaving this "hack" as is. Refer to KT-64525 "Clean-up target-related fields in manifest of klibs" for the
* plan on proper fixes
*/
properties[KLIB_PROPERTY_NATIVE_TARGETS] = ""
properties.saveToFile(org.jetbrains.kotlin.konan.file.File(manifestFile.toPath()))
return SharedCompilationData(manifestFile, refinesModule)