[K/JS] Introduce the ability to consume platform-specific cli arguments inside the main function ^KT-16981 Fixed
This commit is contained in:
+1
@@ -57,6 +57,7 @@ fun copyK2JSCompilerArguments(from: K2JSCompilerArguments, to: K2JSCompilerArgum
|
||||
to.outputPrefix = from.outputPrefix
|
||||
to.partialLinkageLogLevel = from.partialLinkageLogLevel
|
||||
to.partialLinkageMode = from.partialLinkageMode
|
||||
to.platformArgumentsProviderJsExpression = from.platformArgumentsProviderJsExpression
|
||||
to.sourceMap = from.sourceMap
|
||||
to.sourceMapBaseDirs = from.sourceMapBaseDirs
|
||||
to.sourceMapEmbedSources = from.sourceMapEmbedSources
|
||||
|
||||
+10
@@ -494,6 +494,16 @@ In combination with '-meta-info', this generates both IR and pre-IR versions of
|
||||
field = value
|
||||
}
|
||||
|
||||
@Argument(
|
||||
value = "-Xplatform-arguments-in-main-function",
|
||||
description = "JS expression that will be executed in runtime and be put as an Array<String> parameter of the main function"
|
||||
)
|
||||
var platformArgumentsProviderJsExpression: String? = null
|
||||
set(value) {
|
||||
checkFrozen()
|
||||
field = value
|
||||
}
|
||||
|
||||
@GradleOption(
|
||||
value = DefaultValue.BOOLEAN_TRUE_DEFAULT,
|
||||
gradleInputType = GradleInputTypes.INPUT,
|
||||
|
||||
@@ -23,7 +23,6 @@ import org.jetbrains.kotlin.cli.common.arguments.K2JsArgumentConstants
|
||||
import org.jetbrains.kotlin.cli.common.arguments.K2JsArgumentConstants.RUNTIME_DIAGNOSTIC_EXCEPTION
|
||||
import org.jetbrains.kotlin.cli.common.arguments.K2JsArgumentConstants.RUNTIME_DIAGNOSTIC_LOG
|
||||
import org.jetbrains.kotlin.cli.common.config.addKotlinSourceRoot
|
||||
import org.jetbrains.kotlin.cli.common.fir.reportToMessageCollector
|
||||
import org.jetbrains.kotlin.cli.common.messages.AnalyzerWithCompilerReport
|
||||
import org.jetbrains.kotlin.cli.common.messages.CompilerMessageLocation
|
||||
import org.jetbrains.kotlin.cli.common.messages.CompilerMessageSeverity.*
|
||||
@@ -211,6 +210,10 @@ class K2JsIrCompiler : CLICompiler<K2JSCompilerArguments>() {
|
||||
configurationJs.put(JSConfigurationKeys.GENERATE_DTS, arguments.generateDts)
|
||||
configurationJs.put(JSConfigurationKeys.GENERATE_INLINE_ANONYMOUS_FUNCTIONS, arguments.irGenerateInlineAnonymousFunctions)
|
||||
|
||||
arguments.platformArgumentsProviderJsExpression?.let {
|
||||
configurationJs.put(JSConfigurationKeys.DEFINE_PLATFORM_MAIN_FUNCTION_ARGUMENTS, it)
|
||||
}
|
||||
|
||||
val zipAccessor = DisposableZipFileSystemAccessor(64)
|
||||
Disposer.register(rootDisposable, zipAccessor)
|
||||
configurationJs.put(JSConfigurationKeys.ZIP_FILE_SYSTEM_ACCESSOR, zipAccessor)
|
||||
|
||||
@@ -105,6 +105,7 @@ class JsIrBackendContext(
|
||||
val devMode = configuration[JSConfigurationKeys.DEVELOPER_MODE] ?: false
|
||||
val errorPolicy = configuration[JSConfigurationKeys.ERROR_TOLERANCE_POLICY] ?: ErrorTolerancePolicy.DEFAULT
|
||||
override val es6mode = configuration[JSConfigurationKeys.USE_ES6_CLASSES] ?: false
|
||||
val platformArgumentsProviderJsExpression = configuration[JSConfigurationKeys.DEFINE_PLATFORM_MAIN_FUNCTION_ARGUMENTS]
|
||||
|
||||
val externalPackageFragment = mutableMapOf<IrFileSymbol, IrFile>()
|
||||
|
||||
|
||||
+7
-1
@@ -179,7 +179,13 @@ internal class ICHasher {
|
||||
hashCalculator.update(value.ordinal)
|
||||
}
|
||||
|
||||
hashCalculator.updateConfigKeys(config, listOf(JSConfigurationKeys.SOURCE_MAP_PREFIX)) { value: String ->
|
||||
hashCalculator.updateConfigKeys(
|
||||
config,
|
||||
listOf(
|
||||
JSConfigurationKeys.SOURCE_MAP_PREFIX,
|
||||
JSConfigurationKeys.DEFINE_PLATFORM_MAIN_FUNCTION_ARGUMENTS
|
||||
)
|
||||
) { value: String ->
|
||||
hashCalculator.update(value)
|
||||
}
|
||||
|
||||
|
||||
+5
-1
@@ -72,7 +72,11 @@ class MainFunctionCallWrapperLowering(private val context: JsIrBackendContext) :
|
||||
|
||||
return listOfNotNull(
|
||||
runIf(generateArgv) {
|
||||
JsIrBuilder.buildArray(
|
||||
context.platformArgumentsProviderJsExpression?.let {
|
||||
JsIrBuilder.buildCall(context.intrinsics.jsCode).apply {
|
||||
putValueArgument(0, it.toIrConst(context.irBuiltIns.stringType))
|
||||
}
|
||||
} ?: JsIrBuilder.buildArray(
|
||||
mainFunctionArgs.map { it.toIrConst(context.irBuiltIns.stringType) },
|
||||
valueParameters.first().type,
|
||||
context.irBuiltIns.stringType
|
||||
|
||||
+2
@@ -49,6 +49,8 @@ where advanced options include:
|
||||
Define the compile-time log level for partial linkage.
|
||||
-Xpartial-linkage={enable|disable}
|
||||
Use partial linkage mode.
|
||||
-Xplatform-arguments-in-main-function
|
||||
JS expression that will be executed in runtime and be put as an Array<String> parameter of the main function
|
||||
-Xstrict-implicit-export-types Generate strict types for implicitly exported entities inside d.ts files. This is available in the IR backend only.
|
||||
-Xtyped-arrays Translate primitive arrays into JS typed arrays.
|
||||
-Xes-classes Let generated JavaScript code use ES2015 classes.
|
||||
|
||||
Reference in New Issue
Block a user