Fix extracted metadata for IDE erased when scopes conflict, KT-44845

The root cause was that extractors for different scopes used the same
base directory, and each erased its contents. Using different base dirs
fixes the issue.

Issue #KT-44845
This commit is contained in:
Sergey Igushkin
2021-02-12 13:33:51 +03:00
committed by Space
parent 54636f1af7
commit a719656118
3 changed files with 39 additions and 1 deletions
@@ -585,6 +585,41 @@ class HierarchicalMppIT : BaseGradleIT() {
}
}
@Test
fun testMixedScopesFilesExistKt44845() {
publishThirdPartyLib(withGranularMetadata = true)
transformNativeTestProjectWithPluginDsl("my-lib-foo", gradleVersion, "hierarchical-mpp-published-modules").run {
gradleBuildScript().appendText(
"""
${"\n"}
dependencies {
"jvmAndJsMainImplementation"("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.4.2")
"jvmAndJsMainCompileOnly"("org.jetbrains.kotlinx:kotlinx-serialization-json:1.0.1")
}
""".trimIndent()
)
testDependencyTransformations { reports ->
val reportsForJvmAndJsMain = reports.filter { it.sourceSetName == "jvmAndJsMain" }
val thirdPartyLib = reportsForJvmAndJsMain.single {
it.scope == "api" && it.groupAndModule.startsWith("com.example")
}
val coroutinesCore = reportsForJvmAndJsMain.single {
it.scope == "implementation" && it.groupAndModule.contains("kotlinx-coroutines-core")
}
val serialization = reportsForJvmAndJsMain.single {
it.scope == "compileOnly" && it.groupAndModule.contains("kotlinx-serialization-json")
}
listOf(thirdPartyLib, coroutinesCore, serialization).forEach { report ->
assertTrue(report.newVisibleSourceSets.isNotEmpty(), "Expected visible source sets for $report")
assertTrue(report.useFiles.isNotEmpty(), "Expected non-empty useFiles for $report")
report.useFiles.forEach { assertTrue(it.isFile, "Expected $it to exist for $report") }
}
}
}
}
private fun Project.testDependencyTransformations(
subproject: String? = null,
check: CompiledProject.(reports: Iterable<DependencyTransformationReport>) -> Unit
@@ -156,7 +156,7 @@ class DefaultKotlinSourceSet(
?.associateBy { ModuleIds.fromComponent(project, it.dependency) }
?: emptyMap()
val baseDir = SourceSetMetadataStorageForIde.sourceSetStorage(project, this@DefaultKotlinSourceSet.name)
val baseDir = SourceSetMetadataStorageForIde.sourceSetStorageWithScope(project, this@DefaultKotlinSourceSet.name, scope)
if (metadataDependencyResolutionByModule.values.any { it is MetadataDependencyResolution.ChooseVisibleSourceSets }) {
if (baseDir.isDirectory) {
@@ -39,4 +39,7 @@ object SourceSetMetadataStorageForIde {
}
fun sourceSetStorage(project: Project, sourceSetName: String) = projectStorage(project).resolve(sourceSetName)
internal fun sourceSetStorageWithScope(project: Project, sourceSetName: String, scope: KotlinDependencyScope) =
sourceSetStorage(project, sourceSetName).resolve(scope.scopeName)
}