Add immutable LanguageSettings interface and apply it to compilation
LanguageSettingsBuilder extends LanguageSettings
This commit is contained in:
committed by
Sergey Igushkin
parent
54c6ae2cce
commit
de4221afd8
+8
-6
@@ -5,18 +5,20 @@
|
|||||||
|
|
||||||
package org.jetbrains.kotlin.gradle.plugin
|
package org.jetbrains.kotlin.gradle.plugin
|
||||||
|
|
||||||
interface LanguageSettingsBuilder {
|
import org.jetbrains.kotlin.project.model.LanguageSettings
|
||||||
var languageVersion: String?
|
|
||||||
|
|
||||||
var apiVersion: String?
|
interface LanguageSettingsBuilder : LanguageSettings {
|
||||||
|
override var languageVersion: String?
|
||||||
|
|
||||||
var progressiveMode: Boolean
|
override var apiVersion: String?
|
||||||
|
|
||||||
|
override var progressiveMode: Boolean
|
||||||
|
|
||||||
fun enableLanguageFeature(name: String)
|
fun enableLanguageFeature(name: String)
|
||||||
|
|
||||||
val enabledLanguageFeatures: Set<String>
|
override val enabledLanguageFeatures: Set<String>
|
||||||
|
|
||||||
fun useExperimentalAnnotation(name: String)
|
fun useExperimentalAnnotation(name: String)
|
||||||
|
|
||||||
val experimentalAnnotationsInUse: Set<String>
|
override val experimentalAnnotationsInUse: Set<String>
|
||||||
}
|
}
|
||||||
+3
-3
@@ -11,7 +11,7 @@ import org.gradle.api.file.SourceDirectorySet
|
|||||||
import org.jetbrains.kotlin.gradle.dsl.KotlinCommonOptions
|
import org.jetbrains.kotlin.gradle.dsl.KotlinCommonOptions
|
||||||
import org.jetbrains.kotlin.gradle.plugin.KotlinCompilationOutput
|
import org.jetbrains.kotlin.gradle.plugin.KotlinCompilationOutput
|
||||||
import org.jetbrains.kotlin.gradle.plugin.KotlinPlatformType
|
import org.jetbrains.kotlin.gradle.plugin.KotlinPlatformType
|
||||||
import org.jetbrains.kotlin.gradle.plugin.LanguageSettingsBuilder
|
import org.jetbrains.kotlin.project.model.LanguageSettings
|
||||||
|
|
||||||
interface KotlinCompilationData<T : KotlinCommonOptions> {
|
interface KotlinCompilationData<T : KotlinCommonOptions> {
|
||||||
val project: Project
|
val project: Project
|
||||||
@@ -27,7 +27,7 @@ interface KotlinCompilationData<T : KotlinCommonOptions> {
|
|||||||
val compileDependencyFiles: FileCollection
|
val compileDependencyFiles: FileCollection
|
||||||
val output: KotlinCompilationOutput
|
val output: KotlinCompilationOutput
|
||||||
|
|
||||||
val languageSettings: LanguageSettingsBuilder
|
val languageSettings: LanguageSettings
|
||||||
val platformType: KotlinPlatformType
|
val platformType: KotlinPlatformType
|
||||||
|
|
||||||
val moduleName: String
|
val moduleName: String
|
||||||
@@ -61,7 +61,7 @@ interface KotlinVariantCompilationData<T : KotlinCommonOptions> : KotlinCompilat
|
|||||||
override val compileDependencyFiles: FileCollection
|
override val compileDependencyFiles: FileCollection
|
||||||
get() = owner.compileDependencyFiles
|
get() = owner.compileDependencyFiles
|
||||||
|
|
||||||
override val languageSettings: LanguageSettingsBuilder
|
override val languageSettings: LanguageSettings
|
||||||
get() = owner.languageSettings
|
get() = owner.languageSettings
|
||||||
|
|
||||||
override val platformType: KotlinPlatformType
|
override val platformType: KotlinPlatformType
|
||||||
|
|||||||
+1
-4
@@ -22,10 +22,7 @@ interface KotlinGradleFragment : KotlinModuleFragment, HasKotlinDependencies, Na
|
|||||||
|
|
||||||
override fun getName(): String = fragmentName
|
override fun getName(): String = fragmentName
|
||||||
|
|
||||||
// TODO pull up to KotlinModuleFragment
|
override val languageSettings: LanguageSettingsBuilder
|
||||||
// FIXME apply to compilation
|
|
||||||
// FIXME check for consistency
|
|
||||||
val languageSettings: LanguageSettingsBuilder
|
|
||||||
|
|
||||||
val project: Project
|
val project: Project
|
||||||
get() = containingModule.project
|
get() = containingModule.project
|
||||||
|
|||||||
+5
-4
@@ -19,6 +19,7 @@ import org.jetbrains.kotlin.gradle.dsl.kotlinExtension
|
|||||||
import org.jetbrains.kotlin.gradle.dsl.multiplatformExtensionOrNull
|
import org.jetbrains.kotlin.gradle.dsl.multiplatformExtensionOrNull
|
||||||
import org.jetbrains.kotlin.gradle.plugin.*
|
import org.jetbrains.kotlin.gradle.plugin.*
|
||||||
import org.jetbrains.kotlin.gradle.plugin.mpp.pm20.*
|
import org.jetbrains.kotlin.gradle.plugin.mpp.pm20.*
|
||||||
|
import org.jetbrains.kotlin.gradle.plugin.sources.DefaultLanguageSettingsBuilder
|
||||||
import org.jetbrains.kotlin.gradle.plugin.sources.KotlinDependencyScope
|
import org.jetbrains.kotlin.gradle.plugin.sources.KotlinDependencyScope
|
||||||
import org.jetbrains.kotlin.gradle.plugin.sources.getVisibleSourceSetsFromAssociateCompilations
|
import org.jetbrains.kotlin.gradle.plugin.sources.getVisibleSourceSetsFromAssociateCompilations
|
||||||
import org.jetbrains.kotlin.project.model.*
|
import org.jetbrains.kotlin.project.model.*
|
||||||
@@ -32,11 +33,11 @@ class ProjectStructureMetadataModuleBuilder {
|
|||||||
): KotlinModule {
|
): KotlinModule {
|
||||||
val moduleData = BasicKotlinModule(component.toSingleModuleIdentifier()).apply {
|
val moduleData = BasicKotlinModule(component.toSingleModuleIdentifier()).apply {
|
||||||
metadata.sourceSetNamesByVariantName.keys.forEach { variantName ->
|
metadata.sourceSetNamesByVariantName.keys.forEach { variantName ->
|
||||||
fragments.add(BasicKotlinModuleVariant(this@apply, variantName))
|
fragments.add(BasicKotlinModuleVariant(this@apply, variantName, DefaultLanguageSettingsBuilder()))
|
||||||
}
|
}
|
||||||
fun fragment(sourceSetName: String): BasicKotlinModuleFragment {
|
fun fragment(sourceSetName: String): BasicKotlinModuleFragment {
|
||||||
if (fragments.none { it.fragmentName == sourceSetName })
|
if (fragments.none { it.fragmentName == sourceSetName })
|
||||||
fragments.add(BasicKotlinModuleFragment(this@apply, sourceSetName))
|
fragments.add(BasicKotlinModuleFragment(this@apply, sourceSetName, DefaultLanguageSettingsBuilder()))
|
||||||
return fragmentByName(sourceSetName)
|
return fragmentByName(sourceSetName)
|
||||||
}
|
}
|
||||||
metadata.sourceSetNamesByVariantName.forEach { (variantName, sourceSets) ->
|
metadata.sourceSetNamesByVariantName.forEach { (variantName, sourceSets) ->
|
||||||
@@ -163,7 +164,7 @@ class GradleProjectModuleBuilder(private val addInferredSourceSetVisibilityAsExp
|
|||||||
?: listOf(compilation.defaultSourceSetName)
|
?: listOf(compilation.defaultSourceSetName)
|
||||||
|
|
||||||
variantNames.forEach { variantName ->
|
variantNames.forEach { variantName ->
|
||||||
val variant = BasicKotlinModuleVariant(this@apply, variantName)
|
val variant = BasicKotlinModuleVariant(this@apply, variantName, DefaultLanguageSettingsBuilder())
|
||||||
moduleByFragment[variant] = this@apply
|
moduleByFragment[variant] = this@apply
|
||||||
variantToCompilation[variant] = compilation
|
variantToCompilation[variant] = compilation
|
||||||
fragments.add(variant)
|
fragments.add(variant)
|
||||||
@@ -180,7 +181,7 @@ class GradleProjectModuleBuilder(private val addInferredSourceSetVisibilityAsExp
|
|||||||
// Once all fragments are created, add dependencies between them
|
// Once all fragments are created, add dependencies between them
|
||||||
sourceSetsToInclude.forEach { sourceSet ->
|
sourceSetsToInclude.forEach { sourceSet ->
|
||||||
val existingVariant = fragments.filterIsInstance<BasicKotlinModuleVariant>().find { it.fragmentName == sourceSet.name }
|
val existingVariant = fragments.filterIsInstance<BasicKotlinModuleVariant>().find { it.fragmentName == sourceSet.name }
|
||||||
val fragment = existingVariant ?: BasicKotlinModuleFragment(this@apply, sourceSet.name).also { fragments.add(it) }
|
val fragment = existingVariant ?: BasicKotlinModuleFragment(this@apply, sourceSet.name, sourceSet.languageSettings).also { fragments.add(it) }
|
||||||
moduleByFragment[fragment] = this@apply
|
moduleByFragment[fragment] = this@apply
|
||||||
fragment.kotlinSourceRoots = sourceSet.kotlin.sourceDirectories.toList()
|
fragment.kotlinSourceRoots = sourceSet.kotlin.sourceDirectories.toList()
|
||||||
|
|
||||||
|
|||||||
+2
-1
@@ -16,6 +16,7 @@ import org.jetbrains.kotlin.gradle.plugin.KotlinSourceSet
|
|||||||
import org.jetbrains.kotlin.gradle.plugin.mpp.*
|
import org.jetbrains.kotlin.gradle.plugin.mpp.*
|
||||||
import org.jetbrains.kotlin.gradle.plugin.mpp.getProjectStructureMetadata
|
import org.jetbrains.kotlin.gradle.plugin.mpp.getProjectStructureMetadata
|
||||||
import org.jetbrains.kotlin.gradle.plugin.mpp.resolvableMetadataConfiguration
|
import org.jetbrains.kotlin.gradle.plugin.mpp.resolvableMetadataConfiguration
|
||||||
|
import org.jetbrains.kotlin.gradle.plugin.sources.DefaultLanguageSettingsBuilder
|
||||||
import org.jetbrains.kotlin.gradle.plugin.sources.KotlinDependencyScope
|
import org.jetbrains.kotlin.gradle.plugin.sources.KotlinDependencyScope
|
||||||
import org.jetbrains.kotlin.project.model.*
|
import org.jetbrains.kotlin.project.model.*
|
||||||
import java.util.ArrayDeque
|
import java.util.ArrayDeque
|
||||||
@@ -148,7 +149,7 @@ class FragmentDependenciesDiscovery(
|
|||||||
internal fun buildSyntheticModule(resolvedComponentResult: ResolvedComponentResult, singleVariantName: String): ExternalSyntheticKotlinModule {
|
internal fun buildSyntheticModule(resolvedComponentResult: ResolvedComponentResult, singleVariantName: String): ExternalSyntheticKotlinModule {
|
||||||
val moduleDependency = resolvedComponentResult.toModuleDependency()
|
val moduleDependency = resolvedComponentResult.toModuleDependency()
|
||||||
return ExternalSyntheticKotlinModule(BasicKotlinModule(moduleDependency.moduleIdentifier).apply {
|
return ExternalSyntheticKotlinModule(BasicKotlinModule(moduleDependency.moduleIdentifier).apply {
|
||||||
BasicKotlinModuleVariant(this@apply, singleVariantName).apply {
|
BasicKotlinModuleVariant(this@apply, singleVariantName, DefaultLanguageSettingsBuilder()).apply {
|
||||||
fragments.add(this)
|
fragments.add(this)
|
||||||
this.declaredModuleDependencies.addAll(
|
this.declaredModuleDependencies.addAll(
|
||||||
resolvedComponentResult.dependencies
|
resolvedComponentResult.dependencies
|
||||||
|
|||||||
+1
-1
@@ -72,7 +72,7 @@ internal abstract class AbstractKotlinFragmentMetadataCompilationData<T : Kotlin
|
|||||||
project.provider { project.buildDir.resolve("processedResources/${fragment.disambiguateName("metadata")}") }
|
project.provider { project.buildDir.resolve("processedResources/${fragment.disambiguateName("metadata")}") }
|
||||||
)
|
)
|
||||||
|
|
||||||
override val languageSettings: LanguageSettingsBuilder = DefaultLanguageSettingsBuilder() // FIXME apply settings
|
override val languageSettings: LanguageSettingsBuilder = fragment.languageSettings
|
||||||
|
|
||||||
override val platformType: KotlinPlatformType
|
override val platformType: KotlinPlatformType
|
||||||
get() = KotlinPlatformType.common
|
get() = KotlinPlatformType.common
|
||||||
|
|||||||
+1
-1
@@ -77,5 +77,5 @@ internal class KotlinNativeVariantCompilationData(
|
|||||||
override val owner: KotlinNativeVariant
|
override val owner: KotlinNativeVariant
|
||||||
get() = variant
|
get() = variant
|
||||||
|
|
||||||
override val kotlinOptions: KotlinCommonOptions = NativeCompileOptions { languageSettings }
|
override val kotlinOptions: KotlinCommonOptions = NativeCompileOptions { variant.languageSettings }
|
||||||
}
|
}
|
||||||
|
|||||||
+2
-1
@@ -17,6 +17,7 @@ import org.jetbrains.kotlin.gradle.plugin.LanguageSettingsBuilder
|
|||||||
import org.jetbrains.kotlin.gradle.plugin.statistics.KotlinBuildStatsService
|
import org.jetbrains.kotlin.gradle.plugin.statistics.KotlinBuildStatsService
|
||||||
import org.jetbrains.kotlin.gradle.tasks.AbstractKotlinCompile
|
import org.jetbrains.kotlin.gradle.tasks.AbstractKotlinCompile
|
||||||
import org.jetbrains.kotlin.gradle.tasks.AbstractKotlinNativeCompile
|
import org.jetbrains.kotlin.gradle.tasks.AbstractKotlinNativeCompile
|
||||||
|
import org.jetbrains.kotlin.project.model.LanguageSettings
|
||||||
import org.jetbrains.kotlin.statistics.metrics.BooleanMetrics
|
import org.jetbrains.kotlin.statistics.metrics.BooleanMetrics
|
||||||
import org.jetbrains.kotlin.statistics.metrics.StringMetrics
|
import org.jetbrains.kotlin.statistics.metrics.StringMetrics
|
||||||
|
|
||||||
@@ -98,7 +99,7 @@ internal class DefaultLanguageSettingsBuilder : LanguageSettingsBuilder {
|
|||||||
}
|
}
|
||||||
|
|
||||||
internal fun applyLanguageSettingsToKotlinOptions(
|
internal fun applyLanguageSettingsToKotlinOptions(
|
||||||
languageSettingsBuilder: LanguageSettingsBuilder,
|
languageSettingsBuilder: LanguageSettings,
|
||||||
kotlinOptions: KotlinCommonOptions
|
kotlinOptions: KotlinCommonOptions
|
||||||
) = with(kotlinOptions) {
|
) = with(kotlinOptions) {
|
||||||
languageVersion = languageVersion ?: languageSettingsBuilder.languageVersion
|
languageVersion = languageVersion ?: languageSettingsBuilder.languageVersion
|
||||||
|
|||||||
+2
-1
@@ -43,6 +43,7 @@ import org.jetbrains.kotlin.konan.target.Distribution
|
|||||||
import org.jetbrains.kotlin.konan.target.HostManager
|
import org.jetbrains.kotlin.konan.target.HostManager
|
||||||
import org.jetbrains.kotlin.konan.target.KonanTarget
|
import org.jetbrains.kotlin.konan.target.KonanTarget
|
||||||
import org.jetbrains.kotlin.library.*
|
import org.jetbrains.kotlin.library.*
|
||||||
|
import org.jetbrains.kotlin.project.model.LanguageSettings
|
||||||
import java.io.File
|
import java.io.File
|
||||||
import java.nio.charset.StandardCharsets
|
import java.nio.charset.StandardCharsets
|
||||||
import java.security.MessageDigest
|
import java.security.MessageDigest
|
||||||
@@ -180,7 +181,7 @@ abstract class AbstractKotlinNativeCompile<T : KotlinCommonToolOptions, K : Kotl
|
|||||||
abstract val additionalCompilerOptions: Provider<Collection<String>>
|
abstract val additionalCompilerOptions: Provider<Collection<String>>
|
||||||
|
|
||||||
@get:Internal
|
@get:Internal
|
||||||
val languageSettings: LanguageSettingsBuilder by project.provider {
|
val languageSettings: LanguageSettings by project.provider {
|
||||||
compilation.languageSettings
|
compilation.languageSettings
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -14,6 +14,8 @@ interface KotlinModuleFragment {
|
|||||||
val fragmentName: String
|
val fragmentName: String
|
||||||
val directRefinesDependencies: Iterable<KotlinModuleFragment>
|
val directRefinesDependencies: Iterable<KotlinModuleFragment>
|
||||||
|
|
||||||
|
val languageSettings: LanguageSettings
|
||||||
|
|
||||||
// TODO: scopes
|
// TODO: scopes
|
||||||
val declaredModuleDependencies: Iterable<KotlinModuleDependency>
|
val declaredModuleDependencies: Iterable<KotlinModuleDependency>
|
||||||
|
|
||||||
@@ -46,7 +48,8 @@ val KotlinModuleFragment.refinesClosure: Set<KotlinModuleFragment>
|
|||||||
|
|
||||||
open class BasicKotlinModuleFragment(
|
open class BasicKotlinModuleFragment(
|
||||||
override val containingModule: KotlinModule,
|
override val containingModule: KotlinModule,
|
||||||
override val fragmentName: String
|
override val fragmentName: String,
|
||||||
|
override val languageSettings: LanguageSettings
|
||||||
) : KotlinModuleFragment {
|
) : KotlinModuleFragment {
|
||||||
|
|
||||||
override val directRefinesDependencies: MutableSet<BasicKotlinModuleFragment> = mutableSetOf()
|
override val directRefinesDependencies: MutableSet<BasicKotlinModuleFragment> = mutableSetOf()
|
||||||
@@ -59,10 +62,12 @@ open class BasicKotlinModuleFragment(
|
|||||||
|
|
||||||
class BasicKotlinModuleVariant(
|
class BasicKotlinModuleVariant(
|
||||||
containingModule: KotlinModule,
|
containingModule: KotlinModule,
|
||||||
fragmentName: String
|
fragmentName: String,
|
||||||
|
languageSettings: LanguageSettings
|
||||||
) : BasicKotlinModuleFragment (
|
) : BasicKotlinModuleFragment (
|
||||||
containingModule,
|
containingModule,
|
||||||
fragmentName
|
fragmentName,
|
||||||
|
languageSettings
|
||||||
), KotlinModuleVariant {
|
), KotlinModuleVariant {
|
||||||
override val variantAttributes: MutableMap<KotlinAttributeKey, String> = mutableMapOf()
|
override val variantAttributes: MutableMap<KotlinAttributeKey, String> = mutableMapOf()
|
||||||
override fun toString(): String = "variant $fragmentName"
|
override fun toString(): String = "variant $fragmentName"
|
||||||
|
|||||||
@@ -0,0 +1,14 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2010-2021 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||||
|
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.jetbrains.kotlin.project.model
|
||||||
|
|
||||||
|
interface LanguageSettings {
|
||||||
|
val languageVersion: String?
|
||||||
|
val apiVersion: String?
|
||||||
|
val progressiveMode: Boolean
|
||||||
|
val enabledLanguageFeatures: Set<String>
|
||||||
|
val experimentalAnnotationsInUse: Set<String>
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user