From a4dd4c241a18a5dccc8574deb4edf3685af7b7ff Mon Sep 17 00:00:00 2001 From: Vasily Levchenko Date: Sun, 23 Oct 2016 10:00:25 +0300 Subject: [PATCH] gradle replacement for Makefile in tests --- backend.native/build.gradle | 2 + backend.native/tests/build.gradle | 84 +++++++++++++++++++++++++++++++ settings.gradle | 1 + 3 files changed, 87 insertions(+) create mode 100644 backend.native/tests/build.gradle diff --git a/backend.native/build.gradle b/backend.native/build.gradle index 5faa5acc5ca..780c943510a 100644 --- a/backend.native/build.gradle +++ b/backend.native/build.gradle @@ -17,6 +17,8 @@ apply plugin: org.jetbrains.kotlin.NativeInteropPlugin def deps = files("$kotlin_ir_path/kotlinc/lib/kotlin-compiler.jar", "$kotlin_ir_path/kotlinc/lib/kotlin-runtime.jar", "$kotlin_ir_path/kotlinc/lib/kotlin-reflect.jar") +//export dependencies jars +ext['deps'] = deps sourceSets { compiler { diff --git a/backend.native/tests/build.gradle b/backend.native/tests/build.gradle new file mode 100644 index 00000000000..789f5dce6c5 --- /dev/null +++ b/backend.native/tests/build.gradle @@ -0,0 +1,84 @@ +import org.gradle.api.internal.file.DefaultCompositeFileTree +import org.gradle.api.internal.file.FileTreeInternal + + +public class KonanTest extends DefaultTask { + protected String source + def backendNative = project.project(":backend.native") + def runtimeProject = project.project(":runtime") + def llvmLlc = llvmTool("llc") + def llvmC = llvmTool("clang") + + @TaskAction + public void compileBc() { + def classpathSs = new DefaultCompositeFileTree(new ArrayList()) + project.sourceSets.each{classpathSs += it.output} + project.project(":Interop:Runtime").sourceSets.each{ classpathSs += it.output } + classpathSs += backendNative.ext.deps + def sourceKt = project.file(source) + def sourceBc = new File("${sourceKt.absolutePath}.bc") + def runtimeBc = new File("${runtimeProject.buildDir.canonicalPath}/runtime.bc") + println "${runtimeBc}" + project.javaexec { + main='org.jetbrains.kotlin.cli.bc.K2NativeKt' + classpath = classpathSs + args "-output", "${sourceBc.absolutePath}", + "-runtime", "${runtimeBc.absolutePath}", + "${sourceKt.absolutePath}" + jvmArgs "-Djava.library.path=${backendNative.buildDir.canonicalPath}/nativelibs" + } + def runtimeS = bc2s(runtimeBc) + def sourceS = bc2s(sourceBc) + def testC = sourceS.absolutePath.replace(".kt.S", "-test.c") + def mainC = "main.c" + def exe = sourceS.absolutePath.replace(".kt.S", "") + project.exec { + commandLine "${llvmC}", "${testC}", "${runtimeS.absolutePath}", "${sourceS.absolutePath}", "${mainC}", + "-o", "${exe}" + + } + def res = project.exec { + commandLine "${exe}" + } + } + + private File bc2s(File bcFile) { + def outputFile = new File("${bcFile.absolutePath.replace(".bc",".S")}") + println "${bcFile.absolutePath} -> ${outputFile.absolutePath}" + println "tool: ${llvmLlc}" + project.exec { + commandLine "${llvmLlc}", "-o", "${outputFile.absolutePath}" , "${bcFile}" + } + return outputFile + } + + private String llvmTool(String tool) { + return "${project.llvmDir}/bin/${tool}" + } +} + +task run() { + dependsOn(tasks.withType(KonanTest)) +} + +task sum (type:KonanTest) { + source = "codegen/function/sum.kt" +} + +/* Investigate +task objectInitialization(type: KonanTest) { + source = "codegen/object/initialization.kt" +} +*/ + +/* task objectBasic(type: KonanTest) { + source = "$codegen/klass/basic.kt" +} */ + +task aritmetic(type: KonanTest) { + source = "codegen/function/arithmetic.kt" +} + +task sum1(type: KonanTest) { + source = "codegen/function/sum_foo_bar.kt" +} \ No newline at end of file diff --git a/settings.gradle b/settings.gradle index eb5e9b8a330..a4cb6759f92 100644 --- a/settings.gradle +++ b/settings.gradle @@ -6,3 +6,4 @@ include ':InteropExample' include ':backend.native' include ':runtime' include ':common' +include ':backend.native:tests'