From 5da131d9f11c932ecec53738be37b9670d2a3df6 Mon Sep 17 00:00:00 2001 From: Ilya Matveev Date: Wed, 25 Jan 2017 12:16:20 +0300 Subject: [PATCH] buildSrc: Add multifile support for internal tests --- .../org/jetbrains/kotlin/KonanTest.groovy | 81 ++++++++++--------- 1 file changed, 41 insertions(+), 40 deletions(-) diff --git a/buildSrc/src/main/groovy/org/jetbrains/kotlin/KonanTest.groovy b/buildSrc/src/main/groovy/org/jetbrains/kotlin/KonanTest.groovy index 569fff6f663..fa28a04c97e 100644 --- a/buildSrc/src/main/groovy/org/jetbrains/kotlin/KonanTest.groovy +++ b/buildSrc/src/main/groovy/org/jetbrains/kotlin/KonanTest.groovy @@ -83,8 +83,42 @@ abstract class KonanTest extends DefaultTask { return "$outputDirectory/$exeName" } + // TODO refactor List buildCompileList() { - return [project.file(source).absolutePath] + def result = [] + def filePattern = ~/(?m)\/\/\s*FILE:\s*(.*)$/ + def srcFile = project.file(source) + def srcText = srcFile.text + def matcher = filePattern.matcher(srcText) + + if (!matcher.find()) { + // There is only one file in the input + project.copy{ + from srcFile.absolutePath + into outputDirectory + } + def newFile ="$outputDirectory/${srcFile.name}" + result.add(newFile) + } else { + // There are several files + def processedChars = 0 + while (true) { + def filePath = "$outputDirectory/${matcher.group(1)}" + def start = processedChars + def nextFileExists = matcher.find() + def end = nextFileExists ? matcher.start() : srcText.length() + def fileText = srcText.substring(start, end) + processedChars = end + createFile(filePath, fileText) + result.add(filePath) + if (!nextFileExists) break + } + } + return result + } + + void createFile(String file, String text) { + project.file(file).write(text) } @TaskAction @@ -183,47 +217,18 @@ class RunExternalTestGroup extends RunKonanTest { } } - // TODO refactor List buildCompileList() { - def result = [] - def filePattern = ~/(?m)\/\/\s*FILE:\s*(.*)$/ def packagePattern = ~/(?m)package\s*([a-zA-z-][a-zA-Z0-9.-]*)/ //TODO check the regex def boxPattern = ~/(?m)fun\s*box\s*\(\s*\)/ def boxPackage = "" - def srcFile = project.file(source) - def srcText = srcFile.text - def matcher = filePattern.matcher(srcText) - if (!matcher.find()) { - // There is only one file in the input - project.copy{ - from srcFile.absolutePath - into outputDirectory - } - def newFile ="$outputDirectory/${srcFile.name}" - if (srcText =~ boxPattern && srcText =~ packagePattern){ - boxPackage = (srcText =~ packagePattern)[0][1] + def result = super.buildCompileList() + for (String filePath : result) { + def text = project.file(filePath).text + if (text =~ boxPattern && text =~ packagePattern){ + boxPackage = (text =~ packagePattern)[0][1] boxPackage += '.' - } - result.add(newFile) - } else { - // There are several files - def processedChars = 0 - while (true) { - def filePath = matcher.group(1) - filePath = "$outputDirectory/$filePath" - def start = processedChars - def nextFileExists = matcher.find() - def end = nextFileExists ? matcher.start() : srcText.length() - def fileText = srcText.substring(start, end) - processedChars = end - createFile(filePath, fileText) - if (fileText =~ boxPattern && fileText =~ packagePattern){ - boxPackage = (fileText =~ packagePattern)[0][1] - boxPackage += '.' - } - result.add(filePath) - if (!nextFileExists) break + break } } createLauncherFile("$outputDirectory/_launcher.kt", boxPackage) @@ -235,10 +240,6 @@ class RunExternalTestGroup extends RunKonanTest { createFile(file, "fun main(args : Array) { print(${pkg}box()) }") } - void createFile(String file, String text) { - project.file(file).write(text) - } - List findLinesWithPrefixesRemoved(String text, String prefix) { def result = [] text.eachLine {