JS: make -meta-info cli option boolean
This commit is contained in:
@@ -26,7 +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
|
||||
public var metaInfo: Boolean = false
|
||||
|
||||
/**
|
||||
* {@link K2JsArgumentConstants.CALL} (default) if need generate a main function call (main function will be auto detected)
|
||||
@@ -72,10 +72,6 @@ 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)
|
||||
}
|
||||
if (metaInfo) args.add("-meta-info")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -259,7 +259,6 @@
|
||||
|
||||
<macrodef name="new-kotlin2js">
|
||||
<attribute name="output"/>
|
||||
<attribute name="meta-info"/>
|
||||
<element name="src"/>
|
||||
|
||||
<sequential>
|
||||
@@ -287,7 +286,6 @@
|
||||
<arg value="@{output}"/>
|
||||
<arg value="-no-stdlib"/>
|
||||
<arg value="-meta-info"/>
|
||||
<arg value="@{meta-info}"/>
|
||||
<arg line="-main noCall"/>
|
||||
</java>
|
||||
</sequential>
|
||||
@@ -300,13 +298,13 @@
|
||||
<property name="compiled.stdlib.meta.js" value="stdlib.meta.js"/>
|
||||
<property name="stdlib.js.dir" value="${basedir}/js/js.translator/testData"/>
|
||||
|
||||
<new-kotlin2js output="${output}/${compiled.builtins.js}" meta-info="${output}/${compiled.builtins.meta.js}">
|
||||
<new-kotlin2js output="${output}/${compiled.builtins.js}">
|
||||
<src>
|
||||
<fileset refid="kotlin.builtin.files"/>
|
||||
</src>
|
||||
</new-kotlin2js>
|
||||
|
||||
<new-kotlin2js output="${output}/${compiled.stdlib.js}" meta-info="${output}/${compiled.stdlib.meta.js}">
|
||||
<new-kotlin2js output="${output}/${compiled.stdlib.js}">
|
||||
<src>
|
||||
<resources refid="js.lib.files"/>
|
||||
</src>
|
||||
|
||||
+2
-3
@@ -38,9 +38,8 @@ 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 = "meta-info", description = "Generate metadata")
|
||||
public boolean metaInfo;
|
||||
|
||||
@Argument(value = "target", description = "Generate JS files for specific ECMA version (only ECMA 5 is supported)")
|
||||
@ValueDescription("<version>")
|
||||
|
||||
@@ -244,7 +244,7 @@ public class K2JSCompiler extends CLICompiler<K2JSCompilerArguments> {
|
||||
.ecmaVersion(ecmaVersion)
|
||||
.sourceMap(arguments.sourceMap)
|
||||
.inlineEnabled(inlineEnabled)
|
||||
.metaFileOutputPath(arguments.metaInfo)
|
||||
.metaInfo(arguments.metaInfo)
|
||||
.build();
|
||||
}
|
||||
|
||||
|
||||
@@ -39,6 +39,8 @@ public object KotlinJavascriptMetadataUtils {
|
||||
private val METADATA_PATTERN = "(?m)\\w+\\.$KOTLIN_JAVASCRIPT_METHOD_NAME\\((\\d+),\\s*(['\"])([^'\"]*)\\2,\\s*(['\"])([^'\"]*)\\4\\)".toRegex()
|
||||
private val ABI_VERSION = 2
|
||||
|
||||
public fun replaceSuffix(filePath: String): String = filePath.substringBeforeLast(JS_EXT) + META_JS_SUFFIX
|
||||
|
||||
platformStatic
|
||||
public fun hasMetadata(text: String): Boolean = METADATA_PATTERN.matcher(text).find()
|
||||
|
||||
|
||||
@@ -72,11 +72,10 @@ public class KotlinCompilerRunner {
|
||||
@NotNull OutputItemsCollector collector,
|
||||
@NotNull Collection<File> sourceFiles,
|
||||
@NotNull List<String> libraryFiles,
|
||||
@NotNull File outputFile,
|
||||
@Nullable File metaInfoFile
|
||||
@NotNull File outputFile
|
||||
) {
|
||||
K2JSCompilerArguments arguments = mergeBeans(commonArguments, k2jsArguments);
|
||||
setupK2JsArguments(outputFile, metaInfoFile, sourceFiles, libraryFiles, arguments);
|
||||
setupK2JsArguments(outputFile, sourceFiles, libraryFiles, arguments);
|
||||
|
||||
runCompiler(K2JS_COMPILER, arguments, compilerSettings.getAdditionalArguments(), messageCollector, collector, environment);
|
||||
}
|
||||
@@ -191,7 +190,6 @@ public class KotlinCompilerRunner {
|
||||
|
||||
private static void setupK2JsArguments(
|
||||
@NotNull File outputFile,
|
||||
@Nullable File metaInfoFile,
|
||||
@NotNull Collection<File> sourceFiles,
|
||||
@NotNull List<String> libraryFiles,
|
||||
@NotNull K2JSCompilerArguments settings
|
||||
@@ -204,11 +202,7 @@ public class KotlinCompilerRunner {
|
||||
}
|
||||
});
|
||||
settings.outputFile = outputFile.getPath();
|
||||
|
||||
if (metaInfoFile != null) {
|
||||
settings.metaInfo = metaInfoFile.getPath();
|
||||
}
|
||||
|
||||
settings.metaInfo = true;
|
||||
settings.libraryFiles = ArrayUtil.toStringArray(libraryFiles);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -400,12 +400,11 @@ public class KotlinBuilder : ModuleLevelBuilder(BuilderCategory.SOURCE_PROCESSOR
|
||||
|
||||
val moduleName = representativeTarget.getModule().getName()
|
||||
val outputFile = JpsJsModuleUtils.getOutputFile(outputDir, moduleName)
|
||||
val metaInfoFile = JpsJsModuleUtils.getOutputMetaFile(outputDir, moduleName)
|
||||
val libraryFiles = JpsJsModuleUtils.getLibraryFilesAndDependencies(representativeTarget)
|
||||
val compilerSettings = JpsKotlinCompilerSettings.getCompilerSettings(project)
|
||||
val k2JsArguments = JpsKotlinCompilerSettings.getK2JsCompilerArguments(project)
|
||||
|
||||
runK2JsCompiler(commonArguments, k2JsArguments, compilerSettings, messageCollector, environment, outputItemCollector, sourceFiles, libraryFiles, outputFile, metaInfoFile)
|
||||
runK2JsCompiler(commonArguments, k2JsArguments, compilerSettings, messageCollector, environment, outputItemCollector, sourceFiles, libraryFiles, outputFile)
|
||||
return outputItemCollector
|
||||
}
|
||||
|
||||
|
||||
@@ -54,8 +54,7 @@ public abstract class Config {
|
||||
private final String moduleId;
|
||||
|
||||
private final boolean sourcemap;
|
||||
@Nullable
|
||||
private final String metaFileOutputPath;
|
||||
private final boolean metaInfo;
|
||||
|
||||
@NotNull
|
||||
protected final List<KotlinJavascriptMetadata> metadata = new SmartList<KotlinJavascriptMetadata>();
|
||||
@@ -71,23 +70,22 @@ public abstract class Config {
|
||||
@NotNull EcmaVersion ecmaVersion,
|
||||
boolean sourcemap,
|
||||
boolean inlineEnabled,
|
||||
@Nullable String metaFileOutputPath
|
||||
boolean metaInfo
|
||||
) {
|
||||
this.project = project;
|
||||
this.target = ecmaVersion;
|
||||
this.moduleId = moduleId;
|
||||
this.sourcemap = sourcemap;
|
||||
this.inlineEnabled = inlineEnabled;
|
||||
this.metaFileOutputPath = metaFileOutputPath;
|
||||
this.metaInfo = metaInfo;
|
||||
}
|
||||
|
||||
public boolean isSourcemap() {
|
||||
return sourcemap;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public String getMetaInfo() {
|
||||
return metaFileOutputPath;
|
||||
public boolean isMetaInfo() {
|
||||
return metaInfo;
|
||||
}
|
||||
|
||||
public boolean isInlineEnabled() {
|
||||
|
||||
@@ -71,9 +71,9 @@ public class LibrarySourcesConfig extends Config {
|
||||
boolean sourceMap,
|
||||
boolean inlineEnabled,
|
||||
boolean isUnitTestConfig,
|
||||
@Nullable String metaFileOutputPath
|
||||
boolean metaInfo
|
||||
) {
|
||||
super(project, moduleId, ecmaVersion, sourceMap, inlineEnabled, metaFileOutputPath);
|
||||
super(project, moduleId, ecmaVersion, sourceMap, inlineEnabled, metaInfo);
|
||||
this.files = files;
|
||||
this.isUnitTestConfig = isUnitTestConfig;
|
||||
}
|
||||
@@ -186,7 +186,7 @@ public class LibrarySourcesConfig extends Config {
|
||||
boolean sourceMap = false;
|
||||
boolean inlineEnabled = true;
|
||||
boolean isUnitTestConfig = false;
|
||||
String metaFileOutputPath;
|
||||
boolean metaInfo = false;
|
||||
|
||||
public Builder(@NotNull Project project, @NotNull String moduleId, @NotNull List<String> files) {
|
||||
this.project = project;
|
||||
@@ -214,13 +214,13 @@ public class LibrarySourcesConfig extends Config {
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder metaFileOutputPath(@Nullable String metaFileOutputPath) {
|
||||
this.metaFileOutputPath = metaFileOutputPath;
|
||||
public Builder metaInfo(boolean metaInfo) {
|
||||
this.metaInfo = metaInfo;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Config build() {
|
||||
return new LibrarySourcesConfig(project, moduleId, files, ecmaVersion, sourceMap, inlineEnabled, isUnitTestConfig, metaFileOutputPath);
|
||||
return new LibrarySourcesConfig(project, moduleId, files, ecmaVersion, sourceMap, inlineEnabled, isUnitTestConfig, metaInfo);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -32,6 +32,7 @@ import org.jetbrains.kotlin.js.sourceMap.SourceMapBuilder
|
||||
import org.jetbrains.kotlin.psi.JetFile
|
||||
import org.jetbrains.kotlin.resolve.diagnostics.Diagnostics
|
||||
import org.jetbrains.kotlin.serialization.js.KotlinJavascriptSerializationUtil
|
||||
import org.jetbrains.kotlin.utils.KotlinJavascriptMetadataUtils
|
||||
import org.jetbrains.kotlin.utils.fileUtils.readTextOrEmpty
|
||||
import java.io.File
|
||||
import java.util.ArrayList
|
||||
@@ -71,11 +72,11 @@ public abstract class TranslationResult protected (public val diagnostics: Diagn
|
||||
val jsFile = SimpleOutputFile(sourceFiles, outputFile.getName(), prefix + code + postfix)
|
||||
val outputFiles = arrayListOf(jsFile)
|
||||
|
||||
config.getMetaInfo()?.let {
|
||||
val metaFile = File(it)
|
||||
if (config.isMetaInfo()) {
|
||||
val metaFileName = KotlinJavascriptMetadataUtils.replaceSuffix(outputFile.getName())
|
||||
val metaFileContent = KotlinJavascriptSerializationUtil.metadataAsString(config.getModuleId(), moduleDescriptor)
|
||||
val sourceFilesForMetaFile = ArrayList<File>(sourceFiles)
|
||||
val jsMetaFile = SimpleOutputFile(sourceFilesForMetaFile, metaFile.getName(), metaFileContent)
|
||||
val sourceFilesForMetaFile = ArrayList(sourceFiles)
|
||||
val jsMetaFile = SimpleOutputFile(sourceFilesForMetaFile, metaFileName, metaFileContent)
|
||||
outputFiles.add(jsMetaFile)
|
||||
}
|
||||
|
||||
|
||||
+9
-5
@@ -27,6 +27,9 @@ import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.kotlin.cli.common.arguments.K2JSCompilerArguments;
|
||||
import org.jetbrains.kotlin.cli.js.K2JSCompiler;
|
||||
import org.jetbrains.kotlin.utils.LibraryUtils;
|
||||
import org.jetbrains.kotlin.utils.KotlinJavascriptMetadataUtils;
|
||||
import org.jetbrains.kotlin.js.JavaScript;
|
||||
import kotlin.KotlinPackage;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
@@ -54,10 +57,10 @@ public class K2JSCompilerMojo extends KotlinCompileMojoBase<K2JSCompilerArgument
|
||||
private String outputFile;
|
||||
|
||||
/**
|
||||
* The output metafile name
|
||||
* Flag enables or disables metafile generation
|
||||
*/
|
||||
@Parameter(defaultValue = "${project.build.directory}/js/${project.artifactId}.meta.js")
|
||||
private String metaFile;
|
||||
@Parameter(defaultValue = "true")
|
||||
private boolean metaInfo;
|
||||
|
||||
/**
|
||||
* Flags enables or disable source map generation
|
||||
@@ -69,7 +72,7 @@ public class K2JSCompilerMojo extends KotlinCompileMojoBase<K2JSCompilerArgument
|
||||
protected void configureSpecificCompilerArguments(@NotNull K2JSCompilerArguments arguments) throws MojoExecutionException {
|
||||
arguments.outputFile = outputFile;
|
||||
arguments.noStdlib = true;
|
||||
arguments.metaInfo = metaFile;
|
||||
arguments.metaInfo = metaInfo;
|
||||
|
||||
List<String> libraries = getKotlinJavascriptLibraryFiles();
|
||||
LOG.debug("libraryFiles: " + libraries);
|
||||
@@ -82,7 +85,8 @@ public class K2JSCompilerMojo extends KotlinCompileMojoBase<K2JSCompilerArgument
|
||||
if (outputFile != null) {
|
||||
collector.add(new File(outputFile).getParent());
|
||||
}
|
||||
if (metaFile != null) {
|
||||
if (metaInfo) {
|
||||
String metaFile = KotlinPackage.substringBeforeLast(outputFile, JavaScript.DOT_EXTENSION, outputFile) + KotlinJavascriptMetadataUtils.META_JS_SUFFIX;
|
||||
collector.add(new File(metaFile).getParent());
|
||||
}
|
||||
}
|
||||
|
||||
+4
-4
@@ -77,10 +77,10 @@ public class KotlinTestJSCompilerMojo extends K2JSCompilerMojo {
|
||||
private String outputFile;
|
||||
|
||||
/**
|
||||
* The output metafile name
|
||||
* Flag enables or disables metafile generation
|
||||
*/
|
||||
@Parameter(defaultValue = "${project.build.directory}/test-js/${project.artifactId}-tests.meta.js")
|
||||
private String metaFile;
|
||||
@Parameter(defaultValue = "true")
|
||||
private boolean metaInfo;
|
||||
|
||||
@Override
|
||||
protected void configureSpecificCompilerArguments(@NotNull K2JSCompilerArguments arguments) throws MojoExecutionException {
|
||||
@@ -90,7 +90,7 @@ public class KotlinTestJSCompilerMojo extends K2JSCompilerMojo {
|
||||
super.configureSpecificCompilerArguments(arguments);
|
||||
|
||||
arguments.outputFile = outputFile;
|
||||
arguments.metaInfo = metaFile;
|
||||
arguments.metaInfo = metaInfo;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Reference in New Issue
Block a user