Deprecate old DSL method for binary configuration
In 1.3.20 a new binaries DSL was introduced. This patch deprecates old DSL methods used for binary configuration in 1.3.0 and 1.3.1x. Issue #KT-29998 Fixed
This commit is contained in:
+5
-5
@@ -298,14 +298,14 @@ open class KotlinNativeTargetConfigurator(
|
||||
val binaries = target.binaries
|
||||
val konanTarget = compilation.target.konanTarget
|
||||
val name = compilation.name
|
||||
val buildTypes = compilation.buildTypes
|
||||
val availableOutputKinds = compilation.outputKinds.filter { it.availableFor(konanTarget) }
|
||||
val buildTypes = compilation.buildTypesNoWarn
|
||||
val availableOutputKinds = compilation.outputKindsNoWarn.filter { it.availableFor(konanTarget) }
|
||||
|
||||
val configure: NativeBinary.() -> Unit = {
|
||||
this.compilation = compilation
|
||||
linkerOpts.addAll(compilation.linkerOpts)
|
||||
linkerOpts.addAll(compilation.linkerOptsNoWarn)
|
||||
if (this is Executable) {
|
||||
entryPoint = compilation.entryPoint
|
||||
entryPoint = compilation.entryPointNoWarn
|
||||
}
|
||||
compilation.binaries[outputKind to buildType] = this
|
||||
}
|
||||
@@ -322,7 +322,7 @@ open class KotlinNativeTargetConfigurator(
|
||||
// Allow setting linker options for the default test executable using the
|
||||
// corresponding properties of the test compilation.
|
||||
target.binaries.getDefaultTestExecutable().apply {
|
||||
linkerOpts.addAll(target.compilations.getByName(TEST_COMPILATION_NAME).linkerOpts)
|
||||
linkerOpts.addAll(target.compilations.getByName(TEST_COMPILATION_NAME).linkerOptsNoWarn)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+112
-11
@@ -3,7 +3,7 @@
|
||||
* that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
|
||||
@file:Suppress("PackageDirectoryMismatch") // Old package for compatibility
|
||||
@file:Suppress("PackageDirectoryMismatch", "DEPRECATION") // Old package for compatibility
|
||||
package org.jetbrains.kotlin.gradle.plugin.mpp
|
||||
|
||||
import groovy.lang.Closure
|
||||
@@ -19,9 +19,39 @@ import org.jetbrains.kotlin.gradle.plugin.KotlinCompilationWithResources
|
||||
import org.jetbrains.kotlin.gradle.plugin.KotlinSourceSet
|
||||
import org.jetbrains.kotlin.gradle.tasks.KotlinNativeCompile
|
||||
import org.jetbrains.kotlin.gradle.tasks.KotlinNativeLink
|
||||
import org.jetbrains.kotlin.gradle.utils.SingleWarningPerBuild
|
||||
import org.jetbrains.kotlin.gradle.utils.lowerCamelCaseName
|
||||
import java.io.File
|
||||
|
||||
private const val OLD_BINARY_API_DEPRECATION =
|
||||
"Use the `binaries` block instead. See: https://kotlinlang.org/docs/reference/building-mpp-with-gradle.html#building-final-native-binaries"
|
||||
|
||||
private fun KotlinNativeCompilation.printDeprecationWarning() {
|
||||
SingleWarningPerBuild.show(
|
||||
target.project,
|
||||
"""
|
||||
Some native binaries in this build are configured using deprecated APIs. Use the `binaries` block instead.
|
||||
The following APIs are deprecated:
|
||||
KotlinNativeCompilation.buildTypes
|
||||
KotlinNativeCompilation.outputKinds
|
||||
KotlinNativeCompilation.outputKinds(...)
|
||||
KotlinNativeCompilation.outputKind(...)
|
||||
KotlinNativeCompilation.entryPoint
|
||||
KotlinNativeCompilation.entryPoint(...)
|
||||
KotlinNativeCompilation.linkerOpts
|
||||
KotlinNativeCompilation.linkerOpts(...)
|
||||
KotlinNativeCompilation.findLinkTask(...)
|
||||
KotlinNativeCompilation.getLinkTask(...)
|
||||
KotlinNativeCompilation.findBinary(...)
|
||||
KotlinNativeCompilation.getBinary(...)
|
||||
KotlinNativeCompilation.linkTaskName(...)
|
||||
|
||||
|
||||
See details about the `binaries` block at https://kotlinlang.org/docs/reference/building-mpp-with-gradle.html#building-final-native-binaries
|
||||
""".trimIndent()
|
||||
)
|
||||
}
|
||||
|
||||
class KotlinNativeCompilation(
|
||||
override val target: KotlinNativeTarget,
|
||||
name: String
|
||||
@@ -54,7 +84,7 @@ class KotlinNativeCompilation(
|
||||
target.compilations.getByName(it)
|
||||
}
|
||||
|
||||
// Used only to support the old APIs. TODO: Remove when the old APIs are removed.
|
||||
// Used only to support the old APIs. TODO@binaries: Remove when the old APIs are removed.
|
||||
internal val binaries = mutableMapOf<Pair<NativeOutputKind, NativeBuildType>, NativeBinary>()
|
||||
|
||||
// Native-specific DSL.
|
||||
@@ -65,19 +95,46 @@ class KotlinNativeCompilation(
|
||||
extraOpts.addAll(values.map { it.toString() })
|
||||
}
|
||||
|
||||
var buildTypes = mutableListOf<NativeBuildType>()
|
||||
var outputKinds = mutableListOf<NativeOutputKind>()
|
||||
// Used to access build types from internals of the plugin without printing
|
||||
// the deprecation warning during user's project configuration.
|
||||
// TODO@binaries: Drop when the old API are removed.
|
||||
internal var buildTypesNoWarn = mutableListOf<NativeBuildType>()
|
||||
|
||||
@Deprecated(OLD_BINARY_API_DEPRECATION)
|
||||
var buildTypes: MutableList<NativeBuildType>
|
||||
get() = buildTypesNoWarn.also { printDeprecationWarning() }
|
||||
set(value) {
|
||||
printDeprecationWarning()
|
||||
buildTypesNoWarn = value
|
||||
}
|
||||
|
||||
// Used to access output kinds from internals of the plugin without printing
|
||||
// the deprecation warning during user's project configuration.
|
||||
// TODO@binaries: Drop when the old API are removed.
|
||||
internal var outputKindsNoWarn = mutableListOf<NativeOutputKind>()
|
||||
|
||||
@Deprecated(OLD_BINARY_API_DEPRECATION)
|
||||
var outputKinds: MutableList<NativeOutputKind>
|
||||
get() = outputKindsNoWarn.also { printDeprecationWarning() }
|
||||
set(value) {
|
||||
printDeprecationWarning()
|
||||
outputKindsNoWarn = value
|
||||
}
|
||||
|
||||
@Deprecated(OLD_BINARY_API_DEPRECATION)
|
||||
fun outputKind(kind: NativeOutputKind) = outputKinds.add(kind)
|
||||
|
||||
@Deprecated(OLD_BINARY_API_DEPRECATION)
|
||||
fun outputKinds(vararg kinds: NativeOutputKind) {
|
||||
outputKinds = kinds.toMutableList()
|
||||
}
|
||||
|
||||
@Deprecated(OLD_BINARY_API_DEPRECATION)
|
||||
fun outputKinds(vararg kinds: String) {
|
||||
outputKinds = kinds.map { NativeOutputKind.valueOf(it.toUpperCase()) }.toMutableList()
|
||||
}
|
||||
|
||||
@Deprecated(OLD_BINARY_API_DEPRECATION)
|
||||
fun outputKinds(kinds: List<Any>) {
|
||||
outputKinds = kinds.map {
|
||||
when (it) {
|
||||
@@ -88,7 +145,20 @@ class KotlinNativeCompilation(
|
||||
}.toMutableList()
|
||||
}
|
||||
|
||||
var entryPoint: String? = null
|
||||
// Used to access entry point from internals of the plugin without printing
|
||||
// the deprecation warning during user's project configuration.
|
||||
// TODO@binaries: Drop when the old API are removed.
|
||||
internal var entryPointNoWarn: String? = null
|
||||
|
||||
@Deprecated(OLD_BINARY_API_DEPRECATION)
|
||||
var entryPoint: String?
|
||||
get() = entryPointNoWarn.also { printDeprecationWarning() }
|
||||
set(value) {
|
||||
printDeprecationWarning()
|
||||
entryPointNoWarn = value
|
||||
}
|
||||
|
||||
@Deprecated(OLD_BINARY_API_DEPRECATION)
|
||||
fun entryPoint(value: String) {
|
||||
entryPoint = value
|
||||
}
|
||||
@@ -98,53 +168,84 @@ class KotlinNativeCompilation(
|
||||
DefaultCInteropSettings(project, cinteropName, this)
|
||||
}
|
||||
|
||||
var linkerOpts = mutableListOf<String>()
|
||||
// Used to access linker options from internals of the plugin without printing
|
||||
// the deprecation warning during user's project configuration.
|
||||
// TODO@binaries: Drop when the old API are removed.
|
||||
internal var linkerOptsNoWarn = mutableListOf<String>()
|
||||
|
||||
@Deprecated(OLD_BINARY_API_DEPRECATION)
|
||||
var linkerOpts: MutableList<String>
|
||||
get() = linkerOptsNoWarn.also { printDeprecationWarning() }
|
||||
set(value) {
|
||||
printDeprecationWarning()
|
||||
linkerOptsNoWarn = value
|
||||
}
|
||||
|
||||
fun cinterops(action: NamedDomainObjectContainer<DefaultCInteropSettings>.() -> Unit) = cinterops.action()
|
||||
fun cinterops(action: Closure<Unit>) = cinterops(ConfigureUtil.configureUsing(action))
|
||||
fun cinterops(action: Action<NamedDomainObjectContainer<DefaultCInteropSettings>>) = action.execute(cinterops)
|
||||
|
||||
@Deprecated(OLD_BINARY_API_DEPRECATION)
|
||||
fun linkerOpts(vararg values: String) = linkerOpts(values.toList())
|
||||
@Deprecated(OLD_BINARY_API_DEPRECATION)
|
||||
fun linkerOpts(values: List<String>) {
|
||||
linkerOpts.addAll(values)
|
||||
}
|
||||
|
||||
// Task accessors.
|
||||
fun findLinkTask(kind: NativeOutputKind, buildType: NativeBuildType): KotlinNativeLink? = binaries[kind to buildType]?.linkTask
|
||||
@Deprecated(OLD_BINARY_API_DEPRECATION)
|
||||
fun findLinkTask(kind: NativeOutputKind, buildType: NativeBuildType): KotlinNativeLink? =
|
||||
binaries[kind to buildType]?.linkTask.also { printDeprecationWarning() }
|
||||
|
||||
@Deprecated(OLD_BINARY_API_DEPRECATION)
|
||||
fun getLinkTask(kind: NativeOutputKind, buildType: NativeBuildType): KotlinNativeLink =
|
||||
findLinkTask(kind, buildType)
|
||||
findLinkTask(kind, buildType).also { printDeprecationWarning() }
|
||||
?: throw IllegalArgumentException("Cannot find a link task for the binary kind '$kind' and the build type '$buildType'")
|
||||
|
||||
@Deprecated(OLD_BINARY_API_DEPRECATION)
|
||||
fun findLinkTask(kind: String, buildType: String) =
|
||||
findLinkTask(NativeOutputKind.valueOf(kind.toUpperCase()), NativeBuildType.valueOf(buildType.toUpperCase()))
|
||||
.also { printDeprecationWarning() }
|
||||
|
||||
@Deprecated(OLD_BINARY_API_DEPRECATION)
|
||||
fun getLinkTask(kind: String, buildType: String) =
|
||||
getLinkTask(NativeOutputKind.valueOf(kind.toUpperCase()), NativeBuildType.valueOf(buildType.toUpperCase()))
|
||||
.also { printDeprecationWarning() }
|
||||
|
||||
fun findBinary(kind: NativeOutputKind, buildType: NativeBuildType): File? = findLinkTask(kind, buildType)?.outputFile?.get()
|
||||
@Deprecated(OLD_BINARY_API_DEPRECATION)
|
||||
fun findBinary(kind: NativeOutputKind, buildType: NativeBuildType): File? =
|
||||
findLinkTask(kind, buildType)?.outputFile?.get().also { printDeprecationWarning() }
|
||||
|
||||
fun getBinary(kind: NativeOutputKind, buildType: NativeBuildType): File = getLinkTask(kind, buildType).outputFile.get()
|
||||
@Deprecated(OLD_BINARY_API_DEPRECATION)
|
||||
fun getBinary(kind: NativeOutputKind, buildType: NativeBuildType): File =
|
||||
getLinkTask(kind, buildType).outputFile.get().also { printDeprecationWarning() }
|
||||
|
||||
@Deprecated(OLD_BINARY_API_DEPRECATION)
|
||||
fun findBinary(kind: String, buildType: String) =
|
||||
findBinary(NativeOutputKind.valueOf(kind.toUpperCase()), NativeBuildType.valueOf(buildType.toUpperCase()))
|
||||
.also { printDeprecationWarning() }
|
||||
|
||||
@Deprecated(OLD_BINARY_API_DEPRECATION)
|
||||
fun getBinary(kind: String, buildType: String) =
|
||||
getBinary(NativeOutputKind.valueOf(kind.toUpperCase()), NativeBuildType.valueOf(buildType.toUpperCase()))
|
||||
.also { printDeprecationWarning() }
|
||||
|
||||
// Naming
|
||||
override val processResourcesTaskName: String
|
||||
get() = disambiguateName("processResources")
|
||||
|
||||
@Deprecated(OLD_BINARY_API_DEPRECATION)
|
||||
fun linkTaskName(kind: NativeOutputKind, buildType: NativeBuildType): String =
|
||||
lowerCamelCaseName(
|
||||
"link",
|
||||
KotlinNativeBinaryContainer.generateBinaryName(compilationName, buildType, kind.taskNameClassifier),
|
||||
target.targetName
|
||||
)
|
||||
).also { printDeprecationWarning() }
|
||||
|
||||
@Deprecated(OLD_BINARY_API_DEPRECATION)
|
||||
fun linkTaskName(kind: String, buildType: String) =
|
||||
linkTaskName(NativeOutputKind.valueOf(kind.toUpperCase()), NativeBuildType.valueOf(buildType.toUpperCase()))
|
||||
.also { printDeprecationWarning() }
|
||||
|
||||
override val compileDependencyConfigurationName: String
|
||||
get() = lowerCamelCaseName(
|
||||
|
||||
+1
-1
@@ -23,7 +23,7 @@ class KotlinNativeCompilationFactory(
|
||||
friendCompilationName = KotlinCompilation.MAIN_COMPILATION_NAME
|
||||
isTestCompilation = true
|
||||
}
|
||||
buildTypes = mutableListOf(NativeBuildType.DEBUG, NativeBuildType.RELEASE)
|
||||
buildTypesNoWarn = mutableListOf(NativeBuildType.DEBUG, NativeBuildType.RELEASE)
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user