HMPP: Fix serialization of TargetPlatform in Kotlin facet

This commit is contained in:
Dmitriy Dolovov
2020-04-06 22:13:47 +07:00
parent adc457548b
commit fee6a752e0
4 changed files with 68 additions and 28 deletions
@@ -57,7 +57,14 @@ open class TargetPlatform(val componentPlatforms: Set<SimplePlatform>) : Collect
* Ideally, each specific subtype should be either a data class or singleton.
*/
abstract class SimplePlatform(val platformName: String) {
override fun toString(): String = platformName
override fun toString(): String {
val targetName = targetName
return if (targetName.isNotEmpty()) "$platformName ($targetName)" else platformName
}
// description of TargetPlatformVersion or name of custom platform-specific target; used in serialization
open val targetName: String
get() = targetPlatformVersion.description
/** See KDoc for [TargetPlatform.oldFashionedDescription] */
abstract val oldFashionedDescription: String
@@ -87,4 +94,4 @@ fun TargetPlatform?.isCommon(): Boolean = this != null && size > 1 && iterator()
fun SimplePlatform.toTargetPlatform(): TargetPlatform = TargetPlatform(setOf(this))
fun SimplePlatform.serializeToString() = "${this.platformName} [${this.targetPlatformVersion.description}]"
fun SimplePlatform.serializeToString(): String = "$platformName [$targetName]"
@@ -25,16 +25,16 @@ fun <T> TargetPlatform?.has(klass: Class<T>): Boolean = this != null && subplatf
* also provides better description for multiplatforms.
*/
val TargetPlatform.oldFashionedDescription: String
// the invocation if isCommon is not preferable as it could be governed by separate flag and may
// to appear independently on count of target platforms
// this method mistakenly detects "common native" platform as "Common (experimental)"
// though this does not seem to have any significant effect
get() = this.singleOrNull()?.oldFashionedDescription ?: "Common (experimental) "
/**
* Renders multiplatform in form
* '$PLATFORM_1 / $PLATFORM_2 / ...'
* '$PLATFORM_1/$PLATFORM_2/...'
* e.g.
* 'JVM (1.8) / JS / Native'
* 'JVM (1.8)/JS/Native (ios_x64)'
*/
val TargetPlatform.presentableDescription: String
get() = componentPlatforms.joinToString(separator = "/")
get() = componentPlatforms.joinToString(separator = "/")