[kotlinx-metadata-klib] Bugfixes:
1. Add dependency on `:core:descriptors` 2. Wrap module name with < and > 3. Remove redundant question marks. 4. Fix string table writing.
This commit is contained in:
@@ -28,6 +28,8 @@ configurations.getByName("testCompile").extendsFrom(shadows)
|
||||
dependencies {
|
||||
compile(kotlinStdlib())
|
||||
shadows(project(":kotlinx-metadata"))
|
||||
// TODO: Get rid of this heavyweight dependency.
|
||||
shadows(project(":core:descriptors"))
|
||||
shadows(project(":core:metadata"))
|
||||
shadows(project(":compiler:serialization"))
|
||||
shadows(project(":kotlin-util-klib-metadata"))
|
||||
|
||||
@@ -104,7 +104,7 @@ class KlibModuleMetadata(
|
||||
writeStrategy: KlibModuleFragmentWriteStrategy = KlibModuleFragmentWriteStrategy.DEFAULT
|
||||
): SerializedKlibMetadata {
|
||||
val reverseIndex = ReverseSourceFileIndexWriteExtension()
|
||||
val c = WriteContext(KlibMetadataStringTable(), listOf(reverseIndex))
|
||||
|
||||
|
||||
val groupedFragments = fragments
|
||||
.groupBy(KmModuleFragment::fqNameOrFail)
|
||||
@@ -119,9 +119,12 @@ class KlibModuleMetadata(
|
||||
)
|
||||
val groupedProtos = groupedFragments.mapValues { (_, fragments) ->
|
||||
fragments.map {
|
||||
val c = WriteContext(KlibMetadataStringTable(), listOf(reverseIndex))
|
||||
KlibModuleFragmentWriter(c.strings as KlibMetadataStringTable, c.contextExtensions).also(it::accept).write()
|
||||
}
|
||||
}
|
||||
// This context and string table is only required for module-level annotations.
|
||||
val c = WriteContext(KlibMetadataStringTable(), listOf(reverseIndex))
|
||||
return SerializedKlibMetadata(
|
||||
header.writeHeader(c).build().toByteArray(),
|
||||
groupedProtos.map { it.value.map(ProtoBuf.PackageFragment::toByteArray) },
|
||||
|
||||
@@ -18,10 +18,15 @@ internal fun UniqId.writeUniqId(): KlibMetadataProtoBuf.DescriptorUniqId.Builder
|
||||
index = this@writeUniqId.index
|
||||
}
|
||||
|
||||
private fun wrapModuleName(moduleName: String): String =
|
||||
moduleName
|
||||
.let { if (it.startsWith("<")) it else "<$it" }
|
||||
.let { if (it.endsWith(">")) it else "$it>" }
|
||||
|
||||
internal fun KlibHeader.writeHeader(context: WriteContext): KlibMetadataProtoBuf.Header.Builder =
|
||||
KlibMetadataProtoBuf.Header.newBuilder().also { proto ->
|
||||
val (strings, qualifiedNames) = (context.strings as StringTableImpl).buildProto()
|
||||
proto.moduleName = moduleName
|
||||
proto.moduleName = wrapModuleName(moduleName)
|
||||
proto.qualifiedNames = qualifiedNames
|
||||
proto.strings = strings
|
||||
proto.addAllPackageFragmentName(packageFragmentName)
|
||||
|
||||
@@ -34,6 +34,12 @@ class KlibModuleFragmentWriter(
|
||||
t.build()
|
||||
|
||||
override fun visitEnd() {
|
||||
|
||||
// TODO: This should be moved to ModuleFragmentWriter.
|
||||
val (strings, qualifiedNames) = (c.strings as KlibMetadataStringTable).buildProto()
|
||||
t.strings = strings
|
||||
t.qualifiedNames = qualifiedNames
|
||||
|
||||
val isPackageEmpty = if (t.`package` == null) {
|
||||
true
|
||||
} else {
|
||||
|
||||
@@ -89,10 +89,10 @@ var KmModuleFragment.fqName: String?
|
||||
klibExtensions.fqName = value
|
||||
}
|
||||
|
||||
val KmModuleFragment.className: MutableList<ClassName>?
|
||||
val KmModuleFragment.className: MutableList<ClassName>
|
||||
get() = klibExtensions.className
|
||||
|
||||
val KmModuleFragment.moduleFragmentFiles: MutableList<KlibSourceFile>?
|
||||
val KmModuleFragment.moduleFragmentFiles: MutableList<KlibSourceFile>
|
||||
get() = klibExtensions.moduleFragmentFiles
|
||||
|
||||
val KmTypeParameter.annotations: MutableList<KmAnnotation>
|
||||
|
||||
Reference in New Issue
Block a user