Skip to content

Commit

Permalink
[Gradle] Cover LanguageSettingsSetupAction with test
Browse files Browse the repository at this point in the history
^KT-75216
  • Loading branch information
antohaby authored and Space Team committed Feb 19, 2025
1 parent dbe822f commit 507a797
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ internal open class DefaultLanguageSettingsBuilder @Inject constructor(
@Transient // not needed during Gradle Instant Execution
var compilerPluginOptionsTask: Lazy<AbstractKotlinCompileTool<*>?> = lazyOf(null)

@Suppress("unused") // Used during IDE import
val compilerPluginArguments: List<String>?
get() {
val pluginOptionsTask = compilerPluginOptionsTask.value ?: return null
Expand All @@ -122,6 +123,7 @@ internal open class DefaultLanguageSettingsBuilder @Inject constructor(
}.arguments
}

@Suppress("unused") // Used during IDE import
val compilerPluginClasspath: FileCollection?
get() {
val pluginClasspathTask = compilerPluginOptionsTask.value ?: return null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import org.jetbrains.kotlin.gradle.plugin.KotlinPlatformType
import org.jetbrains.kotlin.gradle.plugin.KotlinProjectSetupAction
import org.jetbrains.kotlin.gradle.tasks.AbstractKotlinCompileTool

// FIXME: KT-75216 Synchronise common source set language settings with compile tasks in a better way
internal val LanguageSettingsSetupAction = KotlinProjectSetupAction {
// common source sets use the compiler options from the metadata compilation:
val metadataCompilation = multiplatformExtension.metadata().compilations.getByName(KotlinCompilation.MAIN_COMPILATION_NAME)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,14 @@ import org.gradle.api.internal.project.ProjectInternal
import org.jetbrains.kotlin.gradle.ExperimentalWasmDsl
import org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformExtension
import org.jetbrains.kotlin.gradle.dsl.KotlinVersion
import org.jetbrains.kotlin.gradle.dsl.kotlinExtension
import org.jetbrains.kotlin.gradle.dsl.multiplatformExtension
import org.jetbrains.kotlin.gradle.plugin.KotlinSourceSet
import org.jetbrains.kotlin.gradle.plugin.sources.DefaultLanguageSettingsBuilder
import org.jetbrains.kotlin.gradle.tasks.KotlinCompilationTask
import org.jetbrains.kotlin.gradle.tasks.withType
import org.jetbrains.kotlin.gradle.util.allCauses
import org.jetbrains.kotlin.gradle.util.androidLibrary
import org.jetbrains.kotlin.gradle.util.assertContains
import org.jetbrains.kotlin.gradle.util.buildProjectWithMPP
import org.jetbrains.kotlin.util.assertThrows
Expand Down Expand Up @@ -220,6 +223,67 @@ class LanguageSettingsTests {
project.evaluate()
}

/**
* See: [org.jetbrains.kotlin.gradle.plugin.sources.LanguageSettingsSetupAction]
* FIXME: KT-75216 Update this test to actually verify Language Settings propagation to IDE import when legacy way is deprecated and removed
* */
@Test
fun `language settings setup action test`() {
val project = kmpProject {
androidLibrary { compileSdk = 31 }
with(multiplatformExtension) {
androidTarget()
jvm().compilations.create("custom")
}
}
project.evaluate()

val sourceSetToCompileTask = mapOf(
"androidDebug" to "compileDebugKotlinAndroid",
"androidInstrumentedTest" to "compileDebugAndroidTestKotlinAndroid",
"androidInstrumentedTestDebug" to "compileDebugAndroidTestKotlinAndroid",
"androidMain" to "compileDebugKotlinAndroid",
"androidRelease" to "compileReleaseKotlinAndroid",
"androidUnitTest" to "compileDebugUnitTestKotlinAndroid",
"androidUnitTestDebug" to "compileDebugUnitTestKotlinAndroid",
"androidUnitTestRelease" to "compileReleaseUnitTestKotlinAndroid",
"appleMain" to "compileKotlinMetadata",
"appleTest" to "compileKotlinMetadata",
"commonMain" to "compileKotlinMetadata",
"commonTest" to "compileKotlinMetadata",
"jsMain" to "compileKotlinJs",
"jsTest" to "compileTestKotlinJs",
"jvmCustom" to "compileCustomKotlinJvm",
"jvmMain" to "compileKotlinJvm",
"jvmTest" to "compileTestKotlinJvm",
"linuxArm64Main" to "compileKotlinLinuxArm64",
"linuxArm64Test" to "compileTestKotlinLinuxArm64",
"linuxMain" to "compileKotlinMetadata",
"linuxTest" to "compileKotlinMetadata",
"linuxX64Main" to "compileKotlinLinuxX64",
"linuxX64Test" to "compileTestKotlinLinuxX64",
"macosArm64Main" to "compileKotlinMacosArm64",
"macosArm64Test" to "compileTestKotlinMacosArm64",
"macosMain" to "compileKotlinMetadata",
"macosTest" to "compileKotlinMetadata",
"macosX64Main" to "compileKotlinMacosX64",
"macosX64Test" to "compileTestKotlinMacosX64",
"mingwMain" to "compileKotlinMingwX64",
"mingwTest" to "compileTestKotlinMingwX64",
"mingwX64Main" to "compileKotlinMingwX64",
"mingwX64Test" to "compileTestKotlinMingwX64",
"nativeMain" to "compileKotlinMetadata",
"nativeTest" to "compileKotlinMetadata",
"wasmJsMain" to "compileKotlinWasmJs",
"wasmJsTest" to "compileTestKotlinWasmJs",
)
val actualTasks = project.kotlinExtension.sourceSets.associate { sourceSet ->
sourceSet.name to (sourceSet.languageSettings as DefaultLanguageSettingsBuilder).compilerPluginOptionsTask.value?.name
}

assertEquals(sourceSetToCompileTask, actualTasks)
}

companion object {
private fun kmpProject(
configure: Project.() -> Unit = {},
Expand Down

0 comments on commit 507a797

Please sign in to comment.