[Gradle] Ensure pluginClasspath is imported into the IDE

See
`[KTIJ-24976] Implement initial KotlinMppCompilerPluginImportingTests`
in intellij.git

KTIJ-24976
This commit is contained in:
Sebastian Sellmair
2023-04-05 23:20:03 +02:00
committed by Space Team
parent 6c2087983c
commit 777955b4e2
9 changed files with 36 additions and 17 deletions
@@ -83,5 +83,6 @@ interface CompilerArgumentAware<T : CommonToolArguments> : KotlinCompilerArgumen
private val includedArgumentTypes = setOf(
ArgumentType.Primitive,
ArgumentType.Classpath,
ArgumentType.PluginClasspath,
ArgumentType.DependencyClasspath,
)
@@ -28,7 +28,6 @@ import org.jetbrains.kotlin.cli.common.arguments.K2JVMCompilerArguments
import org.jetbrains.kotlin.gradle.dsl.KotlinJvmCompilerOptions
import org.jetbrains.kotlin.gradle.dsl.KotlinJvmCompilerOptionsDefault
import org.jetbrains.kotlin.gradle.dsl.KotlinJvmCompilerOptionsHelper
import org.jetbrains.kotlin.gradle.plugin.KotlinCompilerArgumentsProducer
import org.jetbrains.kotlin.gradle.plugin.KotlinCompilerArgumentsProducer.CreateCompilerArgumentsContext
import org.jetbrains.kotlin.gradle.plugin.KotlinCompilerArgumentsProducer.CreateCompilerArgumentsContext.Companion.create
import org.jetbrains.kotlin.gradle.report.BuildReportMode
@@ -126,13 +125,15 @@ abstract class KaptGenerateStubsTask @Inject constructor(
args.destinationAsFile = destinationDirectory.get().asFile
}
classpath { args ->
pluginClasspath { args ->
args.pluginClasspaths = runSafe {
listOfNotNull(
pluginClasspath, kotlinPluginData?.orNull?.classpath
).reduce(FileCollection::plus).toPathsArray()
}
}
dependencyClasspath { args ->
args.classpathAsList = runSafe { libraries.toList().filter { it.exists() } }.orEmpty()
args.friendPaths = friendPaths.toPathsArray()
}
@@ -16,7 +16,8 @@ interface KotlinCompilerArgumentsProducer {
enum class ArgumentType {
Primitive,
Classpath,
PluginClasspath,
DependencyClasspath,
Sources;
companion object {
@@ -40,7 +41,8 @@ interface KotlinCompilerArgumentsProducer {
interface ContributeCompilerArgumentsContext<T : CommonToolArguments> {
fun <T> runSafe(action: () -> T): T?
fun primitive(contribution: (args: T) -> Unit)
fun classpath(contribution: (args: T) -> Unit)
fun pluginClasspath(contribution: (args: T) -> Unit)
fun dependencyClasspath(contribution: (args: T) -> Unit)
fun sources(contribution: (args: T) -> Unit)
}
@@ -99,8 +101,14 @@ private class CreateCompilerArgumentsContextImpl(
}
}
override fun classpath(contribution: (args: T) -> Unit) {
if (KotlinCompilerArgumentsProducer.ArgumentType.Classpath in includedArgumentTypes) {
override fun pluginClasspath(contribution: (args: T) -> Unit) {
if (KotlinCompilerArgumentsProducer.ArgumentType.PluginClasspath in includedArgumentTypes) {
applyContribution(contribution)
}
}
override fun dependencyClasspath(contribution: (args: T) -> Unit) {
if (KotlinCompilerArgumentsProducer.ArgumentType.DependencyClasspath in includedArgumentTypes) {
applyContribution(contribution)
}
}
@@ -32,7 +32,8 @@ internal class IdeCompilerArgumentsResolverImpl(
isLenient = true,
includeArgumentTypes = setOfNotNull(
KotlinCompilerArgumentsProducer.ArgumentType.Primitive,
KotlinCompilerArgumentsProducer.ArgumentType.Classpath
KotlinCompilerArgumentsProducer.ArgumentType.PluginClasspath,
KotlinCompilerArgumentsProducer.ArgumentType.DependencyClasspath
.takeIf { extension !is KotlinMultiplatformExtension }
.takeIf { producer is KotlinCompile }
.takeIf { !extension.project.hasAndroidPlugin }
@@ -20,7 +20,6 @@ import org.gradle.process.ExecOperations
import org.jetbrains.kotlin.cli.common.arguments.K2NativeCompilerArguments
import org.jetbrains.kotlin.compilerRunner.*
import org.jetbrains.kotlin.gradle.dsl.*
import org.jetbrains.kotlin.gradle.plugin.KotlinCompilerArgumentsProducer
import org.jetbrains.kotlin.gradle.plugin.KotlinCompilerArgumentsProducer.CreateCompilerArgumentsContext
import org.jetbrains.kotlin.gradle.plugin.KotlinCompilerArgumentsProducer.CreateCompilerArgumentsContext.Companion.create
import org.jetbrains.kotlin.gradle.plugin.PropertiesProvider
@@ -226,8 +225,11 @@ constructor(
KotlinCommonCompilerToolOptionsHelper.fillCompilerArguments(toolOptions, args)
}
classpath { args ->
pluginClasspath { args ->
args.pluginClasspaths = compilerPlugins.flatMap { classpath -> runSafe { classpath.files } ?: emptySet() }.toPathsArray()
}
dependencyClasspath { args ->
args.libraries = runSafe { libraries.files.filterKlibsPassedToCompiler() }?.toPathsArray()
args.exportedLibraries = runSafe { exportLibraries.files.filterKlibsPassedToCompiler() }?.toPathsArray()
args.friendModules = runSafe { friendModule.files.toList().takeIf { it.isNotEmpty() } }
@@ -30,7 +30,6 @@ import org.jetbrains.kotlin.gradle.internal.ensureParentDirsCreated
import org.jetbrains.kotlin.gradle.internal.isInIdeaSync
import org.jetbrains.kotlin.gradle.plugin.KotlinCompilation
import org.jetbrains.kotlin.gradle.plugin.KotlinCompilationInfo
import org.jetbrains.kotlin.gradle.plugin.KotlinCompilerArgumentsProducer
import org.jetbrains.kotlin.gradle.plugin.KotlinCompilerArgumentsProducer.CreateCompilerArgumentsContext
import org.jetbrains.kotlin.gradle.plugin.KotlinCompilerArgumentsProducer.CreateCompilerArgumentsContext.Companion.create
import org.jetbrains.kotlin.gradle.plugin.cocoapods.asValidFrameworkName
@@ -454,9 +453,11 @@ internal constructor(
KotlinNativeCompilerOptionsHelper.fillCompilerArguments(compilerOptions, args)
}
classpath { args ->
pluginClasspath { args ->
args.pluginClasspaths = compilerPlugins.flatMap { classpath -> runSafe { classpath.files } ?: emptySet() }.toPathsArray()
}
dependencyClasspath { args ->
args.libraries = runSafe { libraries.files.filterKlibsPassedToCompiler().toPathsArray() }
args.friendModules = runSafe {
friendModule.files.takeIf { it.isNotEmpty() }?.map { it.absolutePath }?.joinToString(File.pathSeparator)
@@ -167,13 +167,15 @@ abstract class Kotlin2JsCompile @Inject constructor(
args.freeArgs = executionTimeFreeCompilerArgs ?: enhancedFreeCompilerArgs.get()
}
classpath { args ->
pluginClasspath { args ->
args.pluginClasspaths = runSafe {
listOfNotNull(
pluginClasspath, kotlinPluginData?.orNull?.classpath
).reduce(FileCollection::plus).toPathsArray()
}
}
dependencyClasspath { args ->
args.friendModules = friendDependencies.files.joinToString(File.pathSeparator) { it.absolutePath }
args.libraries = runSafe {
@@ -245,13 +245,15 @@ abstract class KotlinCompile @Inject constructor(
}
}
classpath { args ->
pluginClasspath { args ->
args.pluginClasspaths = runSafe {
listOfNotNull(
pluginClasspath, kotlinPluginData?.orNull?.classpath
).reduce(FileCollection::plus).toPathsArray()
}
}
dependencyClasspath { args ->
args.friendPaths = friendPaths.toPathsArray()
args.classpathAsList = runSafe {
libraries.toList().filter { it.exists() }
@@ -23,7 +23,6 @@ import org.gradle.api.tasks.*
import org.gradle.work.InputChanges
import org.gradle.work.NormalizeLineEndings
import org.gradle.workers.WorkerExecutor
import org.jetbrains.kotlin.cli.common.arguments.CommonCompilerArguments
import org.jetbrains.kotlin.cli.common.arguments.K2MetadataCompilerArguments
import org.jetbrains.kotlin.compilerRunner.GradleCompilerEnvironment
import org.jetbrains.kotlin.compilerRunner.OutputItemsCollectorImpl
@@ -31,7 +30,6 @@ import org.jetbrains.kotlin.gradle.dsl.*
import org.jetbrains.kotlin.gradle.internal.tasks.allOutputFiles
import org.jetbrains.kotlin.gradle.logging.GradleErrorMessageCollector
import org.jetbrains.kotlin.gradle.logging.GradlePrintingMessageCollector
import org.jetbrains.kotlin.gradle.plugin.KotlinCompilerArgumentsProducer
import org.jetbrains.kotlin.gradle.plugin.KotlinCompilerArgumentsProducer.CreateCompilerArgumentsContext
import org.jetbrains.kotlin.gradle.plugin.KotlinCompilerArgumentsProducer.CreateCompilerArgumentsContext.Companion.create
import org.jetbrains.kotlin.gradle.report.BuildReportMode
@@ -93,12 +91,15 @@ abstract class KotlinCompileCommon @Inject constructor(
}
}
classpath { args ->
pluginClasspath { args ->
args.pluginClasspaths = runSafe {
listOfNotNull(
pluginClasspath, kotlinPluginData?.orNull?.classpath
).reduce(FileCollection::plus).toPathsArray()
}
}
dependencyClasspath { args ->
args.classpath = runSafe { libraries.files.filter { it.exists() }.joinToString(File.pathSeparator) }
args.friendPaths = runSafe { this@KotlinCompileCommon.friendPaths.files.toPathsArray() }
args.refinesPaths = refinesMetadataPaths.toPathsArray()