A -produce dynamic test.

This commit is contained in:
Alexander Gorshenev
2017-12-13 17:40:43 +03:00
committed by alexander-gorshenev
parent ff4a0a03b2
commit bf612fdbdc
6 changed files with 61 additions and 5 deletions
@@ -71,7 +71,7 @@ class KonanConfig(val project: Project, val configuration: CompilerConfiguration
private val suffix = produce.suffix(target)
val outputName = configuration.get(KonanConfigKeys.OUTPUT)?.removeSuffixIfPresent(suffix) ?: produce.name.toLowerCase()
val outputFile = outputName
.prefixIfNot(prefix)
.prefixBaseNameIfNot(prefix)
.suffixIfNot(suffix)
val tempFiles = TempFiles(outputName)
@@ -17,6 +17,7 @@
package org.jetbrains.kotlin.backend.konan.util
import kotlin.system.measureTimeMillis
import org.jetbrains.kotlin.konan.file.*
fun printMillisec(message: String, body: () -> Unit) {
val msec = measureTimeMillis{
@@ -39,6 +40,13 @@ fun nTabs(amount: Int): String {
fun String.prefixIfNot(prefix: String) =
if (this.startsWith(prefix)) this else "$prefix$this"
fun String.prefixBaseNameIfNot(prefix: String): String {
val file = File(this)
val name = file.name
val directory = file.parent
return "$directory/${name.prefixIfNot(prefix)}"
}
fun String.suffixIfNot(suffix: String) =
if (this.endsWith(suffix)) this else "$this$suffix"
+6
View File
@@ -2336,6 +2336,12 @@ if (isMac()) {
}
}
task produce_dynamic(type: DynamicKonanTest) {
source = "produce_dynamic/simple/hello.kt"
cSource = "$projectDir/produce_dynamic/simple/main.c"
goldValue = "Hello, dynamic!\n"
}
task buildKonanTests(type: BuildKonanTest) {
compileList = [ "codegen", "datagen", "lower", "runtime", "serialization"]
@@ -0,0 +1,4 @@
fun hello() {
println("Hello, dynamic!")
}
@@ -0,0 +1,7 @@
#include "testlib_api.h"
int main(void) {
testlib_symbols()->kotlin.root.hello();
return 0;
}
@@ -492,14 +492,45 @@ class LinkKonanTest extends KonanTest {
protected String lib
void compileTest(List<String> filesToCompile, String exe) {
def libDir = project.file(lib).absolutePath
def libBc = "${libDir}.bc"
def libname = "testklib"
def klib = "$outputDirectory/$libname"
runCompiler(lib, libBc, ['-produce', 'library'] + ((flags != null) ? flags :[]))
runCompiler(filesToCompile, exe, ['-library', libBc] + ((flags != null) ? flags :[]))
runCompiler(lib, klib, ['-produce', 'library'] + ((flags != null) ? flags :[]))
runCompiler(filesToCompile, exe, ['-library', klib] + ((flags != null) ? flags :[]))
}
}
class DynamicKonanTest extends KonanTest {
protected String cSource
void compileTest(List<String> filesToCompile, String exe) {
def libname = "testlib"
def dylib = "$outputDirectory/$libname"
def realExe = "${exe}.${targetManager.target.family.exeSuffix}"
runCompiler(filesToCompile, dylib, ['-produce', 'dynamic'] + ((flags != null) ? flags :[]))
runClang([cSource], realExe, ['-I', outputDirectory, '-L', outputDirectory, '-l', libname])
}
void runClang(List<String> cSources, String output, List<String> moreArgs) {
def log = new ByteArrayOutputStream()
project.execKonanClang(project.testTarget) {
workingDir outputDirectory
executable "clang"
args cSources
args '-o', output
args moreArgs
args "-Wl,-rpath,$outputDirectory"
standardOutput = log
errorOutput = log
}
def logString = log.toString("UTF-8")
project.file("${output}.compilation.log").write(logString)
println(logString)
}
}
class RunExternalTestGroup extends RunStandaloneKonanTest {
def groupDirectory = "."