From 2b893365aae84cf096b7fcbb310e86673b5a78a8 Mon Sep 17 00:00:00 2001 From: Sebastian Sellmair Date: Thu, 30 Mar 2023 18:51:04 +0200 Subject: [PATCH] [Gradle] Replace FakeK2NativeCompilerArguments with K2NativeCompilerArguments KTIJ-24976 --- .../kotlin/config/facetSerialization.kt | 3 +-- .../platform/impl/NativeIdePlatformKind.kt | 17 +++++++++++------ .../jps/build/dependeciestxt/ModulesTxt.kt | 4 ++-- .../ide/IdeCompilerArgumentsResolverImpl.kt | 4 ++-- 4 files changed, 16 insertions(+), 12 deletions(-) diff --git a/jps/jps-common/src/org/jetbrains/kotlin/config/facetSerialization.kt b/jps/jps-common/src/org/jetbrains/kotlin/config/facetSerialization.kt index c013b289b5d..434a11680e3 100644 --- a/jps/jps-common/src/org/jetbrains/kotlin/config/facetSerialization.kt +++ b/jps/jps-common/src/org/jetbrains/kotlin/config/facetSerialization.kt @@ -18,7 +18,6 @@ import org.jetbrains.kotlin.arguments.CompilerArgumentsSerializerV5 import org.jetbrains.kotlin.cli.common.arguments.* import org.jetbrains.kotlin.load.java.JvmAbi import org.jetbrains.kotlin.platform.* -import org.jetbrains.kotlin.platform.impl.FakeK2NativeCompilerArguments import org.jetbrains.kotlin.platform.impl.JvmIdePlatformKind import org.jetbrains.kotlin.platform.jvm.JdkPlatform import org.jetbrains.kotlin.platform.jvm.JvmPlatforms @@ -43,7 +42,7 @@ fun TargetPlatform.createArguments(init: (CommonCompilerArguments).() -> Unit = jvmTarget = (single() as? JdkPlatform)?.targetVersion?.description ?: JvmTarget.DEFAULT.description } isJs() -> K2JSCompilerArguments().apply { init() } - isNative() -> FakeK2NativeCompilerArguments().apply { init() } + isNative() -> K2NativeCompilerArguments().apply { init() } else -> error("Unknown platform $this") } } diff --git a/jps/jps-common/src/org/jetbrains/kotlin/platform/impl/NativeIdePlatformKind.kt b/jps/jps-common/src/org/jetbrains/kotlin/platform/impl/NativeIdePlatformKind.kt index f5b721007ef..12d0e360929 100644 --- a/jps/jps-common/src/org/jetbrains/kotlin/platform/impl/NativeIdePlatformKind.kt +++ b/jps/jps-common/src/org/jetbrains/kotlin/platform/impl/NativeIdePlatformKind.kt @@ -11,6 +11,7 @@ package org.jetbrains.kotlin.platform.impl import org.jetbrains.kotlin.cli.common.arguments.CommonCompilerArguments import org.jetbrains.kotlin.cli.common.arguments.Freezable import org.jetbrains.kotlin.cli.common.arguments.copyCommonCompilerArguments +import org.jetbrains.kotlin.cli.common.arguments.K2NativeCompilerArguments import org.jetbrains.kotlin.platform.IdePlatform import org.jetbrains.kotlin.platform.IdePlatformKind import org.jetbrains.kotlin.platform.TargetPlatform @@ -22,14 +23,14 @@ object NativeIdePlatformKind : IdePlatformKind() { override fun supportsTargetPlatform(platform: TargetPlatform): Boolean = platform.isNative() override fun platformByCompilerArguments(arguments: CommonCompilerArguments): TargetPlatform? { - return if (arguments is FakeK2NativeCompilerArguments) + return if (arguments is K2NativeCompilerArguments) NativePlatforms.unspecifiedNativePlatform else null } - override fun createArguments(): CommonCompilerArguments { - return FakeK2NativeCompilerArguments() + override fun createArguments(): K2NativeCompilerArguments { + return K2NativeCompilerArguments() } override val defaultPlatform: TargetPlatform @@ -42,7 +43,7 @@ object NativeIdePlatformKind : IdePlatformKind() { override fun getDefaultPlatform(): IdePlatform<*, *> = Platform override val argumentsClass - get() = FakeK2NativeCompilerArguments::class.java + get() = K2NativeCompilerArguments::class.java override val name get() = "Native" @@ -51,14 +52,18 @@ object NativeIdePlatformKind : IdePlatformKind() { message = "IdePlatform is deprecated and will be removed soon, please, migrate to org.jetbrains.kotlin.platform.TargetPlatform", level = DeprecationLevel.ERROR ) - object Platform : IdePlatform() { + object Platform : IdePlatform() { override val kind get() = NativeIdePlatformKind override val version get() = TargetPlatformVersion.NoVersion - override fun createArguments(init: FakeK2NativeCompilerArguments.() -> Unit) = FakeK2NativeCompilerArguments().apply(init) + override fun createArguments(init: K2NativeCompilerArguments.() -> Unit) = K2NativeCompilerArguments().apply(init) } } // These are fake compiler arguments for Kotlin/Native - only for usage within IDEA plugin: +@Deprecated( + message = "Use K2NativeCompilerArguments instead", + level = DeprecationLevel.ERROR +) class FakeK2NativeCompilerArguments : CommonCompilerArguments() { override fun copyOf(): Freezable = copyCommonCompilerArguments(this, FakeK2NativeCompilerArguments()) } diff --git a/jps/jps-plugin/jps-tests/test/org/jetbrains/kotlin/jps/build/dependeciestxt/ModulesTxt.kt b/jps/jps-plugin/jps-tests/test/org/jetbrains/kotlin/jps/build/dependeciestxt/ModulesTxt.kt index cd8b403f54b..fd563d05cb7 100644 --- a/jps/jps-plugin/jps-tests/test/org/jetbrains/kotlin/jps/build/dependeciestxt/ModulesTxt.kt +++ b/jps/jps-plugin/jps-tests/test/org/jetbrains/kotlin/jps/build/dependeciestxt/ModulesTxt.kt @@ -10,13 +10,13 @@ import org.jetbrains.jps.model.module.JpsModule import org.jetbrains.kotlin.cli.common.arguments.K2JSCompilerArguments import org.jetbrains.kotlin.cli.common.arguments.K2JVMCompilerArguments import org.jetbrains.kotlin.cli.common.arguments.K2MetadataCompilerArguments +import org.jetbrains.kotlin.cli.common.arguments.K2NativeCompilerArguments import org.jetbrains.kotlin.config.CompilerSettings import org.jetbrains.kotlin.config.KotlinFacetSettings import org.jetbrains.kotlin.config.KotlinModuleKind.COMPILATION_AND_SOURCE_SET_HOLDER import org.jetbrains.kotlin.config.KotlinModuleKind.SOURCE_SET_HOLDER import org.jetbrains.kotlin.jps.build.dependeciestxt.ModulesTxt.Dependency.Kind.* import org.jetbrains.kotlin.platform.CommonPlatforms -import org.jetbrains.kotlin.platform.impl.FakeK2NativeCompilerArguments import org.jetbrains.kotlin.platform.isCommon import org.jetbrains.kotlin.platform.js.JsPlatforms import org.jetbrains.kotlin.platform.jvm.JvmPlatforms @@ -267,7 +267,7 @@ class ModulesTxtBuilder { it.forceDeprecatedLegacyCompilerUsage = true } "native" -> settings.compilerArguments = - FakeK2NativeCompilerArguments().also { settings.targetPlatform = NativePlatforms.unspecifiedNativePlatform } + K2NativeCompilerArguments().also { settings.targetPlatform = NativePlatforms.unspecifiedNativePlatform } else -> { val flagProperty = ModulesTxt.Module.flags[flag] if (flagProperty != null) flagProperty.set(module, true) diff --git a/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/plugin/ide/IdeCompilerArgumentsResolverImpl.kt b/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/plugin/ide/IdeCompilerArgumentsResolverImpl.kt index 524fdea2164..42375da260d 100644 --- a/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/plugin/ide/IdeCompilerArgumentsResolverImpl.kt +++ b/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/plugin/ide/IdeCompilerArgumentsResolverImpl.kt @@ -5,7 +5,7 @@ package org.jetbrains.kotlin.gradle.plugin.ide -import org.jetbrains.kotlin.compilerRunner.toArgumentStrings +import org.jetbrains.kotlin.compilerRunner.ArgumentUtils import org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformExtension import org.jetbrains.kotlin.gradle.dsl.KotlinProjectExtension import org.jetbrains.kotlin.gradle.plugin.CreateCompilerArgumentsContext @@ -43,6 +43,6 @@ internal class IdeCompilerArgumentsResolverImpl( ), ) ) - return compilerArguments.toArgumentStrings(useShortNames = true) + return ArgumentUtils.convertArgumentsToStringList(compilerArguments) } } \ No newline at end of file