Improve framework test configuration: use DSL with Closure
This commit is contained in:
committed by
Pavel Punegov
parent
21862ef847
commit
d2f8b3b142
@@ -4018,7 +4018,8 @@ standaloneTest("fake_override_0") {
|
||||
|
||||
Task frameworkTest(String name, Closure<FrameworkTest> configurator) {
|
||||
return KotlinNativeTestKt.createTest(project, name, FrameworkTest) { task ->
|
||||
task.configure(configurator)
|
||||
configurator.delegate = task
|
||||
configurator()
|
||||
if (task.enabled) {
|
||||
konanArtifacts {
|
||||
task.frameworks.forEach { fr ->
|
||||
@@ -4026,7 +4027,7 @@ Task frameworkTest(String name, Closure<FrameworkTest> configurator) {
|
||||
fr.sources.forEach { src ->
|
||||
srcFiles src
|
||||
}
|
||||
baseDir "$testOutputFramework/${task.testName}"
|
||||
baseDir "$testOutputFramework/${task.name}"
|
||||
|
||||
if (fr.library != null) {
|
||||
libraries {
|
||||
@@ -4055,8 +4056,7 @@ Task frameworkTest(String name, Closure<FrameworkTest> configurator) {
|
||||
if (isAppleTarget(project)) {
|
||||
frameworkTest('testObjCExport') {
|
||||
final String frameworkName = 'Kt'
|
||||
testName = "ObjCExport"
|
||||
final String dir = "$testOutputFramework/$testName"
|
||||
final String dir = "$testOutputFramework/$name"
|
||||
final File lazyHeader = file("$dir/$target-lazy.h")
|
||||
|
||||
doLast {
|
||||
@@ -4095,8 +4095,11 @@ if (isAppleTarget(project)) {
|
||||
extraOpts "-module-name", "org.jetbrains.kotlin.native.test-library"
|
||||
}
|
||||
}
|
||||
it.createFramework(frameworkName, ['objcexport'], false,
|
||||
frameworkName, libraryName, ["-Xemit-lazy-objc-header=$lazyHeader"])
|
||||
framework(frameworkName) {
|
||||
sources = ['objcexport']
|
||||
library = libraryName
|
||||
opts = ["-Xemit-lazy-objc-header=$lazyHeader"]
|
||||
}
|
||||
swiftSources = ['objcexport']
|
||||
}
|
||||
|
||||
@@ -4119,21 +4122,29 @@ if (isAppleTarget(project)) {
|
||||
}
|
||||
}
|
||||
|
||||
testName = "ObjCExportStatic"
|
||||
codesign = false
|
||||
it.createFramework(frameworkName, ['objcexport'], false, frameworkArtifactName, libraryName, ['-Xstatic-framework'])
|
||||
framework(frameworkName) {
|
||||
sources = ['objcexport']
|
||||
bitcode = false
|
||||
artifact = frameworkArtifactName
|
||||
library = libraryName
|
||||
opts = ['-Xstatic-framework']
|
||||
}
|
||||
swiftSources = ['objcexport']
|
||||
}
|
||||
|
||||
frameworkTest('testValuesGenericsFramework') {
|
||||
testName = 'ValuesGenerics'
|
||||
it.createFramework('ValuesGenerics', ['objcexport/values.kt', 'framework/values_generics'])
|
||||
framework('ValuesGenerics') {
|
||||
sources = ['objcexport/values.kt', 'framework/values_generics']
|
||||
}
|
||||
swiftSources = ['framework/values_generics/']
|
||||
}
|
||||
|
||||
frameworkTest("testStdlibFramework") {
|
||||
testName = 'Stdlib'
|
||||
it.createFramework('Stdlib', ['framework/stdlib'], true)
|
||||
framework('Stdlib') {
|
||||
sources = ['framework/stdlib']
|
||||
bitcode = true
|
||||
}
|
||||
if (cacheTesting == null) fullBitcode = true
|
||||
swiftSources = ['framework/stdlib/']
|
||||
}
|
||||
@@ -4141,21 +4152,22 @@ if (isAppleTarget(project)) {
|
||||
if (cacheTesting != null && cacheTesting.isDynamic) {
|
||||
// testMultipleFrameworks disabled until https://youtrack.jetbrains.com/issue/KT-34262 is fixed.
|
||||
} else frameworkTest("testMultipleFrameworks") {
|
||||
testName = "MultipleFrameworks"
|
||||
it.createFramework('First',
|
||||
['framework/multiple/framework1', 'framework/multiple/shared'],
|
||||
true // bitcode
|
||||
)
|
||||
it.createFramework('Second',
|
||||
['framework/multiple/framework2', 'framework/multiple/shared'],
|
||||
true // bitcode
|
||||
)
|
||||
framework('First') {
|
||||
sources = ['framework/multiple/framework1', 'framework/multiple/shared']
|
||||
bitcode = true
|
||||
}
|
||||
framework('Second') {
|
||||
sources = ['framework/multiple/framework2', 'framework/multiple/shared']
|
||||
bitcode = true
|
||||
}
|
||||
swiftSources = ['framework/multiple']
|
||||
}
|
||||
|
||||
frameworkTest("testGh3343Framework") {
|
||||
testName = 'Gh3343'
|
||||
it.createFramework('Gh3343', ['framework/gh3343'], false, 'Gh3343', 'objcGh3343')
|
||||
framework('Gh3343') {
|
||||
sources = ['framework/gh3343']
|
||||
library = 'objcGh3343'
|
||||
}
|
||||
swiftSources = ['framework/gh3343/']
|
||||
}
|
||||
}
|
||||
|
||||
@@ -503,7 +503,7 @@ fun KonanTestExecutable.configureXcodeBuild() {
|
||||
// Copy each framework to the Frameworks dir.
|
||||
it += frameworks.map { framework ->
|
||||
val name = framework.artifact
|
||||
"cp -r \"$testOutput/$testName/${project.testTarget.name}/$name.framework\" " +
|
||||
"cp -r \"$testOutput/$name/${project.testTarget.name}/$name.framework\" " +
|
||||
"\"\$TARGET_BUILD_DIR/\$FRAMEWORKS_FOLDER_PATH/$name.framework\""
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,7 +4,6 @@ import groovy.lang.Closure
|
||||
import org.gradle.api.Action
|
||||
import org.gradle.api.DefaultTask
|
||||
import org.gradle.api.Task
|
||||
import org.gradle.api.file.FileCollection
|
||||
import org.gradle.api.file.FileTree
|
||||
import org.gradle.api.tasks.Input
|
||||
import org.gradle.api.tasks.TaskAction
|
||||
@@ -24,16 +23,12 @@ import java.nio.file.Paths
|
||||
* according to a pattern "compileKonan${frameworkName}".
|
||||
*
|
||||
* @property swiftSources Swift-language test sources that use a given framework
|
||||
* @property testName test name
|
||||
* @property frameworks names of frameworks
|
||||
*/
|
||||
open class FrameworkTest : DefaultTask(), KonanTestExecutable {
|
||||
@Input
|
||||
lateinit var swiftSources: List<String>
|
||||
|
||||
@Input
|
||||
lateinit var testName: String
|
||||
|
||||
@Input
|
||||
lateinit var frameworks: MutableList<Framework>
|
||||
|
||||
@@ -54,32 +49,29 @@ open class FrameworkTest : DefaultTask(), KonanTestExecutable {
|
||||
* @param library library dependency name,
|
||||
* @param opts additional options for the compiler.
|
||||
*/
|
||||
data class Framework(
|
||||
class Framework(
|
||||
val name: String,
|
||||
val sources: List<String>,
|
||||
val bitcode: Boolean = false,
|
||||
val artifact: String = name,
|
||||
val library: String? = null,
|
||||
val opts: List<String> = emptyList()
|
||||
var sources: List<String> = emptyList(),
|
||||
var bitcode: Boolean = false,
|
||||
var artifact: String = name,
|
||||
var library: String? = null,
|
||||
var opts: List<String> = emptyList()
|
||||
)
|
||||
|
||||
@JvmOverloads
|
||||
fun createFramework(name: String,
|
||||
sources: List<String>,
|
||||
bitcode: Boolean = false,
|
||||
artifact: String = name,
|
||||
library: String? = null,
|
||||
opts: List<String> = emptyList()
|
||||
) = Framework(
|
||||
name,
|
||||
sources.toFiles(Language.Kotlin).map { it.path },
|
||||
bitcode, artifact, library, opts
|
||||
).also {
|
||||
if (!::frameworks.isInitialized) {
|
||||
frameworks = mutableListOf(it)
|
||||
} else {
|
||||
frameworks.add(it)
|
||||
fun framework(name: String, closure: Closure<Framework>): Framework {
|
||||
val f = Framework(name).apply {
|
||||
closure.delegate = this
|
||||
closure.resolveStrategy = Closure.DELEGATE_FIRST
|
||||
closure.call()
|
||||
// map to file paths
|
||||
sources = sources.toFiles(Language.Kotlin).map { it.path }
|
||||
}
|
||||
if (!::frameworks.isInitialized) {
|
||||
frameworks = mutableListOf(f)
|
||||
} else {
|
||||
frameworks.add(f)
|
||||
}
|
||||
return f
|
||||
}
|
||||
|
||||
enum class Language(val extension: String) {
|
||||
@@ -96,10 +88,7 @@ open class FrameworkTest : DefaultTask(), KonanTestExecutable {
|
||||
.flatMap { it.files }
|
||||
|
||||
override val executable: String
|
||||
get() {
|
||||
check(::testName.isInitialized) { "Test name should be set" }
|
||||
return Paths.get(testOutput, testName, "swiftTestExecutable").toString()
|
||||
}
|
||||
get() = Paths.get(testOutput, name, "swiftTestExecutable").toString()
|
||||
|
||||
override var doBeforeRun: Action<in Task>? = null
|
||||
|
||||
@@ -118,14 +107,12 @@ open class FrameworkTest : DefaultTask(), KonanTestExecutable {
|
||||
group = LifecycleBasePlugin.VERIFICATION_GROUP
|
||||
description = "Kotlin/Native test infrastructure task"
|
||||
|
||||
check(::testName.isInitialized) { "Test name should be set" }
|
||||
check(::frameworks.isInitialized) { "Frameworks should be set" }
|
||||
|
||||
return this
|
||||
}
|
||||
|
||||
private fun buildTestExecutable() {
|
||||
val frameworkParentDirPath = "$testOutput/$testName/${project.testTarget.name}"
|
||||
val frameworkParentDirPath = "$testOutput/$name/${project.testTarget.name}"
|
||||
frameworks.forEach { framework ->
|
||||
val frameworkArtifact = framework.artifact
|
||||
val frameworkPath = "$frameworkParentDirPath/$frameworkArtifact.framework"
|
||||
@@ -135,7 +122,7 @@ open class FrameworkTest : DefaultTask(), KonanTestExecutable {
|
||||
}
|
||||
|
||||
// create a test provider and get main entry point
|
||||
val provider = Paths.get(testOutput, testName, "provider.swift")
|
||||
val provider = Paths.get(testOutput, name, "provider.swift")
|
||||
FileWriter(provider.toFile()).use { writer ->
|
||||
val providers = swiftSources.toFiles(Language.Swift)
|
||||
.map { it.name.toString().removeSuffix(".swift").capitalize() }
|
||||
|
||||
Reference in New Issue
Block a user