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.
上级 970ee453
......@@ -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
......
......@@ -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")))
}
}
}
}
\ No newline at end of file
......@@ -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()
......
......@@ -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)
}
}
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册