[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 {
|
dependencies {
|
||||||
compile(kotlinStdlib())
|
compile(kotlinStdlib())
|
||||||
shadows(project(":kotlinx-metadata"))
|
shadows(project(":kotlinx-metadata"))
|
||||||
|
// TODO: Get rid of this heavyweight dependency.
|
||||||
|
shadows(project(":core:descriptors"))
|
||||||
shadows(project(":core:metadata"))
|
shadows(project(":core:metadata"))
|
||||||
shadows(project(":compiler:serialization"))
|
shadows(project(":compiler:serialization"))
|
||||||
shadows(project(":kotlin-util-klib-metadata"))
|
shadows(project(":kotlin-util-klib-metadata"))
|
||||||
|
|||||||
@@ -104,7 +104,7 @@ class KlibModuleMetadata(
|
|||||||
writeStrategy: KlibModuleFragmentWriteStrategy = KlibModuleFragmentWriteStrategy.DEFAULT
|
writeStrategy: KlibModuleFragmentWriteStrategy = KlibModuleFragmentWriteStrategy.DEFAULT
|
||||||
): SerializedKlibMetadata {
|
): SerializedKlibMetadata {
|
||||||
val reverseIndex = ReverseSourceFileIndexWriteExtension()
|
val reverseIndex = ReverseSourceFileIndexWriteExtension()
|
||||||
val c = WriteContext(KlibMetadataStringTable(), listOf(reverseIndex))
|
|
||||||
|
|
||||||
val groupedFragments = fragments
|
val groupedFragments = fragments
|
||||||
.groupBy(KmModuleFragment::fqNameOrFail)
|
.groupBy(KmModuleFragment::fqNameOrFail)
|
||||||
@@ -119,9 +119,12 @@ class KlibModuleMetadata(
|
|||||||
)
|
)
|
||||||
val groupedProtos = groupedFragments.mapValues { (_, fragments) ->
|
val groupedProtos = groupedFragments.mapValues { (_, fragments) ->
|
||||||
fragments.map {
|
fragments.map {
|
||||||
|
val c = WriteContext(KlibMetadataStringTable(), listOf(reverseIndex))
|
||||||
KlibModuleFragmentWriter(c.strings as KlibMetadataStringTable, c.contextExtensions).also(it::accept).write()
|
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(
|
return SerializedKlibMetadata(
|
||||||
header.writeHeader(c).build().toByteArray(),
|
header.writeHeader(c).build().toByteArray(),
|
||||||
groupedProtos.map { it.value.map(ProtoBuf.PackageFragment::toByteArray) },
|
groupedProtos.map { it.value.map(ProtoBuf.PackageFragment::toByteArray) },
|
||||||
|
|||||||
@@ -18,10 +18,15 @@ internal fun UniqId.writeUniqId(): KlibMetadataProtoBuf.DescriptorUniqId.Builder
|
|||||||
index = this@writeUniqId.index
|
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 =
|
internal fun KlibHeader.writeHeader(context: WriteContext): KlibMetadataProtoBuf.Header.Builder =
|
||||||
KlibMetadataProtoBuf.Header.newBuilder().also { proto ->
|
KlibMetadataProtoBuf.Header.newBuilder().also { proto ->
|
||||||
val (strings, qualifiedNames) = (context.strings as StringTableImpl).buildProto()
|
val (strings, qualifiedNames) = (context.strings as StringTableImpl).buildProto()
|
||||||
proto.moduleName = moduleName
|
proto.moduleName = wrapModuleName(moduleName)
|
||||||
proto.qualifiedNames = qualifiedNames
|
proto.qualifiedNames = qualifiedNames
|
||||||
proto.strings = strings
|
proto.strings = strings
|
||||||
proto.addAllPackageFragmentName(packageFragmentName)
|
proto.addAllPackageFragmentName(packageFragmentName)
|
||||||
|
|||||||
@@ -34,6 +34,12 @@ class KlibModuleFragmentWriter(
|
|||||||
t.build()
|
t.build()
|
||||||
|
|
||||||
override fun visitEnd() {
|
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) {
|
val isPackageEmpty = if (t.`package` == null) {
|
||||||
true
|
true
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -89,10 +89,10 @@ var KmModuleFragment.fqName: String?
|
|||||||
klibExtensions.fqName = value
|
klibExtensions.fqName = value
|
||||||
}
|
}
|
||||||
|
|
||||||
val KmModuleFragment.className: MutableList<ClassName>?
|
val KmModuleFragment.className: MutableList<ClassName>
|
||||||
get() = klibExtensions.className
|
get() = klibExtensions.className
|
||||||
|
|
||||||
val KmModuleFragment.moduleFragmentFiles: MutableList<KlibSourceFile>?
|
val KmModuleFragment.moduleFragmentFiles: MutableList<KlibSourceFile>
|
||||||
get() = klibExtensions.moduleFragmentFiles
|
get() = klibExtensions.moduleFragmentFiles
|
||||||
|
|
||||||
val KmTypeParameter.annotations: MutableList<KmAnnotation>
|
val KmTypeParameter.annotations: MutableList<KmAnnotation>
|
||||||
|
|||||||
Reference in New Issue
Block a user