From 28044c18cdcb9a4450d256809784e3dc3d4008ad Mon Sep 17 00:00:00 2001 From: Evgeny Goldin Date: Sun, 15 Jan 2012 17:35:49 +0200 Subject: [PATCH] "build-tools" module + "buildTools" Ant target added --- .../core/KotlinBytecodeCompiler.java | 47 +++++++++++++++++++ .../core/KotlinJavaScriptCompiler.java | 8 ++++ build.xml | 24 +++++++++- .../org/jetbrains/jet/cli/KotlinCompiler.java | 6 +-- 4 files changed, 80 insertions(+), 5 deletions(-) create mode 100644 build-tools/core/src/org/jetbrains/jet/buildtools/core/KotlinBytecodeCompiler.java create mode 100644 build-tools/core/src/org/jetbrains/jet/buildtools/core/KotlinJavaScriptCompiler.java diff --git a/build-tools/core/src/org/jetbrains/jet/buildtools/core/KotlinBytecodeCompiler.java b/build-tools/core/src/org/jetbrains/jet/buildtools/core/KotlinBytecodeCompiler.java new file mode 100644 index 00000000000..5ab862111c8 --- /dev/null +++ b/build-tools/core/src/org/jetbrains/jet/buildtools/core/KotlinBytecodeCompiler.java @@ -0,0 +1,47 @@ +package org.jetbrains.jet.buildtools.core; + +import org.jetbrains.jet.cli.KotlinCompiler; + +import java.io.File; +import java.io.IOException; + + +/** + * Wrapper class for Kotlin bytecode compiler. + */ +public class KotlinBytecodeCompiler { + + /** + * Compiles a single file. + * + * @param sourceFile source file to compile + * @param destinationDirectory destination directory to compile the file to + */ + public static void file ( File sourceFile, File destinationDirectory ) { + + String sourcePath = getPath( sourceFile ); + String destinationPath = getPath( destinationDirectory ); + + try { + KotlinCompiler.main( "-src", sourcePath, "-output", destinationPath ); + } + catch ( Exception e ) { + throw new RuntimeException( String.format( "Failed to compile [%s] to [%s]: %s", sourcePath, destinationPath, e ), e ); + } + } + + + /** + * {@code file.getCanonicalFile().getPath()} convenience wrapper. + * @param f file to get its canonical path. + * @return file's canonical path + */ + private static String getPath( File f ) { + try { + return f.getCanonicalFile().getPath(); + } + catch ( IOException e ) { + throw new RuntimeException( String.format( "Failed to resolve canonical file of [%s]: %s", f, e ), e ); + } + } +} diff --git a/build-tools/core/src/org/jetbrains/jet/buildtools/core/KotlinJavaScriptCompiler.java b/build-tools/core/src/org/jetbrains/jet/buildtools/core/KotlinJavaScriptCompiler.java new file mode 100644 index 00000000000..f4079188a08 --- /dev/null +++ b/build-tools/core/src/org/jetbrains/jet/buildtools/core/KotlinJavaScriptCompiler.java @@ -0,0 +1,8 @@ +package org.jetbrains.jet.buildtools.core; + + +/** + * Wrapper class for Kotlin JavaScript compiler. + */ +public class KotlinJavaScriptCompiler { +} diff --git a/build.xml b/build.xml index 4084ccf2e94..19f07a6e888 100644 --- a/build.xml +++ b/build.xml @@ -24,6 +24,15 @@ + + + + + + + + + @@ -52,7 +61,7 @@ - + @@ -72,7 +81,18 @@ - + + + + + + + + + + + + diff --git a/compiler/cli/src/org/jetbrains/jet/cli/KotlinCompiler.java b/compiler/cli/src/org/jetbrains/jet/cli/KotlinCompiler.java index 9b1d16180a8..2f43457dc3d 100644 --- a/compiler/cli/src/org/jetbrains/jet/cli/KotlinCompiler.java +++ b/compiler/cli/src/org/jetbrains/jet/cli/KotlinCompiler.java @@ -32,12 +32,12 @@ public class KotlinCompiler { @Argument(value = "help", alias = "h", description = "show help") public boolean help; } - + private static void usage(PrintStream target) { target.println("Usage: KotlinCompiler [-output |-jar ] [-src |-module ] [-includeRuntime] [-excludeStdlib]"); } - public static void main(String[] args) { + public static void main(String ... args) { System.setProperty("java.awt.headless", "true"); Arguments arguments = new Arguments(); try { @@ -53,7 +53,7 @@ public class KotlinCompiler { System.exit(1); return; } - + if (arguments.help) { usage(System.out); System.exit(0);