[Gradle] Don't convert free compiler arguments to set, avoid args duplication

#KT-55363 Fixed
This commit is contained in:
Alexander Likhachev
2022-12-08 18:26:44 +01:00
committed by Space Team
parent a5810d88a5
commit 0466fc536d
6 changed files with 38 additions and 30 deletions
@@ -8,7 +8,6 @@ package org.jetbrains.kotlin.gradle
import org.gradle.api.logging.LogLevel
import org.gradle.util.GradleVersion
import org.jetbrains.kotlin.gradle.testbase.*
import org.junit.jupiter.api.Disabled
import org.junit.jupiter.api.DisplayName
import kotlin.io.path.appendText
@@ -62,7 +61,6 @@ internal class CompilerOptionsIT : KGPBaseTest() {
@DisplayName("compiler plugin arguments set via kotlinOptions.freeCompilerArgs on task execution applied properly")
@JvmGradlePluginTests
@GradleTest
@Disabled
internal fun freeArgsModifiedAtExecutionTimeCorrectly(gradleVersion: GradleVersion) {
project("simpleProject", gradleVersion) {
buildGradle.appendText(
@@ -95,7 +93,6 @@ internal class CompilerOptionsIT : KGPBaseTest() {
@DisplayName("compiler plugin arguments set via kotlinOptions.freeCompilerArgs on task execution applied properly in MPP")
@MppGradlePluginTests
@GradleTest
@Disabled
internal fun freeArgsModifiedAtExecutionTimeCorrectlyMpp(gradleVersion: GradleVersion) {
project("new-mpp-lib-with-tests", gradleVersion) {
buildGradle.appendText(
@@ -61,7 +61,7 @@ abstract class KotlinCompileCommon @Inject constructor(
* this input will always be empty.
*/
@get:Internal
internal var additionalFreeCompilerArgs: List<String> = listOf()
internal var executionTimeFreeCompilerArgs: List<String>? = null
override fun createCompilerArgs(): K2MetadataCompilerArguments =
K2MetadataCompilerArguments()
@@ -90,8 +90,9 @@ abstract class KotlinCompileCommon @Inject constructor(
(compilerOptions as KotlinMultiplatformCommonCompilerOptionsDefault).fillCompilerArguments(args)
if (additionalFreeCompilerArgs.isNotEmpty()) {
args.freeArgs = compilerOptions.freeCompilerArgs.get().union(additionalFreeCompilerArgs).toList()
val localExecutionTimeFreeCompilerArgs = executionTimeFreeCompilerArgs
if (localExecutionTimeFreeCompilerArgs != null) {
args.freeArgs = localExecutionTimeFreeCompilerArgs
}
}
@@ -701,7 +701,7 @@ abstract class KotlinCompile @Inject constructor(
* this input will always be empty.
*/
@get:Internal
internal var additionalFreeCompilerArgs: List<String> = listOf()
internal var executionTimeFreeCompilerArgs: List<String>? = null
override fun setupCompilerArgs(args: K2JVMCompilerArguments, defaultsOnly: Boolean, ignoreClasspathResolutionErrors: Boolean) {
compilerArgumentsContributor.contributeArguments(
@@ -715,8 +715,9 @@ abstract class KotlinCompile @Inject constructor(
args.reportPerf = true
}
if (additionalFreeCompilerArgs.isNotEmpty()) {
args.freeArgs = compilerOptions.freeCompilerArgs.get().union(additionalFreeCompilerArgs).toList()
val localExecutionTimeFreeCompilerArgs = executionTimeFreeCompilerArgs
if (localExecutionTimeFreeCompilerArgs != null) {
args.freeArgs = localExecutionTimeFreeCompilerArgs
}
}
@@ -1009,7 +1010,7 @@ abstract class Kotlin2JsCompile @Inject constructor(
* this input will always be empty.
*/
@get:Internal
internal var additionalFreeCompilerArgs: List<String> = listOf()
internal var executionTimeFreeCompilerArgs: List<String>? = null
override fun createCompilerArgs(): K2JSCompilerArguments =
K2JSCompilerArguments()
@@ -1039,7 +1040,8 @@ abstract class Kotlin2JsCompile @Inject constructor(
}
// Overriding freeArgs from compilerOptions with enhanced one + additional one set on execution phase
// containing additional arguments based on the js compilation configuration
args.freeArgs = enhancedFreeCompilerArgs.get().union(additionalFreeCompilerArgs).toList()
val localExecutionTimeFreeCompilerArgs = executionTimeFreeCompilerArgs
args.freeArgs = if (localExecutionTimeFreeCompilerArgs != null) localExecutionTimeFreeCompilerArgs else enhancedFreeCompilerArgs.get()
}
@get:InputFiles
@@ -18,17 +18,21 @@ class KotlinJsOptionsCompat(
override val options: KotlinJsCompilerOptions
) : KotlinJsOptions {
override var freeCompilerArgs: List<String>
get() = if (isTaskExecuting) {
task().enhancedFreeCompilerArgs.get()
.union(task().additionalFreeCompilerArgs)
.toList()
} else {
options.freeCompilerArgs.get()
get() {
val executionTimeFreeCompilerArgs = task().executionTimeFreeCompilerArgs
return if (!isTaskExecuting) {
options.freeCompilerArgs.get()
} else if (executionTimeFreeCompilerArgs != null) {
executionTimeFreeCompilerArgs
} else {
// returned at execution time before freeCompilerArgs modification
task().enhancedFreeCompilerArgs.get()
}
}
set(value) = if (isTaskExecuting) {
task().nagUserFreeArgsModifiedOnExecution(value)
task().additionalFreeCompilerArgs = value
task().executionTimeFreeCompilerArgs = value
} else {
options.freeCompilerArgs.set(value)
}
@@ -18,15 +18,18 @@ class KotlinJvmOptionsCompat(
override val options: KotlinJvmCompilerOptions
) : KotlinJvmOptions {
override var freeCompilerArgs: List<String>
get() = if (isTaskExecuting) {
options.freeCompilerArgs.get().union(task().additionalFreeCompilerArgs).toList()
} else {
options.freeCompilerArgs.get()
get() {
val executionTimeFreeCompilerArgs = task().executionTimeFreeCompilerArgs
return if (isTaskExecuting && executionTimeFreeCompilerArgs != null) {
executionTimeFreeCompilerArgs
} else {
options.freeCompilerArgs.get()
}
}
set(value) = if (isTaskExecuting) {
task().nagUserFreeArgsModifiedOnExecution(value)
task().additionalFreeCompilerArgs = value
task().executionTimeFreeCompilerArgs = value
} else {
options.freeCompilerArgs.set(value)
}
@@ -15,17 +15,18 @@ class KotlinMultiplatformCommonOptionsCompat(
) : KotlinMultiplatformCommonOptions {
override var freeCompilerArgs: List<String>
get() = if (isTaskExecuting) {
options.freeCompilerArgs.get()
.union(task().additionalFreeCompilerArgs)
.toList()
} else {
options.freeCompilerArgs.get()
get() {
val executionTimeFreeCompilerArgs = task().executionTimeFreeCompilerArgs
return if (isTaskExecuting && executionTimeFreeCompilerArgs != null) {
executionTimeFreeCompilerArgs
} else {
options.freeCompilerArgs.get()
}
}
set(value) = if (isTaskExecuting) {
task().nagUserFreeArgsModifiedOnExecution(value)
task().additionalFreeCompilerArgs = value
task().executionTimeFreeCompilerArgs = value
} else {
options.freeCompilerArgs.set(value)
}