Rename built-in metadata files starting with dot
Files starting with dot are considered as hidden on Unix systems, and sometimes are ignored by the tools. For example, Android build tools do not package such files to the resulting application, which causes Kotlin reflection to fail there #KT-7088 Fixed
This commit is contained in:
@@ -423,6 +423,14 @@
|
|||||||
<arg value="core/builtins/native"/>
|
<arg value="core/builtins/native"/>
|
||||||
<arg value="core/builtins/src"/>
|
<arg value="core/builtins/src"/>
|
||||||
</java>
|
</java>
|
||||||
|
|
||||||
|
<!-- TODO: remove after bootstrap -->
|
||||||
|
<copy file="${output}/builtins/kotlin/.kotlin_package" tofile="${output}/builtins/kotlin/kotlin.kotlin_package"/>
|
||||||
|
<copy file="${output}/builtins/kotlin/.kotlin_string_table" tofile="${output}/builtins/kotlin/kotlin.kotlin_string_table"/>
|
||||||
|
<copy file="${output}/builtins/kotlin/internal/.kotlin_package" tofile="${output}/builtins/kotlin/internal/internal.kotlin_package"/>
|
||||||
|
<copy file="${output}/builtins/kotlin/internal/.kotlin_string_table" tofile="${output}/builtins/kotlin/internal/internal.kotlin_string_table"/>
|
||||||
|
<copy file="${output}/builtins/kotlin/reflect/.kotlin_package" tofile="${output}/builtins/kotlin/reflect/reflect.kotlin_package"/>
|
||||||
|
<copy file="${output}/builtins/kotlin/reflect/.kotlin_string_table" tofile="${output}/builtins/kotlin/reflect/reflect.kotlin_string_table"/>
|
||||||
</target>
|
</target>
|
||||||
|
|
||||||
<macrodef name="pack-compiler">
|
<macrodef name="pack-compiler">
|
||||||
|
|||||||
+11
-6
@@ -128,20 +128,25 @@ public class BuiltInsSerializer(private val dependOnOldBuiltIns: Boolean) {
|
|||||||
val fragments = module.getPackageFragmentProvider().getPackageFragments(fqName)
|
val fragments = module.getPackageFragmentProvider().getPackageFragments(fqName)
|
||||||
val packageProto = serializer.packageProto(fragments).build() ?: error("Package fragments not serialized: $fragments")
|
val packageProto = serializer.packageProto(fragments).build() ?: error("Package fragments not serialized: $fragments")
|
||||||
packageProto.writeTo(packageStream)
|
packageProto.writeTo(packageStream)
|
||||||
write(destDir, BuiltInsSerializationUtil.getPackageFilePath(fqName), packageStream)
|
write(destDir, BuiltInsSerializationUtil.getPackageFilePath(fqName), packageStream,
|
||||||
|
BuiltInsSerializationUtil.FallbackPaths.getPackageFilePath(fqName))
|
||||||
|
|
||||||
val nameStream = ByteArrayOutputStream()
|
val nameStream = ByteArrayOutputStream()
|
||||||
val strings = serializer.getStringTable()
|
val strings = serializer.getStringTable()
|
||||||
SerializationUtil.serializeStringTable(nameStream, strings.serializeSimpleNames(), strings.serializeQualifiedNames())
|
SerializationUtil.serializeStringTable(nameStream, strings.serializeSimpleNames(), strings.serializeQualifiedNames())
|
||||||
write(destDir, BuiltInsSerializationUtil.getStringTableFilePath(fqName), nameStream)
|
write(destDir, BuiltInsSerializationUtil.getStringTableFilePath(fqName), nameStream,
|
||||||
|
BuiltInsSerializationUtil.FallbackPaths.getStringTableFilePath(fqName))
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun write(destDir: File, fileName: String, stream: ByteArrayOutputStream) {
|
internal /* KT-5786 */ fun write(destDir: File, fileName: String, stream: ByteArrayOutputStream, legacyFileName: String? = null) {
|
||||||
totalSize += stream.size()
|
totalSize += stream.size()
|
||||||
totalFiles++
|
totalFiles++
|
||||||
val file = File(destDir, fileName)
|
File(destDir, fileName).getParentFile().mkdirs()
|
||||||
file.getParentFile()?.mkdirs()
|
File(destDir, fileName).writeBytes(stream.toByteArray())
|
||||||
file.writeBytes(stream.toByteArray())
|
|
||||||
|
legacyFileName?.let { fileName ->
|
||||||
|
File(destDir, fileName).writeBytes(stream.toByteArray())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun serializeClass(
|
private fun serializeClass(
|
||||||
|
|||||||
@@ -29,7 +29,7 @@ Usage: ... <destination dir> (<source dir>)+
|
|||||||
|
|
||||||
Analyzes Kotlin sources found in the given source directories and serializes
|
Analyzes Kotlin sources found in the given source directories and serializes
|
||||||
found top-level declarations to <destination dir> (files such as
|
found top-level declarations to <destination dir> (files such as
|
||||||
.kotlin_string_table, .kotlin_package, *.kotlin_class)"""
|
*.kotlin_string_table, *.kotlin_package, *.kotlin_class)"""
|
||||||
)
|
)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,7 +20,6 @@ import com.google.protobuf.ExtensionRegistryLite
|
|||||||
import org.jetbrains.kotlin.name.ClassId
|
import org.jetbrains.kotlin.name.ClassId
|
||||||
import org.jetbrains.kotlin.name.FqName
|
import org.jetbrains.kotlin.name.FqName
|
||||||
import org.jetbrains.kotlin.serialization.builtins.BuiltInsProtoBuf
|
import org.jetbrains.kotlin.serialization.builtins.BuiltInsProtoBuf
|
||||||
import kotlin.platform.platformStatic
|
|
||||||
|
|
||||||
public object BuiltInsSerializationUtil {
|
public object BuiltInsSerializationUtil {
|
||||||
public val EXTENSION_REGISTRY: ExtensionRegistryLite
|
public val EXTENSION_REGISTRY: ExtensionRegistryLite
|
||||||
@@ -31,20 +30,33 @@ public object BuiltInsSerializationUtil {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private val CLASS_METADATA_FILE_EXTENSION = "kotlin_class"
|
private val CLASS_METADATA_FILE_EXTENSION = "kotlin_class"
|
||||||
private val PACKAGE_FILE_NAME = ".kotlin_package"
|
private val PACKAGE_FILE_EXTENSION = "kotlin_package"
|
||||||
private val STRING_TABLE_FILE_NAME = ".kotlin_string_table"
|
private val STRING_TABLE_FILE_EXTENSION = "kotlin_string_table"
|
||||||
|
|
||||||
platformStatic public fun getClassMetadataPath(classId: ClassId): String {
|
// TODO: remove this after M12
|
||||||
|
public object FallbackPaths {
|
||||||
|
public fun getPackageFilePath(fqName: FqName): String =
|
||||||
|
packageFqNameToPath(fqName) + "/.kotlin_package"
|
||||||
|
|
||||||
|
public fun getStringTableFilePath(fqName: FqName): String =
|
||||||
|
packageFqNameToPath(fqName) + "/.kotlin_string_table"
|
||||||
|
}
|
||||||
|
|
||||||
|
public fun getClassMetadataPath(classId: ClassId): String {
|
||||||
return packageFqNameToPath(classId.getPackageFqName()) + "/" + classId.getRelativeClassName().asString() +
|
return packageFqNameToPath(classId.getPackageFqName()) + "/" + classId.getRelativeClassName().asString() +
|
||||||
"." + CLASS_METADATA_FILE_EXTENSION
|
"." + CLASS_METADATA_FILE_EXTENSION
|
||||||
}
|
}
|
||||||
|
|
||||||
platformStatic public fun getPackageFilePath(fqName: FqName): String =
|
public fun getPackageFilePath(fqName: FqName): String =
|
||||||
packageFqNameToPath(fqName) + "/" + PACKAGE_FILE_NAME
|
packageFqNameToPath(fqName) + "/" + shortName(fqName) + "." + PACKAGE_FILE_EXTENSION
|
||||||
|
|
||||||
|
public fun getStringTableFilePath(fqName: FqName): String =
|
||||||
|
packageFqNameToPath(fqName) + "/" + shortName(fqName) + "." + STRING_TABLE_FILE_EXTENSION
|
||||||
|
|
||||||
platformStatic public fun getStringTableFilePath(fqName: FqName): String =
|
|
||||||
packageFqNameToPath(fqName) + "/" + STRING_TABLE_FILE_NAME
|
|
||||||
|
|
||||||
private fun packageFqNameToPath(fqName: FqName): String =
|
private fun packageFqNameToPath(fqName: FqName): String =
|
||||||
fqName.asString().replace('.', '/')
|
fqName.asString().replace('.', '/')
|
||||||
|
|
||||||
|
private fun shortName(fqName: FqName): String =
|
||||||
|
if (fqName.isRoot()) "default-package" else fqName.shortName().asString()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -36,7 +36,10 @@ public class BuiltinsPackageFragment(
|
|||||||
private val loadResource: (path: String) -> InputStream?
|
private val loadResource: (path: String) -> InputStream?
|
||||||
) : PackageFragmentDescriptorImpl(module, fqName) {
|
) : PackageFragmentDescriptorImpl(module, fqName) {
|
||||||
|
|
||||||
val nameResolver = NameResolver.read(loadResourceSure(BuiltInsSerializationUtil.getStringTableFilePath(fqName)))
|
val nameResolver = NameResolver.read(
|
||||||
|
loadResource(BuiltInsSerializationUtil.getStringTableFilePath(fqName))
|
||||||
|
?: loadResourceSure(BuiltInsSerializationUtil.FallbackPaths.getStringTableFilePath(fqName))
|
||||||
|
)
|
||||||
|
|
||||||
private var components: DeserializationComponents by Delegates.notNull()
|
private var components: DeserializationComponents by Delegates.notNull()
|
||||||
|
|
||||||
@@ -46,7 +49,8 @@ public class BuiltinsPackageFragment(
|
|||||||
}
|
}
|
||||||
|
|
||||||
private val memberScope = storageManager.createLazyValue {
|
private val memberScope = storageManager.createLazyValue {
|
||||||
val stream = loadResourceSure(BuiltInsSerializationUtil.getPackageFilePath(fqName))
|
val stream = loadResource(BuiltInsSerializationUtil.getPackageFilePath(fqName))
|
||||||
|
?: loadResourceSure(BuiltInsSerializationUtil.FallbackPaths.getPackageFilePath(fqName))
|
||||||
val proto = ProtoBuf.Package.parseFrom(stream, BuiltInsSerializationUtil.EXTENSION_REGISTRY)
|
val proto = ProtoBuf.Package.parseFrom(stream, BuiltInsSerializationUtil.EXTENSION_REGISTRY)
|
||||||
DeserializedPackageMemberScope(this, proto, nameResolver, components, classNames = {
|
DeserializedPackageMemberScope(this, proto, nameResolver, components, classNames = {
|
||||||
proto.getExtension(BuiltInsProtoBuf.className)?.map { id -> nameResolver.getName(id) } ?: listOf()
|
proto.getExtension(BuiltInsProtoBuf.className)?.map { id -> nameResolver.getName(id) } ?: listOf()
|
||||||
|
|||||||
+3
-2
@@ -117,12 +117,13 @@ public object KotlinJavascriptSerializationUtil {
|
|||||||
val fragments = module.getPackageFragmentProvider().getPackageFragments(fqName)
|
val fragments = module.getPackageFragmentProvider().getPackageFragments(fqName)
|
||||||
val packageProto = serializer.packageProto(fragments, skip).build() ?: error("Package fragments not serialized: $fragments")
|
val packageProto = serializer.packageProto(fragments, skip).build() ?: error("Package fragments not serialized: $fragments")
|
||||||
packageProto.writeTo(packageStream)
|
packageProto.writeTo(packageStream)
|
||||||
writeFun(BuiltInsSerializationUtil.getPackageFilePath(fqName), packageStream)
|
// TODO: don't use fallback paths here
|
||||||
|
writeFun(BuiltInsSerializationUtil.FallbackPaths.getPackageFilePath(fqName), packageStream)
|
||||||
|
|
||||||
val nameStream = ByteArrayOutputStream()
|
val nameStream = ByteArrayOutputStream()
|
||||||
val strings = serializer.getStringTable()
|
val strings = serializer.getStringTable()
|
||||||
SerializationUtil.serializeStringTable(nameStream, strings.serializeSimpleNames(), strings.serializeQualifiedNames())
|
SerializationUtil.serializeStringTable(nameStream, strings.serializeSimpleNames(), strings.serializeQualifiedNames())
|
||||||
writeFun(BuiltInsSerializationUtil.getStringTableFilePath(fqName), nameStream)
|
writeFun(BuiltInsSerializationUtil.FallbackPaths.getStringTableFilePath(fqName), nameStream)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun getFileName(classDescriptor: ClassDescriptor): String {
|
fun getFileName(classDescriptor: ClassDescriptor): String {
|
||||||
|
|||||||
Reference in New Issue
Block a user