[Gradle] Inverse usesService declaration
KT-52149 Fixed
This commit is contained in:
committed by
Space Team
parent
36a6809d55
commit
278229d2fa
+21
-5
@@ -5,16 +5,26 @@
|
||||
|
||||
package org.jetbrains.kotlin.compilerRunner
|
||||
|
||||
import org.gradle.api.invocation.Gradle
|
||||
import org.gradle.api.Project
|
||||
import org.gradle.api.Task
|
||||
import org.gradle.api.provider.MapProperty
|
||||
import org.gradle.api.provider.Property
|
||||
import org.gradle.api.provider.Provider
|
||||
import org.gradle.api.services.BuildService
|
||||
import org.gradle.api.services.BuildServiceParameters
|
||||
import org.gradle.api.tasks.Internal
|
||||
import org.jetbrains.kotlin.cli.common.CompilerSystemProperties
|
||||
import org.jetbrains.kotlin.gradle.plugin.internal.configurationTimePropertiesAccessor
|
||||
import org.jetbrains.kotlin.gradle.plugin.internal.usedAtConfigurationTime
|
||||
import org.jetbrains.kotlin.gradle.tasks.withType
|
||||
import org.jetbrains.kotlin.gradle.utils.SingleActionPerProject
|
||||
import org.jetbrains.kotlin.gradle.utils.isConfigurationCacheAvailable
|
||||
|
||||
internal interface UsesCompilerSystemPropertiesService : Task {
|
||||
@get:Internal
|
||||
val systemPropertiesService: Property<CompilerSystemPropertiesService>
|
||||
}
|
||||
|
||||
internal abstract class CompilerSystemPropertiesService : BuildService<CompilerSystemPropertiesService.Parameters>, AutoCloseable {
|
||||
internal interface Parameters : BuildServiceParameters {
|
||||
val properties: MapProperty<String, Provider<String>>
|
||||
@@ -53,20 +63,26 @@ internal abstract class CompilerSystemPropertiesService : BuildService<CompilerS
|
||||
}
|
||||
|
||||
companion object {
|
||||
fun registerIfAbsent(gradle: Gradle): Provider<CompilerSystemPropertiesService> = gradle.sharedServices.registerIfAbsent(
|
||||
fun registerIfAbsent(project: Project): Provider<CompilerSystemPropertiesService> = project.gradle.sharedServices.registerIfAbsent(
|
||||
"${CompilerSystemPropertiesService::class.java.canonicalName}_${CompilerSystemPropertiesService::class.java.classLoader.hashCode()}",
|
||||
CompilerSystemPropertiesService::class.java
|
||||
) { service ->
|
||||
if (isConfigurationCacheAvailable(gradle)) {
|
||||
if (isConfigurationCacheAvailable(project.gradle)) {
|
||||
service.parameters.properties.set(
|
||||
CompilerSystemProperties.values()
|
||||
.filterNot { it.alwaysDirectAccess }
|
||||
.associate {
|
||||
it.property to gradle.rootProject.providers.systemProperty(it.property)
|
||||
.usedAtConfigurationTime(gradle.configurationTimePropertiesAccessor)
|
||||
it.property to project.providers.systemProperty(it.property)
|
||||
.usedAtConfigurationTime(project.configurationTimePropertiesAccessor)
|
||||
}.toMap()
|
||||
)
|
||||
}
|
||||
}.also { serviceProvider ->
|
||||
SingleActionPerProject.run(project, UsesCompilerSystemPropertiesService::class.java.name) {
|
||||
project.tasks.withType<UsesCompilerSystemPropertiesService>().configureEach { task ->
|
||||
task.usesService(serviceProvider)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -382,7 +382,7 @@ internal open class GradleCompilerRunner(
|
||||
project: Project,
|
||||
sourceSetName: String
|
||||
): File? {
|
||||
val sourceSets = project.gradle.variantImplementationFactory<JavaSourceSetsAccessor.JavaSourceSetsAccessorVariantFactory>()
|
||||
val sourceSets = project.variantImplementationFactory<JavaSourceSetsAccessor.JavaSourceSetsAccessorVariantFactory>()
|
||||
.getInstance(project)
|
||||
.sourceSetsIfAvailable ?: return null
|
||||
val sourceSet = sourceSets.findByName(sourceSetName) ?: return null
|
||||
|
||||
+1
-1
@@ -45,7 +45,7 @@ internal fun Project.getKonanCacheKind(target: KonanTarget): NativeCacheKind {
|
||||
return when {
|
||||
targetCacheKind != null -> targetCacheKind
|
||||
commonCacheKind != null -> commonCacheKind
|
||||
else -> KonanPropertiesBuildService.registerIfAbsent(gradle).get().defaultCacheKindForTarget(target)
|
||||
else -> KonanPropertiesBuildService.registerIfAbsent(this).get().defaultCacheKindForTarget(target)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+23
-1
@@ -5,9 +5,15 @@
|
||||
|
||||
package org.jetbrains.kotlin.gradle.incremental
|
||||
|
||||
import org.gradle.api.Project
|
||||
import org.gradle.api.Task
|
||||
import org.gradle.api.provider.Property
|
||||
import org.gradle.api.provider.Provider
|
||||
import org.gradle.api.services.BuildService
|
||||
import org.gradle.api.services.BuildServiceParameters
|
||||
import org.gradle.api.tasks.Internal
|
||||
import org.jetbrains.kotlin.gradle.tasks.withType
|
||||
import org.jetbrains.kotlin.gradle.utils.SingleActionPerProject
|
||||
import org.jetbrains.kotlin.incremental.IncrementalModuleInfo
|
||||
|
||||
/**
|
||||
@@ -18,6 +24,11 @@ interface IncrementalModuleInfoProvider {
|
||||
val info: IncrementalModuleInfo
|
||||
}
|
||||
|
||||
internal interface UsesIncrementalModuleInfoBuildService : Task {
|
||||
@get:Internal
|
||||
val incrementalModuleInfoProvider: Property<IncrementalModuleInfoProvider>
|
||||
}
|
||||
|
||||
/** A build service used to provide [IncrementalModuleInfo] instance for all tasks. */
|
||||
abstract class IncrementalModuleInfoBuildService : BuildService<IncrementalModuleInfoBuildService.Parameters>,
|
||||
IncrementalModuleInfoProvider {
|
||||
@@ -30,9 +41,20 @@ abstract class IncrementalModuleInfoBuildService : BuildService<IncrementalModul
|
||||
|
||||
companion object {
|
||||
// Use class name + class loader in case there are multiple class loaders in the same build
|
||||
fun getServiceName(): String {
|
||||
private fun getServiceName(): String {
|
||||
val clazz = IncrementalModuleInfoBuildService::class.java
|
||||
return clazz.canonicalName + "_" + clazz.classLoader.hashCode()
|
||||
}
|
||||
|
||||
fun registerIfAbsent(project: Project, modulesInfo: Provider<IncrementalModuleInfo>): Provider<IncrementalModuleInfoBuildService> =
|
||||
project.gradle.sharedServices.registerIfAbsent(getServiceName(), IncrementalModuleInfoBuildService::class.java) {
|
||||
it.parameters.info.set(modulesInfo)
|
||||
}.also { serviceProvider ->
|
||||
SingleActionPerProject.run(project, UsesIncrementalModuleInfoBuildService::class.java.name) {
|
||||
project.tasks.withType<UsesIncrementalModuleInfoBuildService>().configureEach { task ->
|
||||
task.usesService(serviceProvider)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+1
-2
@@ -10,7 +10,6 @@ import org.jetbrains.kotlin.gradle.plugin.internal.IdeaSyncDetector
|
||||
import org.jetbrains.kotlin.gradle.plugin.variantImplementationFactory
|
||||
|
||||
internal val Project.isInIdeaSync
|
||||
get() = gradle
|
||||
.variantImplementationFactory<IdeaSyncDetector.IdeaSyncDetectorVariantFactory>()
|
||||
get() = variantImplementationFactory<IdeaSyncDetector.IdeaSyncDetectorVariantFactory>()
|
||||
.getInstance(this)
|
||||
.isInIdeaSync
|
||||
+1
-1
@@ -268,7 +268,7 @@ abstract class KaptTask @Inject constructor(
|
||||
return project
|
||||
.providers
|
||||
.gradleProperty(KAPT_VERBOSE_OPTION_NAME)
|
||||
.usedAtConfigurationTime(project.gradle.configurationTimePropertiesAccessor)
|
||||
.usedAtConfigurationTime(project.configurationTimePropertiesAccessor)
|
||||
.map { it.toString().toBoolean() }
|
||||
.orElse(false)
|
||||
}
|
||||
|
||||
+1
-1
@@ -76,7 +76,7 @@ class KotlinModelBuilder(private val kotlinPluginVersion: String, private val an
|
||||
private fun Project.pathOrName() = if (path == ":") name else path
|
||||
|
||||
private fun AbstractKotlinCompile<*>.createSourceSet(project: Project, projectType: KotlinProject.ProjectType): SourceSet? {
|
||||
val javaSourceSet = project.gradle
|
||||
val javaSourceSet = project
|
||||
.variantImplementationFactory<JavaSourceSetsAccessor.JavaSourceSetsAccessorVariantFactory>()
|
||||
.getInstance(project)
|
||||
.sourceSetsIfAvailable
|
||||
|
||||
+2
-3
@@ -96,7 +96,7 @@ internal abstract class AbstractKotlinPlugin(
|
||||
)
|
||||
inspectTask.classesListFile.disallowChanges()
|
||||
|
||||
val sourceSetClassesDir = project.gradle
|
||||
val sourceSetClassesDir = project
|
||||
.variantImplementationFactory<JavaSourceSetsAccessor.JavaSourceSetsAccessorVariantFactory>()
|
||||
.getInstance(project)
|
||||
.sourceSetsIfAvailable
|
||||
@@ -134,7 +134,7 @@ internal abstract class AbstractKotlinPlugin(
|
||||
}
|
||||
}
|
||||
|
||||
project.gradle
|
||||
project
|
||||
.variantImplementationFactory<MavenPluginConfigurator.MavenPluginConfiguratorVariantFactory>()
|
||||
.getInstance()
|
||||
.applyConfiguration(project, target, shouldRewritePoms)
|
||||
@@ -163,7 +163,6 @@ internal abstract class AbstractKotlinPlugin(
|
||||
) {
|
||||
val project = kotlinTarget.project
|
||||
val javaSourceSets = project
|
||||
.gradle
|
||||
.variantImplementationFactory<JavaSourceSetsAccessor.JavaSourceSetsAccessorVariantFactory>()
|
||||
.getInstance(project)
|
||||
.sourceSets
|
||||
|
||||
+1
-1
@@ -117,7 +117,7 @@ open class KotlinPlatformImplementationPluginBase(platformName: String) : Kotlin
|
||||
addCommonSourceSetToPlatformSourceSet(commonSourceSet, platformProject)
|
||||
|
||||
// Workaround for older versions of Kotlin/Native overriding the old signature
|
||||
commonProject.gradle.variantImplementationFactory<JavaSourceSetsAccessor.JavaSourceSetsAccessorVariantFactory>()
|
||||
commonProject.variantImplementationFactory<JavaSourceSetsAccessor.JavaSourceSetsAccessorVariantFactory>()
|
||||
.getInstance(commonProject)
|
||||
.sourceSetsIfAvailable
|
||||
?.findByName(commonSourceSet.name)
|
||||
|
||||
+1
@@ -127,6 +127,7 @@ abstract class DefaultKotlinBasePlugin : KotlinBasePlugin {
|
||||
}
|
||||
|
||||
private fun Project.registerDefaultVariantImplementations() {
|
||||
@Suppress("DEPRECATION_ERROR")
|
||||
val factories = VariantImplementationFactories.get(project.gradle)
|
||||
factories.putIfAbsent(
|
||||
MavenPluginConfigurator.MavenPluginConfiguratorVariantFactory::class,
|
||||
|
||||
+1
-1
@@ -42,7 +42,7 @@ internal abstract class KotlinSourceSetProcessor<T : AbstractKotlinCompile<*>>(
|
||||
get() = when (val compilation = compilationInfo.safeAs<KotlinCompilationInfo.TCS>()?.origin) {
|
||||
is KotlinWithJavaCompilation<*, *> -> compilation.javaSourceSet
|
||||
is KotlinJvmCompilation -> if (compilation.target.withJavaEnabled) {
|
||||
project.gradle.variantImplementationFactory<JavaSourceSetsAccessor.JavaSourceSetsAccessorVariantFactory>()
|
||||
project.variantImplementationFactory<JavaSourceSetsAccessor.JavaSourceSetsAccessorVariantFactory>()
|
||||
.getInstance(project)
|
||||
.sourceSets
|
||||
.maybeCreate(compilation.name)
|
||||
|
||||
+21
-7
@@ -5,14 +5,19 @@
|
||||
|
||||
package org.jetbrains.kotlin.gradle.plugin
|
||||
|
||||
import org.gradle.api.Project
|
||||
import org.gradle.api.Task
|
||||
import org.gradle.api.invocation.Gradle
|
||||
import org.gradle.api.provider.Provider
|
||||
import org.gradle.api.services.BuildService
|
||||
import org.gradle.api.services.BuildServiceParameters
|
||||
import org.jetbrains.kotlin.gradle.tasks.withType
|
||||
import org.jetbrains.kotlin.gradle.utils.SingleActionPerProject
|
||||
import java.util.concurrent.ConcurrentHashMap
|
||||
import kotlin.reflect.KClass
|
||||
|
||||
internal interface UsesVariantImplementationFactories : Task
|
||||
|
||||
/**
|
||||
* Provides a way for Gradle plugin variants to register specific implementation factories,
|
||||
* that could be used inside common code.
|
||||
@@ -44,7 +49,7 @@ abstract class VariantImplementationFactories : BuildService<BuildServiceParamet
|
||||
interface VariantImplementationFactory
|
||||
|
||||
companion object {
|
||||
fun getProvider(
|
||||
private fun getProvider(
|
||||
gradle: Gradle
|
||||
): Provider<VariantImplementationFactories> {
|
||||
// Use class loader hashcode in case there are multiple class loaders in the same build
|
||||
@@ -55,18 +60,27 @@ abstract class VariantImplementationFactories : BuildService<BuildServiceParamet
|
||||
) {}
|
||||
}
|
||||
|
||||
fun getProvider(
|
||||
project: Project
|
||||
) = getProvider(project.gradle).also { serviceProvider ->
|
||||
SingleActionPerProject.run(project, UsesVariantImplementationFactories::class.java.name) {
|
||||
project.tasks.withType<UsesVariantImplementationFactories>().configureEach { task ->
|
||||
task.usesService(serviceProvider)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Deprecated("Should be used with `Project` instance to be able to declare usages in tasks", level = DeprecationLevel.ERROR)
|
||||
fun get(gradle: Gradle): VariantImplementationFactories = getProvider(gradle).get()
|
||||
|
||||
fun get(project: Project): VariantImplementationFactories = getProvider(project).get()
|
||||
}
|
||||
}
|
||||
|
||||
internal inline fun <reified T : VariantImplementationFactories.VariantImplementationFactory> Gradle.variantImplementationFactory(): T =
|
||||
internal inline fun <reified T : VariantImplementationFactories.VariantImplementationFactory> Project.variantImplementationFactory(): T =
|
||||
VariantImplementationFactories.get(this)[T::class]
|
||||
|
||||
internal fun Task.declareVariantImplementationFactoryUsage() {
|
||||
usesService(VariantImplementationFactories.getProvider(project.gradle))
|
||||
}
|
||||
|
||||
internal inline fun <
|
||||
reified T : VariantImplementationFactories.VariantImplementationFactory
|
||||
> Gradle.variantImplementationFactoryProvider(): Provider<T> =
|
||||
> Project.variantImplementationFactoryProvider(): Provider<T> =
|
||||
VariantImplementationFactories.getProvider(this).map { it[T::class] }
|
||||
|
||||
+3
-4
@@ -5,7 +5,7 @@
|
||||
|
||||
package org.jetbrains.kotlin.gradle.plugin.internal
|
||||
|
||||
import org.gradle.api.invocation.Gradle
|
||||
import org.gradle.api.Project
|
||||
import org.gradle.api.provider.Provider
|
||||
import org.jetbrains.kotlin.gradle.plugin.VariantImplementationFactories
|
||||
import org.jetbrains.kotlin.gradle.plugin.variantImplementationFactory
|
||||
@@ -35,9 +35,8 @@ internal class DefaultConfigurationTimePropertiesAccessor : ConfigurationTimePro
|
||||
override fun <T> Provider<T>.usedAtConfigurationTime(): Provider<T> = this
|
||||
}
|
||||
|
||||
internal val Gradle.configurationTimePropertiesAccessor
|
||||
get() = gradle
|
||||
.variantImplementationFactory<ConfigurationTimePropertiesAccessor.ConfigurationTimePropertiesAccessorVariantFactory>()
|
||||
internal val Project.configurationTimePropertiesAccessor
|
||||
get() = variantImplementationFactory<ConfigurationTimePropertiesAccessor.ConfigurationTimePropertiesAccessorVariantFactory>()
|
||||
.getInstance()
|
||||
|
||||
internal fun <T> Provider<T>.usedAtConfigurationTime(accessor: ConfigurationTimePropertiesAccessor) = with(accessor) {
|
||||
|
||||
+3
-6
@@ -26,8 +26,7 @@ fun Project.currentBuildId(): BuildIdentifier =
|
||||
* The base name to use for archive files.
|
||||
*/
|
||||
val Project.archivesName
|
||||
get() = gradle
|
||||
.variantImplementationFactory<BasePluginConfiguration.BasePluginConfigurationVariantFactory>()
|
||||
get() = variantImplementationFactory<BasePluginConfiguration.BasePluginConfigurationVariantFactory>()
|
||||
.getInstance(this)
|
||||
.archivesName
|
||||
|
||||
@@ -37,8 +36,7 @@ val Project.archivesName
|
||||
* @return The directory. Never returns null.
|
||||
*/
|
||||
val Project.distsDirectory
|
||||
get() = gradle
|
||||
.variantImplementationFactory<BasePluginConfiguration.BasePluginConfigurationVariantFactory>()
|
||||
get() = variantImplementationFactory<BasePluginConfiguration.BasePluginConfigurationVariantFactory>()
|
||||
.getInstance(this)
|
||||
.distsDirectory
|
||||
|
||||
@@ -48,7 +46,6 @@ val Project.distsDirectory
|
||||
* @return The directory. Never returns null.
|
||||
*/
|
||||
val Project.libsDirectory
|
||||
get() = gradle
|
||||
.variantImplementationFactory<BasePluginConfiguration.BasePluginConfigurationVariantFactory>()
|
||||
get() = variantImplementationFactory<BasePluginConfiguration.BasePluginConfigurationVariantFactory>()
|
||||
.getInstance(this)
|
||||
.libsDirectory
|
||||
|
||||
+18
-2
@@ -6,10 +6,13 @@
|
||||
package org.jetbrains.kotlin.gradle.report
|
||||
|
||||
import org.gradle.api.Project
|
||||
import org.gradle.api.Task
|
||||
import org.gradle.api.logging.Logging
|
||||
import org.gradle.api.provider.Property
|
||||
import org.gradle.api.provider.Provider
|
||||
import org.gradle.api.services.BuildService
|
||||
import org.gradle.api.services.BuildServiceParameters
|
||||
import org.gradle.api.tasks.Internal
|
||||
import org.gradle.tooling.events.FailureResult
|
||||
import org.gradle.tooling.events.FinishEvent
|
||||
import org.gradle.tooling.events.OperationCompletionListener
|
||||
@@ -24,12 +27,18 @@ import org.jetbrains.kotlin.build.report.metrics.BuildTime
|
||||
import org.jetbrains.kotlin.gradle.plugin.internal.state.TaskExecutionResults
|
||||
import org.jetbrains.kotlin.gradle.plugin.statistics.KotlinBuildStatsService
|
||||
import org.jetbrains.kotlin.gradle.report.data.BuildOperationRecord
|
||||
import org.jetbrains.kotlin.gradle.utils.isProjectIsolationEnabled
|
||||
import org.jetbrains.kotlin.gradle.tasks.withType
|
||||
import org.jetbrains.kotlin.gradle.utils.SingleActionPerProject
|
||||
import org.jetbrains.kotlin.statistics.metrics.NumericalMetrics
|
||||
import org.jetbrains.kotlin.statistics.metrics.BooleanMetrics
|
||||
import java.util.concurrent.ConcurrentHashMap
|
||||
import java.util.concurrent.ConcurrentLinkedQueue
|
||||
|
||||
internal interface UsesBuildMetricsService : Task {
|
||||
@get:Internal
|
||||
val buildMetricsService: Property<BuildMetricsService?>
|
||||
}
|
||||
|
||||
abstract class BuildMetricsService : BuildService<BuildServiceParameters.None>, OperationCompletionListener {
|
||||
|
||||
private val log = Logging.getLogger(this.javaClass)
|
||||
@@ -127,7 +136,7 @@ abstract class BuildMetricsService : BuildService<BuildServiceParameters.None>,
|
||||
private val serviceClass = BuildMetricsService::class.java
|
||||
private val serviceName = "${serviceClass.name}_${serviceClass.classLoader.hashCode()}"
|
||||
|
||||
fun registerIfAbsent(project: Project): Provider<BuildMetricsService>? {
|
||||
private fun registerIfAbsentImpl(project: Project): Provider<BuildMetricsService>? {
|
||||
// Return early if the service was already registered to avoid the overhead of reading the reporting settings below
|
||||
project.gradle.sharedServices.registrations.findByName(serviceName)?.let {
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
@@ -143,6 +152,13 @@ abstract class BuildMetricsService : BuildService<BuildServiceParameters.None>,
|
||||
return project.gradle.sharedServices.registerIfAbsent(serviceName, serviceClass) {}!!
|
||||
}
|
||||
|
||||
fun registerIfAbsent(project: Project) = registerIfAbsentImpl(project)?.also { serviceProvider ->
|
||||
SingleActionPerProject.run(project, UsesBuildMetricsService::class.java.name) {
|
||||
project.tasks.withType<UsesBuildMetricsService>().configureEach { task ->
|
||||
task.usesService(serviceProvider)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+22
-1
@@ -6,6 +6,7 @@
|
||||
package org.jetbrains.kotlin.gradle.report
|
||||
|
||||
import org.gradle.api.Project
|
||||
import org.gradle.api.Task
|
||||
import org.gradle.api.file.DirectoryProperty
|
||||
import org.gradle.api.invocation.Gradle
|
||||
import org.gradle.api.logging.Logging
|
||||
@@ -14,6 +15,7 @@ import org.gradle.api.provider.Property
|
||||
import org.gradle.api.provider.Provider
|
||||
import org.gradle.api.services.BuildService
|
||||
import org.gradle.api.services.BuildServiceParameters
|
||||
import org.gradle.api.tasks.Internal
|
||||
import org.gradle.tooling.events.FinishEvent
|
||||
import org.gradle.tooling.events.OperationCompletionListener
|
||||
import org.gradle.tooling.events.task.TaskFinishEvent
|
||||
@@ -25,6 +27,8 @@ import org.jetbrains.kotlin.gradle.plugin.stat.CompileStatisticsData
|
||||
import org.jetbrains.kotlin.gradle.plugin.stat.GradleBuildStartParameters
|
||||
import org.jetbrains.kotlin.gradle.plugin.stat.StatTag
|
||||
import org.jetbrains.kotlin.gradle.report.data.BuildExecutionData
|
||||
import org.jetbrains.kotlin.gradle.tasks.withType
|
||||
import org.jetbrains.kotlin.gradle.utils.SingleActionPerProject
|
||||
import org.jetbrains.kotlin.gradle.utils.formatSize
|
||||
import org.jetbrains.kotlin.gradle.utils.isConfigurationCacheAvailable
|
||||
import org.jetbrains.kotlin.utils.addToStdlib.measureTimeMillisWithResult
|
||||
@@ -37,6 +41,11 @@ import java.util.concurrent.Executors
|
||||
import java.util.concurrent.TimeUnit
|
||||
import kotlin.system.measureTimeMillis
|
||||
|
||||
internal interface UsesBuildReportsService : Task {
|
||||
@get:Internal
|
||||
val buildReportsService: Property<BuildReportsService?>
|
||||
}
|
||||
|
||||
abstract class BuildReportsService : BuildService<BuildReportsService.Parameters>, AutoCloseable, OperationCompletionListener {
|
||||
|
||||
private val log = Logging.getLogger(this.javaClass)
|
||||
@@ -301,7 +310,10 @@ abstract class BuildReportsService : BuildService<BuildReportsService.Parameters
|
||||
)
|
||||
}
|
||||
|
||||
fun registerIfAbsent(project: Project, buildMetricsService: Provider<BuildMetricsService>): Provider<BuildReportsService>? {
|
||||
private fun registerIfAbsentImpl(
|
||||
project: Project,
|
||||
buildMetricsService: Provider<BuildMetricsService>
|
||||
): Provider<BuildReportsService>? {
|
||||
val serviceClass = BuildReportsService::class.java
|
||||
val serviceName = "${serviceClass.name}_${serviceClass.classLoader.hashCode()}"
|
||||
|
||||
@@ -346,6 +358,15 @@ abstract class BuildReportsService : BuildService<BuildReportsService.Parameters
|
||||
}
|
||||
}
|
||||
|
||||
fun registerIfAbsent(project: Project, buildMetricsService: Provider<BuildMetricsService>) =
|
||||
registerIfAbsentImpl(project, buildMetricsService)?.also { serviceProvider ->
|
||||
SingleActionPerProject.run(project, UsesBuildReportsService::class.java.name) {
|
||||
project.tasks.withType<UsesBuildReportsService>().configureEach { task ->
|
||||
task.usesService(serviceProvider)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun setupTags(gradle: Gradle): ArrayList<StatTag> {
|
||||
val additionalTags = ArrayList<StatTag>()
|
||||
if (isConfigurationCacheAvailable(gradle)) {
|
||||
|
||||
-1
@@ -56,7 +56,6 @@ class ScriptingGradleSubplugin : Plugin<Project> {
|
||||
|
||||
project.afterEvaluate {
|
||||
val javaSourceSets = project
|
||||
.gradle
|
||||
.variantImplementationFactory<JavaSourceSetsAccessor.JavaSourceSetsAccessorVariantFactory>()
|
||||
.getInstance(project)
|
||||
.sourceSetsIfAvailable
|
||||
|
||||
+51
@@ -0,0 +1,51 @@
|
||||
/*
|
||||
* Copyright 2010-2023 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.gradle.targets.js.internal
|
||||
|
||||
import org.gradle.api.Project
|
||||
import org.gradle.api.Task
|
||||
import org.gradle.api.provider.Property
|
||||
import org.gradle.api.provider.Provider
|
||||
import org.gradle.api.services.BuildService
|
||||
import org.gradle.api.services.BuildServiceParameters
|
||||
import org.gradle.api.tasks.Internal
|
||||
import org.jetbrains.kotlin.gradle.tasks.withType
|
||||
import org.jetbrains.kotlin.gradle.utils.SingleActionPerProject
|
||||
import java.io.File
|
||||
import java.util.concurrent.ConcurrentHashMap
|
||||
|
||||
internal interface UsesLibraryFilterCachingService : Task {
|
||||
@get:Internal
|
||||
val libraryFilterCacheService: Property<LibraryFilterCachingService>
|
||||
}
|
||||
|
||||
internal abstract class LibraryFilterCachingService : BuildService<BuildServiceParameters.None>, AutoCloseable {
|
||||
internal data class LibraryFilterCacheKey(val dependency: File, val irEnabled: Boolean, val preIrDisabled: Boolean)
|
||||
|
||||
private val cache = ConcurrentHashMap<LibraryFilterCacheKey, Boolean>()
|
||||
|
||||
fun getOrCompute(key: LibraryFilterCacheKey, compute: (File) -> Boolean) = cache.computeIfAbsent(key) {
|
||||
compute(it.dependency)
|
||||
}
|
||||
|
||||
override fun close() {
|
||||
cache.clear()
|
||||
}
|
||||
|
||||
companion object {
|
||||
fun registerIfAbsent(project: Project): Provider<LibraryFilterCachingService> =
|
||||
project.rootProject.gradle.sharedServices.registerIfAbsent(
|
||||
"${LibraryFilterCachingService::class.java.canonicalName}_${LibraryFilterCachingService::class.java.classLoader.hashCode()}",
|
||||
LibraryFilterCachingService::class.java
|
||||
) {}.also { serviceProvider ->
|
||||
SingleActionPerProject.run(project, UsesLibraryFilterCachingService::class.java.name) {
|
||||
project.tasks.withType<UsesLibraryFilterCachingService>().configureEach { task ->
|
||||
task.usesService(serviceProvider)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
+2
-5
@@ -30,7 +30,7 @@ import org.jetbrains.kotlin.gradle.plugin.PropertiesProvider
|
||||
import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinJsCompilation
|
||||
import org.jetbrains.kotlin.gradle.plugin.mpp.pm20.util.archivesName
|
||||
import org.jetbrains.kotlin.gradle.plugin.mpp.pm20.util.distsDirectory
|
||||
import org.jetbrains.kotlin.gradle.report.BuildMetricsService
|
||||
import org.jetbrains.kotlin.gradle.report.UsesBuildMetricsService
|
||||
import org.jetbrains.kotlin.gradle.targets.js.RequiredKotlinJsDependency
|
||||
import org.jetbrains.kotlin.gradle.targets.js.dsl.KotlinWebpackRulesContainer
|
||||
import org.jetbrains.kotlin.gradle.targets.js.dsl.WebpackRulesDsl
|
||||
@@ -53,7 +53,7 @@ constructor(
|
||||
@Transient
|
||||
override val compilation: KotlinJsCompilation,
|
||||
private val objects: ObjectFactory
|
||||
) : DefaultTask(), RequiresNpmDependencies, WebpackRulesDsl {
|
||||
) : DefaultTask(), RequiresNpmDependencies, WebpackRulesDsl, UsesBuildMetricsService {
|
||||
@Transient
|
||||
private val nodeJs = NodeJsRootPlugin.apply(project.rootProject)
|
||||
private val versions = nodeJs.versions
|
||||
@@ -69,9 +69,6 @@ constructor(
|
||||
open val execHandleFactory: ExecHandleFactory
|
||||
get() = injected
|
||||
|
||||
@get:Internal
|
||||
internal abstract val buildMetricsService: Property<BuildMetricsService?>
|
||||
|
||||
private val metrics: Property<BuildMetricsReporter> = project.objects
|
||||
.property(BuildMetricsReporterImpl())
|
||||
|
||||
|
||||
+1
-1
@@ -45,7 +45,7 @@ open class KotlinJvmCompilation @Inject internal constructor(
|
||||
val compileJavaTaskProvider: TaskProvider<out JavaCompile>?
|
||||
get() = if (target.withJavaEnabled) {
|
||||
val project = target.project
|
||||
val javaSourceSets = project.gradle.variantImplementationFactory<JavaSourceSetsAccessor.JavaSourceSetsAccessorVariantFactory>()
|
||||
val javaSourceSets = project.variantImplementationFactory<JavaSourceSetsAccessor.JavaSourceSetsAccessorVariantFactory>()
|
||||
.getInstance(project)
|
||||
.sourceSets
|
||||
val javaSourceSet = javaSourceSets.getByName(compilationName)
|
||||
|
||||
+1
-1
@@ -58,7 +58,7 @@ abstract class KotlinJvmTarget @Inject constructor(
|
||||
withJavaEnabled = true
|
||||
|
||||
project.plugins.apply(JavaPlugin::class.java)
|
||||
val javaSourceSets = project.gradle.variantImplementationFactory<JavaSourceSetsAccessor.JavaSourceSetsAccessorVariantFactory>()
|
||||
val javaSourceSets = project.variantImplementationFactory<JavaSourceSetsAccessor.JavaSourceSetsAccessorVariantFactory>()
|
||||
.getInstance(project)
|
||||
.sourceSets
|
||||
AbstractKotlinPlugin.setUpJavaSourceSets(this, duplicateJavaSourceSetsAsKotlinSourceSets = false)
|
||||
|
||||
+1
-2
@@ -66,7 +66,6 @@ abstract class KotlinWithJavaTarget<KotlinOptionsType : KotlinCommonOptions, CO
|
||||
private fun sanitizeFileName(candidate: String): String = candidate.filter { it.isLetterOrDigit() }
|
||||
|
||||
internal val Project.javaSourceSets: SourceSetContainer
|
||||
get() = gradle
|
||||
.variantImplementationFactory<JavaSourceSetsAccessor.JavaSourceSetsAccessorVariantFactory>()
|
||||
get() = variantImplementationFactory<JavaSourceSetsAccessor.JavaSourceSetsAccessorVariantFactory>()
|
||||
.getInstance(project)
|
||||
.sourceSets
|
||||
+3
-2
@@ -10,16 +10,17 @@ import org.gradle.api.tasks.CacheableTask
|
||||
import org.gradle.api.tasks.Input
|
||||
import org.gradle.api.tasks.Optional
|
||||
import org.gradle.api.tasks.testing.Test
|
||||
import org.jetbrains.kotlin.gradle.plugin.UsesVariantImplementationFactories
|
||||
import org.jetbrains.kotlin.gradle.plugin.internal.MppTestReportHelper
|
||||
import org.jetbrains.kotlin.gradle.plugin.variantImplementationFactory
|
||||
|
||||
@CacheableTask
|
||||
open class KotlinJvmTest : Test() {
|
||||
open class KotlinJvmTest : Test(), UsesVariantImplementationFactories {
|
||||
@Input
|
||||
@Optional
|
||||
var targetName: String? = null
|
||||
|
||||
private val testReporter = project.gradle
|
||||
private val testReporter = project
|
||||
.variantImplementationFactory<MppTestReportHelper.MppTestReportHelperVariantFactory>()
|
||||
.getInstance()
|
||||
|
||||
|
||||
+19
-4
@@ -5,19 +5,28 @@
|
||||
|
||||
package org.jetbrains.kotlin.gradle.targets.native
|
||||
|
||||
import org.gradle.api.invocation.Gradle
|
||||
import org.gradle.api.Project
|
||||
import org.gradle.api.Task
|
||||
import org.gradle.api.provider.Property
|
||||
import org.gradle.api.provider.Provider
|
||||
import org.gradle.api.services.BuildService
|
||||
import org.gradle.api.services.BuildServiceParameters
|
||||
import org.gradle.api.tasks.Internal
|
||||
import org.jetbrains.kotlin.compilerRunner.konanHome
|
||||
import org.jetbrains.kotlin.gradle.dsl.NativeCacheKind
|
||||
import org.jetbrains.kotlin.gradle.tasks.withType
|
||||
import org.jetbrains.kotlin.gradle.utils.SingleActionPerProject
|
||||
import org.jetbrains.kotlin.konan.properties.resolvablePropertyList
|
||||
import org.jetbrains.kotlin.konan.target.Distribution
|
||||
import org.jetbrains.kotlin.konan.target.HostManager
|
||||
import org.jetbrains.kotlin.konan.target.KonanTarget
|
||||
import java.util.*
|
||||
|
||||
internal interface UsesKonanPropertiesBuildService : Task {
|
||||
@get:Internal
|
||||
val konanPropertiesService: Property<KonanPropertiesBuildService>
|
||||
}
|
||||
|
||||
abstract class KonanPropertiesBuildService : BuildService<KonanPropertiesBuildService.Parameters> {
|
||||
|
||||
internal interface Parameters : BuildServiceParameters {
|
||||
@@ -58,9 +67,15 @@ abstract class KonanPropertiesBuildService : BuildService<KonanPropertiesBuildSe
|
||||
}
|
||||
|
||||
companion object {
|
||||
fun registerIfAbsent(gradle: Gradle): Provider<KonanPropertiesBuildService> =
|
||||
gradle.sharedServices.registerIfAbsent(serviceName, KonanPropertiesBuildService::class.java) { service ->
|
||||
service.parameters.konanHome.set(gradle.rootProject.konanHome)
|
||||
fun registerIfAbsent(project: Project): Provider<KonanPropertiesBuildService> =
|
||||
project.gradle.sharedServices.registerIfAbsent(serviceName, KonanPropertiesBuildService::class.java) { service ->
|
||||
service.parameters.konanHome.set(project.rootProject.konanHome)
|
||||
}.also { serviceProvider ->
|
||||
SingleActionPerProject.run(project, UsesKonanPropertiesBuildService::class.java.name) {
|
||||
project.tasks.withType<UsesKonanPropertiesBuildService>().configureEach { task ->
|
||||
task.usesService(serviceProvider)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private val serviceName: String
|
||||
|
||||
+1
-1
@@ -60,6 +60,7 @@ open class KotlinNativeTargetConfigurator<T : KotlinNativeTarget> : AbstractKotl
|
||||
// which leads to not able run project.afterEvaluate because of wrong context
|
||||
// this afterEvaluate comes from NativeCompilerOptions
|
||||
val compilationCompilerOptions = binary.compilation.compilerOptions
|
||||
val konanPropertiesBuildService = KonanPropertiesBuildService.registerIfAbsent(project)
|
||||
val result = registerTask<KotlinNativeLink>(
|
||||
binary.linkTaskName, listOf(binary)
|
||||
) {
|
||||
@@ -67,7 +68,6 @@ open class KotlinNativeTargetConfigurator<T : KotlinNativeTarget> : AbstractKotl
|
||||
it.group = BasePlugin.BUILD_GROUP
|
||||
it.description = "Links ${binary.outputKind.description} '${binary.name}' for a target '${target.name}'."
|
||||
it.enabled = binary.konanTarget.enabledOnCurrentHost
|
||||
val konanPropertiesBuildService = KonanPropertiesBuildService.registerIfAbsent(project.gradle)
|
||||
it.konanPropertiesService.set(konanPropertiesBuildService)
|
||||
it.usesService(konanPropertiesBuildService)
|
||||
it.toolOptions.freeCompilerArgs.convention(
|
||||
|
||||
+1
-1
@@ -37,7 +37,7 @@ internal class PlatformLibrariesGenerator(val project: Project, val konanTarget:
|
||||
File(distribution.platformDefs(konanTarget)).absoluteFile
|
||||
|
||||
private val konanPropertiesService: KonanPropertiesBuildService
|
||||
get() = KonanPropertiesBuildService.registerIfAbsent(project.gradle).get()
|
||||
get() = KonanPropertiesBuildService.registerIfAbsent(project).get()
|
||||
|
||||
private val konanCacheKind: NativeCacheKind by lazy {
|
||||
project.getKonanCacheKind(konanTarget)
|
||||
|
||||
+2
-4
@@ -26,7 +26,7 @@ import org.jetbrains.kotlin.gradle.dsl.*
|
||||
import org.jetbrains.kotlin.gradle.plugin.PropertiesProvider
|
||||
import org.jetbrains.kotlin.gradle.plugin.cocoapods.asValidFrameworkName
|
||||
import org.jetbrains.kotlin.gradle.plugin.mpp.*
|
||||
import org.jetbrains.kotlin.gradle.targets.native.KonanPropertiesBuildService
|
||||
import org.jetbrains.kotlin.gradle.targets.native.UsesKonanPropertiesBuildService
|
||||
import org.jetbrains.kotlin.gradle.targets.native.tasks.CompilerPluginData
|
||||
import org.jetbrains.kotlin.gradle.targets.native.tasks.buildKotlinNativeBinaryLinkerArgs
|
||||
import org.jetbrains.kotlin.gradle.utils.*
|
||||
@@ -48,6 +48,7 @@ constructor(
|
||||
private val objectFactory: ObjectFactory,
|
||||
private val execOperations: ExecOperations
|
||||
) : AbstractKotlinCompileTool<StubK2NativeCompilerArguments>(objectFactory),
|
||||
UsesKonanPropertiesBuildService,
|
||||
KotlinToolTask<KotlinCommonCompilerToolOptions> {
|
||||
@Deprecated("Visibility will be lifted to private in the future releases")
|
||||
@get:Internal
|
||||
@@ -241,9 +242,6 @@ constructor(
|
||||
}
|
||||
}
|
||||
|
||||
@get:Internal
|
||||
internal abstract val konanPropertiesService: Property<KonanPropertiesBuildService>
|
||||
|
||||
@Suppress("DEPRECATION")
|
||||
@get:Classpath
|
||||
protected val friendModule: FileCollection = objectFactory.fileCollection().from({ compilation.friendPaths })
|
||||
|
||||
+1
-1
@@ -519,7 +519,7 @@ internal class ExternalDependenciesBuilder(
|
||||
intermediateLibraryName?.let { KResolvedDependencyId(it) } ?: KResolvedDependencyId.DEFAULT_SOURCE_CODE_MODULE_ID
|
||||
|
||||
private val konanPropertiesService: KonanPropertiesBuildService
|
||||
get() = KonanPropertiesBuildService.registerIfAbsent(project.gradle).get()
|
||||
get() = KonanPropertiesBuildService.registerIfAbsent(project).get()
|
||||
|
||||
fun buildCompilerArgs(): List<String> {
|
||||
val compilerVersion = Distribution.getCompilerVersion(konanPropertiesService.compilerVersion, project.konanHome)
|
||||
|
||||
+3
-2
@@ -15,12 +15,13 @@ import org.gradle.process.internal.ExecHandleFactory
|
||||
import org.jetbrains.kotlin.gradle.internal.testing.KotlinTestRunnerListener
|
||||
import org.jetbrains.kotlin.gradle.internal.testing.TCServiceMessagesTestExecutor
|
||||
import org.jetbrains.kotlin.gradle.plugin.PropertiesProvider
|
||||
import org.jetbrains.kotlin.gradle.plugin.UsesVariantImplementationFactories
|
||||
import org.jetbrains.kotlin.gradle.plugin.internal.MppTestReportHelper
|
||||
import org.jetbrains.kotlin.gradle.plugin.variantImplementationFactory
|
||||
import org.jetbrains.kotlin.gradle.utils.injected
|
||||
import javax.inject.Inject
|
||||
|
||||
abstract class KotlinTest : AbstractTestTask() {
|
||||
abstract class KotlinTest : AbstractTestTask(), UsesVariantImplementationFactories {
|
||||
@Input
|
||||
@Optional
|
||||
var targetName: String? = null
|
||||
@@ -64,7 +65,7 @@ abstract class KotlinTest : AbstractTestTask() {
|
||||
PropertiesProvider(project).ignoreTcsmOverflow
|
||||
}
|
||||
|
||||
private val testReporter = project.gradle
|
||||
private val testReporter = project
|
||||
.variantImplementationFactory<MppTestReportHelper.MppTestReportHelperVariantFactory>()
|
||||
.getInstance()
|
||||
|
||||
|
||||
+15
-54
@@ -52,10 +52,9 @@ import org.jetbrains.kotlin.gradle.logging.kotlinDebug
|
||||
import org.jetbrains.kotlin.gradle.plugin.*
|
||||
import org.jetbrains.kotlin.gradle.plugin.mpp.*
|
||||
import org.jetbrains.kotlin.gradle.plugin.statistics.KotlinBuildStatsService
|
||||
import org.jetbrains.kotlin.gradle.report.BuildMetricsService
|
||||
import org.jetbrains.kotlin.gradle.report.BuildReportMode
|
||||
import org.jetbrains.kotlin.gradle.report.BuildReportsService
|
||||
import org.jetbrains.kotlin.gradle.report.ReportingSettings
|
||||
import org.jetbrains.kotlin.gradle.report.*
|
||||
import org.jetbrains.kotlin.gradle.targets.js.internal.LibraryFilterCachingService
|
||||
import org.jetbrains.kotlin.gradle.targets.js.internal.UsesLibraryFilterCachingService
|
||||
import org.jetbrains.kotlin.gradle.tasks.internal.KotlinJvmOptionsCompat
|
||||
import org.jetbrains.kotlin.gradle.targets.js.ir.*
|
||||
import org.jetbrains.kotlin.gradle.targets.js.ir.DISABLE_PRE_IR
|
||||
@@ -188,7 +187,8 @@ abstract class GradleCompileTaskProvider @Inject constructor(
|
||||
projectLayout: ProjectLayout,
|
||||
gradle: Gradle,
|
||||
task: Task,
|
||||
project: Project
|
||||
project: Project,
|
||||
incrementalModuleInfoProvider: Provider<IncrementalModuleInfoProvider>
|
||||
) {
|
||||
|
||||
@get:Internal
|
||||
@@ -217,26 +217,8 @@ abstract class GradleCompileTaskProvider @Inject constructor(
|
||||
.property(project.rootProject.name.normalizeForFlagFile())
|
||||
|
||||
@get:Internal
|
||||
val buildModulesInfo: Provider<out IncrementalModuleInfoProvider> = objectFactory.property(
|
||||
/**
|
||||
* See https://youtrack.jetbrains.com/issue/KT-46820. Build service that holds the incremental info may
|
||||
* be instantiated during execution phase and there could be multiple threads trying to do that. Because the
|
||||
* underlying mechanism does not support multi-threaded access, we need to add external synchronization.
|
||||
*/
|
||||
synchronized(gradle.sharedServices) {
|
||||
gradle.sharedServices.registerIfAbsent(
|
||||
IncrementalModuleInfoBuildService.getServiceName(), IncrementalModuleInfoBuildService::class.java
|
||||
) {
|
||||
it.parameters.info.set(
|
||||
objectFactory.providerWithLazyConvention {
|
||||
GradleCompilerRunner.buildModulesInfo(gradle)
|
||||
}
|
||||
)
|
||||
}.also {
|
||||
task.usesService(it)
|
||||
}
|
||||
}
|
||||
)
|
||||
val buildModulesInfo: Provider<out IncrementalModuleInfoProvider> = objectFactory
|
||||
.property(incrementalModuleInfoProvider)
|
||||
|
||||
@get:Internal
|
||||
val errorsFile: Provider<File?> = objectFactory
|
||||
@@ -250,6 +232,11 @@ abstract class AbstractKotlinCompile<T : CommonCompilerArguments> @Inject constr
|
||||
workerExecutor: WorkerExecutor
|
||||
) : AbstractKotlinCompileTool<T>(objectFactory),
|
||||
CompileUsingKotlinDaemonWithNormalization,
|
||||
UsesBuildMetricsService,
|
||||
UsesBuildReportsService,
|
||||
UsesIncrementalModuleInfoBuildService,
|
||||
UsesCompilerSystemPropertiesService,
|
||||
UsesVariantImplementationFactories,
|
||||
BaseKotlinCompile {
|
||||
|
||||
init {
|
||||
@@ -292,12 +279,6 @@ abstract class AbstractKotlinCompile<T : CommonCompilerArguments> @Inject constr
|
||||
@get:Input
|
||||
abstract val ownModuleName: Property<String>
|
||||
|
||||
@get:Internal
|
||||
internal abstract val buildMetricsService: Property<BuildMetricsService?>
|
||||
|
||||
@get:Internal
|
||||
internal abstract val buildReportsService: Property<BuildReportsService?>
|
||||
|
||||
@get:Internal
|
||||
val startParameters = BuildReportsService.getStartParameters(project)
|
||||
|
||||
@@ -346,7 +327,7 @@ abstract class AbstractKotlinCompile<T : CommonCompilerArguments> @Inject constr
|
||||
@get:Internal
|
||||
protected val gradleCompileTaskProvider: Provider<GradleCompileTaskProvider> = objectFactory
|
||||
.property(
|
||||
objectFactory.newInstance<GradleCompileTaskProvider>(project.gradle, this, project)
|
||||
objectFactory.newInstance<GradleCompileTaskProvider>(project.gradle, this, project, incrementalModuleInfoProvider)
|
||||
)
|
||||
|
||||
@get:Internal
|
||||
@@ -381,10 +362,6 @@ abstract class AbstractKotlinCompile<T : CommonCompilerArguments> @Inject constr
|
||||
}
|
||||
)
|
||||
|
||||
private val systemPropertiesService = CompilerSystemPropertiesService.registerIfAbsent(project.gradle).also {
|
||||
usesService(it)
|
||||
}
|
||||
|
||||
@get:Internal
|
||||
internal abstract val preciseCompilationResultsBackup: Property<Boolean>
|
||||
|
||||
@@ -936,6 +913,7 @@ abstract class Kotlin2JsCompile @Inject constructor(
|
||||
workerExecutor: WorkerExecutor
|
||||
) : AbstractKotlinCompile<K2JSCompilerArguments>(objectFactory, workerExecutor),
|
||||
KotlinCompilationTask<KotlinJsCompilerOptions>,
|
||||
UsesLibraryFilterCachingService,
|
||||
KotlinJsCompile {
|
||||
|
||||
init {
|
||||
@@ -943,20 +921,6 @@ abstract class Kotlin2JsCompile @Inject constructor(
|
||||
compilerOptions.verbose.convention(logger.isDebugEnabled)
|
||||
}
|
||||
|
||||
internal abstract class LibraryFilterCachingService : BuildService<BuildServiceParameters.None>, AutoCloseable {
|
||||
internal data class LibraryFilterCacheKey(val dependency: File, val irEnabled: Boolean, val preIrDisabled: Boolean)
|
||||
|
||||
private val cache = ConcurrentHashMap<LibraryFilterCacheKey, Boolean>()
|
||||
|
||||
fun getOrCompute(key: LibraryFilterCacheKey, compute: (File) -> Boolean) = cache.computeIfAbsent(key) {
|
||||
compute(it.dependency)
|
||||
}
|
||||
|
||||
override fun close() {
|
||||
cache.clear()
|
||||
}
|
||||
}
|
||||
|
||||
override val kotlinOptions: KotlinJsOptions = KotlinJsOptionsCompat(
|
||||
{ this },
|
||||
compilerOptions
|
||||
@@ -1115,9 +1079,6 @@ abstract class Kotlin2JsCompile @Inject constructor(
|
||||
JsLibraryUtils::isKotlinJavascriptLibrary
|
||||
}
|
||||
|
||||
@get:Internal
|
||||
internal abstract val libraryCache: Property<LibraryFilterCachingService>
|
||||
|
||||
@get:Input
|
||||
internal val jsLegacyNoWarn: Provider<Boolean> = objectFactory.property(
|
||||
PropertiesProvider(project).jsCompilerNoWarn
|
||||
@@ -1126,7 +1087,7 @@ abstract class Kotlin2JsCompile @Inject constructor(
|
||||
@get:Internal
|
||||
protected val libraryFilter: (File) -> Boolean
|
||||
get() = { file ->
|
||||
libraryCache.get().getOrCompute(file.asLibraryFilterCacheKey, libraryFilterBody)
|
||||
libraryFilterCacheService.get().getOrCompute(file.asLibraryFilterCacheKey, libraryFilterBody)
|
||||
}
|
||||
|
||||
override val incrementalProps: List<FileCollection>
|
||||
|
||||
+18
-7
@@ -12,8 +12,12 @@ import org.gradle.api.model.ObjectFactory
|
||||
import org.gradle.api.provider.Provider
|
||||
import org.gradle.api.provider.ProviderFactory
|
||||
import org.gradle.api.tasks.TaskProvider
|
||||
import org.jetbrains.kotlin.compilerRunner.CompilerSystemPropertiesService
|
||||
import org.jetbrains.kotlin.compilerRunner.GradleCompilerRunner
|
||||
import org.jetbrains.kotlin.gradle.dsl.KotlinTopLevelExtension
|
||||
import org.jetbrains.kotlin.gradle.dsl.topLevelExtension
|
||||
import org.jetbrains.kotlin.gradle.incremental.IncrementalModuleInfoBuildService
|
||||
import org.jetbrains.kotlin.gradle.incremental.IncrementalModuleInfoProvider
|
||||
import org.jetbrains.kotlin.gradle.plugin.*
|
||||
import org.jetbrains.kotlin.gradle.plugin.PropertiesProvider.Companion.kotlinPropertiesProvider
|
||||
import org.jetbrains.kotlin.gradle.plugin.mpp.associateWithClosure
|
||||
@@ -23,6 +27,7 @@ import org.jetbrains.kotlin.gradle.report.BuildMetricsService
|
||||
import org.jetbrains.kotlin.gradle.report.BuildReportsService
|
||||
import org.jetbrains.kotlin.gradle.tasks.AbstractKotlinCompile
|
||||
import org.jetbrains.kotlin.gradle.tasks.KOTLIN_BUILD_DIR_NAME
|
||||
import org.jetbrains.kotlin.gradle.utils.providerWithLazyConvention
|
||||
import org.jetbrains.kotlin.project.model.LanguageSettings
|
||||
|
||||
/**
|
||||
@@ -48,6 +53,13 @@ internal abstract class AbstractKotlinCompileConfig<TASK : AbstractKotlinCompile
|
||||
}
|
||||
}
|
||||
|
||||
val compilerSystemPropertiesService = CompilerSystemPropertiesService.registerIfAbsent(project)
|
||||
val buildMetricsService = BuildMetricsService.registerIfAbsent(project)
|
||||
val buildReportsService = buildMetricsService?.let { BuildReportsService.registerIfAbsent(project, buildMetricsService) }
|
||||
val incrementalModuleInfoProvider =
|
||||
IncrementalModuleInfoBuildService.registerIfAbsent(project, objectFactory.providerWithLazyConvention {
|
||||
GradleCompilerRunner.buildModulesInfo(project.gradle)
|
||||
})
|
||||
configureTask { task ->
|
||||
val propertiesProvider = project.kotlinPropertiesProvider
|
||||
|
||||
@@ -59,14 +71,14 @@ internal abstract class AbstractKotlinCompileConfig<TASK : AbstractKotlinCompile
|
||||
.disallowChanges()
|
||||
|
||||
task.localStateDirectories.from(task.taskBuildLocalStateDirectory).disallowChanges()
|
||||
BuildMetricsService.registerIfAbsent(project)?.also { metricsService ->
|
||||
task.buildMetricsService.value(metricsService)
|
||||
task.usesService(metricsService)
|
||||
BuildReportsService.registerIfAbsent(project, metricsService)?.also { reportsService ->
|
||||
task.buildReportsService.value(reportsService)
|
||||
task.usesService(reportsService)
|
||||
buildMetricsService?.also { metricsService ->
|
||||
task.buildMetricsService.value(metricsService).disallowChanges()
|
||||
buildReportsService?.also { reportsService ->
|
||||
task.buildReportsService.value(reportsService).disallowChanges()
|
||||
}
|
||||
}
|
||||
task.systemPropertiesService.value(compilerSystemPropertiesService).disallowChanges()
|
||||
task.incrementalModuleInfoProvider.value(incrementalModuleInfoProvider).disallowChanges()
|
||||
|
||||
propertiesProvider.kotlinDaemonJvmArgs?.let { kotlinDaemonJvmArgs ->
|
||||
task.kotlinDaemonJvmArguments.set(providers.provider {
|
||||
@@ -112,7 +124,6 @@ internal abstract class AbstractKotlinCompileConfig<TASK : AbstractKotlinCompile
|
||||
compilation.internal.configurations.pluginConfiguration
|
||||
)
|
||||
}
|
||||
task.declareVariantImplementationFactoryUsage()
|
||||
task.moduleName.set(providers.provider { compilationInfo.moduleName })
|
||||
@Suppress("DEPRECATION")
|
||||
task.ownModuleName.set(project.provider { compilationInfo.moduleName })
|
||||
|
||||
+3
-8
@@ -6,9 +6,9 @@
|
||||
package org.jetbrains.kotlin.gradle.tasks.configuration
|
||||
|
||||
import org.jetbrains.kotlin.gradle.plugin.KotlinCompilationInfo
|
||||
import org.jetbrains.kotlin.gradle.targets.js.internal.LibraryFilterCachingService
|
||||
import org.jetbrains.kotlin.gradle.targets.js.ir.*
|
||||
import org.jetbrains.kotlin.gradle.tasks.Kotlin2JsCompile
|
||||
import org.jetbrains.kotlin.gradle.utils.chainedDisallowChanges
|
||||
import org.jetbrains.kotlin.gradle.utils.klibModuleName
|
||||
import java.io.File
|
||||
|
||||
@@ -19,10 +19,7 @@ internal open class BaseKotlin2JsCompileConfig<TASK : Kotlin2JsCompile>(
|
||||
) : AbstractKotlinCompileConfig<TASK>(compilation) {
|
||||
|
||||
init {
|
||||
val libraryCacheService = project.rootProject.gradle.sharedServices.registerIfAbsent(
|
||||
"${Kotlin2JsCompile.LibraryFilterCachingService::class.java.canonicalName}_${Kotlin2JsCompile.LibraryFilterCachingService::class.java.classLoader.hashCode()}",
|
||||
Kotlin2JsCompile.LibraryFilterCachingService::class.java
|
||||
) {}
|
||||
val libraryFilterCachingService = LibraryFilterCachingService.registerIfAbsent(project)
|
||||
|
||||
configureTask { task ->
|
||||
task.incremental = propertiesProvider.incrementalJs ?: true
|
||||
@@ -68,9 +65,7 @@ internal open class BaseKotlin2JsCompileConfig<TASK : Kotlin2JsCompile>(
|
||||
)
|
||||
)
|
||||
|
||||
task.libraryCache.value(libraryCacheService).chainedDisallowChanges().also {
|
||||
task.usesService(libraryCacheService)
|
||||
}
|
||||
task.libraryFilterCacheService.value(libraryFilterCachingService).disallowChanges()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+1
-3
@@ -44,7 +44,7 @@ import org.jetbrains.kotlin.gradle.utils.toUri
|
||||
* In this case, only topmost aggregate test task will override reporting,
|
||||
* event if child tasks will be executed.
|
||||
*/
|
||||
abstract class KotlinTestReport : TestReport() {
|
||||
abstract class KotlinTestReport : TestReport(), UsesTestReportService {
|
||||
@Transient
|
||||
@Internal
|
||||
val testTasks = mutableListOf<AbstractTestTask>()
|
||||
@@ -70,8 +70,6 @@ abstract class KotlinTestReport : TestReport() {
|
||||
@Input
|
||||
var ignoreFailures: Boolean = false
|
||||
|
||||
@get:Internal
|
||||
internal abstract val testReportServiceProvider: Property<TestReportService>
|
||||
private val testReportService
|
||||
get() = testReportServiceProvider.get()
|
||||
|
||||
|
||||
+1
-2
@@ -87,7 +87,7 @@ class KotlinTestsRegistry(val project: Project, val allTestsTaskName: String = "
|
||||
aggregate.description = description
|
||||
aggregate.group = JavaBasePlugin.VERIFICATION_GROUP
|
||||
|
||||
val compatibilityHelper = project.gradle
|
||||
val compatibilityHelper = project
|
||||
.variantImplementationFactory<KotlinTestReportCompatibilityHelper.KotlinTestReportCompatibilityHelperVariantFactory>()
|
||||
.getInstance(project.objects)
|
||||
|
||||
@@ -99,7 +99,6 @@ class KotlinTestsRegistry(val project: Project, val allTestsTaskName: String = "
|
||||
aggregate.extensions.extraProperties.set("idea.internal.test", true)
|
||||
}
|
||||
aggregate.htmlReportFile.value(compatibilityHelper.getDestinationDirectory(aggregate).file("index.html")).disallowChanges()
|
||||
aggregate.usesService(testReportService)
|
||||
aggregate.testReportServiceProvider.value(testReportService).finalizeValueOnRead()
|
||||
aggregate.testReportCompatibilityHelper.value(compatibilityHelper).finalizeValueOnRead()
|
||||
|
||||
|
||||
+18
-3
@@ -6,16 +6,26 @@
|
||||
package org.jetbrains.kotlin.gradle.testing.internal
|
||||
|
||||
import org.gradle.api.Project
|
||||
import org.gradle.api.Task
|
||||
import org.gradle.api.file.RegularFileProperty
|
||||
import org.gradle.api.logging.Logging
|
||||
import org.gradle.api.provider.Property
|
||||
import org.gradle.api.provider.Provider
|
||||
import org.gradle.api.services.BuildService
|
||||
import org.gradle.api.services.BuildServiceParameters
|
||||
import org.gradle.api.tasks.Internal
|
||||
import org.jetbrains.kotlin.gradle.tasks.withType
|
||||
import org.jetbrains.kotlin.gradle.utils.SingleActionPerProject
|
||||
import java.io.*
|
||||
import java.util.concurrent.ConcurrentHashMap
|
||||
|
||||
internal typealias TaskError = Pair<String, Error>
|
||||
|
||||
internal interface UsesTestReportService : Task {
|
||||
@get:Internal
|
||||
val testReportServiceProvider: Property<TestReportService>
|
||||
}
|
||||
|
||||
/**
|
||||
* A build service required for correct test failures detection in [KotlinTestReport] as it requires cross-task interaction.
|
||||
*/
|
||||
@@ -101,14 +111,19 @@ internal abstract class TestReportService : BuildService<TestReportService.TestR
|
||||
}
|
||||
|
||||
companion object {
|
||||
fun registerIfAbsent(project: Project): Provider<TestReportService> {
|
||||
return project.gradle.sharedServices
|
||||
fun registerIfAbsent(project: Project): Provider<TestReportService> =
|
||||
project.gradle.sharedServices
|
||||
.registerIfAbsent(
|
||||
"${TestReportService::class.java.canonicalName}_${project.path}",
|
||||
TestReportService::class.java
|
||||
) { spec ->
|
||||
spec.parameters.testTasksStateFile.set(project.buildDir.resolve("test-results/kotlin-test-tasks-state.bin"))
|
||||
}.also { serviceProvider ->
|
||||
SingleActionPerProject.run(project, UsesTestReportService::class.java.name) {
|
||||
project.tasks.withType<UsesTestReportService>().configureEach { task ->
|
||||
task.usesService(serviceProvider)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -29,7 +29,7 @@ internal fun isConfigurationCacheAvailable(gradle: Gradle) =
|
||||
} ?: false
|
||||
|
||||
internal fun Project.readSystemPropertyAtConfigurationTime(key: String): Provider<String> {
|
||||
return providers.systemProperty(key).usedAtConfigurationTime(gradle.configurationTimePropertiesAccessor)
|
||||
return providers.systemProperty(key).usedAtConfigurationTime(configurationTimePropertiesAccessor)
|
||||
}
|
||||
|
||||
internal fun unavailableValueError(propertyName: String): Nothing =
|
||||
|
||||
+1
-1
@@ -82,7 +82,7 @@ private fun Project.syncExceptionsAreNotEmpty(): Boolean {
|
||||
private val Project.providerModeSystemPropertyValue: Provider<String>
|
||||
get() = providers
|
||||
.systemProperty(KotlinDslModelsParameters.PROVIDER_MODE_SYSTEM_PROPERTY_NAME)
|
||||
.usedAtConfigurationTime(gradle.configurationTimePropertiesAccessor)
|
||||
.usedAtConfigurationTime(configurationTimePropertiesAccessor)
|
||||
|
||||
private fun Project.inLenientMode() =
|
||||
providerModeSystemPropertyValue.orNull == KotlinDslModelsParameters.CLASSPATH_MODE_SYSTEM_PROPERTY_VALUE
|
||||
|
||||
+1
@@ -15,6 +15,7 @@ import org.jetbrains.kotlin.gradle.plugin.internal.DefaultConfigurationTimePrope
|
||||
* This helper function is for simple tests that are testing granular logic without applying Kotlin plugin
|
||||
*/
|
||||
fun Gradle.registerConfigurationTimePropertiesAccessorForTests() {
|
||||
@Suppress("DEPRECATION_ERROR")
|
||||
VariantImplementationFactories.get(gradle).putIfAbsent(
|
||||
ConfigurationTimePropertiesAccessor.ConfigurationTimePropertiesAccessorVariantFactory::class,
|
||||
DefaultConfigurationTimePropertiesAccessorVariantFactory()
|
||||
|
||||
+1
@@ -136,6 +136,7 @@ open class KotlinPlatformCommonPlugin : KotlinPlatformPluginBase("common") {
|
||||
}
|
||||
|
||||
private fun Project.registerVariantImplementations() {
|
||||
@Suppress("DEPRECATION_ERROR")
|
||||
val factories = VariantImplementationFactories.get(gradle)
|
||||
factories[JavaSourceSetsAccessor.JavaSourceSetsAccessorVariantFactory::class] =
|
||||
JavaSourceSetsAccessorG70.JavaSourceSetAccessorVariantFactoryG70()
|
||||
|
||||
+1
@@ -141,6 +141,7 @@ open class KotlinPlatformCommonPlugin : KotlinPlatformPluginBase("common") {
|
||||
}
|
||||
|
||||
private fun Project.registerVariantImplementations() {
|
||||
@Suppress("DEPRECATION_ERROR")
|
||||
val factories = VariantImplementationFactories.get(gradle)
|
||||
factories[IdeaSyncDetector.IdeaSyncDetectorVariantFactory::class] =
|
||||
IdeaSyncDetectorG71.IdeaSyncDetectorVariantFactoryG71()
|
||||
|
||||
+1
@@ -139,6 +139,7 @@ open class KotlinPlatformCommonPlugin : KotlinPlatformPluginBase("common") {
|
||||
}
|
||||
|
||||
private fun Project.registerVariantImplementations() {
|
||||
@Suppress("DEPRECATION_ERROR")
|
||||
val factories = VariantImplementationFactories.get(gradle)
|
||||
factories[MppTestReportHelper.MppTestReportHelperVariantFactory::class] =
|
||||
MppTestReportHelperG74.MppTestReportHelperVariantFactoryG74()
|
||||
|
||||
+1
@@ -140,6 +140,7 @@ open class KotlinPlatformCommonPlugin : KotlinPlatformPluginBase("common") {
|
||||
}
|
||||
|
||||
private fun Project.registerVariantImplementations() {
|
||||
@Suppress("DEPRECATION_ERROR")
|
||||
val factories = VariantImplementationFactories.get(gradle)
|
||||
factories[MppTestReportHelper.MppTestReportHelperVariantFactory::class] =
|
||||
MppTestReportHelperG75.MppTestReportHelperVariantFactoryG75()
|
||||
|
||||
+1
@@ -140,6 +140,7 @@ open class KotlinPlatformCommonPlugin : KotlinPlatformPluginBase("common") {
|
||||
}
|
||||
|
||||
private fun Project.registerVariantImplementations() {
|
||||
@Suppress("DEPRECATION_ERROR")
|
||||
val factories = VariantImplementationFactories.get(gradle)
|
||||
factories[MavenPluginConfigurator.MavenPluginConfiguratorVariantFactory::class] =
|
||||
MavenPluginConfiguratorG6.Gradle6MavenPluginConfiguratorVariantFactory()
|
||||
|
||||
Reference in New Issue
Block a user