Fix FIR bootstrap in version 2.0
This commit is contained in:
@@ -172,14 +172,18 @@ fun Project.configureKotlinCompilationOptions() {
|
||||
kotlinOptions {
|
||||
freeCompilerArgs += jvmCompilerArgs
|
||||
|
||||
if (useJvmFir && project.path !in projectsWithDisabledFirBootstrap) {
|
||||
freeCompilerArgs += "-Xuse-k2"
|
||||
freeCompilerArgs += "-Xabi-stability=stable"
|
||||
if (useFirLT) {
|
||||
freeCompilerArgs += "-Xuse-fir-lt"
|
||||
}
|
||||
if (useFirIC) {
|
||||
freeCompilerArgs += "-Xuse-fir-ic"
|
||||
if (useJvmFir) {
|
||||
if (project.path !in projectsWithDisabledFirBootstrap) {
|
||||
freeCompilerArgs += "-Xuse-k2"
|
||||
freeCompilerArgs += "-Xabi-stability=stable"
|
||||
if (useFirLT) {
|
||||
freeCompilerArgs += "-Xuse-fir-lt"
|
||||
}
|
||||
if (useFirIC) {
|
||||
freeCompilerArgs += "-Xuse-fir-ic"
|
||||
}
|
||||
} else {
|
||||
freeCompilerArgs += "-Xskip-prerelease-check"
|
||||
}
|
||||
}
|
||||
if (renderDiagnosticNames) {
|
||||
|
||||
+1
-1
@@ -53,7 +53,7 @@ class ModuleMapping private constructor(
|
||||
debugName: String,
|
||||
skipMetadataVersionCheck: Boolean,
|
||||
isJvmPackageNameSupported: Boolean,
|
||||
metadataVersionFromLanguageVersion: JvmMetadataVersion,
|
||||
metadataVersionFromLanguageVersion: JvmMetadataVersion = JvmMetadataVersion.INSTANCE,
|
||||
reportIncompatibleVersionError: (JvmMetadataVersion) -> Unit,
|
||||
): ModuleMapping {
|
||||
if (bytes == null) {
|
||||
|
||||
@@ -62,6 +62,8 @@ ext.configureFrontendIr = { Project project ->
|
||||
if (project.kotlinBuildProperties.useFirForLibraries) {
|
||||
freeCompilerArgs += "-Xuse-k2"
|
||||
allWarningsAsErrors = false
|
||||
} else if (project.kotlinBuildProperties.useFir) {
|
||||
freeCompilerArgs += "-Xskip-prerelease-check"
|
||||
}
|
||||
if (project.properties.renderDiagnosticNames) {
|
||||
freeCompilerArgs += "-Xrender-internal-diagnostic-names"
|
||||
|
||||
@@ -63,32 +63,40 @@ dependencies {
|
||||
class KotlinModuleShadowTransformer(private val logger: Logger) : Transformer {
|
||||
@Suppress("ArrayInDataClass")
|
||||
private data class Entry(val path: String, val bytes: ByteArray)
|
||||
|
||||
private val data = mutableListOf<Entry>()
|
||||
|
||||
override fun getName() = "KotlinModuleShadowTransformer"
|
||||
|
||||
override fun canTransformResource(element: FileTreeElement): Boolean =
|
||||
element.path.substringAfterLast(".") == KOTLIN_MODULE
|
||||
element.path.substringAfterLast(".") == KOTLIN_MODULE
|
||||
|
||||
override fun transform(context: TransformerContext) {
|
||||
fun relocate(content: String): String =
|
||||
context.relocators.fold(content) { acc, relocator -> relocator.applyToSourceContent(acc) }
|
||||
context.relocators.fold(content) { acc, relocator -> relocator.applyToSourceContent(acc) }
|
||||
|
||||
val metadata = KotlinModuleMetadata.read(context.`is`.readBytes())
|
||||
?: error("Not a .kotlin_module file: ${context.path}")
|
||||
val internalData = org.jetbrains.kotlin.metadata.jvm.deserialization.ModuleMapping.loadModuleMapping(
|
||||
context.`is`.readBytes(), javaClass.name, skipMetadataVersionCheck = true, isJvmPackageNameSupported = true
|
||||
) {
|
||||
}
|
||||
val writer = KotlinModuleMetadata.Writer()
|
||||
logger.info("Transforming ${context.path}")
|
||||
metadata.accept(object : KmModuleVisitor(writer) {
|
||||
val visitor = object : KmModuleVisitor(writer) {
|
||||
override fun visitPackageParts(fqName: String, fileFacades: List<String>, multiFileClassParts: Map<String, String>) {
|
||||
assert(multiFileClassParts.isEmpty()) { multiFileClassParts } // There are no multi-file class parts in core
|
||||
super.visitPackageParts(relocate(fqName), fileFacades.map(::relocate), multiFileClassParts)
|
||||
}
|
||||
})
|
||||
}
|
||||
for ((fqName, parts) in internalData.packageFqName2Parts) {
|
||||
val (fileFacades, multiFileClassParts) = parts.parts.partition { parts.getMultifileFacadeName(it) == null }
|
||||
visitor.visitPackageParts(fqName, fileFacades, multiFileClassParts.associateWith { parts.getMultifileFacadeName(it)!! })
|
||||
}
|
||||
visitor.visitEnd()
|
||||
|
||||
data += Entry(context.path, writer.write().bytes)
|
||||
}
|
||||
|
||||
override fun hasTransformedResource(): Boolean =
|
||||
data.isNotEmpty()
|
||||
override fun hasTransformedResource(): Boolean = data.isNotEmpty()
|
||||
|
||||
override fun modifyOutputStream(os: ZipOutputStream, preserveFileTimestamps: Boolean) {
|
||||
for ((path, bytes) in data) {
|
||||
|
||||
Reference in New Issue
Block a user