[kotlin] fix "IllegalStateException: Could not find stdlib"
The commit removes all the KLib resolution logic, now Analysis API Standalone clients need to provide all the KLib list directly. The resolution logic was removed as too error-prone and requiring compiler configurations. Kotlin Gradle plugin can provide a full set of required KLibs, so if a client is a Gradle plugin, this should not be an issue. Probably, some fancy API which will explicitly perform all KLib dependency searches should be introduced in the future (KT-63395) ^KT-63126 fixed
This commit is contained in:
committed by
Space Team
parent
1c17f4a835
commit
6aeabc83ea
@@ -0,0 +1,37 @@
|
||||
import org.jetbrains.kotlin.kotlinNativeDist
|
||||
|
||||
plugins {
|
||||
kotlin("jvm")
|
||||
id("jps-compatible")
|
||||
}
|
||||
|
||||
dependencies {
|
||||
testImplementation(projectTests(":compiler:tests-common"))
|
||||
testImplementation(project(":analysis:analysis-api-standalone"))
|
||||
testImplementation(projectTests(":analysis:analysis-api-standalone"))
|
||||
testImplementation(projectTests(":native:native.tests"))
|
||||
|
||||
testImplementation(platform(libs.junit.bom))
|
||||
testImplementation(libs.junit.jupiter.api)
|
||||
testRuntimeOnly(libs.junit.jupiter.engine)
|
||||
}
|
||||
|
||||
sourceSets {
|
||||
"main" { none() }
|
||||
"test" {
|
||||
projectDefault()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
projectTest(jUnitMode = JUnitMode.JUnit5) {
|
||||
dependsOn(":dist")
|
||||
workingDir = rootDir
|
||||
useJUnitPlatform()
|
||||
}
|
||||
|
||||
val test by nativeTest("test", null) {
|
||||
systemProperty("kotlin.native.home", kotlinNativeDist.absolutePath)
|
||||
}
|
||||
|
||||
testsJar()
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
package nativeKLib
|
||||
|
||||
fun nativeKLibFunction(arg: String): Int {
|
||||
return 1
|
||||
}
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
import nativeKLib.nativeKLibFunction
|
||||
|
||||
fun main() {
|
||||
nativeKLibFunction("aaa")
|
||||
}
|
||||
+61
@@ -0,0 +1,61 @@
|
||||
/*
|
||||
* Copyright 2010-2023 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.analysis.api.standalone.konan.fir.test.cases.session.builder
|
||||
|
||||
import org.jetbrains.kotlin.analysis.api.KtAnalysisApiInternals
|
||||
import org.jetbrains.kotlin.analysis.api.lifetime.KtLifetimeTokenProvider
|
||||
import org.jetbrains.kotlin.analysis.api.standalone.KtAlwaysAccessibleLifetimeTokenProvider
|
||||
import org.jetbrains.kotlin.analysis.api.standalone.buildStandaloneAnalysisAPISession
|
||||
import org.jetbrains.kotlin.analysis.api.standalone.fir.test.cases.session.builder.assertIsCallOf
|
||||
import org.jetbrains.kotlin.analysis.project.structure.KtSourceModule
|
||||
import org.jetbrains.kotlin.analysis.project.structure.builder.buildKtLibraryModule
|
||||
import org.jetbrains.kotlin.analysis.project.structure.builder.buildKtSourceModule
|
||||
import org.jetbrains.kotlin.konan.target.HostManager
|
||||
import org.jetbrains.kotlin.name.CallableId
|
||||
import org.jetbrains.kotlin.name.FqName
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
import org.jetbrains.kotlin.platform.konan.NativePlatforms
|
||||
import org.jetbrains.kotlin.psi.KtCallExpression
|
||||
import org.jetbrains.kotlin.psi.KtFile
|
||||
import org.jetbrains.kotlin.psi.psiUtil.findDescendantOfType
|
||||
import org.junit.jupiter.api.Test
|
||||
|
||||
@OptIn(KtAnalysisApiInternals::class)
|
||||
class NativeStandaloneSessionBuilderTest {
|
||||
@Test
|
||||
fun testResolveAgainstCommonKlib() {
|
||||
lateinit var sourceModule: KtSourceModule
|
||||
val currentArchitectureTarget = HostManager.host
|
||||
val nativePlatform = NativePlatforms.nativePlatformByTargets(listOf(currentArchitectureTarget))
|
||||
val session = buildStandaloneAnalysisAPISession {
|
||||
registerProjectService(KtLifetimeTokenProvider::class.java, KtAlwaysAccessibleLifetimeTokenProvider())
|
||||
|
||||
buildKtModuleProvider {
|
||||
platform = nativePlatform
|
||||
val kLib = addModule(
|
||||
buildKtLibraryModule {
|
||||
val compiledKLibRoot = compileToNativeKLib(testDataPath("resolveAgainstNativeKLib/klibSrc"))
|
||||
addBinaryRoot(compiledKLibRoot)
|
||||
platform = nativePlatform
|
||||
libraryName = "klib"
|
||||
}
|
||||
)
|
||||
sourceModule = addModule(
|
||||
buildKtSourceModule {
|
||||
addSourceRoot(testDataPath("resolveAgainstNativeKLib/src"))
|
||||
addRegularDependency(kLib)
|
||||
platform = nativePlatform
|
||||
moduleName = "source"
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
val ktFile = session.modulesWithFiles.getValue(sourceModule).single() as KtFile
|
||||
|
||||
val ktCallExpression = ktFile.findDescendantOfType<KtCallExpression>()!!
|
||||
ktCallExpression.assertIsCallOf(CallableId(FqName("nativeKLib"), Name.identifier("nativeKLibFunction")))
|
||||
}
|
||||
}
|
||||
+39
@@ -0,0 +1,39 @@
|
||||
/*
|
||||
* Copyright 2010-2023 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.analysis.api.standalone.konan.fir.test.cases.session.builder
|
||||
|
||||
import org.jetbrains.kotlin.cli.common.ExitCode
|
||||
import org.jetbrains.kotlin.konan.test.blackbox.support.compilation.callCompilerWithoutOutputInterceptor
|
||||
import org.jetbrains.kotlin.test.util.KtTestUtil
|
||||
import java.nio.file.Files
|
||||
import java.nio.file.Path
|
||||
import java.nio.file.Paths
|
||||
import kotlin.io.path.absolutePathString
|
||||
import kotlin.io.path.extension
|
||||
import kotlin.streams.asSequence
|
||||
|
||||
internal fun testDataPath(path: String): Path {
|
||||
return Paths.get("analysis/analysis-api-standalone/analysis-api-standalone-native/testData/nativeSessionBuilder").resolve(path)
|
||||
}
|
||||
|
||||
internal fun compileToNativeKLib(kLibSourcesRoot: Path): Path {
|
||||
val ktFiles = Files.walk(kLibSourcesRoot).asSequence().filter { it.extension == "kt" }.toList()
|
||||
val testKlib = KtTestUtil.tmpDir("testLibrary").resolve("library.klib").toPath()
|
||||
|
||||
val arguments = buildList {
|
||||
ktFiles.mapTo(this) { it.absolutePathString() }
|
||||
addAll(listOf("-produce", "library"))
|
||||
addAll(listOf("-output", testKlib.absolutePathString()))
|
||||
}
|
||||
|
||||
val compileResult = callCompilerWithoutOutputInterceptor(arguments.toTypedArray())
|
||||
|
||||
check(compileResult.exitCode == ExitCode.OK) {
|
||||
"Compilation error: $compileResult"
|
||||
}
|
||||
|
||||
return testKlib
|
||||
}
|
||||
Reference in New Issue
Block a user