Update KotlinNativeCompile task to use compiler options
^KT-27301 In Progress
This commit is contained in:
+77
-53
@@ -34,6 +34,7 @@ import org.jetbrains.kotlin.gradle.dsl.KotlinCompile
|
|||||||
import org.jetbrains.kotlin.gradle.internal.ensureParentDirsCreated
|
import org.jetbrains.kotlin.gradle.internal.ensureParentDirsCreated
|
||||||
import org.jetbrains.kotlin.gradle.internal.isInIdeaSync
|
import org.jetbrains.kotlin.gradle.internal.isInIdeaSync
|
||||||
import org.jetbrains.kotlin.gradle.plugin.KotlinCompilation
|
import org.jetbrains.kotlin.gradle.plugin.KotlinCompilation
|
||||||
|
import org.jetbrains.kotlin.gradle.plugin.cocoapods.asValidFrameworkName
|
||||||
import org.jetbrains.kotlin.gradle.plugin.mpp.*
|
import org.jetbrains.kotlin.gradle.plugin.mpp.*
|
||||||
import org.jetbrains.kotlin.gradle.plugin.mpp.pm20.KotlinNativeCompilationData
|
import org.jetbrains.kotlin.gradle.plugin.mpp.pm20.KotlinNativeCompilationData
|
||||||
import org.jetbrains.kotlin.gradle.plugin.mpp.pm20.KotlinNativeFragmentMetadataCompilationData
|
import org.jetbrains.kotlin.gradle.plugin.mpp.pm20.KotlinNativeFragmentMetadataCompilationData
|
||||||
@@ -90,15 +91,6 @@ internal fun MutableList<String>.addFileArgs(parameter: String, values: FileColl
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
internal fun MutableList<String>.addFileArgs(parameter: String, values: Collection<FileCollection>) {
|
|
||||||
values.forEach {
|
|
||||||
addFileArgs(parameter, it)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun File.providedByCompiler(project: Project): Boolean =
|
|
||||||
toPath().startsWith(project.file(project.konanHome).resolve("klib").toPath())
|
|
||||||
|
|
||||||
// We need to filter out interop duplicates because we create copy of them for IDE.
|
// We need to filter out interop duplicates because we create copy of them for IDE.
|
||||||
// TODO: Remove this after interop rework.
|
// TODO: Remove this after interop rework.
|
||||||
internal fun FileCollection.filterOutPublishableInteropLibs(project: Project): FileCollection =
|
internal fun FileCollection.filterOutPublishableInteropLibs(project: Project): FileCollection =
|
||||||
@@ -140,7 +132,7 @@ abstract class AbstractKotlinNativeCompile<
|
|||||||
>
|
>
|
||||||
@Inject constructor(
|
@Inject constructor(
|
||||||
private val objectFactory: ObjectFactory
|
private val objectFactory: ObjectFactory
|
||||||
): AbstractKotlinCompileTool<M>(objectFactory) {
|
) : AbstractKotlinCompileTool<M>(objectFactory) {
|
||||||
|
|
||||||
@get:Inject
|
@get:Inject
|
||||||
protected abstract val projectLayout: ProjectLayout
|
protected abstract val projectLayout: ProjectLayout
|
||||||
@@ -183,11 +175,26 @@ abstract class AbstractKotlinNativeCompile<
|
|||||||
val target: String by project.provider { compilation.konanTarget.name }
|
val target: String by project.provider { compilation.konanTarget.name }
|
||||||
|
|
||||||
// region Compiler options.
|
// region Compiler options.
|
||||||
|
@Deprecated(
|
||||||
|
message = "AbstractKotlinNativeCompile will not provide access to kotlinOptions." +
|
||||||
|
" Implementations should provide access to compilerOptions",
|
||||||
|
)
|
||||||
@get:Internal
|
@get:Internal
|
||||||
abstract val kotlinOptions: T
|
abstract val kotlinOptions: T
|
||||||
|
|
||||||
|
@Deprecated(
|
||||||
|
message = "AbstractKotlinNativeCompile will not provide access to kotlinOptions()." +
|
||||||
|
" Implementations should provide access to compilerOptions()",
|
||||||
|
)
|
||||||
abstract fun kotlinOptions(fn: T.() -> Unit)
|
abstract fun kotlinOptions(fn: T.() -> Unit)
|
||||||
|
|
||||||
|
@Deprecated(
|
||||||
|
message = "AbstractKotlinNativeCompile will not provide access to kotlinOptions()." +
|
||||||
|
" Implementations should provide access to compilerOptions()",
|
||||||
|
)
|
||||||
abstract fun kotlinOptions(fn: Closure<*>)
|
abstract fun kotlinOptions(fn: Closure<*>)
|
||||||
|
|
||||||
|
@Deprecated("Use implementations compilerOptions to get/set freeCompilerArgs")
|
||||||
@get:Input
|
@get:Input
|
||||||
abstract val additionalCompilerOptions: Provider<Collection<String>>
|
abstract val additionalCompilerOptions: Provider<Collection<String>>
|
||||||
|
|
||||||
@@ -264,25 +271,7 @@ abstract class AbstractKotlinNativeCompile<
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Args used by both the compiler and IDEA.
|
// Args used by both the compiler and IDEA.
|
||||||
private fun buildCommonArgs(defaultsOnly: Boolean = false): List<String> {
|
abstract fun buildCommonArgs(defaultsOnly: Boolean = false): List<String>
|
||||||
val plugins = listOfNotNull(
|
|
||||||
compilerPluginClasspath?.let { CompilerPluginData(it, compilerPluginOptions) },
|
|
||||||
kotlinPluginData?.orNull?.let { CompilerPluginData(it.classpath, it.options) }
|
|
||||||
)
|
|
||||||
val opts = object : KotlinCommonToolOptions {
|
|
||||||
override var allWarningsAsErrors = kotlinOptions.allWarningsAsErrors
|
|
||||||
override var suppressWarnings = kotlinOptions.suppressWarnings
|
|
||||||
override var verbose = kotlinOptions.verbose
|
|
||||||
override var freeCompilerArgs = if (defaultsOnly) emptyList() else additionalCompilerOptions.get().toList()
|
|
||||||
}
|
|
||||||
|
|
||||||
return buildKotlinNativeCommonArgs(
|
|
||||||
languageSettings,
|
|
||||||
enableEndorsedLibs,
|
|
||||||
opts,
|
|
||||||
plugins
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
@get:Input
|
@get:Input
|
||||||
@get:Optional
|
@get:Optional
|
||||||
@@ -315,7 +304,8 @@ constructor(
|
|||||||
private val providerFactory: ProviderFactory,
|
private val providerFactory: ProviderFactory,
|
||||||
private val execOperations: ExecOperations
|
private val execOperations: ExecOperations
|
||||||
) : AbstractKotlinNativeCompile<KotlinCommonOptions, KotlinNativeCompilationData<*>, StubK2NativeCompilerArguments>(objectFactory),
|
) : AbstractKotlinNativeCompile<KotlinCommonOptions, KotlinNativeCompilationData<*>, StubK2NativeCompilerArguments>(objectFactory),
|
||||||
KotlinCompile<KotlinCommonOptions> {
|
KotlinCompile<KotlinCommonOptions>,
|
||||||
|
KotlinCompilationTask<CompilerCommonOptions> {
|
||||||
|
|
||||||
@get:Input
|
@get:Input
|
||||||
override val outputKind = LIBRARY
|
override val outputKind = LIBRARY
|
||||||
@@ -354,20 +344,23 @@ constructor(
|
|||||||
@get:Internal // these sources are normally a subset of `source` ones which are already tracked
|
@get:Internal // these sources are normally a subset of `source` ones which are already tracked
|
||||||
val commonSources: ConfigurableFileCollection = project.files()
|
val commonSources: ConfigurableFileCollection = project.files()
|
||||||
|
|
||||||
// private val commonSources: FileCollection by lazy {
|
|
||||||
// // Already taken into account in getSources method.
|
|
||||||
// project.files(compilation.map { it.commonSources }).asFileTree
|
|
||||||
// }
|
|
||||||
|
|
||||||
private val commonSourcesTree: FileTree
|
private val commonSourcesTree: FileTree
|
||||||
get() = commonSources.asFileTree
|
get() = commonSources.asFileTree
|
||||||
|
|
||||||
// endregion.
|
// endregion.
|
||||||
|
|
||||||
// region Language settings imported from a SourceSet.
|
// region Language settings imported from a SourceSet.
|
||||||
|
@Deprecated(
|
||||||
|
message = "Replaced with compilerOptions.languageVersion",
|
||||||
|
replaceWith = ReplaceWith("compilerOptions.languageVersion")
|
||||||
|
)
|
||||||
val languageVersion: String?
|
val languageVersion: String?
|
||||||
@Optional @Input get() = languageSettings.languageVersion
|
@Optional @Input get() = languageSettings.languageVersion
|
||||||
|
|
||||||
|
@Deprecated(
|
||||||
|
message = "Replaced with compilerOptions.apiVersion",
|
||||||
|
replaceWith = ReplaceWith("compilerOptions.apiVersion")
|
||||||
|
)
|
||||||
val apiVersion: String?
|
val apiVersion: String?
|
||||||
@Optional @Input get() = languageSettings.apiVersion
|
@Optional @Input get() = languageSettings.apiVersion
|
||||||
|
|
||||||
@@ -379,26 +372,50 @@ constructor(
|
|||||||
// endregion.
|
// endregion.
|
||||||
|
|
||||||
// region Kotlin options.
|
// region Kotlin options.
|
||||||
override val kotlinOptions: KotlinCommonOptions by providerFactory.provider {
|
override val compilerOptions: CompilerCommonOptions = compilation.compilerOptions.options
|
||||||
compilation.kotlinOptions
|
|
||||||
|
@Deprecated(
|
||||||
|
message = "Replaced with compilerOptions",
|
||||||
|
replaceWith = ReplaceWith("compilerOptions")
|
||||||
|
)
|
||||||
|
@Suppress("DEPRECATION")
|
||||||
|
override val kotlinOptions: KotlinCommonOptions = object : KotlinCommonOptions {
|
||||||
|
override val options: CompilerCommonOptions
|
||||||
|
get() = compilerOptions
|
||||||
}
|
}
|
||||||
|
|
||||||
@get:Input
|
@Suppress("DEPRECATION")
|
||||||
override val additionalCompilerOptions: Provider<Collection<String>> = providerFactory.provider {
|
@Deprecated(
|
||||||
kotlinOptions.freeCompilerArgs + ((languageSettings as? DefaultLanguageSettingsBuilder)?.freeCompilerArgs ?: emptyList())
|
message = "Replaced with compilerOptions()",
|
||||||
}
|
replaceWith = ReplaceWith("compilerOptions(fn)")
|
||||||
|
)
|
||||||
private val runnerSettings = KotlinNativeCompilerRunner.Settings.fromProject(project)
|
|
||||||
private val isAllowCommonizer: Boolean by lazy { project.isAllowCommonizer() }
|
|
||||||
|
|
||||||
override fun kotlinOptions(fn: KotlinCommonOptions.() -> Unit) {
|
override fun kotlinOptions(fn: KotlinCommonOptions.() -> Unit) {
|
||||||
kotlinOptions.fn()
|
kotlinOptions.fn()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Deprecated(
|
||||||
|
message = "Replaced with compilerOptions()",
|
||||||
|
replaceWith = ReplaceWith("compilerOptions(fn)")
|
||||||
|
)
|
||||||
override fun kotlinOptions(fn: Closure<*>) {
|
override fun kotlinOptions(fn: Closure<*>) {
|
||||||
|
@Suppress("DEPRECATION")
|
||||||
fn.delegate = kotlinOptions
|
fn.delegate = kotlinOptions
|
||||||
fn.call()
|
fn.call()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Deprecated(
|
||||||
|
message = "Replaced with compilerOptions.freeCompilerArgs",
|
||||||
|
replaceWith = ReplaceWith("compilerOptions.freeCompilerArgs")
|
||||||
|
)
|
||||||
|
@get:Input
|
||||||
|
override val additionalCompilerOptions: Provider<Collection<String>> get() = compilerOptions
|
||||||
|
.freeCompilerArgs
|
||||||
|
.map {
|
||||||
|
it + (languageSettings as DefaultLanguageSettingsBuilder).freeCompilerArgs
|
||||||
|
}
|
||||||
|
|
||||||
|
private val runnerSettings = KotlinNativeCompilerRunner.Settings.fromProject(project)
|
||||||
|
private val isAllowCommonizer: Boolean by lazy { project.isAllowCommonizer() }
|
||||||
// endregion.
|
// endregion.
|
||||||
|
|
||||||
override fun createCompilerArgs(): StubK2NativeCompilerArguments = StubK2NativeCompilerArguments()
|
override fun createCompilerArgs(): StubK2NativeCompilerArguments = StubK2NativeCompilerArguments()
|
||||||
@@ -409,6 +426,20 @@ constructor(
|
|||||||
ignoreClasspathResolutionErrors: Boolean
|
ignoreClasspathResolutionErrors: Boolean
|
||||||
) = Unit
|
) = 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(
|
||||||
|
enableEndorsedLibs,
|
||||||
|
languageSettings,
|
||||||
|
compilerOptions,
|
||||||
|
plugins
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
@TaskAction
|
@TaskAction
|
||||||
fun compile() {
|
fun compile() {
|
||||||
val output = outputFile.get()
|
val output = outputFile.get()
|
||||||
@@ -428,13 +459,6 @@ constructor(
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
val localKotlinOptions = object : KotlinCommonToolOptions {
|
|
||||||
override var allWarningsAsErrors = kotlinOptions.allWarningsAsErrors
|
|
||||||
override var suppressWarnings = kotlinOptions.suppressWarnings
|
|
||||||
override var verbose = kotlinOptions.verbose
|
|
||||||
override var freeCompilerArgs = additionalCompilerOptions.get().toList()
|
|
||||||
}
|
|
||||||
|
|
||||||
val plugins = listOfNotNull(
|
val plugins = listOfNotNull(
|
||||||
compilerPluginClasspath?.let { CompilerPluginData(it, compilerPluginOptions) },
|
compilerPluginClasspath?.let { CompilerPluginData(it, compilerPluginOptions) },
|
||||||
kotlinPluginData?.orNull?.let { CompilerPluginData(it.classpath, it.options) }
|
kotlinPluginData?.orNull?.let { CompilerPluginData(it.classpath, it.options) }
|
||||||
@@ -448,7 +472,7 @@ constructor(
|
|||||||
libraries.files.filterKlibsPassedToCompiler(),
|
libraries.files.filterKlibsPassedToCompiler(),
|
||||||
languageSettings,
|
languageSettings,
|
||||||
enableEndorsedLibs,
|
enableEndorsedLibs,
|
||||||
localKotlinOptions,
|
compilerOptions,
|
||||||
plugins,
|
plugins,
|
||||||
moduleName,
|
moduleName,
|
||||||
shortModuleName,
|
shortModuleName,
|
||||||
|
|||||||
Reference in New Issue
Block a user