[JPS] Rebuild module on facet change
The logic of detecting changes in Kotlin facets was changed from "Include selected fields" to "Include all compiler arguments and exclude selected". This will help to avoid multiple IC issues when new change-sensitive compiler arguments will be added (#KTIJ-17137, #KT-51536, #KTIJ-17170, #KTIJ-17300, #KT-47983) Fixed Merge-request: KT-MR-7455 Merged-by: Aleksei Cherepanov <aleksei.cherepanov@jetbrains.com>
This commit is contained in:
committed by
Space Team
parent
50cd560d09
commit
26e7c29a91
@@ -6,70 +6,132 @@
|
||||
package org.jetbrains.kotlin.build
|
||||
|
||||
import org.jetbrains.kotlin.cli.common.arguments.CommonCompilerArguments
|
||||
import org.jetbrains.kotlin.config.KotlinCompilerVersion
|
||||
import org.jetbrains.kotlin.config.ApiVersion
|
||||
import org.jetbrains.kotlin.config.LanguageVersion
|
||||
import org.jetbrains.kotlin.config.PluginClasspaths
|
||||
import org.jetbrains.kotlin.metadata.deserialization.BinaryVersion
|
||||
import kotlin.reflect.KClass
|
||||
import org.jetbrains.kotlin.config.PluginClasspathsComparator
|
||||
|
||||
interface BuildMetaInfo {
|
||||
val isEAP: Boolean
|
||||
val compilerBuildVersion: String
|
||||
val languageVersionString: String
|
||||
val apiVersionString: String
|
||||
val multiplatformEnable: Boolean
|
||||
val metadataVersionMajor: Int
|
||||
val metadataVersionMinor: Int
|
||||
val metadataVersionPatch: Int
|
||||
val ownVersion: Int
|
||||
val coroutinesVersion: Int
|
||||
val multiplatformVersion: Int
|
||||
val pluginClasspaths: String
|
||||
}
|
||||
|
||||
abstract class BuildMetaInfoFactory<T : BuildMetaInfo>(private val metaInfoClass: KClass<T>) {
|
||||
protected abstract fun create(
|
||||
isEAP: Boolean,
|
||||
compilerBuildVersion: String,
|
||||
languageVersionString: String,
|
||||
apiVersionString: String,
|
||||
multiplatformEnable: Boolean,
|
||||
ownVersion: Int,
|
||||
coroutinesVersion: Int,
|
||||
multiplatformVersion: Int,
|
||||
metadataVersionArray: IntArray?,
|
||||
pluginClasspaths: String
|
||||
): T
|
||||
|
||||
fun create(args: CommonCompilerArguments): T {
|
||||
val languageVersion = args.languageVersion?.let { LanguageVersion.fromVersionString(it) } ?: LanguageVersion.LATEST_STABLE
|
||||
|
||||
return create(
|
||||
isEAP = !languageVersion.isStable,
|
||||
compilerBuildVersion = KotlinCompilerVersion.VERSION,
|
||||
languageVersionString = languageVersion.versionString,
|
||||
apiVersionString = args.apiVersion ?: languageVersion.versionString,
|
||||
multiplatformEnable = args.multiPlatform,
|
||||
ownVersion = OWN_VERSION,
|
||||
coroutinesVersion = COROUTINES_VERSION,
|
||||
multiplatformVersion = MULTIPLATFORM_VERSION,
|
||||
metadataVersionArray = args.metadataVersion?.let { BinaryVersion.parseVersionArray(it) },
|
||||
pluginClasspaths = PluginClasspaths(args.pluginClasspaths).serialize()
|
||||
)
|
||||
abstract class BuildMetaInfo {
|
||||
enum class CustomKeys {
|
||||
LANGUAGE_VERSION_STRING, IS_EAP, METADATA_VERSION_STRING, PLUGIN_CLASSPATHS, API_VERSION_STRING
|
||||
}
|
||||
|
||||
fun serializeToString(args: CommonCompilerArguments): String =
|
||||
serializeToString(create(args))
|
||||
fun obtainReasonForRebuild(currentCompilerArgumentsMap: Map<String, String>, previousCompilerArgsMap: Map<String, String>): String? {
|
||||
if (currentCompilerArgumentsMap.keys != previousCompilerArgsMap.keys) {
|
||||
return "Compiler arguments version was changed"
|
||||
}
|
||||
|
||||
fun serializeToString(info: T): String =
|
||||
serializeToPlainText(info, metaInfoClass)
|
||||
val changedCompilerArguments = currentCompilerArgumentsMap.mapNotNull {
|
||||
val key = it.key
|
||||
val previousValue = previousCompilerArgsMap[it.key] ?: return@mapNotNull key
|
||||
val currentValue = it.value
|
||||
return@mapNotNull if (compareIsChanged(key, currentValue, previousValue)) key else null
|
||||
}
|
||||
|
||||
fun deserializeFromString(str: String): T? =
|
||||
deserializeFromPlainText(str, metaInfoClass)
|
||||
|
||||
companion object {
|
||||
const val OWN_VERSION: Int = 0
|
||||
const val COROUTINES_VERSION: Int = 0
|
||||
const val MULTIPLATFORM_VERSION: Int = 0
|
||||
if (changedCompilerArguments.isNotEmpty()) {
|
||||
val rebuildReason = when (changedCompilerArguments.size) {
|
||||
1 -> "One of compiler arguments was changed: "
|
||||
else -> "Some compiler arguments were changed: "
|
||||
} + changedCompilerArguments.joinToReadableString()
|
||||
return rebuildReason
|
||||
}
|
||||
return null
|
||||
}
|
||||
}
|
||||
|
||||
private fun compareIsChanged(key: String, currentValue: String, previousValue: String): Boolean {
|
||||
// check for specific key changes
|
||||
checkIfPlatformSpecificCompilerArgumentWasChanged(key, currentValue, previousValue)?.let { comparisonResult ->
|
||||
return comparisonResult
|
||||
}
|
||||
when (key) {
|
||||
CustomKeys.LANGUAGE_VERSION_STRING.name ->
|
||||
return LanguageVersion.fromVersionString(currentValue) != LanguageVersion.fromVersionString(previousValue)
|
||||
CustomKeys.API_VERSION_STRING.name -> return ApiVersion.parse(currentValue) != ApiVersion.parse(previousValue)
|
||||
CustomKeys.PLUGIN_CLASSPATHS.name -> return !PluginClasspathsComparator(previousValue, currentValue).equals()
|
||||
}
|
||||
|
||||
// check keys that are sensitive for true -> false change
|
||||
if (key in argumentsListForSpecialCheck) {
|
||||
return previousValue == "true" && currentValue != "true"
|
||||
}
|
||||
|
||||
// compare all other change-sensitive values
|
||||
if (previousValue != currentValue) {
|
||||
return true
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
open fun checkIfPlatformSpecificCompilerArgumentWasChanged(key: String, currentValue: String, previousValue: String): Boolean? {
|
||||
return null
|
||||
}
|
||||
|
||||
open fun createPropertiesMapFromCompilerArguments(args: CommonCompilerArguments): Map<String, String> {
|
||||
val resultMap = transformClassToPropertiesMap(args, excludedProperties).toMutableMap()
|
||||
val languageVersion = args.languageVersion?.let { LanguageVersion.fromVersionString(it) }
|
||||
?: LanguageVersion.LATEST_STABLE
|
||||
val languageVersionSting = languageVersion.versionString
|
||||
resultMap[CustomKeys.LANGUAGE_VERSION_STRING.name] = languageVersionSting
|
||||
|
||||
val isEAP = !languageVersion.isStable
|
||||
resultMap[CustomKeys.IS_EAP.name] = isEAP.toString()
|
||||
|
||||
val apiVersionString = args.apiVersion ?: languageVersionSting
|
||||
resultMap[CustomKeys.API_VERSION_STRING.name] = apiVersionString
|
||||
|
||||
val pluginClasspaths = PluginClasspaths(args.pluginClasspaths).serialize()
|
||||
resultMap[CustomKeys.PLUGIN_CLASSPATHS.name] = pluginClasspaths
|
||||
|
||||
return resultMap
|
||||
}
|
||||
|
||||
fun deserializeMapFromString(inputString: String): Map<String, String> = inputString
|
||||
.split("\n")
|
||||
.filter(String::isNotBlank)
|
||||
.associate { it.substringBefore("=") to it.substringAfter("=") }
|
||||
|
||||
private fun serializeMapToString(myList: Map<String, String>) = myList.map { "${it.key}=${it.value}" }.joinToString("\n")
|
||||
fun serializeArgsToString(args: CommonCompilerArguments) = serializeMapToString(createPropertiesMapFromCompilerArguments(args))
|
||||
|
||||
open val excludedProperties = listOf(
|
||||
"languageVersion",
|
||||
"apiVersion",
|
||||
"pluginClasspaths",
|
||||
"metadataVersion",
|
||||
"dumpDirectory",
|
||||
"dumpOnlyFqName",
|
||||
"dumpPerf",
|
||||
"errors",
|
||||
"extraHelp",
|
||||
"freeArgs",
|
||||
"help",
|
||||
"intellijPluginRoot",
|
||||
"kotlinHome",
|
||||
"listPhases",
|
||||
"namesExcludedFromDumping",
|
||||
"phasesToDump",
|
||||
"phasesToDumpAfter",
|
||||
"phasesToDumpBefore",
|
||||
"profilePhases",
|
||||
"renderInternalDiagnosticNames",
|
||||
"reportOutputFiles",
|
||||
"reportPerf",
|
||||
"script",
|
||||
"verbose",
|
||||
"verbosePhases",
|
||||
"version"
|
||||
)
|
||||
|
||||
open val argumentsListForSpecialCheck = listOf(
|
||||
"allowAnyScriptsInSourceRoots",
|
||||
"allowKotlinPackage",
|
||||
"allowResultReturnType",
|
||||
"noCheckActual",
|
||||
"skipMetadataVersionCheck",
|
||||
"skipPrereleaseCheck",
|
||||
"suppressVersionWarnings",
|
||||
"suppressWarnings",
|
||||
CustomKeys.IS_EAP.name
|
||||
)
|
||||
}
|
||||
@@ -5,53 +5,34 @@
|
||||
|
||||
package org.jetbrains.kotlin.build
|
||||
|
||||
import org.jetbrains.kotlin.cli.common.arguments.CommonCompilerArguments
|
||||
import org.jetbrains.kotlin.metadata.deserialization.BinaryVersion
|
||||
import org.jetbrains.kotlin.metadata.jvm.deserialization.JvmMetadataVersion
|
||||
|
||||
/**
|
||||
* If you want to add a new field, check its type is supported by [serializeToPlainText], [deserializeFromPlainText]
|
||||
*/
|
||||
data class CommonBuildMetaInfo(
|
||||
override val isEAP: Boolean,
|
||||
override val compilerBuildVersion: String,
|
||||
override val languageVersionString: String,
|
||||
override val apiVersionString: String,
|
||||
override val multiplatformEnable: Boolean,
|
||||
override val metadataVersionMajor: Int,
|
||||
override val metadataVersionMinor: Int,
|
||||
override val metadataVersionPatch: Int,
|
||||
override val ownVersion: Int,
|
||||
override val coroutinesVersion: Int,
|
||||
override val multiplatformVersion: Int,
|
||||
override val pluginClasspaths: String
|
||||
) : BuildMetaInfo {
|
||||
companion object : BuildMetaInfoFactory<CommonBuildMetaInfo>(CommonBuildMetaInfo::class) {
|
||||
override fun create(
|
||||
isEAP: Boolean,
|
||||
compilerBuildVersion: String,
|
||||
languageVersionString: String,
|
||||
apiVersionString: String,
|
||||
multiplatformEnable: Boolean,
|
||||
ownVersion: Int,
|
||||
coroutinesVersion: Int,
|
||||
multiplatformVersion: Int,
|
||||
metadataVersionArray: IntArray?,
|
||||
pluginClasspaths: String
|
||||
): CommonBuildMetaInfo {
|
||||
val metadataVersion = metadataVersionArray?.let(::JvmMetadataVersion) ?: JvmMetadataVersion.INSTANCE
|
||||
return CommonBuildMetaInfo(
|
||||
isEAP = isEAP,
|
||||
compilerBuildVersion = compilerBuildVersion,
|
||||
languageVersionString = languageVersionString,
|
||||
apiVersionString = apiVersionString,
|
||||
multiplatformEnable = multiplatformEnable,
|
||||
metadataVersionMajor = metadataVersion.major,
|
||||
metadataVersionMinor = metadataVersion.minor,
|
||||
metadataVersionPatch = metadataVersion.patch,
|
||||
ownVersion = ownVersion,
|
||||
coroutinesVersion = coroutinesVersion,
|
||||
multiplatformVersion = multiplatformVersion,
|
||||
pluginClasspaths = pluginClasspaths
|
||||
)
|
||||
class CommonBuildMetaInfo : BuildMetaInfo() {
|
||||
override fun checkIfPlatformSpecificCompilerArgumentWasChanged(key: String, currentValue: String, previousValue: String): Boolean? {
|
||||
when (key) {
|
||||
CustomKeys.METADATA_VERSION_STRING.name -> {
|
||||
val currentVersionIntArray = BinaryVersion.parseVersionArray(currentValue)
|
||||
if (currentVersionIntArray?.size != 3) return null
|
||||
val currentVersion = JvmMetadataVersion(currentVersionIntArray[0], currentVersionIntArray[1], currentVersionIntArray[2])
|
||||
|
||||
val previousVersionIntArray = BinaryVersion.parseVersionArray(previousValue)
|
||||
if (previousVersionIntArray?.size != 3) return null
|
||||
val previousVersion = JvmMetadataVersion(previousVersionIntArray[0], previousVersionIntArray[1], previousVersionIntArray[2])
|
||||
return currentVersion == previousVersion
|
||||
}
|
||||
}
|
||||
return null
|
||||
}
|
||||
}
|
||||
|
||||
override fun createPropertiesMapFromCompilerArguments(args: CommonCompilerArguments): Map<String, String> {
|
||||
val resultMap = mutableMapOf<String, String>()
|
||||
val metadataVersionArray = args.metadataVersion?.let { BinaryVersion.parseVersionArray(it) }
|
||||
val metadataVersion = metadataVersionArray?.let(::JvmMetadataVersion) ?: JvmMetadataVersion.INSTANCE
|
||||
val metadataVersionString = metadataVersion.toString()
|
||||
resultMap[CustomKeys.METADATA_VERSION_STRING.name] = metadataVersionString
|
||||
|
||||
return super.createPropertiesMapFromCompilerArguments(args) + resultMap
|
||||
}
|
||||
}
|
||||
@@ -5,53 +5,37 @@
|
||||
|
||||
package org.jetbrains.kotlin.build
|
||||
|
||||
import org.jetbrains.kotlin.cli.common.arguments.CommonCompilerArguments
|
||||
import org.jetbrains.kotlin.metadata.deserialization.BinaryVersion
|
||||
import org.jetbrains.kotlin.utils.JsMetadataVersion
|
||||
|
||||
/**
|
||||
* If you want to add a new field, check its type is supported by [serializeToPlainText], [deserializeFromPlainText]
|
||||
*/
|
||||
data class JsBuildMetaInfo(
|
||||
override val isEAP: Boolean,
|
||||
override val compilerBuildVersion: String,
|
||||
override val languageVersionString: String,
|
||||
override val apiVersionString: String,
|
||||
override val multiplatformEnable: Boolean,
|
||||
override val metadataVersionMajor: Int,
|
||||
override val metadataVersionMinor: Int,
|
||||
override val metadataVersionPatch: Int,
|
||||
override val ownVersion: Int,
|
||||
override val coroutinesVersion: Int,
|
||||
override val multiplatformVersion: Int,
|
||||
override val pluginClasspaths: String
|
||||
) : BuildMetaInfo {
|
||||
companion object : BuildMetaInfoFactory<JsBuildMetaInfo>(JsBuildMetaInfo::class) {
|
||||
override fun create(
|
||||
isEAP: Boolean,
|
||||
compilerBuildVersion: String,
|
||||
languageVersionString: String,
|
||||
apiVersionString: String,
|
||||
multiplatformEnable: Boolean,
|
||||
ownVersion: Int,
|
||||
coroutinesVersion: Int,
|
||||
multiplatformVersion: Int,
|
||||
metadataVersionArray: IntArray?,
|
||||
pluginClasspaths: String
|
||||
): JsBuildMetaInfo {
|
||||
val metadataVersion = metadataVersionArray?.let(::JsMetadataVersion) ?: JsMetadataVersion.INSTANCE
|
||||
return JsBuildMetaInfo(
|
||||
isEAP = isEAP,
|
||||
compilerBuildVersion = compilerBuildVersion,
|
||||
languageVersionString = languageVersionString,
|
||||
apiVersionString = apiVersionString,
|
||||
multiplatformEnable = multiplatformEnable,
|
||||
metadataVersionMajor = metadataVersion.major,
|
||||
metadataVersionMinor = metadataVersion.minor,
|
||||
metadataVersionPatch = metadataVersion.patch,
|
||||
ownVersion = ownVersion,
|
||||
coroutinesVersion = coroutinesVersion,
|
||||
multiplatformVersion = multiplatformVersion,
|
||||
pluginClasspaths = pluginClasspaths
|
||||
)
|
||||
class JsBuildMetaInfo : BuildMetaInfo() {
|
||||
override fun checkIfPlatformSpecificCompilerArgumentWasChanged(key: String, currentValue: String, previousValue: String): Boolean? {
|
||||
when (key) {
|
||||
CustomKeys.METADATA_VERSION_STRING.name -> {
|
||||
val currentValueIntArray = BinaryVersion.parseVersionArray(currentValue)
|
||||
if (currentValueIntArray?.size != 3) return null
|
||||
val currentVersion = JsMetadataVersion(currentValueIntArray[0], currentValueIntArray[1], currentValueIntArray[2])
|
||||
|
||||
val previousValueIntArray = BinaryVersion.parseVersionArray(previousValue)
|
||||
if (previousValueIntArray?.size != 3) return null
|
||||
val previousVersion = JsMetadataVersion(previousValueIntArray[0], previousValueIntArray[1], previousValueIntArray[2])
|
||||
return currentVersion == previousVersion
|
||||
}
|
||||
}
|
||||
return null
|
||||
}
|
||||
}
|
||||
|
||||
override fun createPropertiesMapFromCompilerArguments(args: CommonCompilerArguments): Map<String, String> {
|
||||
val resultMap = mutableMapOf<String, String>()
|
||||
val metadataVersionArray = args.metadataVersion?.let { BinaryVersion.parseVersionArray(it) }
|
||||
val metadataVersion = metadataVersionArray?.let(::JsMetadataVersion) ?: JsMetadataVersion.INSTANCE
|
||||
val metadataVersionString = metadataVersion.toInteger().toString()
|
||||
resultMap[CustomKeys.METADATA_VERSION_STRING.name] = metadataVersionString
|
||||
|
||||
return super.createPropertiesMapFromCompilerArguments(args) + resultMap
|
||||
}
|
||||
|
||||
override val argumentsListForSpecialCheck: List<String>
|
||||
get() = super.argumentsListForSpecialCheck + listOf("sourceMap", "metaInfo" + "partialLinkage" + "wasmDebug")
|
||||
}
|
||||
@@ -16,60 +16,62 @@
|
||||
|
||||
package org.jetbrains.kotlin.build
|
||||
|
||||
import org.jetbrains.kotlin.load.kotlin.JvmBytecodeBinaryVersion
|
||||
import org.jetbrains.kotlin.cli.common.arguments.CommonCompilerArguments
|
||||
import org.jetbrains.kotlin.metadata.deserialization.BinaryVersion
|
||||
import org.jetbrains.kotlin.metadata.jvm.deserialization.JvmMetadataVersion
|
||||
|
||||
/**
|
||||
* If you want to add a new field, check its type is supported by [serializeToPlainText], [deserializeFromPlainText]
|
||||
*/
|
||||
data class JvmBuildMetaInfo(
|
||||
override val isEAP: Boolean,
|
||||
override val compilerBuildVersion: String,
|
||||
override val languageVersionString: String,
|
||||
override val apiVersionString: String,
|
||||
override val multiplatformEnable: Boolean,
|
||||
override val metadataVersionMajor: Int,
|
||||
override val metadataVersionMinor: Int,
|
||||
override val metadataVersionPatch: Int,
|
||||
val bytecodeVersionMajor: Int,
|
||||
val bytecodeVersionMinor: Int,
|
||||
val bytecodeVersionPatch: Int,
|
||||
override val ownVersion: Int,
|
||||
override val coroutinesVersion: Int,
|
||||
override val multiplatformVersion: Int,
|
||||
override val pluginClasspaths: String
|
||||
) : BuildMetaInfo {
|
||||
companion object : BuildMetaInfoFactory<JvmBuildMetaInfo>(JvmBuildMetaInfo::class) {
|
||||
override fun create(
|
||||
isEAP: Boolean,
|
||||
compilerBuildVersion: String,
|
||||
languageVersionString: String,
|
||||
apiVersionString: String,
|
||||
multiplatformEnable: Boolean,
|
||||
ownVersion: Int,
|
||||
coroutinesVersion: Int,
|
||||
multiplatformVersion: Int,
|
||||
metadataVersionArray: IntArray?,
|
||||
pluginClasspaths: String
|
||||
): JvmBuildMetaInfo {
|
||||
val metadataVersion = metadataVersionArray?.let(::JvmMetadataVersion) ?: JvmMetadataVersion.INSTANCE
|
||||
return JvmBuildMetaInfo(
|
||||
isEAP = isEAP,
|
||||
compilerBuildVersion = compilerBuildVersion,
|
||||
languageVersionString = languageVersionString,
|
||||
apiVersionString = apiVersionString,
|
||||
multiplatformEnable = multiplatformEnable,
|
||||
metadataVersionMajor = metadataVersion.major,
|
||||
metadataVersionMinor = metadataVersion.minor,
|
||||
metadataVersionPatch = metadataVersion.patch,
|
||||
bytecodeVersionMajor = JvmBytecodeBinaryVersion.INSTANCE.major,
|
||||
bytecodeVersionMinor = JvmBytecodeBinaryVersion.INSTANCE.minor,
|
||||
bytecodeVersionPatch = JvmBytecodeBinaryVersion.INSTANCE.patch,
|
||||
ownVersion = ownVersion,
|
||||
coroutinesVersion = coroutinesVersion,
|
||||
multiplatformVersion = multiplatformVersion,
|
||||
pluginClasspaths = pluginClasspaths
|
||||
)
|
||||
class JvmBuildMetaInfo : BuildMetaInfo() {
|
||||
override fun checkIfPlatformSpecificCompilerArgumentWasChanged(key: String, currentValue: String, previousValue: String): Boolean? {
|
||||
when (key) {
|
||||
CustomKeys.METADATA_VERSION_STRING.name -> {
|
||||
val currentVersionIntArray = BinaryVersion.parseVersionArray(currentValue)
|
||||
if (currentVersionIntArray?.size != 3) return null
|
||||
val currentVersion = JvmMetadataVersion(currentVersionIntArray[0], currentVersionIntArray[1], currentVersionIntArray[2])
|
||||
|
||||
val previousVersionIntArray = BinaryVersion.parseVersionArray(previousValue)
|
||||
if (previousVersionIntArray?.size != 3) return null
|
||||
val previousVersion = JvmMetadataVersion(previousVersionIntArray[0], previousVersionIntArray[1], previousVersionIntArray[2])
|
||||
return currentVersion != previousVersion
|
||||
}
|
||||
}
|
||||
return null
|
||||
}
|
||||
|
||||
override fun createPropertiesMapFromCompilerArguments(args: CommonCompilerArguments): Map<String, String> {
|
||||
val resultMap = mutableMapOf<String, String>()
|
||||
val metadataVersionArray = args.metadataVersion?.let { BinaryVersion.parseVersionArray(it) }
|
||||
val metadataVersion = metadataVersionArray?.let(::JvmMetadataVersion) ?: JvmMetadataVersion.INSTANCE
|
||||
val metadataVersionString = metadataVersion.toString()
|
||||
resultMap[CustomKeys.METADATA_VERSION_STRING.name] = metadataVersionString
|
||||
|
||||
return super.createPropertiesMapFromCompilerArguments(args) + resultMap
|
||||
}
|
||||
|
||||
override val excludedProperties: List<String>
|
||||
get() = super.excludedProperties + listOf(
|
||||
"excludedProperties",
|
||||
"backendThreads",
|
||||
"buildFile",
|
||||
"classpath",
|
||||
"declarationsOutputPath",
|
||||
"defaultScriptExtension",
|
||||
"enableDebugMode",
|
||||
"expression",
|
||||
"internalArguments",
|
||||
"profileCompilerCommand",
|
||||
"repeatCompileModules",
|
||||
"scriptResolverEnvironment",
|
||||
"scriptTemplates",
|
||||
"suppressDeprecatedJvmTargetWarning",
|
||||
"useFastJarFileSystem",
|
||||
)
|
||||
|
||||
override val argumentsListForSpecialCheck: List<String>
|
||||
get() = super.argumentsListForSpecialCheck + listOf(
|
||||
"allowNoSourceFiles",
|
||||
"allowUnstableDependencies",
|
||||
"enableJvmPreview",
|
||||
"ignoreConstOptimizationErrors",
|
||||
"suppressMissingBuiltinsError",
|
||||
)
|
||||
}
|
||||
|
||||
@@ -16,6 +16,8 @@
|
||||
|
||||
package org.jetbrains.kotlin.build
|
||||
|
||||
import org.jetbrains.kotlin.cli.common.arguments.CommonCompilerArguments
|
||||
import org.jetbrains.kotlin.cli.common.arguments.collectProperties
|
||||
import kotlin.reflect.KClass
|
||||
import kotlin.reflect.full.memberProperties
|
||||
import kotlin.reflect.full.primaryConstructor
|
||||
@@ -38,12 +40,12 @@ inline fun <reified T : Any> deserializeFromPlainText(str: String): T? = deseria
|
||||
fun <T : Any> deserializeFromPlainText(str: String, klass: KClass<T>): T? {
|
||||
val args = ArrayList<Any?>()
|
||||
val properties = str
|
||||
.split("\n")
|
||||
.filter(String::isNotBlank)
|
||||
.associate { it.substringBefore("=") to it.substringAfter("=") }
|
||||
.split("\n")
|
||||
.filter(String::isNotBlank)
|
||||
.associate { it.substringBefore("=") to it.substringAfter("=") }
|
||||
|
||||
val primaryConstructor = klass.primaryConstructor
|
||||
?: throw IllegalStateException("${klass.java} does not have primary constructor")
|
||||
?: throw IllegalStateException("${klass.java} does not have primary constructor")
|
||||
for (param in primaryConstructor.parameters.sortedBy { it.index }) {
|
||||
val argumentString = properties[param.name]
|
||||
|
||||
@@ -51,8 +53,7 @@ fun <T : Any> deserializeFromPlainText(str: String, klass: KClass<T>): T? {
|
||||
if (param.type.isMarkedNullable) {
|
||||
args.add(null)
|
||||
continue
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
return null
|
||||
}
|
||||
}
|
||||
@@ -69,3 +70,18 @@ fun <T : Any> deserializeFromPlainText(str: String, klass: KClass<T>): T? {
|
||||
|
||||
return primaryConstructor.call(*args.toTypedArray())
|
||||
}
|
||||
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
fun <T : Any> transformClassToPropertiesMap(classToTransform: T, excludedProperties: List<String> = emptyList()) =
|
||||
collectProperties(classToTransform::class as KClass<T>, false)
|
||||
.filter { property -> property.name !in excludedProperties }
|
||||
.associateBy(
|
||||
keySelector = { property -> property.name },
|
||||
valueTransform = { property -> property.get(classToTransform).toString() })
|
||||
|
||||
fun List<String>.joinToReadableString(): String = when {
|
||||
size > 5 -> take(5).joinToString() + " and ${size - 5} more"
|
||||
size > 1 -> dropLast(1).joinToString() + " and ${last()}"
|
||||
size == 1 -> single()
|
||||
else -> ""
|
||||
}
|
||||
Reference in New Issue
Block a user