[Gradle] Don't collect module-info on using new IC/JVM approach
Collecting 'moduleInfo' is required for the old history-file-based incremental compilation approach. And the way how it is being collected violates Gradle project-isolation feature as it accesses all Kotlin compile tasks from other Gradle subprojects. When the new IC based on classpath snapshot is enabled, the plugin will not collect 'moduleInfo' making it compatible with project isolation. ^KT-59826 Fixed
This commit is contained in:
committed by
Space Team
parent
40928d50a2
commit
e80988d98c
@@ -616,20 +616,24 @@ abstract class CompileServiceImplBase(
|
||||
val rootProjectDir = incrementalCompilationOptions.rootProjectDir
|
||||
val buildDir = incrementalCompilationOptions.buildDir
|
||||
|
||||
val modulesApiHistory = incrementalCompilationOptions.multiModuleICSettings?.run {
|
||||
reporter.info { "Use module detection: $useModuleDetection" }
|
||||
val modulesInfo = incrementalCompilationOptions.modulesInfo
|
||||
?: error("The build is configured to use the history-file based IC approach, but doesn't provide the modulesInfo")
|
||||
check(rootProjectDir != null) {
|
||||
"rootProjectDir is expected to be non null when the history-file based IC approach is used"
|
||||
}
|
||||
val modulesApiHistory = if (incrementalCompilationOptions.classpathChanges is ClasspathChanges.ClasspathSnapshotEnabled) {
|
||||
EmptyModulesApiHistory
|
||||
} else {
|
||||
incrementalCompilationOptions.multiModuleICSettings?.run {
|
||||
reporter.info { "Use module detection: $useModuleDetection" }
|
||||
val modulesInfo = incrementalCompilationOptions.modulesInfo
|
||||
?: error("The build is configured to use the history-file based IC approach, but doesn't provide the modulesInfo")
|
||||
check(rootProjectDir != null) {
|
||||
"rootProjectDir is expected to be non null when the history-file based IC approach is used"
|
||||
}
|
||||
|
||||
if (!useModuleDetection) {
|
||||
ModulesApiHistoryJvm(rootProjectDir, modulesInfo)
|
||||
} else {
|
||||
ModulesApiHistoryAndroid(rootProjectDir, modulesInfo)
|
||||
}
|
||||
} ?: EmptyModulesApiHistory
|
||||
if (!useModuleDetection) {
|
||||
ModulesApiHistoryJvm(rootProjectDir, modulesInfo)
|
||||
} else {
|
||||
ModulesApiHistoryAndroid(rootProjectDir, modulesInfo)
|
||||
}
|
||||
} ?: EmptyModulesApiHistory
|
||||
}
|
||||
|
||||
val useK2 = k2jvmArgs.useK2 || LanguageVersion.fromVersionString(k2jvmArgs.languageVersion)?.usesK2 == true
|
||||
// TODO: This should be reverted after implementing of fir-based java tracker (KT-57147).
|
||||
|
||||
+10
-2
@@ -24,7 +24,11 @@ class BuildServiceDeclarationIT : KGPBaseTest() {
|
||||
@GradleTest
|
||||
@JvmGradlePluginTests
|
||||
fun testJvmProject(gradleVersion: GradleVersion) {
|
||||
project("kotlinJavaProject", gradleVersion) {
|
||||
project(
|
||||
"kotlinJavaProject",
|
||||
gradleVersion,
|
||||
buildOptions = defaultBuildOptions.copy(warningMode = WarningMode.Fail)
|
||||
) {
|
||||
enableStableConfigurationCachePreview()
|
||||
build("build") {
|
||||
assertOutputDoesNotContainBuildServiceDeclarationWarnings()
|
||||
@@ -72,7 +76,11 @@ class BuildServiceDeclarationIT : KGPBaseTest() {
|
||||
@GradleTest
|
||||
@OtherGradlePluginTests
|
||||
fun testKaptProject(gradleVersion: GradleVersion) {
|
||||
project("kapt2/simple", gradleVersion) {
|
||||
project(
|
||||
"kapt2/simple",
|
||||
gradleVersion,
|
||||
buildOptions = defaultBuildOptions.copy(warningMode = WarningMode.Fail)
|
||||
) {
|
||||
enableStableConfigurationCachePreview()
|
||||
build("build") {
|
||||
assertOutputDoesNotContainBuildServiceDeclarationWarnings()
|
||||
|
||||
+1
-2
@@ -14,11 +14,10 @@ class ProjectIsolationIT : KGPBaseTest() {
|
||||
override val defaultBuildOptions: BuildOptions
|
||||
get() = super.defaultBuildOptions.copy(configurationCache = true, projectIsolation = true)
|
||||
|
||||
@DisplayName("Should be compatible with project isolation")
|
||||
@DisplayName("JVM project should be compatible with project isolation")
|
||||
@JvmGradlePluginTests
|
||||
@GradleTestVersions(
|
||||
minVersion = TestVersions.Gradle.G_7_1,
|
||||
maxVersion = TestVersions.Gradle.G_7_6
|
||||
)
|
||||
@GradleTest
|
||||
fun testProjectIsolationInJvmSimple(gradleVersion: GradleVersion) {
|
||||
|
||||
+1
-1
@@ -209,7 +209,7 @@ internal open class GradleCompilerRunner(
|
||||
}
|
||||
|
||||
val incrementalCompilationEnvironment = environment.incrementalCompilationEnvironment
|
||||
val modulesInfo = incrementalCompilationEnvironment?.let { incrementalModuleInfoProvider.get().info }
|
||||
val modulesInfo = incrementalCompilationEnvironment?.let { incrementalModuleInfoProvider.orNull?.info }
|
||||
val workArgs = GradleKotlinCompilerWorkArguments(
|
||||
projectFiles = ProjectFilesForCompilation(
|
||||
loggerProvider,
|
||||
|
||||
+1
-1
@@ -327,7 +327,7 @@ internal class GradleKotlinCompilerWork @Inject constructor(
|
||||
usePreciseJavaTracking = icEnv.usePreciseJavaTracking,
|
||||
outputFiles = outputFiles,
|
||||
multiModuleICSettings = icEnv.multiModuleICSettings,
|
||||
modulesInfo = incrementalModuleInfo!!,
|
||||
modulesInfo = incrementalModuleInfo,
|
||||
rootProjectDir = icEnv.rootProjectDir,
|
||||
buildDir = icEnv.buildDir,
|
||||
kotlinScriptExtensions = kotlinScriptExtensions,
|
||||
|
||||
-8
@@ -13,11 +13,9 @@ 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.ExplicitApiMode
|
||||
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.internal.ClassLoadersCachingBuildService
|
||||
import org.jetbrains.kotlin.gradle.plugin.*
|
||||
import org.jetbrains.kotlin.gradle.plugin.PropertiesProvider.Companion.kotlinPropertiesProvider
|
||||
@@ -27,7 +25,6 @@ import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinMetadataTarget
|
||||
import org.jetbrains.kotlin.gradle.plugin.mpp.internal
|
||||
import org.jetbrains.kotlin.gradle.tasks.AbstractKotlinCompile
|
||||
import org.jetbrains.kotlin.gradle.tasks.KOTLIN_BUILD_DIR_NAME
|
||||
import org.jetbrains.kotlin.gradle.utils.providerWithLazyConvention
|
||||
|
||||
/**
|
||||
* Configuration for the base compile task, [org.jetbrains.kotlin.gradle.tasks.AbstractKotlinCompile].
|
||||
@@ -42,10 +39,6 @@ internal abstract class AbstractKotlinCompileConfig<TASK : AbstractKotlinCompile
|
||||
|
||||
init {
|
||||
val compilerSystemPropertiesService = CompilerSystemPropertiesService.registerIfAbsent(project)
|
||||
val incrementalModuleInfoProvider =
|
||||
IncrementalModuleInfoBuildService.registerIfAbsent(project, objectFactory.providerWithLazyConvention {
|
||||
GradleCompilerRunner.buildModulesInfo(project.gradle)
|
||||
})
|
||||
val buildFinishedListenerService = BuildFinishedListenerService.registerIfAbsent(project)
|
||||
val cachedClassLoadersService = ClassLoadersCachingBuildService.registerIfAbsent(project)
|
||||
val buildIdService = BuildIdService.registerIfAbsent(project)
|
||||
@@ -61,7 +54,6 @@ internal abstract class AbstractKotlinCompileConfig<TASK : AbstractKotlinCompile
|
||||
|
||||
task.localStateDirectories.from(task.taskBuildLocalStateDirectory).disallowChanges()
|
||||
task.systemPropertiesService.value(compilerSystemPropertiesService).disallowChanges()
|
||||
task.incrementalModuleInfoProvider.value(incrementalModuleInfoProvider).disallowChanges()
|
||||
|
||||
propertiesProvider.kotlinDaemonJvmArgs?.let { kotlinDaemonJvmArgs ->
|
||||
task.kotlinDaemonJvmArguments.set(providers.provider {
|
||||
|
||||
+9
@@ -5,6 +5,8 @@
|
||||
|
||||
package org.jetbrains.kotlin.gradle.tasks.configuration
|
||||
|
||||
import org.jetbrains.kotlin.compilerRunner.GradleCompilerRunner
|
||||
import org.jetbrains.kotlin.gradle.incremental.IncrementalModuleInfoBuildService
|
||||
import org.jetbrains.kotlin.gradle.plugin.KotlinCompilationInfo
|
||||
import org.jetbrains.kotlin.gradle.plugin.KotlinPlatformType
|
||||
import org.jetbrains.kotlin.gradle.targets.js.KotlinWasmTargetType
|
||||
@@ -12,6 +14,7 @@ import org.jetbrains.kotlin.gradle.targets.js.internal.LibraryFilterCachingServi
|
||||
import org.jetbrains.kotlin.gradle.targets.js.ir.*
|
||||
import org.jetbrains.kotlin.gradle.tasks.Kotlin2JsCompile
|
||||
import org.jetbrains.kotlin.gradle.utils.klibModuleName
|
||||
import org.jetbrains.kotlin.gradle.utils.providerWithLazyConvention
|
||||
import java.io.File
|
||||
|
||||
internal typealias Kotlin2JsCompileConfig = BaseKotlin2JsCompileConfig<Kotlin2JsCompile>
|
||||
@@ -23,6 +26,11 @@ internal open class BaseKotlin2JsCompileConfig<TASK : Kotlin2JsCompile>(
|
||||
init {
|
||||
val libraryFilterCachingService = LibraryFilterCachingService.registerIfAbsent(project)
|
||||
|
||||
val incrementalModuleInfoProvider = IncrementalModuleInfoBuildService.registerIfAbsent(
|
||||
project,
|
||||
objectFactory.providerWithLazyConvention { GradleCompilerRunner.buildModulesInfo(project.gradle) },
|
||||
)
|
||||
|
||||
configureTask { task ->
|
||||
task.incremental = propertiesProvider.incrementalJs ?: true
|
||||
task.incrementalJsKlib = propertiesProvider.incrementalJsKlib ?: true
|
||||
@@ -65,6 +73,7 @@ internal open class BaseKotlin2JsCompileConfig<TASK : Kotlin2JsCompile>(
|
||||
)
|
||||
|
||||
task.libraryFilterCacheService.value(libraryFilterCachingService).disallowChanges()
|
||||
task.incrementalModuleInfoProvider.value(incrementalModuleInfoProvider).disallowChanges()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+1
@@ -23,6 +23,7 @@ internal class KotlinCompileCommonConfig(
|
||||
).disallowChanges()
|
||||
task.refinesMetadataPaths.from(compilationInfo.refinesPaths).disallowChanges()
|
||||
task.moduleName.set(providers.provider { compilationInfo.moduleName })
|
||||
task.incrementalModuleInfoProvider.disallowChanges()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+12
@@ -12,9 +12,11 @@ import org.gradle.api.artifacts.result.ResolvedDependencyResult
|
||||
import org.gradle.api.artifacts.transform.TransformSpec
|
||||
import org.gradle.api.attributes.Attribute
|
||||
import org.gradle.api.provider.Provider
|
||||
import org.jetbrains.kotlin.compilerRunner.GradleCompilerRunner
|
||||
import org.jetbrains.kotlin.gradle.dsl.KotlinAndroidProjectExtension
|
||||
import org.jetbrains.kotlin.gradle.dsl.KotlinJvmProjectExtension
|
||||
import org.jetbrains.kotlin.gradle.dsl.KotlinTopLevelExtension
|
||||
import org.jetbrains.kotlin.gradle.incremental.IncrementalModuleInfoBuildService
|
||||
import org.jetbrains.kotlin.gradle.internal.ClassLoadersCachingBuildService
|
||||
import org.jetbrains.kotlin.gradle.internal.KOTLIN_BUILD_TOOLS_API_IMPL
|
||||
import org.jetbrains.kotlin.gradle.internal.KOTLIN_MODULE_GROUP
|
||||
@@ -51,6 +53,16 @@ internal open class BaseKotlinCompileConfig<TASK : KotlinCompile> : AbstractKotl
|
||||
).markResolvable()
|
||||
} else null
|
||||
|
||||
if (useClasspathSnapshot) {
|
||||
taskProvider.configure { it.incrementalModuleInfoProvider.disallowChanges() }
|
||||
} else {
|
||||
val incrementalModuleInfoProvider = IncrementalModuleInfoBuildService.registerIfAbsent(
|
||||
project,
|
||||
objectFactory.providerWithLazyConvention { GradleCompilerRunner.buildModulesInfo(project.gradle) },
|
||||
)
|
||||
taskProvider.configure { it.incrementalModuleInfoProvider.value(incrementalModuleInfoProvider).disallowChanges() }
|
||||
}
|
||||
|
||||
taskProvider.configure { task ->
|
||||
task.incremental = propertiesProvider.incrementalJvm ?: true
|
||||
task.usePreciseJavaTracking = propertiesProvider.usePreciseJavaTracking ?: true
|
||||
|
||||
Reference in New Issue
Block a user