Gradle, native: Introduce separate binary type for tests
Earlier native tests were represented by the same binary type as product
executables. We also used to create test tasks in the same manner as run
tasks for product executables. Such tasks could be obtained used a property
of an executable binary with type Exec.
But now we have a separate class for test tasks. Also we probably will want
to create several tasks for the same test. So we cannot use the same run task
property for both test and product executables. Also representing test and
product executables by the same binary type leads to the fact that assemble
task execution causes building not only product binaries but also the test
ones.
This patch solves the issues described above by introducing a separate binary
type for tests. Such a test binary can be created in the same manner as other
binaries:
kotlin.macosX64 {
binaries {
test("integration") { ... }
}
}
One test binary and a task executing it is created by the plugin out of the box.
This test binary replaces a test executable used to be created earlier.
Issue #KT-31609 Fixed
This commit is contained in:
+21
-5
@@ -17,17 +17,25 @@ internal data class BinaryType(
|
||||
val nativeOutputKind: TypeName,
|
||||
val factoryMethod: String,
|
||||
val getMethod: String,
|
||||
val findMethod: String
|
||||
val findMethod: String,
|
||||
val defaultBaseName: String
|
||||
)
|
||||
|
||||
private fun binaryType(description: String, className: String, outputKind: String, baseMethodName: String) =
|
||||
private fun binaryType(
|
||||
description: String,
|
||||
className: String,
|
||||
outputKind: String,
|
||||
baseMethodName: String,
|
||||
defaultBaseName: String = "project.name"
|
||||
) =
|
||||
BinaryType(
|
||||
description,
|
||||
typeName("$MPP_PACKAGE.$className"),
|
||||
typeName("${nativeOutputKindClass.fqName}.$outputKind"),
|
||||
baseMethodName,
|
||||
"get${baseMethodName.capitalize()}",
|
||||
"find${baseMethodName.capitalize()}"
|
||||
"find${baseMethodName.capitalize()}",
|
||||
defaultBaseName
|
||||
)
|
||||
|
||||
private val nativeBuildTypeClass = typeName("$MPP_PACKAGE.NativeBuildType")
|
||||
@@ -41,6 +49,7 @@ private fun generateFactoryMethods(binaryType: BinaryType): String {
|
||||
val nativeBuildType = nativeBuildTypeClass.renderShort()
|
||||
val methodName = binaryType.factoryMethod
|
||||
val binaryDescription = binaryType.description
|
||||
val defaultBaseName = binaryType.defaultBaseName
|
||||
|
||||
return """
|
||||
/** Creates $binaryDescription with the given [namePrefix] for each build type and configures it. */
|
||||
@@ -56,7 +65,7 @@ private fun generateFactoryMethods(binaryType: BinaryType): String {
|
||||
fun $methodName(
|
||||
buildTypes: Collection<$nativeBuildType> = $nativeBuildType.DEFAULT_BUILD_TYPES,
|
||||
configure: $className.() -> Unit = {}
|
||||
) = createBinaries("", project.name, $outputKindClass.$outputKind, buildTypes, ::$className, configure)
|
||||
) = createBinaries("", $defaultBaseName, $outputKindClass.$outputKind, buildTypes, ::$className, configure)
|
||||
|
||||
/** Creates $binaryDescription with the given [namePrefix] for each build type and configures it. */
|
||||
@JvmOverloads
|
||||
@@ -115,7 +124,14 @@ fun generateAbstractKotlinNativeBinaryContainer() {
|
||||
binaryType("an executable","Executable", "EXECUTABLE", "executable"),
|
||||
binaryType("a static library","StaticLibrary", "STATIC", "staticLib"),
|
||||
binaryType("a shared library","SharedLibrary", "DYNAMIC", "sharedLib"),
|
||||
binaryType("an Objective-C framework","Framework", "FRAMEWORK", "framework")
|
||||
binaryType("an Objective-C framework","Framework", "FRAMEWORK", "framework"),
|
||||
binaryType(
|
||||
"a test executable",
|
||||
"Test",
|
||||
"TEST",
|
||||
"test",
|
||||
defaultBaseName = "\"test\""
|
||||
)
|
||||
)
|
||||
|
||||
val className = typeName("org.jetbrains.kotlin.gradle.dsl.AbstractKotlinNativeBinaryContainer")
|
||||
|
||||
Reference in New Issue
Block a user