From d2f8b3b142ebc7884bfaf8b736af3eff7f7b0eb0 Mon Sep 17 00:00:00 2001 From: Pavel Punegov Date: Mon, 1 Jun 2020 21:37:57 +0300 Subject: [PATCH] Improve framework test configuration: use DSL with Closure --- backend.native/tests/build.gradle | 58 +++++++++++-------- .../org/jetbrains/kotlin/ExecutorService.kt | 2 +- .../org/jetbrains/kotlin/FrameworkTest.kt | 57 +++++++----------- 3 files changed, 58 insertions(+), 59 deletions(-) diff --git a/backend.native/tests/build.gradle b/backend.native/tests/build.gradle index dc018afc94b..f611029cd78 100644 --- a/backend.native/tests/build.gradle +++ b/backend.native/tests/build.gradle @@ -4018,7 +4018,8 @@ standaloneTest("fake_override_0") { Task frameworkTest(String name, Closure 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 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 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/'] } } diff --git a/build-tools/src/main/kotlin/org/jetbrains/kotlin/ExecutorService.kt b/build-tools/src/main/kotlin/org/jetbrains/kotlin/ExecutorService.kt index cd9acf57247..5810f786d28 100644 --- a/build-tools/src/main/kotlin/org/jetbrains/kotlin/ExecutorService.kt +++ b/build-tools/src/main/kotlin/org/jetbrains/kotlin/ExecutorService.kt @@ -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\"" } } diff --git a/build-tools/src/main/kotlin/org/jetbrains/kotlin/FrameworkTest.kt b/build-tools/src/main/kotlin/org/jetbrains/kotlin/FrameworkTest.kt index 4cc63573f36..c4f5f8487b6 100644 --- a/build-tools/src/main/kotlin/org/jetbrains/kotlin/FrameworkTest.kt +++ b/build-tools/src/main/kotlin/org/jetbrains/kotlin/FrameworkTest.kt @@ -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 - @Input - lateinit var testName: String - @Input lateinit var frameworks: MutableList @@ -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, - val bitcode: Boolean = false, - val artifact: String = name, - val library: String? = null, - val opts: List = emptyList() + var sources: List = emptyList(), + var bitcode: Boolean = false, + var artifact: String = name, + var library: String? = null, + var opts: List = emptyList() ) - @JvmOverloads - fun createFramework(name: String, - sources: List, - bitcode: Boolean = false, - artifact: String = name, - library: String? = null, - opts: List = 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 { + 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? = 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() }