JS backend: add -meta-info command line option for cli compiler

This commit is contained in:
Michael Nedzelsky
2014-12-29 14:17:34 +03:00
parent 711501af56
commit 3bf14518e8
7 changed files with 26 additions and 0 deletions
@@ -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)
}
}
}
@@ -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("<path>")
public String metaInfo;
@Argument(value = "target", description = "Generate JS files for specific ECMA version (only ECMA 5 is supported)")
@ValueDescription("<version>")
public String target;
+1
View File
@@ -18,6 +18,7 @@
<orderEntry type="module" module-name="backend-common" />
<orderEntry type="module" module-name="serialization" />
<orderEntry type="module" module-name="serialization.jvm" />
<orderEntry type="module" module-name="js.serializer" />
<orderEntry type="module" module-name="util" />
</component>
</module>
@@ -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<K2JSCompilerArguments> {
}
OutputUtilsPackage.writeAll(outputFiles, outputDir, messageCollector);
if (arguments.metaInfo != null) {
new KotlinJavaScriptSerializer().serialize(config.getModuleId(), analysisResult.getModuleDescriptor(), new File(arguments.metaInfo));
}
return OK;
}
+1
View File
@@ -4,6 +4,7 @@ where possible options include:
-no-stdlib Don't use bundled Kotlin stdlib
-library-files <path[,]> Path to zipped library sources or kotlin files separated by commas
-source-map Generate source map
-meta-info <path> Generate meta information and save to the given file
-target <version> 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> Path to file which will be added to the beginning of output file
@@ -218,6 +218,7 @@ public open class Kotlin2JsCompile() : AbstractKotlinCompile<K2JSCompilerArgumen
args.outputFile = outputFile
args.outputPrefix = kotlinOptions.outputPrefix
args.outputPostfix = kotlinOptions.outputPostfix
args.metaInfo = kotlinOptions.metaInfo
val kotlinJsLibsFromDependencies =
getProject().getConfigurations().getByName("compile")
@@ -45,10 +45,18 @@ public class K2JSCompilerMojo extends KotlinCompileMojoBase<K2JSCompilerArgument
*/
private String outputFile;
/**
* The output metafile name
*
* @parameter default-value="${project.build.directory}/js/${project.artifactId}.meta.js"
*/
private String metaFile;
@Override
protected void configureSpecificCompilerArguments(@NotNull K2JSCompilerArguments arguments) throws MojoExecutionException {
arguments.outputFile = outputFile;
arguments.noStdlib = true;
arguments.metaInfo = metaFile;
List<String> libraries = getKotlinJavascriptLibraryFiles();
LOG.info("libraryFiles: " + libraries);