JS backend: add -meta-info command line option for cli compiler
This commit is contained in:
@@ -26,6 +26,7 @@ public class Kotlin2JsTask : KotlinCompilerBaseTask() {
|
|||||||
public var outputPrefix: File? = null
|
public var outputPrefix: File? = null
|
||||||
public var outputPostfix: File? = null
|
public var outputPostfix: File? = null
|
||||||
public var sourceMap: Boolean = false
|
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)
|
* {@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 (noStdlib) args.add("-no-stdlib")
|
||||||
if (sourceMap) args.add("-source-map")
|
if (sourceMap) args.add("-source-map")
|
||||||
|
|
||||||
|
metaInfo?.let {
|
||||||
|
args.add("-meta-info")
|
||||||
|
args.add(it.canonicalPath)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+4
@@ -38,6 +38,10 @@ public class K2JSCompilerArguments extends CommonCompilerArguments {
|
|||||||
@Argument(value = "source-map", description = "Generate source map")
|
@Argument(value = "source-map", description = "Generate source map")
|
||||||
public boolean sourceMap;
|
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)")
|
@Argument(value = "target", description = "Generate JS files for specific ECMA version (only ECMA 5 is supported)")
|
||||||
@ValueDescription("<version>")
|
@ValueDescription("<version>")
|
||||||
public String target;
|
public String target;
|
||||||
|
|||||||
@@ -18,6 +18,7 @@
|
|||||||
<orderEntry type="module" module-name="backend-common" />
|
<orderEntry type="module" module-name="backend-common" />
|
||||||
<orderEntry type="module" module-name="serialization" />
|
<orderEntry type="module" module-name="serialization" />
|
||||||
<orderEntry type="module" module-name="serialization.jvm" />
|
<orderEntry type="module" module-name="serialization.jvm" />
|
||||||
|
<orderEntry type="module" module-name="js.serializer" />
|
||||||
<orderEntry type="module" module-name="util" />
|
<orderEntry type="module" module-name="util" />
|
||||||
</component>
|
</component>
|
||||||
</module>
|
</module>
|
||||||
@@ -29,6 +29,7 @@ import kotlin.Function1;
|
|||||||
import kotlin.Unit;
|
import kotlin.Unit;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
import org.jetbrains.kotlin.utils.serializer.KotlinJavaScriptSerializer;
|
||||||
import org.jetbrains.kotlin.analyzer.AnalysisResult;
|
import org.jetbrains.kotlin.analyzer.AnalysisResult;
|
||||||
import org.jetbrains.kotlin.backend.common.output.OutputFileCollection;
|
import org.jetbrains.kotlin.backend.common.output.OutputFileCollection;
|
||||||
import org.jetbrains.kotlin.cli.common.CLICompiler;
|
import org.jetbrains.kotlin.cli.common.CLICompiler;
|
||||||
@@ -191,6 +192,10 @@ public class K2JSCompiler extends CLICompiler<K2JSCompilerArguments> {
|
|||||||
}
|
}
|
||||||
OutputUtilsPackage.writeAll(outputFiles, outputDir, messageCollector);
|
OutputUtilsPackage.writeAll(outputFiles, outputDir, messageCollector);
|
||||||
|
|
||||||
|
if (arguments.metaInfo != null) {
|
||||||
|
new KotlinJavaScriptSerializer().serialize(config.getModuleId(), analysisResult.getModuleDescriptor(), new File(arguments.metaInfo));
|
||||||
|
}
|
||||||
|
|
||||||
return OK;
|
return OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ where possible options include:
|
|||||||
-no-stdlib Don't use bundled Kotlin stdlib
|
-no-stdlib Don't use bundled Kotlin stdlib
|
||||||
-library-files <path[,]> Path to zipped library sources or kotlin files separated by commas
|
-library-files <path[,]> Path to zipped library sources or kotlin files separated by commas
|
||||||
-source-map Generate source map
|
-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)
|
-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)
|
-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
|
-output-prefix <path> Path to file which will be added to the beginning of output file
|
||||||
|
|||||||
+1
@@ -218,6 +218,7 @@ public open class Kotlin2JsCompile() : AbstractKotlinCompile<K2JSCompilerArgumen
|
|||||||
args.outputFile = outputFile
|
args.outputFile = outputFile
|
||||||
args.outputPrefix = kotlinOptions.outputPrefix
|
args.outputPrefix = kotlinOptions.outputPrefix
|
||||||
args.outputPostfix = kotlinOptions.outputPostfix
|
args.outputPostfix = kotlinOptions.outputPostfix
|
||||||
|
args.metaInfo = kotlinOptions.metaInfo
|
||||||
|
|
||||||
val kotlinJsLibsFromDependencies =
|
val kotlinJsLibsFromDependencies =
|
||||||
getProject().getConfigurations().getByName("compile")
|
getProject().getConfigurations().getByName("compile")
|
||||||
|
|||||||
+8
@@ -45,10 +45,18 @@ public class K2JSCompilerMojo extends KotlinCompileMojoBase<K2JSCompilerArgument
|
|||||||
*/
|
*/
|
||||||
private String outputFile;
|
private String outputFile;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The output metafile name
|
||||||
|
*
|
||||||
|
* @parameter default-value="${project.build.directory}/js/${project.artifactId}.meta.js"
|
||||||
|
*/
|
||||||
|
private String metaFile;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void configureSpecificCompilerArguments(@NotNull K2JSCompilerArguments arguments) throws MojoExecutionException {
|
protected void configureSpecificCompilerArguments(@NotNull K2JSCompilerArguments arguments) throws MojoExecutionException {
|
||||||
arguments.outputFile = outputFile;
|
arguments.outputFile = outputFile;
|
||||||
arguments.noStdlib = true;
|
arguments.noStdlib = true;
|
||||||
|
arguments.metaInfo = metaFile;
|
||||||
|
|
||||||
List<String> libraries = getKotlinJavascriptLibraryFiles();
|
List<String> libraries = getKotlinJavascriptLibraryFiles();
|
||||||
LOG.info("libraryFiles: " + libraries);
|
LOG.info("libraryFiles: " + libraries);
|
||||||
|
|||||||
Reference in New Issue
Block a user