[MPP] SourceSetMetadataStorageForIde: Remove faulty 'cleanupStaleEntries'

^KT-52955 Verification Pending

This method over-aggressively removed libraries in the situation of
isolated KGP ClassLoaders or when a project enabled Gradles configuration
caching. This faulty cleanup is removed in anticipation
of a re-structured SourceSetMetadataStorageForIde in the near future.
This commit is contained in:
sebastian.sellmair
2022-06-24 20:29:41 +02:00
committed by Space
parent a85490ea7d
commit c16955ff3f
2 changed files with 2 additions and 67 deletions
@@ -26,7 +26,6 @@ import org.jetbrains.kotlin.gradle.plugin.mpp.pm20.registerDefaultVariantFactori
import org.jetbrains.kotlin.gradle.plugin.mpp.pm20.setupFragmentsMetadataForKpmModules
import org.jetbrains.kotlin.gradle.plugin.mpp.pm20.setupKpmModulesPublication
import org.jetbrains.kotlin.gradle.plugin.mpp.pm20.util.copyAttributes
import org.jetbrains.kotlin.gradle.plugin.sources.CleanupStaleSourceSetMetadataEntriesService
import org.jetbrains.kotlin.gradle.plugin.sources.DefaultLanguageSettingsBuilder
import org.jetbrains.kotlin.gradle.plugin.sources.SourceSetMetadataStorageForIde
import org.jetbrains.kotlin.gradle.plugin.sources.checkSourceSetVisibilityRequirements
@@ -100,24 +99,6 @@ class KotlinMultiplatformPlugin : Plugin<Project> {
project.pluginManager.apply(ScriptingGradleSubplugin::class.java)
exportProjectStructureMetadataForOtherBuilds(kotlinMultiplatformExtension)
SingleActionPerBuild.run(project.rootProject, "cleanup-processed-metadata") {
if (isConfigurationCacheAvailable(project.gradle)) {
BuildEventsListenerRegistryHolder.getInstance(project).listenerRegistry.onTaskCompletion(
project.gradle.sharedServices
.registerIfAbsent(
"cleanup-stale-sourceset-metadata",
CleanupStaleSourceSetMetadataEntriesService::class.java
) {
CleanupStaleSourceSetMetadataEntriesService.configure(it, project)
}
)
} else {
project.gradle.buildFinished {
SourceSetMetadataStorageForIde.cleanupStaleEntries(project)
}
}
}
}
private fun exportProjectStructureMetadataForOtherBuilds(
@@ -17,31 +17,9 @@ import org.jetbrains.kotlin.gradle.dsl.multiplatformExtensionOrNull
import java.io.File
object SourceSetMetadataStorageForIde {
fun cleanupStaleEntries(project: Project) {
val projectStorageDirectories = project.rootProject.allprojects
.associate { projectStorage(it) to it.multiplatformExtensionOrNull?.sourceSets.orEmpty().map { it.name } }
cleanupStaleEntries(getStorageRoot(project), projectStorageDirectories)
}
private fun getStorageRoot(project: Project): File = project.rootDir.resolve(".gradle/kotlin/sourceSetMetadata")
fun cleanupStaleEntries(projectStorageRoot: File, projectStorageDirectories: Map<File, List<String>>) {
projectStorageRoot.listFiles().orEmpty().filter { it.isDirectory }.forEach { directory ->
// If no project corresponds to the directory, remove the directory
if (directory !in projectStorageDirectories) {
directory.deleteRecursively()
} else {
// Under the project's directory, delete subdirectories that don't correspond to any source set:
val sourceSetNames = projectStorageDirectories.getValue(directory)
directory.listFiles().orEmpty().filter { it.isDirectory }.forEach { subdirectory ->
if (subdirectory.name !in sourceSetNames)
subdirectory.deleteRecursively()
}
}
}
}
internal fun getStorageRoot(project: Project): File = project.rootDir.resolve(".gradle/kotlin/sourceSetMetadata")
internal fun projectStorage(project: Project): File {
private fun projectStorage(project: Project): File {
val projectPathSegments = generateSequence(project) { it.parent }.map { it.name }
return getStorageRoot(project).resolve(
// Escape dots in project names to avoid ambiguous paths.
@@ -54,27 +32,3 @@ object SourceSetMetadataStorageForIde {
internal fun sourceSetStorageWithScope(project: Project, sourceSetName: String, scope: KotlinDependencyScope) =
sourceSetStorage(project, sourceSetName).resolve(scope.scopeName)
}
abstract class CleanupStaleSourceSetMetadataEntriesService : BuildService<CleanupStaleSourceSetMetadataEntriesService.Parameters>, AutoCloseable, OperationCompletionListener {
interface Parameters : BuildServiceParameters {
val projectStorageRoot: Property<File>
val projectStorageDirectories: MapProperty<File, List<String>>
}
override fun onFinish(event: FinishEvent?) {
// noop
}
override fun close() {
SourceSetMetadataStorageForIde.cleanupStaleEntries(parameters.projectStorageRoot.get(), parameters.projectStorageDirectories.get())
}
companion object {
fun configure(spec: BuildServiceSpec<Parameters>, project: Project) {
spec.parameters.projectStorageRoot.set(SourceSetMetadataStorageForIde.getStorageRoot(project))
spec.parameters.projectStorageDirectories.set(project.rootProject.allprojects.associate {
SourceSetMetadataStorageForIde.projectStorage(it) to it.multiplatformExtensionOrNull?.sourceSets.orEmpty().map { it.name }
})
}
}
}