From d85a39b7811c31ba380dfdc344e36a755341e99c Mon Sep 17 00:00:00 2001 From: Ian Lynagh Date: Thu, 12 Sep 2024 11:50:46 +0100 Subject: [PATCH] KE2: Add classpath to analysis context --- .../src/main/kotlin/KotlinExtractor.kt | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/java/kotlin-extractor2/src/main/kotlin/KotlinExtractor.kt b/java/kotlin-extractor2/src/main/kotlin/KotlinExtractor.kt index c88670aad80..abd98ab1f1f 100644 --- a/java/kotlin-extractor2/src/main/kotlin/KotlinExtractor.kt +++ b/java/kotlin-extractor2/src/main/kotlin/KotlinExtractor.kt @@ -176,6 +176,8 @@ fun doAnalysis( val session = buildStandaloneAnalysisAPISession { registerProjectService(KotlinLifetimeTokenProvider::class.java, KotlinAlwaysAccessibleLifetimeTokenProvider()) + // TODO: Is there a better way we can do all this directly from k2args? + buildKtModuleProvider { platform = JvmPlatforms.defaultJvmPlatform val sdk = addModule( @@ -186,10 +188,23 @@ fun doAnalysis( libraryName = "JDK" } ) + val lib = addModule( + buildKtLibraryModule { + val classpath = k2args.classpath + if (classpath != null) { + for (cpEntry in classpath.split(File.pathSeparatorChar)) { + addBinaryRoot(Paths.get(cpEntry)) + } + } + platform = JvmPlatforms.defaultJvmPlatform + libraryName = "Library for classpath" + } + ) sourceModule = addModule( buildKtSourceModule { addSourceRoots(k2args.freeArgs.map { Paths.get(it) }) addRegularDependency(sdk) + addRegularDependency(lib) platform = JvmPlatforms.defaultJvmPlatform moduleName = "" }