From 1030fcf0168b7e66582374320a0576f786c67d65 Mon Sep 17 00:00:00 2001 From: Evgeny Goldin Date: Sun, 22 Jan 2012 20:48:55 +0200 Subject: [PATCH] Ant task - support + test --- .../buildtools/ant/BytecodeCompilerTask.java | 16 ++- build-tools/build.xml | 111 ++++++++++++------ .../jet/buildtools/core/BytecodeCompiler.java | 27 ++++- build-tools/test/modules/smoke/Smoke.kt | 5 + build-tools/test/modules/smoke/Smoke.kts | 7 ++ 5 files changed, 122 insertions(+), 44 deletions(-) create mode 100644 build-tools/test/modules/smoke/Smoke.kt create mode 100644 build-tools/test/modules/smoke/Smoke.kts diff --git a/build-tools/ant/src/org/jetbrains/jet/buildtools/ant/BytecodeCompilerTask.java b/build-tools/ant/src/org/jetbrains/jet/buildtools/ant/BytecodeCompilerTask.java index 7094b6c0ba3..636b71fd9d6 100644 --- a/build-tools/ant/src/org/jetbrains/jet/buildtools/ant/BytecodeCompilerTask.java +++ b/build-tools/ant/src/org/jetbrains/jet/buildtools/ant/BytecodeCompilerTask.java @@ -18,6 +18,7 @@ public class BytecodeCompilerTask extends Task { private final BytecodeCompiler compiler = new BytecodeCompiler(); + private File module; private File srcdir; private File file; private File destdir; @@ -25,6 +26,7 @@ public class BytecodeCompilerTask extends Task { private boolean includeRuntime = true; private boolean excludeStdlib = false; + public void setModule ( File module ) { this.module = module; } public void setSrcdir ( File srcdir ) { this.srcdir = srcdir; } public void setFile ( File file ) { this.file = file; } public void setDestdir ( File destdir ) { this.destdir = destdir; } @@ -49,15 +51,25 @@ public class BytecodeCompilerTask extends Task { log( String.format( "[%s] => [%s]", src, dest )); if ( this.destdir != null ) { - compiler.sourcesToDir( src, dest, this.includeRuntime, this.excludeStdlib ); + compiler.sourcesToDir( src, dest, this.excludeStdlib ); } else { compiler.sourcesToJar( src, dest, this.includeRuntime, this.excludeStdlib ); } + } + else if ( this.module != null ) { + if ( this.destdir != null ) { + throw new RuntimeException( "Module compilation is only supported for jar destination" ); + } + + String modulePath = getPath( this.module ); + String jarPath = ( this.destjar != null ? getPath( this.destjar ) : null ); + + compiler.moduleToJar( modulePath, jarPath, this.includeRuntime ); } else { - throw new RuntimeException( "Operation is not supported yet" ); + throw new RuntimeException( "This operation is not supported" ); } } } diff --git a/build-tools/build.xml b/build-tools/build.xml index 8c92854f1c8..084595c1512 100644 --- a/build-tools/build.xml +++ b/build-tools/build.xml @@ -1,10 +1,10 @@ - - - - - + + + + + @@ -14,8 +14,8 @@ - - + + @@ -65,14 +65,23 @@ - + + + + + + + + + + + - - + @@ -87,23 +96,40 @@ - + - - + + + - - - + - + + + - + + + + + + + + + + + + + + + + + - + @@ -123,10 +149,10 @@ - Running [@{classname}], cp = [${tests-jar}] + Running [@{classname}], classpath = "${tests-jar}" + failonerror = "${failonerror}"> @@ -134,10 +160,10 @@ - Running [@{classname}], cp = [${tests-dir}];[${kotlin-home}/lib/kotlin-runtime.jar] + Running [@{classname}], classpath = "${tests-dir};${kotlin-home}/lib/kotlin-runtime.jar" + failonerror = "${failonerror}"> @@ -158,9 +184,12 @@ ${java-out} - - - + + + + + + @@ -205,17 +234,26 @@ - - - - + + + + - - - - + + + + + + + + + + + + + @@ -287,7 +325,7 @@ - + @@ -298,9 +336,10 @@ - + + diff --git a/build-tools/core/src/org/jetbrains/jet/buildtools/core/BytecodeCompiler.java b/build-tools/core/src/org/jetbrains/jet/buildtools/core/BytecodeCompiler.java index 6c1fb652671..00e75153c26 100644 --- a/build-tools/core/src/org/jetbrains/jet/buildtools/core/BytecodeCompiler.java +++ b/build-tools/core/src/org/jetbrains/jet/buildtools/core/BytecodeCompiler.java @@ -45,11 +45,12 @@ public class BytecodeCompiler { /** * {@code CompileEnvironment#compileBunchOfSources} wrapper. * - * @param source compilation source (directory or file) - * @param destination compilation destination + * @param source compilation source (directory or file) + * @param destination compilation destination + * @param excludeStdlib whether Kotlin standard library is excluded in compilation */ - public void sourcesToDir ( String source, String destination, boolean includeRuntime, boolean excludeStdlib ) { - boolean success = ENV.compileBunchOfSources( source, null, destination, includeRuntime, ! excludeStdlib ); + public void sourcesToDir ( String source, String destination, boolean excludeStdlib ) { + boolean success = ENV.compileBunchOfSources( source, null, destination, true, ! excludeStdlib ); if ( ! success ) { throw new RuntimeException( compilationError( source )); } @@ -59,8 +60,10 @@ public class BytecodeCompiler { /** * {@code CompileEnvironment#compileBunchOfSources} wrapper. * - * @param source compilation source (directory or file) - * @param jar compilation destination jar + * @param source compilation source (directory or file) + * @param jar compilation destination jar + * @param includeRuntime whether Kotlin runtime library is included in destination jar + * @param excludeStdlib whether Kotlin standard library is excluded in compilation */ public void sourcesToJar ( String source, String jar, boolean includeRuntime, boolean excludeStdlib ) { boolean success = ENV.compileBunchOfSources( source, jar, null, includeRuntime, ! excludeStdlib ); @@ -68,4 +71,16 @@ public class BytecodeCompiler { throw new RuntimeException( compilationError( source )); } } + + + /** + * {@code CompileEnvironment#compileModuleScript} wrapper. + * + * @param moduleFile compilation module file + * @param jar compilation destination jar + * @param includeRuntime whether Kotlin runtime library is included in destination jar + */ + public void moduleToJar ( String moduleFile, String jar, boolean includeRuntime ) { + ENV.compileModuleScript( moduleFile, jar, includeRuntime ); + } } diff --git a/build-tools/test/modules/smoke/Smoke.kt b/build-tools/test/modules/smoke/Smoke.kt new file mode 100644 index 00000000000..49d0e6db899 --- /dev/null +++ b/build-tools/test/modules/smoke/Smoke.kt @@ -0,0 +1,5 @@ +package Smoke + +fun main(args: Array) { + print("${args[0]}|${args[1]}|${args[2]}") +} diff --git a/build-tools/test/modules/smoke/Smoke.kts b/build-tools/test/modules/smoke/Smoke.kts new file mode 100644 index 00000000000..179d700646e --- /dev/null +++ b/build-tools/test/modules/smoke/Smoke.kts @@ -0,0 +1,7 @@ +import kotlin.modules.* + +fun project() { + module("smoke") { + sources += "Smoke.kt" + } +}