buildSrc: Add multifile support for internal tests
This commit is contained in:
@@ -83,8 +83,42 @@ abstract class KonanTest extends DefaultTask {
|
|||||||
return "$outputDirectory/$exeName"
|
return "$outputDirectory/$exeName"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO refactor
|
||||||
List<String> buildCompileList() {
|
List<String> 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
|
@TaskAction
|
||||||
@@ -183,47 +217,18 @@ class RunExternalTestGroup extends RunKonanTest {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO refactor
|
|
||||||
List<String> buildCompileList() {
|
List<String> 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 packagePattern = ~/(?m)package\s*([a-zA-z-][a-zA-Z0-9.-]*)/ //TODO check the regex
|
||||||
def boxPattern = ~/(?m)fun\s*box\s*\(\s*\)/
|
def boxPattern = ~/(?m)fun\s*box\s*\(\s*\)/
|
||||||
def boxPackage = ""
|
def boxPackage = ""
|
||||||
def srcFile = project.file(source)
|
|
||||||
def srcText = srcFile.text
|
|
||||||
def matcher = filePattern.matcher(srcText)
|
|
||||||
|
|
||||||
if (!matcher.find()) {
|
def result = super.buildCompileList()
|
||||||
// There is only one file in the input
|
for (String filePath : result) {
|
||||||
project.copy{
|
def text = project.file(filePath).text
|
||||||
from srcFile.absolutePath
|
if (text =~ boxPattern && text =~ packagePattern){
|
||||||
into outputDirectory
|
boxPackage = (text =~ packagePattern)[0][1]
|
||||||
}
|
|
||||||
def newFile ="$outputDirectory/${srcFile.name}"
|
|
||||||
if (srcText =~ boxPattern && srcText =~ packagePattern){
|
|
||||||
boxPackage = (srcText =~ packagePattern)[0][1]
|
|
||||||
boxPackage += '.'
|
boxPackage += '.'
|
||||||
}
|
break
|
||||||
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
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
createLauncherFile("$outputDirectory/_launcher.kt", boxPackage)
|
createLauncherFile("$outputDirectory/_launcher.kt", boxPackage)
|
||||||
@@ -235,10 +240,6 @@ class RunExternalTestGroup extends RunKonanTest {
|
|||||||
createFile(file, "fun main(args : Array<String>) { print(${pkg}box()) }")
|
createFile(file, "fun main(args : Array<String>) { print(${pkg}box()) }")
|
||||||
}
|
}
|
||||||
|
|
||||||
void createFile(String file, String text) {
|
|
||||||
project.file(file).write(text)
|
|
||||||
}
|
|
||||||
|
|
||||||
List<String> findLinesWithPrefixesRemoved(String text, String prefix) {
|
List<String> findLinesWithPrefixesRemoved(String text, String prefix) {
|
||||||
def result = []
|
def result = []
|
||||||
text.eachLine {
|
text.eachLine {
|
||||||
|
|||||||
Reference in New Issue
Block a user