diff --git a/kotlin-native/build-tools/src/main/groovy/org/jetbrains/kotlin/KonanTest.groovy b/kotlin-native/build-tools/src/main/groovy/org/jetbrains/kotlin/KonanTest.groovy index 4c507102489..9994290f02a 100644 --- a/kotlin-native/build-tools/src/main/groovy/org/jetbrains/kotlin/KonanTest.groovy +++ b/kotlin-native/build-tools/src/main/groovy/org/jetbrains/kotlin/KonanTest.groovy @@ -265,7 +265,7 @@ class RunExternalTestGroup extends JavaExec implements CompilerRunner { return text } - List createTestFiles(String src) { + List createTestFiles(String src, TestModule defaultModule) { def identifier = /[a-zA-Z_][a-zA-Z0-9_]/ def fullQualified = /[a-zA-Z_][a-zA-Z0-9_.]/ def importRegex = /(?m)^\s*import\s+/ @@ -279,8 +279,12 @@ class RunExternalTestGroup extends JavaExec implements CompilerRunner { def imports = [] def classes = [] def vars = new HashSet() // variables that has the same name as a package - TestModule mainModule = null - def testFiles = TestDirectivesKt.buildCompileList(project.rootProject.file(src).toPath(), "$outputDirectory/${project.rootProject.file(src).name}") + TestModule mainModule = defaultModule + def testFiles = TestDirectivesKt.buildCompileList( + project.rootProject.file(src).toPath(), + "$outputDirectory/${project.rootProject.file(src).name}", + mainModule + ) for (TestFile testFile : testFiles) { def text = testFile.text def filePath = testFile.path @@ -380,8 +384,7 @@ class RunExternalTestGroup extends JavaExec implements CompilerRunner { "_launcher.kt", "$outputDirectory/$src/_launcher.kt".toString(), launcherText, - mainModule ?: testFiles.collect { it.module }.find { it.isDefaultModule() } - ?: TestModule.default() + mainModule ) ) return testFiles @@ -505,6 +508,8 @@ fun runTest() { } } + def defaultModule = TestModule.default() + testGroupReporter.suite(name) { suite -> // Build tests in the group flags = (flags ?: []) + "-tr" @@ -514,9 +519,14 @@ fun runTest() { if (isEnabledForNativeBackend(src)) { // Create separate output directory for each test in the group. parseLanguageFlags(src) - compileList.addAll(createTestFiles(src)) + compileList.addAll(createTestFiles(src, defaultModule)) } } + if (compileList.any { it.module.dependencies.contains("support") }) { + def supportModule = TestModule.support() + compileList.add(new TestFile("helpers.kt", "$outputDirectory/helpers.kt", + CoroutineTestUtilKt.createTextForHelpers(), supportModule)) + } compileList*.writeTextToFile() try { if (enableTwoStageCompilation) { @@ -532,7 +542,9 @@ fun runTest() { } else { // Regular compilation with modules. Map modules = compileList.stream() - .map { it.module } + .map { + println(it.module) + it.module } .distinct() .collect(Collectors.toMap({ it.name }, UnaryOperator.identity())) @@ -542,6 +554,7 @@ fun runTest() { def compiler = new MultiModuleCompilerInvocations(this, outputDirectory, executablePath(), modules, flags) orderedModules.reverse().each { module -> + println("${module.name} ${module.dependencies}") if (!module.isDefaultModule()) { compiler.produceLibrary(module) } diff --git a/kotlin-native/build-tools/src/main/kotlin/org/jetbrains/kotlin/MultiModule.kt b/kotlin-native/build-tools/src/main/kotlin/org/jetbrains/kotlin/MultiModule.kt index 46dd1bd7eb8..b1830d918db 100644 --- a/kotlin-native/build-tools/src/main/kotlin/org/jetbrains/kotlin/MultiModule.kt +++ b/kotlin-native/build-tools/src/main/kotlin/org/jetbrains/kotlin/MultiModule.kt @@ -61,7 +61,7 @@ class MultiModuleCompilerInvocations( fun produceProgram(compileList: List) { val compileMain = compileList.filter { - it.module.isDefaultModule() || it.module.isSupportModule() + it.module.isDefaultModule() && !it.module.isSupportModule() } compileMain.forEach { f -> libs.addAll(f.module.dependencies) diff --git a/kotlin-native/build-tools/src/main/kotlin/org/jetbrains/kotlin/TestDirectives.kt b/kotlin-native/build-tools/src/main/kotlin/org/jetbrains/kotlin/TestDirectives.kt index e6b9f150bf7..583deef3914 100644 --- a/kotlin-native/build-tools/src/main/kotlin/org/jetbrains/kotlin/TestDirectives.kt +++ b/kotlin-native/build-tools/src/main/kotlin/org/jetbrains/kotlin/TestDirectives.kt @@ -26,20 +26,17 @@ private val DIRECTIVE_PATTERN = Pattern.compile("^//\\s*[!]?([A-Z_]+)(:[ \\t]*(. * * @return list of test files [TestFile] to be compiled */ -fun buildCompileList(source: Path, outputDirectory: String): List { +fun buildCompileList( + source: Path, + outputDirectory: String, + defaultModule: TestModule = TestModule.default()): List { val result = mutableListOf() val srcFile = source.toFile() // Remove diagnostic parameters in external tests. val srcText = srcFile.readText().replace(Regex("(.*?)")) { match -> match.groupValues[1] } - var supportModule: TestModule? = null - if (srcText.contains("// WITH_COROUTINES")) { - supportModule = TestModule.support() - result.add(TestFile("helpers.kt", "$outputDirectory/helpers.kt", - createTextForHelpers(), supportModule)) - } + var supportModule: TestModule? = if (srcText.contains("// WITH_COROUTINES")) TestModule.support() else null - val defaultModule = TestModule.default() val moduleMatcher = MODULE_PATTERN.matcher(srcText) val fileMatcher = FILE_PATTERN.matcher(srcText) var nextModuleExists = moduleMatcher.find() @@ -47,6 +44,7 @@ fun buildCompileList(source: Path, outputDirectory: String): List { if (!nextModuleExists && !nextFileExists) { // There is only one file in the input + if (supportModule != null) defaultModule.dependencies.add(supportModule.name) result.add(TestFile(srcFile.name, "$outputDirectory/${srcFile.name}", srcText, defaultModule)) } else { // There are several files @@ -62,18 +60,22 @@ fun buildCompileList(source: Path, outputDirectory: String): List { if (moduleName != null) { moduleName = moduleName.trim { it <= ' ' } val dependencies = mutableListOf().apply { - addAll(moduleDependencies.parseModuleList()) - if (supportModule != null && !contains("support")) { - add("support") - } - }.map { - if (it != "support") "${srcFile.name}.$it" else it + addAll(moduleDependencies.parseModuleList() + .map { if (it != "support") "${srcFile.name}.$it" else it } + ) } - module = TestModule("${srcFile.name}.$moduleName", - dependencies, - moduleFriends.parseModuleList().map { "${srcFile.name}.$it" }) + module = TestModule( + "${srcFile.name}.$moduleName", + dependencies, + mutableListOf().apply { + addAll(moduleFriends.parseModuleList().map { "${srcFile.name}.$it" }) + } + ) } } + if (supportModule != null && !module.dependencies.contains("support")) { + module.dependencies.add("support") + } nextModuleExists = moduleMatcher.find() while (nextFileExists) { @@ -112,8 +114,8 @@ private fun String?.parseModuleList() = this */ data class TestModule( val name: String, - val dependencies: List, - val friends: List + val dependencies: MutableList, + val friends: MutableList ) { val files = mutableListOf() fun isDefaultModule() = this.name == "default" || name.endsWith(".main") @@ -123,8 +125,8 @@ data class TestModule( fun versionFiles(version: Int) = this.files.filter { it.version == null || it.version == version } companion object { - @JvmStatic fun default() = TestModule("default", emptyList(), emptyList()) - @JvmStatic fun support() = TestModule("support", emptyList(), emptyList()) + @JvmStatic fun default() = TestModule("default", mutableListOf(), mutableListOf()) + @JvmStatic fun support() = TestModule("support", mutableListOf(), mutableListOf()) } }