[Gradle] KotlinCompilerArgumentsProducer: Merge PluginClasspath & DependencyClasspath

KTIJ-24976
This commit is contained in:
Sebastian Sellmair
2023-04-04 21:27:49 +02:00
committed by Space Team
parent 1bbd135de8
commit 86c33ec97c
9 changed files with 9 additions and 26 deletions
@@ -83,6 +83,5 @@ interface CompilerArgumentAware<T : CommonToolArguments> : KotlinCompilerArgumen
private val includedArgumentTypes = setOf( private val includedArgumentTypes = setOf(
ArgumentType.Primitive, ArgumentType.Primitive,
ArgumentType.PluginClasspath, ArgumentType.Classpath,
ArgumentType.DependencyClasspath,
) )
@@ -126,15 +126,13 @@ abstract class KaptGenerateStubsTask @Inject constructor(
args.destinationAsFile = destinationDirectory.get().asFile args.destinationAsFile = destinationDirectory.get().asFile
} }
contribute(KotlinCompilerArgumentsProducer.ArgumentType.PluginClasspath) { args -> contribute(KotlinCompilerArgumentsProducer.ArgumentType.Classpath) { args ->
args.pluginClasspaths = tryLenient { args.pluginClasspaths = tryLenient {
listOfNotNull( listOfNotNull(
pluginClasspath, kotlinPluginData?.orNull?.classpath pluginClasspath, kotlinPluginData?.orNull?.classpath
).reduce(FileCollection::plus).toPathsArray() ).reduce(FileCollection::plus).toPathsArray()
} }
}
contribute(KotlinCompilerArgumentsProducer.ArgumentType.DependencyClasspath) { args ->
args.classpathAsList = tryLenient { libraries.toList().filter { it.exists() } }.orEmpty() args.classpathAsList = tryLenient { libraries.toList().filter { it.exists() } }.orEmpty()
args.friendPaths = friendPaths.toPathsArray() args.friendPaths = friendPaths.toPathsArray()
} }
@@ -5,7 +5,6 @@
package org.jetbrains.kotlin.gradle.plugin package org.jetbrains.kotlin.gradle.plugin
import org.jetbrains.kotlin.cli.common.arguments.CommonCompilerArguments
import org.jetbrains.kotlin.cli.common.arguments.CommonToolArguments import org.jetbrains.kotlin.cli.common.arguments.CommonToolArguments
import org.jetbrains.kotlin.gradle.InternalKotlinGradlePluginApi import org.jetbrains.kotlin.gradle.InternalKotlinGradlePluginApi
import org.jetbrains.kotlin.gradle.plugin.KotlinCompilerArgumentsProducer.ContributeCompilerArgumentsContext import org.jetbrains.kotlin.gradle.plugin.KotlinCompilerArgumentsProducer.ContributeCompilerArgumentsContext
@@ -17,8 +16,7 @@ interface KotlinCompilerArgumentsProducer {
enum class ArgumentType { enum class ArgumentType {
Primitive, Primitive,
DependencyClasspath, Classpath,
PluginClasspath,
Sources; Sources;
companion object { companion object {
@@ -36,7 +36,7 @@ internal class IdeCompilerArgumentsResolverImpl(
isLenient = true, isLenient = true,
includeArgumentTypes = setOfNotNull( includeArgumentTypes = setOfNotNull(
KotlinCompilerArgumentsProducer.ArgumentType.Primitive, KotlinCompilerArgumentsProducer.ArgumentType.Primitive,
KotlinCompilerArgumentsProducer.ArgumentType.DependencyClasspath KotlinCompilerArgumentsProducer.ArgumentType.Classpath
.takeIf { extension !is KotlinMultiplatformExtension } .takeIf { extension !is KotlinMultiplatformExtension }
.takeIf { producer is KotlinCompile } .takeIf { producer is KotlinCompile }
.takeIf { !extension.project.hasAndroidPlugin } .takeIf { !extension.project.hasAndroidPlugin }
@@ -226,11 +226,8 @@ constructor(
KotlinCommonCompilerToolOptionsHelper.fillCompilerArguments(toolOptions, args) KotlinCommonCompilerToolOptionsHelper.fillCompilerArguments(toolOptions, args)
} }
contribute(KotlinCompilerArgumentsProducer.ArgumentType.PluginClasspath) { args -> contribute(KotlinCompilerArgumentsProducer.ArgumentType.Classpath) { args ->
args.pluginClasspaths = compilerPlugins.flatMap { classpath -> tryLenient { classpath.files } ?: emptySet() }.toPathsArray() args.pluginClasspaths = compilerPlugins.flatMap { classpath -> tryLenient { classpath.files } ?: emptySet() }.toPathsArray()
}
contribute(KotlinCompilerArgumentsProducer.ArgumentType.DependencyClasspath) { args ->
args.libraries = tryLenient { libraries.files.filterKlibsPassedToCompiler() }?.toPathsArray() args.libraries = tryLenient { libraries.files.filterKlibsPassedToCompiler() }?.toPathsArray()
args.exportedLibraries = tryLenient { exportLibraries.files.filterKlibsPassedToCompiler() }?.toPathsArray() args.exportedLibraries = tryLenient { exportLibraries.files.filterKlibsPassedToCompiler() }?.toPathsArray()
args.friendModules = tryLenient { friendModule.files.toList().takeIf { it.isNotEmpty() } } args.friendModules = tryLenient { friendModule.files.toList().takeIf { it.isNotEmpty() } }
@@ -454,11 +454,9 @@ internal constructor(
KotlinNativeCompilerOptionsHelper.fillCompilerArguments(compilerOptions, args) KotlinNativeCompilerOptionsHelper.fillCompilerArguments(compilerOptions, args)
} }
contribute(KotlinCompilerArgumentsProducer.ArgumentType.PluginClasspath) { args -> contribute(KotlinCompilerArgumentsProducer.ArgumentType.Classpath) { args ->
args.pluginClasspaths = compilerPlugins.flatMap { classpath -> tryLenient { classpath.files } ?: emptySet() }.toPathsArray() args.pluginClasspaths = compilerPlugins.flatMap { classpath -> tryLenient { classpath.files } ?: emptySet() }.toPathsArray()
}
contribute(KotlinCompilerArgumentsProducer.ArgumentType.DependencyClasspath) { args ->
args.libraries = tryLenient { libraries.files.filterKlibsPassedToCompiler().toPathsArray() } args.libraries = tryLenient { libraries.files.filterKlibsPassedToCompiler().toPathsArray() }
args.friendModules = tryLenient { args.friendModules = tryLenient {
friendModule.files.takeIf { it.isNotEmpty() }?.map { it.absolutePath }?.joinToString(File.pathSeparator) friendModule.files.takeIf { it.isNotEmpty() }?.map { it.absolutePath }?.joinToString(File.pathSeparator)
@@ -172,15 +172,13 @@ abstract class Kotlin2JsCompile @Inject constructor(
args.freeArgs = executionTimeFreeCompilerArgs ?: enhancedFreeCompilerArgs.get() args.freeArgs = executionTimeFreeCompilerArgs ?: enhancedFreeCompilerArgs.get()
} }
contribute(KotlinCompilerArgumentsProducer.ArgumentType.PluginClasspath) { args -> contribute(KotlinCompilerArgumentsProducer.ArgumentType.Classpath) { args ->
args.pluginClasspaths = tryLenient { args.pluginClasspaths = tryLenient {
listOfNotNull( listOfNotNull(
pluginClasspath, kotlinPluginData?.orNull?.classpath pluginClasspath, kotlinPluginData?.orNull?.classpath
).reduce(FileCollection::plus).toPathsArray() ).reduce(FileCollection::plus).toPathsArray()
} }
}
contribute(KotlinCompilerArgumentsProducer.ArgumentType.DependencyClasspath) { args ->
args.friendModules = friendDependencies.files.joinToString(File.pathSeparator) { it.absolutePath } args.friendModules = friendDependencies.files.joinToString(File.pathSeparator) { it.absolutePath }
args.libraries = tryLenient { args.libraries = tryLenient {
@@ -252,15 +252,13 @@ abstract class KotlinCompile @Inject constructor(
} }
} }
contribute(ArgumentType.PluginClasspath) { args -> contribute(ArgumentType.Classpath) { args ->
args.pluginClasspaths = tryLenient { args.pluginClasspaths = tryLenient {
listOfNotNull( listOfNotNull(
pluginClasspath, kotlinPluginData?.orNull?.classpath pluginClasspath, kotlinPluginData?.orNull?.classpath
).reduce(FileCollection::plus).toPathsArray() ).reduce(FileCollection::plus).toPathsArray()
} }
}
contribute(ArgumentType.DependencyClasspath) { args ->
args.friendPaths = friendPaths.toPathsArray() args.friendPaths = friendPaths.toPathsArray()
args.classpathAsList = tryLenient { args.classpathAsList = tryLenient {
libraries.toList().filter { it.exists() } libraries.toList().filter { it.exists() }
@@ -93,15 +93,12 @@ abstract class KotlinCompileCommon @Inject constructor(
} }
} }
contribute(KotlinCompilerArgumentsProducer.ArgumentType.PluginClasspath) { args -> contribute(KotlinCompilerArgumentsProducer.ArgumentType.Classpath) { args ->
args.pluginClasspaths = tryLenient { args.pluginClasspaths = tryLenient {
listOfNotNull( listOfNotNull(
pluginClasspath, kotlinPluginData?.orNull?.classpath pluginClasspath, kotlinPluginData?.orNull?.classpath
).reduce(FileCollection::plus).toPathsArray() ).reduce(FileCollection::plus).toPathsArray()
} }
}
contribute(KotlinCompilerArgumentsProducer.ArgumentType.DependencyClasspath) { args ->
args.classpath = tryLenient { libraries.files.filter { it.exists() }.joinToString(File.pathSeparator) } args.classpath = tryLenient { libraries.files.filter { it.exists() }.joinToString(File.pathSeparator) }
args.friendPaths = tryLenient { this@KotlinCompileCommon.friendPaths.files.toPathsArray() } args.friendPaths = tryLenient { this@KotlinCompileCommon.friendPaths.files.toPathsArray() }
args.refinesPaths = refinesMetadataPaths.toPathsArray() args.refinesPaths = refinesMetadataPaths.toPathsArray()