[Gradle] Implement CompilerArgumentAware (for compatibility) using the new KotlinCompilerArgumentsProducer
KTIJ-24976
This commit is contained in:
committed by
Space Team
parent
30a4911a51
commit
d6e3b63069
+45
-14
@@ -20,38 +20,69 @@ package org.jetbrains.kotlin.gradle.internal
|
||||
|
||||
import org.gradle.api.tasks.Internal
|
||||
import org.jetbrains.kotlin.cli.common.arguments.CommonToolArguments
|
||||
import org.jetbrains.kotlin.cli.common.arguments.copyBeanTo
|
||||
import org.jetbrains.kotlin.compilerRunner.ArgumentUtils
|
||||
import org.jetbrains.kotlin.compilerRunner.ArgumentUtils.convertArgumentsToStringList
|
||||
import org.jetbrains.kotlin.gradle.plugin.CreateCompilerArgumentsContext
|
||||
import org.jetbrains.kotlin.gradle.plugin.KotlinCompilerArgumentsProducer
|
||||
import org.jetbrains.kotlin.gradle.plugin.KotlinCompilerArgumentsProducer.ArgumentType
|
||||
|
||||
|
||||
/**
|
||||
* Only relevant for supporting older IDEs (before 2023.2)
|
||||
*/
|
||||
@Deprecated("Replaced by KotlinCompilerArgumentsProducer")
|
||||
interface CompilerArgumentAware<T : CommonToolArguments> {
|
||||
interface CompilerArgumentAware<T : CommonToolArguments> : KotlinCompilerArgumentsProducer {
|
||||
|
||||
@Deprecated("Replaced by KotlinCompilerArgumentsProducer", level = DeprecationLevel.ERROR)
|
||||
@Suppress("DEPRECATION")
|
||||
@get:Internal
|
||||
val serializedCompilerArguments: List<String>
|
||||
get() = ArgumentUtils.convertArgumentsToStringList(prepareCompilerArguments())
|
||||
get() = convertArgumentsToStringList(prepareCompilerArguments())
|
||||
|
||||
@Deprecated("Replaced by KotlinCompilerArgumentsProducer", level = DeprecationLevel.ERROR)
|
||||
@Suppress("DEPRECATION")
|
||||
@get:Internal
|
||||
val serializedCompilerArgumentsIgnoreClasspathIssues: List<String>
|
||||
get() = ArgumentUtils.convertArgumentsToStringList(prepareCompilerArguments(ignoreClasspathResolutionErrors = true))
|
||||
get() = convertArgumentsToStringList(prepareCompilerArguments(ignoreClasspathResolutionErrors = true))
|
||||
|
||||
@Deprecated("Replaced by KotlinCompilerArgumentsProducer", level = DeprecationLevel.ERROR)
|
||||
@Suppress("DEPRECATION")
|
||||
@get:Internal
|
||||
val defaultSerializedCompilerArguments: List<String>
|
||||
get() = createCompilerArgs()
|
||||
.also { setupCompilerArgs(it, defaultsOnly = true) }
|
||||
.let(ArgumentUtils::convertArgumentsToStringList)
|
||||
get() = createCompilerArguments(
|
||||
CreateCompilerArgumentsContext(includeArgumentTypes = setOf(ArgumentType.Primitive))
|
||||
).let(ArgumentUtils::convertArgumentsToStringList)
|
||||
|
||||
@Deprecated("Replaced by KotlinCompilerArgumentsProducer", level = DeprecationLevel.WARNING)
|
||||
fun createCompilerArgs(): T
|
||||
@Deprecated("Replaced by KotlinCompilerArgumentsProducer", level = DeprecationLevel.ERROR)
|
||||
fun createCompilerArgs(): T = createCompilerArguments(CreateCompilerArgumentsContext(includeArgumentTypes = emptySet()))
|
||||
|
||||
@Deprecated("Replaced by KotlinCompilerArgumentsProducer", level = DeprecationLevel.WARNING)
|
||||
fun setupCompilerArgs(args: T, defaultsOnly: Boolean = false, ignoreClasspathResolutionErrors: Boolean = false)
|
||||
@Deprecated("Replaced by KotlinCompilerArgumentsProducer", level = DeprecationLevel.ERROR)
|
||||
fun setupCompilerArgs(args: T, defaultsOnly: Boolean = false, ignoreClasspathResolutionErrors: Boolean = false) {
|
||||
val newArgs = createCompilerArguments(
|
||||
CreateCompilerArgumentsContext(
|
||||
includeArgumentTypes = if (defaultsOnly) setOf(ArgumentType.Primitive) else includedArgumentTypes,
|
||||
isLenient = ignoreClasspathResolutionErrors
|
||||
)
|
||||
)
|
||||
copyBeanTo(from = newArgs, to = args)
|
||||
}
|
||||
|
||||
override fun createCompilerArguments(context: KotlinCompilerArgumentsProducer.CreateCompilerArgumentsContext): T
|
||||
|
||||
@Suppress("DEPRECATION")
|
||||
private fun <T : CommonToolArguments> CompilerArgumentAware<T>.prepareCompilerArguments(
|
||||
ignoreClasspathResolutionErrors: Boolean = false
|
||||
): T = createCompilerArguments(
|
||||
CreateCompilerArgumentsContext(
|
||||
includeArgumentTypes = includedArgumentTypes,
|
||||
isLenient = ignoreClasspathResolutionErrors
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
@Deprecated("Replaced by KotlinCompilerArgumentsProducer", level = DeprecationLevel.WARNING)
|
||||
@Suppress("DEPRECATION")
|
||||
internal fun <T : CommonToolArguments> CompilerArgumentAware<T>.prepareCompilerArguments(ignoreClasspathResolutionErrors: Boolean = false) =
|
||||
createCompilerArgs().also { setupCompilerArgs(it, ignoreClasspathResolutionErrors = ignoreClasspathResolutionErrors) }
|
||||
private val includedArgumentTypes = setOf(
|
||||
ArgumentType.Primitive,
|
||||
ArgumentType.PluginClasspath,
|
||||
ArgumentType.DependencyClasspath,
|
||||
)
|
||||
+3
-3
@@ -92,7 +92,7 @@ class KotlinModelBuilder(private val kotlinPluginVersion: String, private val an
|
||||
javaSourceSet.resources.srcDirs,
|
||||
destinationDirectory.get().asFile,
|
||||
javaSourceSet.output.resourcesDir!!,
|
||||
createCompilerArguments()
|
||||
buildCompilerArguments()
|
||||
)
|
||||
} else null
|
||||
}
|
||||
@@ -118,12 +118,12 @@ class KotlinModelBuilder(private val kotlinPluginVersion: String, private val an
|
||||
resources,
|
||||
destinationDirectory.get().asFile,
|
||||
compilation.output.resourcesDir,
|
||||
createCompilerArguments()
|
||||
buildCompilerArguments()
|
||||
)
|
||||
}
|
||||
|
||||
@Suppress("DEPRECATION_ERROR")
|
||||
private fun AbstractKotlinCompile<*>.createCompilerArguments(): CompilerArguments {
|
||||
private fun AbstractKotlinCompile<*>.buildCompilerArguments(): CompilerArguments {
|
||||
return CompilerArgumentsImpl(
|
||||
serializedCompilerArguments,
|
||||
defaultSerializedCompilerArguments,
|
||||
|
||||
+6
-5
@@ -6,6 +6,7 @@
|
||||
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.gradle.InternalKotlinGradlePluginApi
|
||||
import org.jetbrains.kotlin.gradle.plugin.KotlinCompilerArgumentsProducer.ContributeCompilerArgumentsContext
|
||||
import kotlin.reflect.KClass
|
||||
@@ -26,7 +27,7 @@ interface KotlinCompilerArgumentsProducer {
|
||||
}
|
||||
|
||||
interface CreateCompilerArgumentsContext {
|
||||
fun <T : CommonCompilerArguments> create(type: KClass<T>, action: ContributeCompilerArgumentsContext<T>.() -> Unit): T
|
||||
fun <T : CommonToolArguments> create(type: KClass<T>, action: ContributeCompilerArgumentsContext<T>.() -> Unit): T
|
||||
|
||||
companion object {
|
||||
val default: CreateCompilerArgumentsContext = CreateCompilerArgumentsContext()
|
||||
@@ -38,14 +39,14 @@ interface KotlinCompilerArgumentsProducer {
|
||||
}
|
||||
}
|
||||
|
||||
interface ContributeCompilerArgumentsContext<T : CommonCompilerArguments> {
|
||||
interface ContributeCompilerArgumentsContext<T : CommonToolArguments> {
|
||||
fun <T> tryLenient(action: () -> T): T?
|
||||
fun contribute(type: ArgumentType, contribution: (T) -> Unit)
|
||||
}
|
||||
|
||||
fun createCompilerArguments(
|
||||
context: CreateCompilerArgumentsContext = CreateCompilerArgumentsContext()
|
||||
): CommonCompilerArguments
|
||||
): CommonToolArguments
|
||||
}
|
||||
|
||||
internal fun CreateCompilerArgumentsContext(
|
||||
@@ -60,7 +61,7 @@ private class CreateCompilerArgumentsContextImpl(
|
||||
private val isLenient: Boolean
|
||||
) : KotlinCompilerArgumentsProducer.CreateCompilerArgumentsContext {
|
||||
|
||||
override fun <T : CommonCompilerArguments> create(
|
||||
override fun <T : CommonToolArguments> create(
|
||||
type: KClass<T>, action: ContributeCompilerArgumentsContext<T>.() -> Unit
|
||||
): T {
|
||||
val constructor = type.java.constructors.firstOrNull { it.parameters.isEmpty() }
|
||||
@@ -70,7 +71,7 @@ private class CreateCompilerArgumentsContextImpl(
|
||||
return arguments
|
||||
}
|
||||
|
||||
private inner class ContributeCompilerArgumentsContextImpl<T : CommonCompilerArguments>(
|
||||
private inner class ContributeCompilerArgumentsContextImpl<T : CommonToolArguments>(
|
||||
private val arguments: T
|
||||
) : ContributeCompilerArgumentsContext<T> {
|
||||
|
||||
|
||||
+1
-36
@@ -270,23 +270,10 @@ abstract class AbstractKotlinNativeCompile<
|
||||
@get:Nested
|
||||
var kotlinPluginData: Provider<KotlinCompilerPluginData>? = null
|
||||
|
||||
// Used by IDE via reflection.
|
||||
@get:Internal
|
||||
override val serializedCompilerArguments: List<String>
|
||||
get() = buildCommonArgs()
|
||||
|
||||
// Used by IDE via reflection.
|
||||
@get:Internal
|
||||
override val defaultSerializedCompilerArguments: List<String>
|
||||
get() = buildCommonArgs(true)
|
||||
|
||||
private val languageSettingsBuilder by project.provider {
|
||||
compilation.languageSettings
|
||||
}
|
||||
|
||||
// Args used by both the compiler and IDEA.
|
||||
abstract fun buildCommonArgs(defaultsOnly: Boolean = false): List<String>
|
||||
|
||||
@get:Input
|
||||
@get:Optional
|
||||
internal val konanTargetsForManifest: String by project.provider {
|
||||
@@ -321,9 +308,8 @@ internal constructor(
|
||||
private val objectFactory: ObjectFactory,
|
||||
private val providerFactory: ProviderFactory,
|
||||
private val execOperations: ExecOperations
|
||||
) : AbstractKotlinNativeCompile<KotlinCommonOptions, StubK2NativeCompilerArguments>(objectFactory),
|
||||
) : AbstractKotlinNativeCompile<KotlinCommonOptions, K2NativeCompilerArguments>(objectFactory),
|
||||
KotlinCompile<KotlinCommonOptions>,
|
||||
KotlinCompilerArgumentsProducer,
|
||||
K2MultiplatformCompilationTask,
|
||||
KotlinCompilationTask<KotlinNativeCompilerOptions> {
|
||||
|
||||
@@ -434,27 +420,6 @@ internal constructor(
|
||||
private val isAllowCommonizer: Boolean by lazy { project.isAllowCommonizer() }
|
||||
// endregion.
|
||||
|
||||
override fun createCompilerArgs(): StubK2NativeCompilerArguments = StubK2NativeCompilerArguments()
|
||||
|
||||
override fun setupCompilerArgs(
|
||||
args: StubK2NativeCompilerArguments,
|
||||
defaultsOnly: Boolean,
|
||||
ignoreClasspathResolutionErrors: Boolean
|
||||
) = Unit
|
||||
|
||||
override fun buildCommonArgs(defaultsOnly: Boolean): List<String> {
|
||||
val plugins = listOfNotNull(
|
||||
compilerPluginClasspath?.let { CompilerPluginData(it, compilerPluginOptions) },
|
||||
kotlinPluginData?.orNull?.let { CompilerPluginData(it.classpath, it.options) }
|
||||
)
|
||||
|
||||
return buildKotlinNativeCompileCommonArgs(
|
||||
languageSettings,
|
||||
compilerOptions,
|
||||
plugins
|
||||
)
|
||||
}
|
||||
|
||||
override fun createCompilerArguments(context: CreateCompilerArgumentsContext) = context.create<K2NativeCompilerArguments> {
|
||||
val sharedCompilationData = createSharedCompilationDataOrNull()
|
||||
|
||||
|
||||
+1
-12
@@ -34,24 +34,16 @@ import org.jetbrains.kotlin.gradle.dsl.KotlinCommonCompilerOptions
|
||||
import org.jetbrains.kotlin.gradle.incremental.UsesIncrementalModuleInfoBuildService
|
||||
import org.jetbrains.kotlin.gradle.internal.AbstractKotlinCompileArgumentsContributor
|
||||
import org.jetbrains.kotlin.gradle.internal.compilerArgumentsConfigurationFlags
|
||||
import org.jetbrains.kotlin.gradle.internal.prepareCompilerArguments
|
||||
import org.jetbrains.kotlin.gradle.internal.tasks.allOutputFiles
|
||||
import org.jetbrains.kotlin.gradle.logging.GradleKotlinLogger
|
||||
import org.jetbrains.kotlin.gradle.logging.kotlinDebug
|
||||
import org.jetbrains.kotlin.gradle.plugin.KotlinCompilerArgumentsProducer
|
||||
import org.jetbrains.kotlin.gradle.plugin.KotlinCompilerArgumentsProducer.CreateCompilerArgumentsContext.Companion.default
|
||||
import org.jetbrains.kotlin.gradle.plugin.PropertiesProvider.PropertyNames.KOTLIN_SUPPRESS_EXPERIMENTAL_IC_OPTIMIZATIONS_WARNING
|
||||
import org.jetbrains.kotlin.gradle.plugin.UsesBuildFinishedListenerService
|
||||
import org.jetbrains.kotlin.gradle.plugin.UsesVariantImplementationFactories
|
||||
import org.jetbrains.kotlin.gradle.plugin.statistics.KotlinBuildStatsService
|
||||
import org.jetbrains.kotlin.gradle.report.*
|
||||
import org.jetbrains.kotlin.gradle.report.UsesBuildMetricsService
|
||||
import org.jetbrains.kotlin.gradle.report.UsesBuildReportsService
|
||||
import org.jetbrains.kotlin.gradle.utils.*
|
||||
import org.jetbrains.kotlin.gradle.utils.newInstance
|
||||
import org.jetbrains.kotlin.gradle.utils.property
|
||||
import org.jetbrains.kotlin.gradle.utils.propertyWithConvention
|
||||
import org.jetbrains.kotlin.gradle.utils.propertyWithNewInstance
|
||||
import org.jetbrains.kotlin.incremental.ChangedFiles
|
||||
import org.jetbrains.kotlin.incremental.IncrementalCompilerRunner
|
||||
import org.jetbrains.kotlin.statistics.metrics.BooleanMetrics
|
||||
@@ -320,10 +312,7 @@ abstract class AbstractKotlinCompile<T : CommonCompilerArguments> @Inject constr
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
val args = @Suppress("unchecked_cast", "deprecation")
|
||||
if (this is KotlinCompilerArgumentsProducer) createCompilerArguments(default) as T
|
||||
else prepareCompilerArguments()
|
||||
val args = createCompilerArguments(default)
|
||||
|
||||
taskBuildCacheableOutputDirectory.get().asFile.mkdirs()
|
||||
taskBuildLocalStateDirectory.get().asFile.mkdirs()
|
||||
|
||||
+2
@@ -23,6 +23,7 @@ import org.jetbrains.kotlin.build.report.metrics.BuildMetricsReporterImpl
|
||||
import org.jetbrains.kotlin.cli.common.arguments.CommonToolArguments
|
||||
import org.jetbrains.kotlin.gradle.internal.CompilerArgumentAware
|
||||
import org.jetbrains.kotlin.gradle.internal.tasks.TaskWithLocalState
|
||||
import org.jetbrains.kotlin.gradle.plugin.KotlinCompilerArgumentsProducer
|
||||
import org.jetbrains.kotlin.gradle.utils.fileExtensionCasePermutations
|
||||
import org.jetbrains.kotlin.gradle.utils.property
|
||||
import javax.inject.Inject
|
||||
@@ -31,6 +32,7 @@ abstract class AbstractKotlinCompileTool<T : CommonToolArguments> @Inject constr
|
||||
objectFactory: ObjectFactory
|
||||
) : DefaultTask(),
|
||||
KotlinCompileTool,
|
||||
KotlinCompilerArgumentsProducer,
|
||||
CompilerArgumentAware<T>,
|
||||
TaskWithLocalState {
|
||||
|
||||
|
||||
-39
@@ -58,7 +58,6 @@ abstract class Kotlin2JsCompile @Inject constructor(
|
||||
workerExecutor: WorkerExecutor
|
||||
) : AbstractKotlinCompile<K2JSCompilerArguments>(objectFactory, workerExecutor),
|
||||
KotlinCompilationTask<KotlinJsCompilerOptions>,
|
||||
KotlinCompilerArgumentsProducer,
|
||||
UsesLibraryFilterCachingService,
|
||||
KotlinJsCompile,
|
||||
K2MultiplatformCompilationTask {
|
||||
@@ -132,44 +131,6 @@ abstract class Kotlin2JsCompile @Inject constructor(
|
||||
override fun createCompilerArgs(): K2JSCompilerArguments =
|
||||
K2JSCompilerArguments()
|
||||
|
||||
@Suppress("OVERRIDE_DEPRECATION")
|
||||
override fun setupCompilerArgs(args: K2JSCompilerArguments, defaultsOnly: Boolean, ignoreClasspathResolutionErrors: Boolean) {
|
||||
KotlinJsCompilerOptionsHelper.fillDefaultValues(args)
|
||||
super.setupCompilerArgs(args, defaultsOnly = defaultsOnly, ignoreClasspathResolutionErrors = ignoreClasspathResolutionErrors)
|
||||
|
||||
if (defaultsOnly) return
|
||||
|
||||
KotlinJsCompilerOptionsHelper.fillCompilerArguments(compilerOptions, args)
|
||||
if (!args.sourceMapPrefix.isNullOrEmpty()) {
|
||||
args.sourceMapBaseDirs = sourceMapBaseDir.get().asFile.absolutePath
|
||||
}
|
||||
if (isIrBackendEnabled()) {
|
||||
val outputFilePath: String? = compilerOptions.outputFile.orNull
|
||||
if (outputFilePath != null) {
|
||||
val outputFile = File(outputFilePath)
|
||||
args.outputDir = (if (outputFile.extension == "") outputFile else outputFile.parentFile).normalize().absolutePath
|
||||
args.moduleName = outputFile.nameWithoutExtension
|
||||
} else {
|
||||
args.outputDir = destinationDirectory.get().asFile.normalize().absolutePath
|
||||
args.moduleName = compilerOptions.moduleName.get()
|
||||
}
|
||||
} else {
|
||||
args.outputFile = outputFileProperty.get().absoluteFile.normalize().absolutePath
|
||||
}
|
||||
|
||||
args.configureMultiplatform(
|
||||
compilerOptions,
|
||||
k1CommonSources = commonSourceSet.asFileTree,
|
||||
k2MultiplatformFragments = multiplatformStructure
|
||||
)
|
||||
|
||||
// Overriding freeArgs from compilerOptions with enhanced one + additional one set on execution phase
|
||||
// containing additional arguments based on the js compilation configuration
|
||||
val localExecutionTimeFreeCompilerArgs = executionTimeFreeCompilerArgs
|
||||
args.freeArgs =
|
||||
if (localExecutionTimeFreeCompilerArgs != null) localExecutionTimeFreeCompilerArgs else enhancedFreeCompilerArgs.get()
|
||||
}
|
||||
|
||||
override fun createCompilerArguments(context: CreateCompilerArgumentsContext) = context.create<K2JSCompilerArguments> {
|
||||
contribute(KotlinCompilerArgumentsProducer.ArgumentType.Primitive) { args ->
|
||||
args.multiPlatform = multiPlatformEnabled.get()
|
||||
|
||||
+3
-29
@@ -69,7 +69,6 @@ abstract class KotlinCompile @Inject constructor(
|
||||
K2MultiplatformCompilationTask,
|
||||
@Suppress("TYPEALIAS_EXPANSION_DEPRECATION") KotlinJvmCompileDsl,
|
||||
KotlinCompilationTask<KotlinJvmCompilerOptions>,
|
||||
KotlinCompilerArgumentsProducer,
|
||||
UsesKotlinJavaToolchain {
|
||||
|
||||
@get:Internal // covered by compiler options
|
||||
@@ -211,9 +210,6 @@ abstract class KotlinCompile @Inject constructor(
|
||||
|
||||
override fun skipCondition(): Boolean = sources.isEmpty && scriptSources.isEmpty
|
||||
|
||||
override fun createCompilerArgs(): K2JVMCompilerArguments =
|
||||
K2JVMCompilerArguments()
|
||||
|
||||
/**
|
||||
* Workaround for those "nasty" plugins that are adding 'freeCompilerArgs' on task execution phase.
|
||||
* With properties api it is not possible to update property value after task configuration is finished.
|
||||
@@ -224,30 +220,6 @@ abstract class KotlinCompile @Inject constructor(
|
||||
@get:Internal
|
||||
internal var executionTimeFreeCompilerArgs: List<String>? = null
|
||||
|
||||
override fun setupCompilerArgs(args: K2JVMCompilerArguments, defaultsOnly: Boolean, ignoreClasspathResolutionErrors: Boolean) {
|
||||
compilerArgumentsContributor.contributeArguments(
|
||||
args, compilerArgumentsConfigurationFlags(
|
||||
defaultsOnly,
|
||||
ignoreClasspathResolutionErrors
|
||||
)
|
||||
)
|
||||
|
||||
args.configureMultiplatform(
|
||||
compilerOptions,
|
||||
k1CommonSources = commonSourceSet.asFileTree,
|
||||
k2MultiplatformFragments = multiplatformStructure
|
||||
)
|
||||
|
||||
if (reportingSettings().buildReportMode == BuildReportMode.VERBOSE) {
|
||||
args.reportPerf = true
|
||||
}
|
||||
|
||||
val localExecutionTimeFreeCompilerArgs = executionTimeFreeCompilerArgs
|
||||
if (localExecutionTimeFreeCompilerArgs != null) {
|
||||
args.freeArgs = localExecutionTimeFreeCompilerArgs
|
||||
}
|
||||
}
|
||||
|
||||
@get:Internal
|
||||
internal val compilerArgumentsContributor: CompilerArgumentsContributor<K2JVMCompilerArguments> by lazy {
|
||||
KotlinJvmCompilerArgumentsContributor(KotlinJvmCompilerArgumentsProvider(this))
|
||||
@@ -325,7 +297,9 @@ abstract class KotlinCompile @Inject constructor(
|
||||
val scriptSources = scriptSources.asFileTree.files
|
||||
val javaSources = javaSources.files
|
||||
val gradlePrintingMessageCollector = GradlePrintingMessageCollector(logger, args.allWarningsAsErrors)
|
||||
val gradleMessageCollector = GradleErrorMessageCollector(gradlePrintingMessageCollector, kotlinPluginVersion = getKotlinPluginVersion(logger))
|
||||
val gradleMessageCollector = GradleErrorMessageCollector(
|
||||
gradlePrintingMessageCollector, kotlinPluginVersion = getKotlinPluginVersion(logger)
|
||||
)
|
||||
val outputItemCollector = OutputItemsCollectorImpl()
|
||||
val compilerRunner = compilerRunner.get()
|
||||
|
||||
|
||||
-38
@@ -47,7 +47,6 @@ abstract class KotlinCompileCommon @Inject constructor(
|
||||
objectFactory: ObjectFactory
|
||||
) : AbstractKotlinCompile<K2MetadataCompilerArguments>(objectFactory, workerExecutor),
|
||||
KotlinCompilationTask<KotlinMultiplatformCommonCompilerOptions>,
|
||||
KotlinCompilerArgumentsProducer,
|
||||
KotlinCommonCompile {
|
||||
|
||||
init {
|
||||
@@ -69,43 +68,6 @@ abstract class KotlinCompileCommon @Inject constructor(
|
||||
@get:Internal
|
||||
internal var executionTimeFreeCompilerArgs: List<String>? = null
|
||||
|
||||
override fun createCompilerArgs(): K2MetadataCompilerArguments =
|
||||
K2MetadataCompilerArguments()
|
||||
|
||||
override fun setupCompilerArgs(args: K2MetadataCompilerArguments, defaultsOnly: Boolean, ignoreClasspathResolutionErrors: Boolean) {
|
||||
KotlinMultiplatformCommonCompilerOptionsHelper.fillDefaultValues(args)
|
||||
super.setupCompilerArgs(args, defaultsOnly = defaultsOnly, ignoreClasspathResolutionErrors = ignoreClasspathResolutionErrors)
|
||||
|
||||
args.moduleName = this@KotlinCompileCommon.moduleName.get()
|
||||
|
||||
if (expectActualLinker.get()) {
|
||||
args.expectActualLinker = true
|
||||
}
|
||||
|
||||
if (defaultsOnly) return
|
||||
|
||||
val classpathList = try {
|
||||
libraries.files.filter { it.exists() }.toMutableList()
|
||||
} catch (t: Throwable) {
|
||||
if (ignoreClasspathResolutionErrors) null else throw t
|
||||
}
|
||||
|
||||
with(args) {
|
||||
classpath = classpathList?.joinToString(File.pathSeparator)
|
||||
destination = destinationDirectory.get().asFile.normalize().absolutePath
|
||||
|
||||
friendPaths = this@KotlinCompileCommon.friendPaths.files.map { it.absolutePath }.toTypedArray()
|
||||
refinesPaths = refinesMetadataPaths.map { it.absolutePath }.toTypedArray()
|
||||
}
|
||||
|
||||
KotlinMultiplatformCommonCompilerOptionsHelper.fillCompilerArguments(compilerOptions, args)
|
||||
|
||||
val localExecutionTimeFreeCompilerArgs = executionTimeFreeCompilerArgs
|
||||
if (localExecutionTimeFreeCompilerArgs != null) {
|
||||
args.freeArgs = localExecutionTimeFreeCompilerArgs
|
||||
}
|
||||
}
|
||||
|
||||
override fun createCompilerArguments(context: CreateCompilerArgumentsContext) = context.create<K2MetadataCompilerArguments> {
|
||||
contribute(KotlinCompilerArgumentsProducer.ArgumentType.Primitive) { args ->
|
||||
args.multiPlatform = multiPlatformEnabled.get()
|
||||
|
||||
+3
-13
@@ -10,19 +10,18 @@ package org.jetbrains.kotlin.gradle.unitTests
|
||||
import org.gradle.kotlin.dsl.newInstance
|
||||
import org.jetbrains.kotlin.cli.common.arguments.CommonCompilerArguments
|
||||
import org.jetbrains.kotlin.cli.common.arguments.K2JVMCompilerArguments
|
||||
import org.jetbrains.kotlin.cli.common.arguments.K2NativeCompilerArguments
|
||||
import org.jetbrains.kotlin.cli.common.arguments.parseCommandLineArguments
|
||||
import org.jetbrains.kotlin.compilerRunner.ArgumentUtils
|
||||
import org.jetbrains.kotlin.gradle.dsl.KotlinVersion
|
||||
import org.jetbrains.kotlin.gradle.dsl.multiplatformExtension
|
||||
import org.jetbrains.kotlin.gradle.internal.CompilerArgumentAware
|
||||
import org.jetbrains.kotlin.gradle.plugin.KotlinCompilation
|
||||
import org.jetbrains.kotlin.gradle.plugin.KotlinCompilerArgumentsProducer.CreateCompilerArgumentsContext.Companion.lenient
|
||||
import org.jetbrains.kotlin.gradle.plugin.KotlinJsCompilerType.IR
|
||||
import org.jetbrains.kotlin.gradle.tasks.K2MultiplatformCompilationTask
|
||||
import org.jetbrains.kotlin.gradle.tasks.K2MultiplatformStructure
|
||||
import org.jetbrains.kotlin.gradle.tasks.K2MultiplatformStructure.RefinesEdge
|
||||
import org.jetbrains.kotlin.gradle.tasks.K2MultiplatformStructure.Fragment
|
||||
import org.jetbrains.kotlin.gradle.tasks.KotlinNativeCompile
|
||||
import org.jetbrains.kotlin.gradle.tasks.K2MultiplatformStructure.RefinesEdge
|
||||
import org.jetbrains.kotlin.gradle.tasks.configureK2Multiplatform
|
||||
import org.jetbrains.kotlin.gradle.util.applyMultiplatformPlugin
|
||||
import org.jetbrains.kotlin.gradle.util.buildProject
|
||||
@@ -156,16 +155,7 @@ class K2MultiplatformStructureTest {
|
||||
|
||||
private fun K2MultiplatformCompilationTask.buildCompilerArguments(): CommonCompilerArguments {
|
||||
/* KotlinNative implements CompilerArgumentAware, but does not adhere to its contract */
|
||||
|
||||
if (this is KotlinNativeCompile) {
|
||||
val arguments = K2NativeCompilerArguments()
|
||||
val argsList = this.buildCompilerArgs()
|
||||
parseCommandLineArguments(argsList, arguments)
|
||||
return arguments
|
||||
}
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
this as CompilerArgumentAware<CommonCompilerArguments>
|
||||
val args = createCompilerArgs()
|
||||
setupCompilerArgs(args)
|
||||
return args
|
||||
return this.createCompilerArguments(lenient)
|
||||
}
|
||||
|
||||
+5
-21
@@ -7,14 +7,8 @@
|
||||
|
||||
package org.jetbrains.kotlin.gradle.unitTests.compilerArgumetns
|
||||
|
||||
import org.gradle.kotlin.dsl.repositories
|
||||
import org.jetbrains.kotlin.compilerRunner.ArgumentUtils
|
||||
import org.jetbrains.kotlin.gradle.dependencyResolutionTests.mavenCentralCacheRedirector
|
||||
import org.jetbrains.kotlin.gradle.dsl.multiplatformExtension
|
||||
import org.jetbrains.kotlin.gradle.internal.prepareCompilerArguments
|
||||
import org.jetbrains.kotlin.gradle.plugin.CreateCompilerArgumentsContext
|
||||
import org.jetbrains.kotlin.gradle.plugin.KotlinCompilerArgumentsProducer
|
||||
import org.jetbrains.kotlin.gradle.plugin.KotlinCompilerArgumentsProducer.ArgumentType
|
||||
import org.jetbrains.kotlin.gradle.plugin.KotlinCompilerArgumentsProducer.CreateCompilerArgumentsContext.Companion.default
|
||||
import org.jetbrains.kotlin.gradle.plugin.KotlinCompilerArgumentsProducer.CreateCompilerArgumentsContext.Companion.lenient
|
||||
import org.jetbrains.kotlin.gradle.plugin.KotlinJsCompilerType
|
||||
@@ -26,15 +20,10 @@ import kotlin.test.assertFails
|
||||
import kotlin.test.assertNull
|
||||
|
||||
class Kotlin2JsCompileArgumentsTest {
|
||||
@Suppress("DEPRECATION")
|
||||
@Test
|
||||
fun `test - simple project - old CompilerArgumentsAware and new CompilerArgumentsProducer - return same arguments`() {
|
||||
val project = buildProjectWithMPP {
|
||||
repositories {
|
||||
mavenLocal()
|
||||
mavenCentralCacheRedirector()
|
||||
}
|
||||
}
|
||||
val project = buildProjectWithMPP()
|
||||
project.repositories.mavenLocal()
|
||||
|
||||
val kotlin = project.multiplatformExtension
|
||||
val jsTarget = kotlin.js(KotlinJsCompilerType.IR)
|
||||
@@ -42,16 +31,11 @@ class Kotlin2JsCompileArgumentsTest {
|
||||
project.evaluate()
|
||||
|
||||
val jsMainCompileTask = jsMainCompilation.compileTaskProvider.get()
|
||||
val argumentsFromCompilerArgumentsProducer = jsMainCompileTask.createCompilerArguments(
|
||||
CreateCompilerArgumentsContext(
|
||||
isLenient = true,
|
||||
includeArgumentTypes = ArgumentType.all - ArgumentType.DependencyClasspath
|
||||
)
|
||||
)
|
||||
val argumentsFromCompilerArgumentsAware = jsMainCompileTask.prepareCompilerArguments(true)
|
||||
val argumentsFromCompilerArgumentsProducer = jsMainCompileTask.createCompilerArguments(lenient)
|
||||
|
||||
@Suppress("DEPRECATION_ERROR")
|
||||
assertEquals(
|
||||
ArgumentUtils.convertArgumentsToStringList(argumentsFromCompilerArgumentsAware),
|
||||
jsMainCompileTask.serializedCompilerArgumentsIgnoreClasspathIssues,
|
||||
ArgumentUtils.convertArgumentsToStringList(argumentsFromCompilerArgumentsProducer),
|
||||
)
|
||||
}
|
||||
|
||||
+2
-4
@@ -18,7 +18,6 @@ import org.jetbrains.kotlin.gradle.dependencyResolutionTests.mavenCentralCacheRe
|
||||
import org.jetbrains.kotlin.gradle.dsl.KotlinVersion
|
||||
import org.jetbrains.kotlin.gradle.dsl.kotlinJvmExtension
|
||||
import org.jetbrains.kotlin.gradle.dsl.multiplatformExtension
|
||||
import org.jetbrains.kotlin.gradle.internal.prepareCompilerArguments
|
||||
import org.jetbrains.kotlin.gradle.plugin.KotlinCompilerArgumentsProducer.CreateCompilerArgumentsContext.Companion.lenient
|
||||
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
|
||||
import org.jetbrains.kotlin.gradle.util.assertNotNull
|
||||
@@ -30,7 +29,6 @@ import kotlin.test.*
|
||||
|
||||
class KotlinCompileArgumentsTest {
|
||||
|
||||
@Suppress("DEPRECATION")
|
||||
@Test
|
||||
fun `test - simple project - compare CompilerArgumentsAware with KotlinCompilerArgumentsAware implementations`() {
|
||||
val project = buildProjectWithJvm()
|
||||
@@ -45,11 +43,11 @@ class KotlinCompileArgumentsTest {
|
||||
|
||||
val mainCompilation = kotlin.target.compilations.getByName("main")
|
||||
val mainCompilationTask = mainCompilation.compileTaskProvider.get() as KotlinCompile
|
||||
val argumentsFromCompilerArgumentsAware = mainCompilationTask.prepareCompilerArguments(true)
|
||||
val argumentsFromKotlinCompilerArgumentsAware = mainCompilationTask.createCompilerArguments(lenient)
|
||||
|
||||
@Suppress("DEPRECATION_ERROR")
|
||||
assertEquals(
|
||||
ArgumentUtils.convertArgumentsToStringList(argumentsFromCompilerArgumentsAware),
|
||||
mainCompilationTask.serializedCompilerArgumentsIgnoreClasspathIssues,
|
||||
ArgumentUtils.convertArgumentsToStringList(argumentsFromKotlinCompilerArgumentsAware)
|
||||
)
|
||||
}
|
||||
|
||||
+2
-4
@@ -9,7 +9,6 @@ package org.jetbrains.kotlin.gradle.unitTests.compilerArgumetns
|
||||
|
||||
import org.jetbrains.kotlin.compilerRunner.ArgumentUtils
|
||||
import org.jetbrains.kotlin.gradle.dsl.multiplatformExtension
|
||||
import org.jetbrains.kotlin.gradle.internal.prepareCompilerArguments
|
||||
import org.jetbrains.kotlin.gradle.plugin.KotlinCompilerArgumentsProducer.CreateCompilerArgumentsContext
|
||||
import org.jetbrains.kotlin.gradle.plugin.KotlinCompilerArgumentsProducer.CreateCompilerArgumentsContext.Companion.lenient
|
||||
import org.jetbrains.kotlin.gradle.tasks.KotlinCompileCommon
|
||||
@@ -21,7 +20,6 @@ import kotlin.test.assertNull
|
||||
|
||||
class KotlinCompileCommonArgumentsTest {
|
||||
@Test
|
||||
@Suppress("DEPRECATION")
|
||||
fun `test - simple project - old CompilerArgumentsAware and new CompilerArgumentsProducer - return same arguments`() {
|
||||
val project = buildProjectWithMPP()
|
||||
project.repositories.mavenLocal()
|
||||
@@ -34,10 +32,10 @@ class KotlinCompileCommonArgumentsTest {
|
||||
val commonMainCompileTask = commonMainCompilation.compileTaskProvider.get() as KotlinCompileCommon
|
||||
|
||||
val argumentsFromCompilerArgumentsProducer = commonMainCompileTask.createCompilerArguments(lenient)
|
||||
val argumentsFromCompilerArgumentsAware = commonMainCompileTask.prepareCompilerArguments(true)
|
||||
|
||||
@Suppress("DEPRECATION_ERROR")
|
||||
assertEquals(
|
||||
ArgumentUtils.convertArgumentsToStringList(argumentsFromCompilerArgumentsAware),
|
||||
commonMainCompileTask.serializedCompilerArgumentsIgnoreClasspathIssues,
|
||||
ArgumentUtils.convertArgumentsToStringList(argumentsFromCompilerArgumentsProducer)
|
||||
)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user