Fix the K/N stdlib leaking into other common source sets
The Kotlin/Native stdlib was added to the shared-native source sets in order for the IDE to import the stdlib dependency. However, it was added to the '*Implementation' configuration, from where it was also collected for the dependency source set visibility inference algorithm. The current implementation of source sets visibility inference only works for module dependencies and is not quite suitable for local file dependencies. The implementation should likely be fixed, but for now, it's enough to add the dependency directly to the place where the visibility inference results are taken from by the IDE during import, i.e. to the '*ImplementationDependenciesMetadata' configurations. Also, since all tests were flawed by the leakin K/N stdlib, the K2Metadata/Klib compiler mistakenly didn't include its own built-ins to the module dependencies (and everything worked because the K/N built-ins were there). Now that the K/N doesn't leak, the compiler must add its own built-ins.
This commit is contained in:
@@ -52,7 +52,7 @@ internal class K2MetadataKlibSerializer(private val metadataVersion: BuiltInsBin
|
||||
LockBasedStorageManager("K2MetadataKlibSerializer")
|
||||
)
|
||||
|
||||
val analyzer = runCommonAnalysisForSerialization(environment, false, dependencyContainer)
|
||||
val analyzer = runCommonAnalysisForSerialization(environment, true, dependencyContainer)
|
||||
|
||||
if (analyzer == null || analyzer.hasErrors()) return
|
||||
|
||||
|
||||
+19
-1
@@ -8,8 +8,9 @@ package org.jetbrains.kotlin.gradle
|
||||
import org.jetbrains.kotlin.gradle.util.modify
|
||||
import org.jetbrains.kotlin.konan.target.HostManager
|
||||
import org.junit.Assume
|
||||
import kotlin.test.Ignore
|
||||
import java.io.File
|
||||
import kotlin.test.Test
|
||||
import kotlin.test.assertFalse
|
||||
|
||||
/** FIXME (sergey.igushkin): please enable these tests back as soon as the Kotlin/Native version that is bundled with the
|
||||
* Kotlin distribution supports compilation to klib and targetless klibs.
|
||||
@@ -89,6 +90,23 @@ class KlibBasedMppIT : BaseGradleIT() {
|
||||
assertSuccessful()
|
||||
|
||||
assertTasksExecuted(*tasksToExecute.toTypedArray())
|
||||
|
||||
assertFileExists("build/classes/kotlin/metadata/jvmAndJsMain/manifest")
|
||||
assertFileExists("build/classes/kotlin/metadata/iosMain/iosMain.klib")
|
||||
|
||||
// Check that the common and JVM+JS source sets don't receive the Kotlin/Native stdlib in the classpath:
|
||||
run {
|
||||
fun getClasspath(taskPath: String): Iterable<String> {
|
||||
val argsPrefix = " $taskPath Kotlin compiler args:"
|
||||
return output.lines().single { argsPrefix in it }
|
||||
.substringAfter("-classpath ").substringBefore(" -").split(File.pathSeparator)
|
||||
}
|
||||
|
||||
fun classpathHasKNStdlib(classpath: Iterable<String>) = classpath.any { "klib/common/stdlib" in it.replace("\\", "/") }
|
||||
|
||||
assertFalse(classpathHasKNStdlib(getClasspath(":compileKotlinMetadata")))
|
||||
assertFalse(classpathHasKNStdlib(getClasspath(":compileJvmAndJsMainKotlinMetadata")))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -126,7 +126,7 @@ internal class GradleKotlinCompilerWork @Inject constructor(
|
||||
with(log) {
|
||||
kotlinDebug { "Kotlin compiler class: ${compilerClassName}" }
|
||||
kotlinDebug { "Kotlin compiler classpath: ${compilerFullClasspath.joinToString { it.canonicalPath }}" }
|
||||
kotlinDebug { "Kotlin compiler args: ${compilerArgs.joinToString(" ")}" }
|
||||
kotlinDebug { "$taskPath Kotlin compiler args: ${compilerArgs.joinToString(" ")}" }
|
||||
}
|
||||
|
||||
val executionStrategy = kotlinCompilerExecutionStrategy()
|
||||
|
||||
+1
-1
@@ -142,7 +142,7 @@ abstract class AbstractKotlinNativeTargetPreset<T : KotlinNativeTarget>(
|
||||
project.kotlinExtension.sourceSets
|
||||
.filter { it.isIntermediateNativeSourceSet() }
|
||||
.forEach {
|
||||
it.dependencies { implementation(stdlib) }
|
||||
project.dependencies.add(it.implementationMetadataConfigurationName, stdlib)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user