Skip to content

Commit

Permalink
Fix extracted metadata for IDE erased when scopes conflict, KT-44845
Browse files Browse the repository at this point in the history
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

(cherry picked from commit a719656)
  • Loading branch information
h0tk3y committed Feb 12, 2021
1 parent 74b4b0a commit 2d14378
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

0 comments on commit 2d14378

Please sign in to comment.