From b31a65749479a255b5e8f3bd445c4a4fd055a8d5 Mon Sep 17 00:00:00 2001 From: Alexander Shabalin Date: Fri, 18 Nov 2022 16:11:37 +0000 Subject: [PATCH] [K/N] Add test support modules to runtime tests ^KT-53776 Previously all modules in a test group would also link in their tests. This is not ideal. For example, an experimental module M depending on module N might not yet implement enough functionality to run all Ns integration tests, but we still want to run Ms unit tests. Now, there's a separate `testSupportModules` list. For each module their main sources and test support sources will get linked into the test group, but the tests will not. Merge-request: KT-MR-7731 Merged-by: Alexander Shabalin --- .../kotlin/bitcode/CompileToBitcodePlugin.kt | 47 +++++++++++++++---- 1 file changed, 37 insertions(+), 10 deletions(-) diff --git a/kotlin-native/build-tools/src/main/kotlin/org/jetbrains/kotlin/bitcode/CompileToBitcodePlugin.kt b/kotlin-native/build-tools/src/main/kotlin/org/jetbrains/kotlin/bitcode/CompileToBitcodePlugin.kt index 5e1a52e1710..2658e05ed84 100644 --- a/kotlin-native/build-tools/src/main/kotlin/org/jetbrains/kotlin/bitcode/CompileToBitcodePlugin.kt +++ b/kotlin-native/build-tools/src/main/kotlin/org/jetbrains/kotlin/bitcode/CompileToBitcodePlugin.kt @@ -127,6 +127,7 @@ open class CompileToBitcodeExtension @Inject constructor(val project: Project) : get() = _sanitizer.orNull abstract val testedModules: ListProperty abstract val testSupportModules: ListProperty + abstract val testFrameworkModules: ListProperty abstract val testLauncherModule: Property } @@ -206,18 +207,18 @@ open class CompileToBitcodeExtension @Inject constructor(val project: Project) : action: Action, ) { val testsGroup = project.objects.newInstance(TestsGroup::class.java, target, sanitizer.asMaybe).apply { - testSupportModules.convention(listOf("googletest", "googlemock")) + testFrameworkModules.convention(listOf("googletest", "googlemock")) testLauncherModule.convention("test_support") action.execute(this) } val target = testsGroup.target val sanitizer = testsGroup.sanitizer val testName = fullTaskName(testTaskName, target.name, sanitizer) - val testedTasks = testsGroup.testedModules.get().map { + val testedModulesMainTasks = testsGroup.testedModules.get().map { val name = fullTaskName(it, target.name, sanitizer) project.tasks.getByName(name) as CompileToBitcode } - val compileToBitcodeTasks = testedTasks.mapNotNull { + val testedModulesTestTasks = testedModulesMainTasks.mapNotNull { val name = "${it.name}TestBitcode" val task = project.tasks.findByName(name) as? CompileToBitcode ?: project.tasks.create(name, CompileToBitcode::class.java, it.target, it.sanitizer.asMaybe).apply { @@ -227,7 +228,7 @@ open class CompileToBitcodeExtension @Inject constructor(val project: Project) : this.compiler.convention("clang++") this.compilerArgs.set(it.compilerArgs) this.inputFiles.from(it.inputFiles.dir) - this.inputFiles.include("**/*Test.cpp", "**/*TestSupport.cpp", "**/*Test.mm", "**/*TestSupport.mm") + this.inputFiles.include("**/*Test.cpp", "**/*Test.mm") this.headersDirs.setFrom(it.headersDirs) this.headersDirs.from(googleTestExtension.headersDirs) this.compilerWorkingDirectory.set(it.compilerWorkingDirectory) @@ -239,15 +240,41 @@ open class CompileToBitcodeExtension @Inject constructor(val project: Project) : addToCompdb(this) } - if (task.inputFiles.count() == 0) null - else task + task.takeUnless { t -> t.inputFiles.isEmpty } } - val testFrameworkTasks = testsGroup.testSupportModules.get().map { + val testSupportModulesMainTasks = testsGroup.testSupportModules.get().map { val name = fullTaskName(it, target.name, sanitizer) project.tasks.getByName(name) as CompileToBitcode } + val testedAndTestSupportModulesTestSupportTasks = (testedModulesMainTasks + testSupportModulesMainTasks).mapNotNull { + val name = "${it.name}TestSupportBitcode" + val task = project.tasks.findByName(name) as? CompileToBitcode + ?: project.tasks.create(name, CompileToBitcode::class.java, it.target, it.sanitizer.asMaybe).apply { + this.moduleName.set(it.moduleName) + this.outputFile.convention(moduleName.flatMap { project.layout.buildDirectory.file("bitcode/test/$target${sanitizer.dirSuffix}/${it}TestSupport.bc") }) + this.outputDirectory.convention(moduleName.flatMap { project.layout.buildDirectory.dir("bitcode/test/$target${sanitizer.dirSuffix}/${it}TestSupport") }) + this.compiler.convention("clang++") + this.compilerArgs.set(it.compilerArgs) + this.inputFiles.from(it.inputFiles.dir) + this.inputFiles.include("**/*TestSupport.cpp", "**/*TestSupport.mm") + this.headersDirs.setFrom(it.headersDirs) + this.headersDirs.from(googleTestExtension.headersDirs) + this.compilerWorkingDirectory.set(it.compilerWorkingDirectory) + this.group = VERIFICATION_BUILD_TASK_GROUP + this.description = "Compiles '${it.name}' test support to bitcode for $target${sanitizer.description}" - val testSupportTask = testsGroup.testLauncherModule.get().let { + dependsOn(":kotlin-native:dependencies:update") + dependsOn("downloadGoogleTest") + + addToCompdb(this) + } + task.takeUnless { t -> t.inputFiles.isEmpty } + } + val testFrameworkMainTasks = testsGroup.testFrameworkModules.get().map { + val name = fullTaskName(it, target.name, sanitizer) + project.tasks.getByName(name) as CompileToBitcode + } + val testLauncherMainTask = testsGroup.testLauncherModule.get().let { val name = fullTaskName(it, target.name, sanitizer) project.tasks.getByName(name) as CompileToBitcode } @@ -262,8 +289,8 @@ open class CompileToBitcodeExtension @Inject constructor(val project: Project) : this.llvmLinkOutputFile.set(project.layout.buildDirectory.file("bitcode/test/$target/$testName.bc")) this.compilerOutputFile.set(project.layout.buildDirectory.file("obj/$target/$testName.o")) this.mimallocEnabled.set(testsGroup.testedModules.get().any { it.contains("mimalloc") }) - this.mainFile.set(testSupportTask.outputFile) - val tasksToLink = (compileToBitcodeTasks + testedTasks + testFrameworkTasks) + this.mainFile.set(testLauncherMainTask.outputFile) + val tasksToLink = (testedModulesTestTasks + testedModulesMainTasks + testFrameworkMainTasks + testSupportModulesMainTasks + testedAndTestSupportModulesTestSupportTasks) this.inputFiles.setFrom(tasksToLink.map { it.outputFile }) usesService(compileTestsSemaphore)