From d6e3b63069e8d653812b45ab19fa2fe6314467b3 Mon Sep 17 00:00:00 2001 From: Sebastian Sellmair Date: Tue, 21 Mar 2023 14:22:15 +0100 Subject: [PATCH] [Gradle] Implement CompilerArgumentAware (for compatibility) using the new KotlinCompilerArgumentsProducer KTIJ-24976 --- .../gradle/internal/CompilerArgumentAware.kt | 59 ++++++++++++++----- .../model/builder/KotlinModelBuilder.kt | 6 +- .../plugin/KotlinCompilerArgumentsProducer.kt | 11 ++-- .../targets/native/tasks/KotlinNativeTasks.kt | 37 +----------- .../gradle/tasks/AbstractKotlinCompile.kt | 13 +--- .../gradle/tasks/AbstractKotlinCompileTool.kt | 2 + .../kotlin/gradle/tasks/Kotlin2JsCompile.kt | 39 ------------ .../kotlin/gradle/tasks/KotlinCompile.kt | 32 +--------- .../gradle/tasks/KotlinCompileCommon.kt | 38 ------------ .../unitTests/K2MultiplatformStructureTest.kt | 16 +---- .../Kotlin2JsCompileArgumentsTest.kt | 26 ++------ .../KotlinCompileArgumentsTest.kt | 6 +- .../KotlinCompileCommonArgumentsTest.kt | 6 +- 13 files changed, 73 insertions(+), 218 deletions(-) diff --git a/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/internal/CompilerArgumentAware.kt b/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/internal/CompilerArgumentAware.kt index d25c2c7edee..fd712efab18 100644 --- a/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/internal/CompilerArgumentAware.kt +++ b/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/internal/CompilerArgumentAware.kt @@ -20,38 +20,69 @@ package org.jetbrains.kotlin.gradle.internal import org.gradle.api.tasks.Internal import org.jetbrains.kotlin.cli.common.arguments.CommonToolArguments +import org.jetbrains.kotlin.cli.common.arguments.copyBeanTo import org.jetbrains.kotlin.compilerRunner.ArgumentUtils +import org.jetbrains.kotlin.compilerRunner.ArgumentUtils.convertArgumentsToStringList +import org.jetbrains.kotlin.gradle.plugin.CreateCompilerArgumentsContext +import org.jetbrains.kotlin.gradle.plugin.KotlinCompilerArgumentsProducer +import org.jetbrains.kotlin.gradle.plugin.KotlinCompilerArgumentsProducer.ArgumentType + +/** + * Only relevant for supporting older IDEs (before 2023.2) + */ @Deprecated("Replaced by KotlinCompilerArgumentsProducer") -interface CompilerArgumentAware { +interface CompilerArgumentAware : KotlinCompilerArgumentsProducer { + @Deprecated("Replaced by KotlinCompilerArgumentsProducer", level = DeprecationLevel.ERROR) @Suppress("DEPRECATION") @get:Internal val serializedCompilerArguments: List - get() = ArgumentUtils.convertArgumentsToStringList(prepareCompilerArguments()) + get() = convertArgumentsToStringList(prepareCompilerArguments()) @Deprecated("Replaced by KotlinCompilerArgumentsProducer", level = DeprecationLevel.ERROR) @Suppress("DEPRECATION") @get:Internal val serializedCompilerArgumentsIgnoreClasspathIssues: List - get() = ArgumentUtils.convertArgumentsToStringList(prepareCompilerArguments(ignoreClasspathResolutionErrors = true)) + get() = convertArgumentsToStringList(prepareCompilerArguments(ignoreClasspathResolutionErrors = true)) @Deprecated("Replaced by KotlinCompilerArgumentsProducer", level = DeprecationLevel.ERROR) @Suppress("DEPRECATION") @get:Internal val defaultSerializedCompilerArguments: List - get() = createCompilerArgs() - .also { setupCompilerArgs(it, defaultsOnly = true) } - .let(ArgumentUtils::convertArgumentsToStringList) + get() = createCompilerArguments( + CreateCompilerArgumentsContext(includeArgumentTypes = setOf(ArgumentType.Primitive)) + ).let(ArgumentUtils::convertArgumentsToStringList) - @Deprecated("Replaced by KotlinCompilerArgumentsProducer", level = DeprecationLevel.WARNING) - fun createCompilerArgs(): T + @Deprecated("Replaced by KotlinCompilerArgumentsProducer", level = DeprecationLevel.ERROR) + fun createCompilerArgs(): T = createCompilerArguments(CreateCompilerArgumentsContext(includeArgumentTypes = emptySet())) - @Deprecated("Replaced by KotlinCompilerArgumentsProducer", level = DeprecationLevel.WARNING) - fun setupCompilerArgs(args: T, defaultsOnly: Boolean = false, ignoreClasspathResolutionErrors: Boolean = false) + @Deprecated("Replaced by KotlinCompilerArgumentsProducer", level = DeprecationLevel.ERROR) + fun setupCompilerArgs(args: T, defaultsOnly: Boolean = false, ignoreClasspathResolutionErrors: Boolean = false) { + val newArgs = createCompilerArguments( + CreateCompilerArgumentsContext( + includeArgumentTypes = if (defaultsOnly) setOf(ArgumentType.Primitive) else includedArgumentTypes, + isLenient = ignoreClasspathResolutionErrors + ) + ) + copyBeanTo(from = newArgs, to = args) + } + + override fun createCompilerArguments(context: KotlinCompilerArgumentsProducer.CreateCompilerArgumentsContext): T + + @Suppress("DEPRECATION") + private fun CompilerArgumentAware.prepareCompilerArguments( + ignoreClasspathResolutionErrors: Boolean = false + ): T = createCompilerArguments( + CreateCompilerArgumentsContext( + includeArgumentTypes = includedArgumentTypes, + isLenient = ignoreClasspathResolutionErrors + ) + ) } -@Deprecated("Replaced by KotlinCompilerArgumentsProducer", level = DeprecationLevel.WARNING) -@Suppress("DEPRECATION") -internal fun CompilerArgumentAware.prepareCompilerArguments(ignoreClasspathResolutionErrors: Boolean = false) = - createCompilerArgs().also { setupCompilerArgs(it, ignoreClasspathResolutionErrors = ignoreClasspathResolutionErrors) } +private val includedArgumentTypes = setOf( + ArgumentType.Primitive, + ArgumentType.PluginClasspath, + ArgumentType.DependencyClasspath, +) \ No newline at end of file diff --git a/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/model/builder/KotlinModelBuilder.kt b/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/model/builder/KotlinModelBuilder.kt index eacdea3f71d..1ca65e9d5a8 100644 --- a/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/model/builder/KotlinModelBuilder.kt +++ b/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/model/builder/KotlinModelBuilder.kt @@ -92,7 +92,7 @@ class KotlinModelBuilder(private val kotlinPluginVersion: String, private val an javaSourceSet.resources.srcDirs, destinationDirectory.get().asFile, javaSourceSet.output.resourcesDir!!, - createCompilerArguments() + buildCompilerArguments() ) } else null } @@ -118,12 +118,12 @@ class KotlinModelBuilder(private val kotlinPluginVersion: String, private val an resources, destinationDirectory.get().asFile, compilation.output.resourcesDir, - createCompilerArguments() + buildCompilerArguments() ) } @Suppress("DEPRECATION_ERROR") - private fun AbstractKotlinCompile<*>.createCompilerArguments(): CompilerArguments { + private fun AbstractKotlinCompile<*>.buildCompilerArguments(): CompilerArguments { return CompilerArgumentsImpl( serializedCompilerArguments, defaultSerializedCompilerArguments, diff --git a/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/plugin/KotlinCompilerArgumentsProducer.kt b/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/plugin/KotlinCompilerArgumentsProducer.kt index e490f9a9e70..322b88d60cb 100644 --- a/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/plugin/KotlinCompilerArgumentsProducer.kt +++ b/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/plugin/KotlinCompilerArgumentsProducer.kt @@ -6,6 +6,7 @@ package org.jetbrains.kotlin.gradle.plugin import org.jetbrains.kotlin.cli.common.arguments.CommonCompilerArguments +import org.jetbrains.kotlin.cli.common.arguments.CommonToolArguments import org.jetbrains.kotlin.gradle.InternalKotlinGradlePluginApi import org.jetbrains.kotlin.gradle.plugin.KotlinCompilerArgumentsProducer.ContributeCompilerArgumentsContext import kotlin.reflect.KClass @@ -26,7 +27,7 @@ interface KotlinCompilerArgumentsProducer { } interface CreateCompilerArgumentsContext { - fun create(type: KClass, action: ContributeCompilerArgumentsContext.() -> Unit): T + fun create(type: KClass, action: ContributeCompilerArgumentsContext.() -> Unit): T companion object { val default: CreateCompilerArgumentsContext = CreateCompilerArgumentsContext() @@ -38,14 +39,14 @@ interface KotlinCompilerArgumentsProducer { } } - interface ContributeCompilerArgumentsContext { + interface ContributeCompilerArgumentsContext { fun tryLenient(action: () -> T): T? fun contribute(type: ArgumentType, contribution: (T) -> Unit) } fun createCompilerArguments( context: CreateCompilerArgumentsContext = CreateCompilerArgumentsContext() - ): CommonCompilerArguments + ): CommonToolArguments } internal fun CreateCompilerArgumentsContext( @@ -60,7 +61,7 @@ private class CreateCompilerArgumentsContextImpl( private val isLenient: Boolean ) : KotlinCompilerArgumentsProducer.CreateCompilerArgumentsContext { - override fun create( + override fun create( type: KClass, action: ContributeCompilerArgumentsContext.() -> Unit ): T { val constructor = type.java.constructors.firstOrNull { it.parameters.isEmpty() } @@ -70,7 +71,7 @@ private class CreateCompilerArgumentsContextImpl( return arguments } - private inner class ContributeCompilerArgumentsContextImpl( + private inner class ContributeCompilerArgumentsContextImpl( private val arguments: T ) : ContributeCompilerArgumentsContext { diff --git a/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/targets/native/tasks/KotlinNativeTasks.kt b/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/targets/native/tasks/KotlinNativeTasks.kt index 4d4287e7644..a845245b71a 100644 --- a/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/targets/native/tasks/KotlinNativeTasks.kt +++ b/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/targets/native/tasks/KotlinNativeTasks.kt @@ -270,23 +270,10 @@ abstract class AbstractKotlinNativeCompile< @get:Nested var kotlinPluginData: Provider? = null - // Used by IDE via reflection. - @get:Internal - override val serializedCompilerArguments: List - get() = buildCommonArgs() - - // Used by IDE via reflection. - @get:Internal - override val defaultSerializedCompilerArguments: List - get() = buildCommonArgs(true) - private val languageSettingsBuilder by project.provider { compilation.languageSettings } - // Args used by both the compiler and IDEA. - abstract fun buildCommonArgs(defaultsOnly: Boolean = false): List - @get:Input @get:Optional internal val konanTargetsForManifest: String by project.provider { @@ -321,9 +308,8 @@ internal constructor( private val objectFactory: ObjectFactory, private val providerFactory: ProviderFactory, private val execOperations: ExecOperations -) : AbstractKotlinNativeCompile(objectFactory), +) : AbstractKotlinNativeCompile(objectFactory), KotlinCompile, - KotlinCompilerArgumentsProducer, K2MultiplatformCompilationTask, KotlinCompilationTask { @@ -434,27 +420,6 @@ internal constructor( private val isAllowCommonizer: Boolean by lazy { project.isAllowCommonizer() } // endregion. - override fun createCompilerArgs(): StubK2NativeCompilerArguments = StubK2NativeCompilerArguments() - - override fun setupCompilerArgs( - args: StubK2NativeCompilerArguments, - defaultsOnly: Boolean, - ignoreClasspathResolutionErrors: Boolean - ) = Unit - - override fun buildCommonArgs(defaultsOnly: Boolean): List { - val plugins = listOfNotNull( - compilerPluginClasspath?.let { CompilerPluginData(it, compilerPluginOptions) }, - kotlinPluginData?.orNull?.let { CompilerPluginData(it.classpath, it.options) } - ) - - return buildKotlinNativeCompileCommonArgs( - languageSettings, - compilerOptions, - plugins - ) - } - override fun createCompilerArguments(context: CreateCompilerArgumentsContext) = context.create { val sharedCompilationData = createSharedCompilationDataOrNull() diff --git a/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/tasks/AbstractKotlinCompile.kt b/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/tasks/AbstractKotlinCompile.kt index ee471cc4c51..5fc56da7463 100644 --- a/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/tasks/AbstractKotlinCompile.kt +++ b/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/tasks/AbstractKotlinCompile.kt @@ -34,24 +34,16 @@ import org.jetbrains.kotlin.gradle.dsl.KotlinCommonCompilerOptions import org.jetbrains.kotlin.gradle.incremental.UsesIncrementalModuleInfoBuildService import org.jetbrains.kotlin.gradle.internal.AbstractKotlinCompileArgumentsContributor import org.jetbrains.kotlin.gradle.internal.compilerArgumentsConfigurationFlags -import org.jetbrains.kotlin.gradle.internal.prepareCompilerArguments import org.jetbrains.kotlin.gradle.internal.tasks.allOutputFiles import org.jetbrains.kotlin.gradle.logging.GradleKotlinLogger import org.jetbrains.kotlin.gradle.logging.kotlinDebug -import org.jetbrains.kotlin.gradle.plugin.KotlinCompilerArgumentsProducer import org.jetbrains.kotlin.gradle.plugin.KotlinCompilerArgumentsProducer.CreateCompilerArgumentsContext.Companion.default import org.jetbrains.kotlin.gradle.plugin.PropertiesProvider.PropertyNames.KOTLIN_SUPPRESS_EXPERIMENTAL_IC_OPTIMIZATIONS_WARNING import org.jetbrains.kotlin.gradle.plugin.UsesBuildFinishedListenerService import org.jetbrains.kotlin.gradle.plugin.UsesVariantImplementationFactories import org.jetbrains.kotlin.gradle.plugin.statistics.KotlinBuildStatsService import org.jetbrains.kotlin.gradle.report.* -import org.jetbrains.kotlin.gradle.report.UsesBuildMetricsService -import org.jetbrains.kotlin.gradle.report.UsesBuildReportsService import org.jetbrains.kotlin.gradle.utils.* -import org.jetbrains.kotlin.gradle.utils.newInstance -import org.jetbrains.kotlin.gradle.utils.property -import org.jetbrains.kotlin.gradle.utils.propertyWithConvention -import org.jetbrains.kotlin.gradle.utils.propertyWithNewInstance import org.jetbrains.kotlin.incremental.ChangedFiles import org.jetbrains.kotlin.incremental.IncrementalCompilerRunner import org.jetbrains.kotlin.statistics.metrics.BooleanMetrics @@ -320,10 +312,7 @@ abstract class AbstractKotlinCompile @Inject constr return } - - val args = @Suppress("unchecked_cast", "deprecation") - if (this is KotlinCompilerArgumentsProducer) createCompilerArguments(default) as T - else prepareCompilerArguments() + val args = createCompilerArguments(default) taskBuildCacheableOutputDirectory.get().asFile.mkdirs() taskBuildLocalStateDirectory.get().asFile.mkdirs() diff --git a/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/tasks/AbstractKotlinCompileTool.kt b/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/tasks/AbstractKotlinCompileTool.kt index 95e328bb018..d68f3c78781 100644 --- a/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/tasks/AbstractKotlinCompileTool.kt +++ b/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/tasks/AbstractKotlinCompileTool.kt @@ -23,6 +23,7 @@ import org.jetbrains.kotlin.build.report.metrics.BuildMetricsReporterImpl import org.jetbrains.kotlin.cli.common.arguments.CommonToolArguments import org.jetbrains.kotlin.gradle.internal.CompilerArgumentAware import org.jetbrains.kotlin.gradle.internal.tasks.TaskWithLocalState +import org.jetbrains.kotlin.gradle.plugin.KotlinCompilerArgumentsProducer import org.jetbrains.kotlin.gradle.utils.fileExtensionCasePermutations import org.jetbrains.kotlin.gradle.utils.property import javax.inject.Inject @@ -31,6 +32,7 @@ abstract class AbstractKotlinCompileTool @Inject constr objectFactory: ObjectFactory ) : DefaultTask(), KotlinCompileTool, + KotlinCompilerArgumentsProducer, CompilerArgumentAware, TaskWithLocalState { diff --git a/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/tasks/Kotlin2JsCompile.kt b/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/tasks/Kotlin2JsCompile.kt index 414b069cd3e..cbc36da3013 100644 --- a/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/tasks/Kotlin2JsCompile.kt +++ b/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/tasks/Kotlin2JsCompile.kt @@ -58,7 +58,6 @@ abstract class Kotlin2JsCompile @Inject constructor( workerExecutor: WorkerExecutor ) : AbstractKotlinCompile(objectFactory, workerExecutor), KotlinCompilationTask, - KotlinCompilerArgumentsProducer, UsesLibraryFilterCachingService, KotlinJsCompile, K2MultiplatformCompilationTask { @@ -132,44 +131,6 @@ abstract class Kotlin2JsCompile @Inject constructor( override fun createCompilerArgs(): K2JSCompilerArguments = K2JSCompilerArguments() - @Suppress("OVERRIDE_DEPRECATION") - override fun setupCompilerArgs(args: K2JSCompilerArguments, defaultsOnly: Boolean, ignoreClasspathResolutionErrors: Boolean) { - KotlinJsCompilerOptionsHelper.fillDefaultValues(args) - super.setupCompilerArgs(args, defaultsOnly = defaultsOnly, ignoreClasspathResolutionErrors = ignoreClasspathResolutionErrors) - - if (defaultsOnly) return - - KotlinJsCompilerOptionsHelper.fillCompilerArguments(compilerOptions, args) - if (!args.sourceMapPrefix.isNullOrEmpty()) { - args.sourceMapBaseDirs = sourceMapBaseDir.get().asFile.absolutePath - } - if (isIrBackendEnabled()) { - val outputFilePath: String? = compilerOptions.outputFile.orNull - if (outputFilePath != null) { - val outputFile = File(outputFilePath) - args.outputDir = (if (outputFile.extension == "") outputFile else outputFile.parentFile).normalize().absolutePath - args.moduleName = outputFile.nameWithoutExtension - } else { - args.outputDir = destinationDirectory.get().asFile.normalize().absolutePath - args.moduleName = compilerOptions.moduleName.get() - } - } else { - args.outputFile = outputFileProperty.get().absoluteFile.normalize().absolutePath - } - - args.configureMultiplatform( - compilerOptions, - k1CommonSources = commonSourceSet.asFileTree, - k2MultiplatformFragments = multiplatformStructure - ) - - // Overriding freeArgs from compilerOptions with enhanced one + additional one set on execution phase - // containing additional arguments based on the js compilation configuration - val localExecutionTimeFreeCompilerArgs = executionTimeFreeCompilerArgs - args.freeArgs = - if (localExecutionTimeFreeCompilerArgs != null) localExecutionTimeFreeCompilerArgs else enhancedFreeCompilerArgs.get() - } - override fun createCompilerArguments(context: CreateCompilerArgumentsContext) = context.create { contribute(KotlinCompilerArgumentsProducer.ArgumentType.Primitive) { args -> args.multiPlatform = multiPlatformEnabled.get() diff --git a/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/tasks/KotlinCompile.kt b/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/tasks/KotlinCompile.kt index e2d0bad8c4b..ee9751cbb8d 100644 --- a/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/tasks/KotlinCompile.kt +++ b/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/tasks/KotlinCompile.kt @@ -69,7 +69,6 @@ abstract class KotlinCompile @Inject constructor( K2MultiplatformCompilationTask, @Suppress("TYPEALIAS_EXPANSION_DEPRECATION") KotlinJvmCompileDsl, KotlinCompilationTask, - KotlinCompilerArgumentsProducer, UsesKotlinJavaToolchain { @get:Internal // covered by compiler options @@ -211,9 +210,6 @@ abstract class KotlinCompile @Inject constructor( override fun skipCondition(): Boolean = sources.isEmpty && scriptSources.isEmpty - override fun createCompilerArgs(): K2JVMCompilerArguments = - K2JVMCompilerArguments() - /** * Workaround for those "nasty" plugins that are adding 'freeCompilerArgs' on task execution phase. * With properties api it is not possible to update property value after task configuration is finished. @@ -224,30 +220,6 @@ abstract class KotlinCompile @Inject constructor( @get:Internal internal var executionTimeFreeCompilerArgs: List? = null - override fun setupCompilerArgs(args: K2JVMCompilerArguments, defaultsOnly: Boolean, ignoreClasspathResolutionErrors: Boolean) { - compilerArgumentsContributor.contributeArguments( - args, compilerArgumentsConfigurationFlags( - defaultsOnly, - ignoreClasspathResolutionErrors - ) - ) - - args.configureMultiplatform( - compilerOptions, - k1CommonSources = commonSourceSet.asFileTree, - k2MultiplatformFragments = multiplatformStructure - ) - - if (reportingSettings().buildReportMode == BuildReportMode.VERBOSE) { - args.reportPerf = true - } - - val localExecutionTimeFreeCompilerArgs = executionTimeFreeCompilerArgs - if (localExecutionTimeFreeCompilerArgs != null) { - args.freeArgs = localExecutionTimeFreeCompilerArgs - } - } - @get:Internal internal val compilerArgumentsContributor: CompilerArgumentsContributor by lazy { KotlinJvmCompilerArgumentsContributor(KotlinJvmCompilerArgumentsProvider(this)) @@ -325,7 +297,9 @@ abstract class KotlinCompile @Inject constructor( val scriptSources = scriptSources.asFileTree.files val javaSources = javaSources.files val gradlePrintingMessageCollector = GradlePrintingMessageCollector(logger, args.allWarningsAsErrors) - val gradleMessageCollector = GradleErrorMessageCollector(gradlePrintingMessageCollector, kotlinPluginVersion = getKotlinPluginVersion(logger)) + val gradleMessageCollector = GradleErrorMessageCollector( + gradlePrintingMessageCollector, kotlinPluginVersion = getKotlinPluginVersion(logger) + ) val outputItemCollector = OutputItemsCollectorImpl() val compilerRunner = compilerRunner.get() diff --git a/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/tasks/KotlinCompileCommon.kt b/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/tasks/KotlinCompileCommon.kt index b5cf46ec496..0ca88b950f2 100644 --- a/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/tasks/KotlinCompileCommon.kt +++ b/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/tasks/KotlinCompileCommon.kt @@ -47,7 +47,6 @@ abstract class KotlinCompileCommon @Inject constructor( objectFactory: ObjectFactory ) : AbstractKotlinCompile(objectFactory, workerExecutor), KotlinCompilationTask, - KotlinCompilerArgumentsProducer, KotlinCommonCompile { init { @@ -69,43 +68,6 @@ abstract class KotlinCompileCommon @Inject constructor( @get:Internal internal var executionTimeFreeCompilerArgs: List? = null - override fun createCompilerArgs(): K2MetadataCompilerArguments = - K2MetadataCompilerArguments() - - override fun setupCompilerArgs(args: K2MetadataCompilerArguments, defaultsOnly: Boolean, ignoreClasspathResolutionErrors: Boolean) { - KotlinMultiplatformCommonCompilerOptionsHelper.fillDefaultValues(args) - super.setupCompilerArgs(args, defaultsOnly = defaultsOnly, ignoreClasspathResolutionErrors = ignoreClasspathResolutionErrors) - - args.moduleName = this@KotlinCompileCommon.moduleName.get() - - if (expectActualLinker.get()) { - args.expectActualLinker = true - } - - if (defaultsOnly) return - - val classpathList = try { - libraries.files.filter { it.exists() }.toMutableList() - } catch (t: Throwable) { - if (ignoreClasspathResolutionErrors) null else throw t - } - - with(args) { - classpath = classpathList?.joinToString(File.pathSeparator) - destination = destinationDirectory.get().asFile.normalize().absolutePath - - friendPaths = this@KotlinCompileCommon.friendPaths.files.map { it.absolutePath }.toTypedArray() - refinesPaths = refinesMetadataPaths.map { it.absolutePath }.toTypedArray() - } - - KotlinMultiplatformCommonCompilerOptionsHelper.fillCompilerArguments(compilerOptions, args) - - val localExecutionTimeFreeCompilerArgs = executionTimeFreeCompilerArgs - if (localExecutionTimeFreeCompilerArgs != null) { - args.freeArgs = localExecutionTimeFreeCompilerArgs - } - } - override fun createCompilerArguments(context: CreateCompilerArgumentsContext) = context.create { contribute(KotlinCompilerArgumentsProducer.ArgumentType.Primitive) { args -> args.multiPlatform = multiPlatformEnabled.get() diff --git a/libraries/tools/kotlin-gradle-plugin/src/functionalTest/kotlin/org/jetbrains/kotlin/gradle/unitTests/K2MultiplatformStructureTest.kt b/libraries/tools/kotlin-gradle-plugin/src/functionalTest/kotlin/org/jetbrains/kotlin/gradle/unitTests/K2MultiplatformStructureTest.kt index 51e2e907f4e..90f25a94b28 100644 --- a/libraries/tools/kotlin-gradle-plugin/src/functionalTest/kotlin/org/jetbrains/kotlin/gradle/unitTests/K2MultiplatformStructureTest.kt +++ b/libraries/tools/kotlin-gradle-plugin/src/functionalTest/kotlin/org/jetbrains/kotlin/gradle/unitTests/K2MultiplatformStructureTest.kt @@ -10,19 +10,18 @@ package org.jetbrains.kotlin.gradle.unitTests import org.gradle.kotlin.dsl.newInstance import org.jetbrains.kotlin.cli.common.arguments.CommonCompilerArguments import org.jetbrains.kotlin.cli.common.arguments.K2JVMCompilerArguments -import org.jetbrains.kotlin.cli.common.arguments.K2NativeCompilerArguments import org.jetbrains.kotlin.cli.common.arguments.parseCommandLineArguments import org.jetbrains.kotlin.compilerRunner.ArgumentUtils import org.jetbrains.kotlin.gradle.dsl.KotlinVersion import org.jetbrains.kotlin.gradle.dsl.multiplatformExtension import org.jetbrains.kotlin.gradle.internal.CompilerArgumentAware import org.jetbrains.kotlin.gradle.plugin.KotlinCompilation +import org.jetbrains.kotlin.gradle.plugin.KotlinCompilerArgumentsProducer.CreateCompilerArgumentsContext.Companion.lenient import org.jetbrains.kotlin.gradle.plugin.KotlinJsCompilerType.IR import org.jetbrains.kotlin.gradle.tasks.K2MultiplatformCompilationTask import org.jetbrains.kotlin.gradle.tasks.K2MultiplatformStructure -import org.jetbrains.kotlin.gradle.tasks.K2MultiplatformStructure.RefinesEdge import org.jetbrains.kotlin.gradle.tasks.K2MultiplatformStructure.Fragment -import org.jetbrains.kotlin.gradle.tasks.KotlinNativeCompile +import org.jetbrains.kotlin.gradle.tasks.K2MultiplatformStructure.RefinesEdge import org.jetbrains.kotlin.gradle.tasks.configureK2Multiplatform import org.jetbrains.kotlin.gradle.util.applyMultiplatformPlugin import org.jetbrains.kotlin.gradle.util.buildProject @@ -156,16 +155,7 @@ class K2MultiplatformStructureTest { private fun K2MultiplatformCompilationTask.buildCompilerArguments(): CommonCompilerArguments { /* KotlinNative implements CompilerArgumentAware, but does not adhere to its contract */ - - if (this is KotlinNativeCompile) { - val arguments = K2NativeCompilerArguments() - val argsList = this.buildCompilerArgs() - parseCommandLineArguments(argsList, arguments) - return arguments - } @Suppress("UNCHECKED_CAST") this as CompilerArgumentAware - val args = createCompilerArgs() - setupCompilerArgs(args) - return args + return this.createCompilerArguments(lenient) } diff --git a/libraries/tools/kotlin-gradle-plugin/src/functionalTest/kotlin/org/jetbrains/kotlin/gradle/unitTests/compilerArgumetns/Kotlin2JsCompileArgumentsTest.kt b/libraries/tools/kotlin-gradle-plugin/src/functionalTest/kotlin/org/jetbrains/kotlin/gradle/unitTests/compilerArgumetns/Kotlin2JsCompileArgumentsTest.kt index 632840ea434..42353b5872f 100644 --- a/libraries/tools/kotlin-gradle-plugin/src/functionalTest/kotlin/org/jetbrains/kotlin/gradle/unitTests/compilerArgumetns/Kotlin2JsCompileArgumentsTest.kt +++ b/libraries/tools/kotlin-gradle-plugin/src/functionalTest/kotlin/org/jetbrains/kotlin/gradle/unitTests/compilerArgumetns/Kotlin2JsCompileArgumentsTest.kt @@ -7,14 +7,8 @@ package org.jetbrains.kotlin.gradle.unitTests.compilerArgumetns -import org.gradle.kotlin.dsl.repositories import org.jetbrains.kotlin.compilerRunner.ArgumentUtils -import org.jetbrains.kotlin.gradle.dependencyResolutionTests.mavenCentralCacheRedirector import org.jetbrains.kotlin.gradle.dsl.multiplatformExtension -import org.jetbrains.kotlin.gradle.internal.prepareCompilerArguments -import org.jetbrains.kotlin.gradle.plugin.CreateCompilerArgumentsContext -import org.jetbrains.kotlin.gradle.plugin.KotlinCompilerArgumentsProducer -import org.jetbrains.kotlin.gradle.plugin.KotlinCompilerArgumentsProducer.ArgumentType import org.jetbrains.kotlin.gradle.plugin.KotlinCompilerArgumentsProducer.CreateCompilerArgumentsContext.Companion.default import org.jetbrains.kotlin.gradle.plugin.KotlinCompilerArgumentsProducer.CreateCompilerArgumentsContext.Companion.lenient import org.jetbrains.kotlin.gradle.plugin.KotlinJsCompilerType @@ -26,15 +20,10 @@ import kotlin.test.assertFails import kotlin.test.assertNull class Kotlin2JsCompileArgumentsTest { - @Suppress("DEPRECATION") @Test fun `test - simple project - old CompilerArgumentsAware and new CompilerArgumentsProducer - return same arguments`() { - val project = buildProjectWithMPP { - repositories { - mavenLocal() - mavenCentralCacheRedirector() - } - } + val project = buildProjectWithMPP() + project.repositories.mavenLocal() val kotlin = project.multiplatformExtension val jsTarget = kotlin.js(KotlinJsCompilerType.IR) @@ -42,16 +31,11 @@ class Kotlin2JsCompileArgumentsTest { project.evaluate() val jsMainCompileTask = jsMainCompilation.compileTaskProvider.get() - val argumentsFromCompilerArgumentsProducer = jsMainCompileTask.createCompilerArguments( - CreateCompilerArgumentsContext( - isLenient = true, - includeArgumentTypes = ArgumentType.all - ArgumentType.DependencyClasspath - ) - ) - val argumentsFromCompilerArgumentsAware = jsMainCompileTask.prepareCompilerArguments(true) + val argumentsFromCompilerArgumentsProducer = jsMainCompileTask.createCompilerArguments(lenient) + @Suppress("DEPRECATION_ERROR") assertEquals( - ArgumentUtils.convertArgumentsToStringList(argumentsFromCompilerArgumentsAware), + jsMainCompileTask.serializedCompilerArgumentsIgnoreClasspathIssues, ArgumentUtils.convertArgumentsToStringList(argumentsFromCompilerArgumentsProducer), ) } diff --git a/libraries/tools/kotlin-gradle-plugin/src/functionalTest/kotlin/org/jetbrains/kotlin/gradle/unitTests/compilerArgumetns/KotlinCompileArgumentsTest.kt b/libraries/tools/kotlin-gradle-plugin/src/functionalTest/kotlin/org/jetbrains/kotlin/gradle/unitTests/compilerArgumetns/KotlinCompileArgumentsTest.kt index 747e2b71b1c..f0acad068bd 100644 --- a/libraries/tools/kotlin-gradle-plugin/src/functionalTest/kotlin/org/jetbrains/kotlin/gradle/unitTests/compilerArgumetns/KotlinCompileArgumentsTest.kt +++ b/libraries/tools/kotlin-gradle-plugin/src/functionalTest/kotlin/org/jetbrains/kotlin/gradle/unitTests/compilerArgumetns/KotlinCompileArgumentsTest.kt @@ -18,7 +18,6 @@ import org.jetbrains.kotlin.gradle.dependencyResolutionTests.mavenCentralCacheRe import org.jetbrains.kotlin.gradle.dsl.KotlinVersion import org.jetbrains.kotlin.gradle.dsl.kotlinJvmExtension import org.jetbrains.kotlin.gradle.dsl.multiplatformExtension -import org.jetbrains.kotlin.gradle.internal.prepareCompilerArguments import org.jetbrains.kotlin.gradle.plugin.KotlinCompilerArgumentsProducer.CreateCompilerArgumentsContext.Companion.lenient import org.jetbrains.kotlin.gradle.tasks.KotlinCompile import org.jetbrains.kotlin.gradle.util.assertNotNull @@ -30,7 +29,6 @@ import kotlin.test.* class KotlinCompileArgumentsTest { - @Suppress("DEPRECATION") @Test fun `test - simple project - compare CompilerArgumentsAware with KotlinCompilerArgumentsAware implementations`() { val project = buildProjectWithJvm() @@ -45,11 +43,11 @@ class KotlinCompileArgumentsTest { val mainCompilation = kotlin.target.compilations.getByName("main") val mainCompilationTask = mainCompilation.compileTaskProvider.get() as KotlinCompile - val argumentsFromCompilerArgumentsAware = mainCompilationTask.prepareCompilerArguments(true) val argumentsFromKotlinCompilerArgumentsAware = mainCompilationTask.createCompilerArguments(lenient) + @Suppress("DEPRECATION_ERROR") assertEquals( - ArgumentUtils.convertArgumentsToStringList(argumentsFromCompilerArgumentsAware), + mainCompilationTask.serializedCompilerArgumentsIgnoreClasspathIssues, ArgumentUtils.convertArgumentsToStringList(argumentsFromKotlinCompilerArgumentsAware) ) } diff --git a/libraries/tools/kotlin-gradle-plugin/src/functionalTest/kotlin/org/jetbrains/kotlin/gradle/unitTests/compilerArgumetns/KotlinCompileCommonArgumentsTest.kt b/libraries/tools/kotlin-gradle-plugin/src/functionalTest/kotlin/org/jetbrains/kotlin/gradle/unitTests/compilerArgumetns/KotlinCompileCommonArgumentsTest.kt index 663a2efa413..197e14c158d 100644 --- a/libraries/tools/kotlin-gradle-plugin/src/functionalTest/kotlin/org/jetbrains/kotlin/gradle/unitTests/compilerArgumetns/KotlinCompileCommonArgumentsTest.kt +++ b/libraries/tools/kotlin-gradle-plugin/src/functionalTest/kotlin/org/jetbrains/kotlin/gradle/unitTests/compilerArgumetns/KotlinCompileCommonArgumentsTest.kt @@ -9,7 +9,6 @@ package org.jetbrains.kotlin.gradle.unitTests.compilerArgumetns import org.jetbrains.kotlin.compilerRunner.ArgumentUtils import org.jetbrains.kotlin.gradle.dsl.multiplatformExtension -import org.jetbrains.kotlin.gradle.internal.prepareCompilerArguments import org.jetbrains.kotlin.gradle.plugin.KotlinCompilerArgumentsProducer.CreateCompilerArgumentsContext import org.jetbrains.kotlin.gradle.plugin.KotlinCompilerArgumentsProducer.CreateCompilerArgumentsContext.Companion.lenient import org.jetbrains.kotlin.gradle.tasks.KotlinCompileCommon @@ -21,7 +20,6 @@ import kotlin.test.assertNull class KotlinCompileCommonArgumentsTest { @Test - @Suppress("DEPRECATION") fun `test - simple project - old CompilerArgumentsAware and new CompilerArgumentsProducer - return same arguments`() { val project = buildProjectWithMPP() project.repositories.mavenLocal() @@ -34,10 +32,10 @@ class KotlinCompileCommonArgumentsTest { val commonMainCompileTask = commonMainCompilation.compileTaskProvider.get() as KotlinCompileCommon val argumentsFromCompilerArgumentsProducer = commonMainCompileTask.createCompilerArguments(lenient) - val argumentsFromCompilerArgumentsAware = commonMainCompileTask.prepareCompilerArguments(true) + @Suppress("DEPRECATION_ERROR") assertEquals( - ArgumentUtils.convertArgumentsToStringList(argumentsFromCompilerArgumentsAware), + commonMainCompileTask.serializedCompilerArgumentsIgnoreClasspathIssues, ArgumentUtils.convertArgumentsToStringList(argumentsFromCompilerArgumentsProducer) ) }