From 3bf14518e8b9d69c5dee1e36f52fe96f0faedcd5 Mon Sep 17 00:00:00 2001 From: Michael Nedzelsky Date: Mon, 29 Dec 2014 14:17:34 +0300 Subject: [PATCH] JS backend: add -meta-info command line option for cli compiler --- ant/src/org/jetbrains/kotlin/ant/Kotlin2JsTask.kt | 6 ++++++ .../cli/common/arguments/K2JSCompilerArguments.java | 4 ++++ compiler/cli/cli.iml | 1 + .../cli/src/org/jetbrains/kotlin/cli/js/K2JSCompiler.java | 5 +++++ compiler/testData/cli/js/jsHelp.out | 1 + .../kotlin/org/jetbrains/kotlin/gradle/tasks/Tasks.kt | 1 + .../java/org/jetbrains/kotlin/maven/K2JSCompilerMojo.java | 8 ++++++++ 7 files changed, 26 insertions(+) diff --git a/ant/src/org/jetbrains/kotlin/ant/Kotlin2JsTask.kt b/ant/src/org/jetbrains/kotlin/ant/Kotlin2JsTask.kt index bfc3a530e2c..942e7493806 100644 --- a/ant/src/org/jetbrains/kotlin/ant/Kotlin2JsTask.kt +++ b/ant/src/org/jetbrains/kotlin/ant/Kotlin2JsTask.kt @@ -26,6 +26,7 @@ public class Kotlin2JsTask : KotlinCompilerBaseTask() { public var outputPrefix: File? = null public var outputPostfix: File? = null public var sourceMap: Boolean = false + public var metaInfo: File? = null /** * {@link K2JsArgumentConstants.CALL} (default) if need generate a main function call (main function will be auto detected) @@ -71,5 +72,10 @@ public class Kotlin2JsTask : KotlinCompilerBaseTask() { if (noStdlib) args.add("-no-stdlib") if (sourceMap) args.add("-source-map") + + metaInfo?.let { + args.add("-meta-info") + args.add(it.canonicalPath) + } } } diff --git a/compiler/cli/cli-common/src/org/jetbrains/kotlin/cli/common/arguments/K2JSCompilerArguments.java b/compiler/cli/cli-common/src/org/jetbrains/kotlin/cli/common/arguments/K2JSCompilerArguments.java index 8d8839f3d87..a168e6b5f2b 100644 --- a/compiler/cli/cli-common/src/org/jetbrains/kotlin/cli/common/arguments/K2JSCompilerArguments.java +++ b/compiler/cli/cli-common/src/org/jetbrains/kotlin/cli/common/arguments/K2JSCompilerArguments.java @@ -38,6 +38,10 @@ public class K2JSCompilerArguments extends CommonCompilerArguments { @Argument(value = "source-map", description = "Generate source map") public boolean sourceMap; + @Argument(value = "meta-info", description = "Generate meta information and save to the given file") + @ValueDescription("") + public String metaInfo; + @Argument(value = "target", description = "Generate JS files for specific ECMA version (only ECMA 5 is supported)") @ValueDescription("") public String target; diff --git a/compiler/cli/cli.iml b/compiler/cli/cli.iml index 071bbf8f03a..0c19a9cc50b 100644 --- a/compiler/cli/cli.iml +++ b/compiler/cli/cli.iml @@ -18,6 +18,7 @@ + \ No newline at end of file diff --git a/compiler/cli/src/org/jetbrains/kotlin/cli/js/K2JSCompiler.java b/compiler/cli/src/org/jetbrains/kotlin/cli/js/K2JSCompiler.java index 5af4668fc31..6ae0be37d4c 100644 --- a/compiler/cli/src/org/jetbrains/kotlin/cli/js/K2JSCompiler.java +++ b/compiler/cli/src/org/jetbrains/kotlin/cli/js/K2JSCompiler.java @@ -29,6 +29,7 @@ import kotlin.Function1; import kotlin.Unit; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; +import org.jetbrains.kotlin.utils.serializer.KotlinJavaScriptSerializer; import org.jetbrains.kotlin.analyzer.AnalysisResult; import org.jetbrains.kotlin.backend.common.output.OutputFileCollection; import org.jetbrains.kotlin.cli.common.CLICompiler; @@ -191,6 +192,10 @@ public class K2JSCompiler extends CLICompiler { } OutputUtilsPackage.writeAll(outputFiles, outputDir, messageCollector); + if (arguments.metaInfo != null) { + new KotlinJavaScriptSerializer().serialize(config.getModuleId(), analysisResult.getModuleDescriptor(), new File(arguments.metaInfo)); + } + return OK; } diff --git a/compiler/testData/cli/js/jsHelp.out b/compiler/testData/cli/js/jsHelp.out index ad309efdc9b..f84ab69da76 100644 --- a/compiler/testData/cli/js/jsHelp.out +++ b/compiler/testData/cli/js/jsHelp.out @@ -4,6 +4,7 @@ where possible options include: -no-stdlib Don't use bundled Kotlin stdlib -library-files Path to zipped library sources or kotlin files separated by commas -source-map Generate source map + -meta-info Generate meta information and save to the given file -target Generate JS files for specific ECMA version (only ECMA 5 is supported) -main {call,noCall} Whether a main function should be called; default 'call' (main function will be auto detected) -output-prefix Path to file which will be added to the beginning of output file diff --git a/libraries/tools/kotlin-gradle-plugin-core/src/main/kotlin/org/jetbrains/kotlin/gradle/tasks/Tasks.kt b/libraries/tools/kotlin-gradle-plugin-core/src/main/kotlin/org/jetbrains/kotlin/gradle/tasks/Tasks.kt index 29a5c622144..bca6e3cc579 100644 --- a/libraries/tools/kotlin-gradle-plugin-core/src/main/kotlin/org/jetbrains/kotlin/gradle/tasks/Tasks.kt +++ b/libraries/tools/kotlin-gradle-plugin-core/src/main/kotlin/org/jetbrains/kotlin/gradle/tasks/Tasks.kt @@ -218,6 +218,7 @@ public open class Kotlin2JsCompile() : AbstractKotlinCompile libraries = getKotlinJavascriptLibraryFiles(); LOG.info("libraryFiles: " + libraries);