[JS IR] Add per-module output module name
This commit is contained in:
committed by
TeamCityServer
parent
4d7f7fc50f
commit
228c6879f5
+2
-2
@@ -157,8 +157,8 @@ class K2JSCompilerArguments : CommonCompilerArguments() {
|
|||||||
@Argument(value = "-Xir-per-module", description = "Splits generated .js per-module")
|
@Argument(value = "-Xir-per-module", description = "Splits generated .js per-module")
|
||||||
var irPerModule: Boolean by FreezableVar(false)
|
var irPerModule: Boolean by FreezableVar(false)
|
||||||
|
|
||||||
@Argument(value = "-Xir-per-module-prefix", description = "Adds a custom prefix to the splitted js files")
|
@Argument(value = "-Xir-per-module-output-name", description = "Adds a custom output name to the splitted js files")
|
||||||
var irPerModulePrefix: String? by NullableStringFreezableVar(null)
|
var irPerModuleOutputName: String? by NullableStringFreezableVar(null)
|
||||||
|
|
||||||
@Argument(
|
@Argument(
|
||||||
value = "-Xinclude",
|
value = "-Xinclude",
|
||||||
|
|||||||
@@ -207,8 +207,7 @@ class K2JsIrCompiler : CLICompiler<K2JSCompilerArguments>() {
|
|||||||
irFactory = PersistentIrFactory(), // TODO IrFactoryImpl?
|
irFactory = PersistentIrFactory(), // TODO IrFactoryImpl?
|
||||||
outputKlibPath = outputFile.path,
|
outputKlibPath = outputFile.path,
|
||||||
nopack = arguments.irProduceKlibDir,
|
nopack = arguments.irProduceKlibDir,
|
||||||
jsOutputName = moduleName
|
jsOutputName = arguments.irPerModuleOutputName,
|
||||||
.substringAfterLast(":"),
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -277,7 +276,6 @@ class K2JsIrCompiler : CLICompiler<K2JSCompilerArguments>() {
|
|||||||
relativeRequirePath = true,
|
relativeRequirePath = true,
|
||||||
propertyLazyInitialization = arguments.irPropertyLazyInitialization,
|
propertyLazyInitialization = arguments.irPropertyLazyInitialization,
|
||||||
legacyPropertyAccess = arguments.irLegacyPropertyAccess,
|
legacyPropertyAccess = arguments.irLegacyPropertyAccess,
|
||||||
irPerModulePrefix = arguments.irPerModulePrefix
|
|
||||||
)
|
)
|
||||||
|
|
||||||
val jsCode = if (arguments.irDce && !arguments.irDceDriven) compiledModule.dceJsCode!! else compiledModule.jsCode!!
|
val jsCode = if (arguments.irDce && !arguments.irDceDriven) compiledModule.dceJsCode!! else compiledModule.jsCode!!
|
||||||
|
|||||||
@@ -53,7 +53,6 @@ fun compile(
|
|||||||
relativeRequirePath: Boolean = false,
|
relativeRequirePath: Boolean = false,
|
||||||
propertyLazyInitialization: Boolean,
|
propertyLazyInitialization: Boolean,
|
||||||
legacyPropertyAccess: Boolean = false,
|
legacyPropertyAccess: Boolean = false,
|
||||||
irPerModulePrefix: String? = null,
|
|
||||||
): CompilerResult {
|
): CompilerResult {
|
||||||
val (moduleFragment: IrModuleFragment, dependencyModules, irBuiltIns, symbolTable, deserializer, moduleToName) =
|
val (moduleFragment: IrModuleFragment, dependencyModules, irBuiltIns, symbolTable, deserializer, moduleToName) =
|
||||||
loadIr(project, mainModule, analyzer, configuration, allDependencies, friendDependencies, irFactory, forceAllJs)
|
loadIr(project, mainModule, analyzer, configuration, allDependencies, friendDependencies, irFactory, forceAllJs)
|
||||||
@@ -112,7 +111,6 @@ fun compile(
|
|||||||
multiModule = multiModule,
|
multiModule = multiModule,
|
||||||
relativeRequirePath = relativeRequirePath,
|
relativeRequirePath = relativeRequirePath,
|
||||||
moduleToName = moduleToName,
|
moduleToName = moduleToName,
|
||||||
irPerModulePrefix = irPerModulePrefix,
|
|
||||||
)
|
)
|
||||||
return transformer.generateModule(allModules)
|
return transformer.generateModule(allModules)
|
||||||
} else {
|
} else {
|
||||||
@@ -125,7 +123,6 @@ fun compile(
|
|||||||
multiModule = multiModule,
|
multiModule = multiModule,
|
||||||
relativeRequirePath = relativeRequirePath,
|
relativeRequirePath = relativeRequirePath,
|
||||||
moduleToName = moduleToName,
|
moduleToName = moduleToName,
|
||||||
irPerModulePrefix = irPerModulePrefix,
|
|
||||||
)
|
)
|
||||||
return transformer.generateModule(allModules)
|
return transformer.generateModule(allModules)
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-2
@@ -33,7 +33,6 @@ class IrModuleToJsTransformer(
|
|||||||
private val multiModule: Boolean = false,
|
private val multiModule: Boolean = false,
|
||||||
private val relativeRequirePath: Boolean = false,
|
private val relativeRequirePath: Boolean = false,
|
||||||
private val moduleToName: Map<IrModuleFragment, String> = emptyMap(),
|
private val moduleToName: Map<IrModuleFragment, String> = emptyMap(),
|
||||||
private val irPerModulePrefix: String? = null,
|
|
||||||
) {
|
) {
|
||||||
private val generateRegionComments = backendContext.configuration.getBoolean(JSConfigurationKeys.GENERATE_REGION_COMMENTS)
|
private val generateRegionComments = backendContext.configuration.getBoolean(JSConfigurationKeys.GENERATE_REGION_COMMENTS)
|
||||||
|
|
||||||
@@ -193,7 +192,7 @@ class IrModuleToJsTransformer(
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun IrModuleFragment.externalModuleName(): String {
|
private fun IrModuleFragment.externalModuleName(): String {
|
||||||
return (irPerModulePrefix ?: "") + (moduleToName[this] ?: sanitizeName(safeName))
|
return moduleToName[this] ?: sanitizeName(safeName)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun generateCrossModuleImports(
|
private fun generateCrossModuleImports(
|
||||||
|
|||||||
@@ -70,7 +70,6 @@ import org.jetbrains.kotlin.storage.LockBasedStorageManager
|
|||||||
import org.jetbrains.kotlin.storage.StorageManager
|
import org.jetbrains.kotlin.storage.StorageManager
|
||||||
import org.jetbrains.kotlin.utils.DFS
|
import org.jetbrains.kotlin.utils.DFS
|
||||||
import java.io.File
|
import java.io.File
|
||||||
import java.util.*
|
|
||||||
import org.jetbrains.kotlin.konan.file.File as KFile
|
import org.jetbrains.kotlin.konan.file.File as KFile
|
||||||
|
|
||||||
val KotlinLibrary.moduleName: String
|
val KotlinLibrary.moduleName: String
|
||||||
@@ -243,7 +242,8 @@ fun loadIr(
|
|||||||
JsIrLinker.JsFePluginContext(moduleDescriptor, symbolTable, typeTranslator, irBuiltIns)
|
JsIrLinker.JsFePluginContext(moduleDescriptor, symbolTable, typeTranslator, irBuiltIns)
|
||||||
}
|
}
|
||||||
val moduleFragmentToUniqueName = mutableMapOf<IrModuleFragment, String>()
|
val moduleFragmentToUniqueName = mutableMapOf<IrModuleFragment, String>()
|
||||||
val irLinker = JsIrLinker(psi2IrContext.moduleDescriptor, messageLogger, irBuiltIns, symbolTable, functionFactory, feContext, null)
|
val irLinker =
|
||||||
|
JsIrLinker(psi2IrContext.moduleDescriptor, messageLogger, irBuiltIns, symbolTable, functionFactory, feContext, null)
|
||||||
val deserializedModuleFragments = sortDependencies(allDependencies.getFullList(), depsDescriptors.descriptors).map { klib ->
|
val deserializedModuleFragments = sortDependencies(allDependencies.getFullList(), depsDescriptors.descriptors).map { klib ->
|
||||||
irLinker.deserializeIrModuleHeader(depsDescriptors.getModuleDescriptor(klib), klib).also { moduleFragment ->
|
irLinker.deserializeIrModuleHeader(depsDescriptors.getModuleDescriptor(klib), klib).also { moduleFragment ->
|
||||||
klib.manifestProperties.getProperty(KLIB_PROPERTY_JS_OUTPUT_NAME)?.let {
|
klib.manifestProperties.getProperty(KLIB_PROPERTY_JS_OUTPUT_NAME)?.let {
|
||||||
@@ -319,7 +319,11 @@ private fun runAnalysisAndPreparePsi2Ir(
|
|||||||
Psi2IrConfiguration(errorIgnorancePolicy.allowErrors)
|
Psi2IrConfiguration(errorIgnorancePolicy.allowErrors)
|
||||||
)
|
)
|
||||||
val symbolTable = SymbolTable(IdSignatureDescriptor(JsManglerDesc), irFactory)
|
val symbolTable = SymbolTable(IdSignatureDescriptor(JsManglerDesc), irFactory)
|
||||||
return psi2Ir.createGeneratorContext(analysisResult.moduleDescriptor, analysisResult.bindingContext, symbolTable) to analysisResult.hasErrors
|
return psi2Ir.createGeneratorContext(
|
||||||
|
analysisResult.moduleDescriptor,
|
||||||
|
analysisResult.bindingContext,
|
||||||
|
symbolTable
|
||||||
|
) to analysisResult.hasErrors
|
||||||
}
|
}
|
||||||
|
|
||||||
fun GeneratorContext.generateModuleFragmentWithPlugins(
|
fun GeneratorContext.generateModuleFragmentWithPlugins(
|
||||||
@@ -571,20 +575,20 @@ fun serializeModuleIntoKlib(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
buildKotlinLibrary(
|
buildKotlinLibrary(
|
||||||
linkDependencies = dependencies,
|
linkDependencies = dependencies,
|
||||||
ir = fullSerializedIr,
|
ir = fullSerializedIr,
|
||||||
metadata = serializedMetadata,
|
metadata = serializedMetadata,
|
||||||
dataFlowGraph = null,
|
dataFlowGraph = null,
|
||||||
manifestProperties = properties,
|
manifestProperties = properties,
|
||||||
moduleName = moduleName,
|
moduleName = moduleName,
|
||||||
nopack = nopack,
|
nopack = nopack,
|
||||||
perFile = perFile,
|
perFile = perFile,
|
||||||
output = klibPath,
|
output = klibPath,
|
||||||
versions = versions,
|
versions = versions,
|
||||||
builtInsPlatform = BuiltInsPlatform.JS
|
builtInsPlatform = BuiltInsPlatform.JS
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
const val KLIB_PROPERTY_JS_OUTPUT_NAME = "jsOutputName"
|
const val KLIB_PROPERTY_JS_OUTPUT_NAME = "jsOutputName"
|
||||||
|
|
||||||
@@ -617,11 +621,12 @@ private fun compareMetadataAndGoToNextICRoundIfNeeded(
|
|||||||
if (nextRoundChecker.shouldGoToNextRound()) throw IncrementalNextRoundException()
|
if (nextRoundChecker.shouldGoToNextRound()) throw IncrementalNextRoundException()
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun KlibMetadataIncrementalSerializer(configuration: CompilerConfiguration, project: Project, allowErrors: Boolean) = KlibMetadataIncrementalSerializer(
|
private fun KlibMetadataIncrementalSerializer(configuration: CompilerConfiguration, project: Project, allowErrors: Boolean) =
|
||||||
languageVersionSettings = configuration.languageVersionSettings,
|
KlibMetadataIncrementalSerializer(
|
||||||
metadataVersion = configuration.metadataVersion,
|
languageVersionSettings = configuration.languageVersionSettings,
|
||||||
project = project,
|
metadataVersion = configuration.metadataVersion,
|
||||||
exportKDoc = false,
|
project = project,
|
||||||
skipExpects = !configuration.expectActualLinker,
|
exportKDoc = false,
|
||||||
allowErrorTypes = allowErrors
|
skipExpects = !configuration.expectActualLinker,
|
||||||
)
|
allowErrorTypes = allowErrors
|
||||||
|
)
|
||||||
|
|||||||
+2
@@ -24,5 +24,7 @@ internal const val PRODUCE_ZIPPED_KLIB = "-Xir-produce-klib-file"
|
|||||||
|
|
||||||
internal const val MODULE_NAME = "-Xir-module-name"
|
internal const val MODULE_NAME = "-Xir-module-name"
|
||||||
|
|
||||||
|
internal const val PER_MODULE_OUTPUT_NAME = "-Xir-per-module-output-name"
|
||||||
|
|
||||||
fun KotlinJsOptions.isProduceUnzippedKlib() = PRODUCE_UNZIPPED_KLIB in freeCompilerArgs
|
fun KotlinJsOptions.isProduceUnzippedKlib() = PRODUCE_UNZIPPED_KLIB in freeCompilerArgs
|
||||||
fun KotlinJsOptions.isProduceZippedKlib() = PRODUCE_ZIPPED_KLIB in freeCompilerArgs
|
fun KotlinJsOptions.isProduceZippedKlib() = PRODUCE_ZIPPED_KLIB in freeCompilerArgs
|
||||||
+7
@@ -58,6 +58,13 @@ abstract class KotlinJsIrSubTarget(
|
|||||||
internal fun configure() {
|
internal fun configure() {
|
||||||
NpmResolverPlugin.apply(project)
|
NpmResolverPlugin.apply(project)
|
||||||
|
|
||||||
|
target.compilations.all {
|
||||||
|
val npmProject = it.npmProject
|
||||||
|
it.kotlinOptions {
|
||||||
|
freeCompilerArgs += "$PER_MODULE_OUTPUT_NAME=${npmProject.name}"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
configureTests()
|
configureTests()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user