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:
@@ -20,7 +20,6 @@ import com.google.protobuf.ExtensionRegistryLite
|
||||
import org.jetbrains.kotlin.name.ClassId
|
||||
import org.jetbrains.kotlin.name.FqName
|
||||
import org.jetbrains.kotlin.serialization.builtins.BuiltInsProtoBuf
|
||||
import kotlin.platform.platformStatic
|
||||
|
||||
public object BuiltInsSerializationUtil {
|
||||
public val EXTENSION_REGISTRY: ExtensionRegistryLite
|
||||
@@ -31,20 +30,33 @@ public object BuiltInsSerializationUtil {
|
||||
}
|
||||
|
||||
private val CLASS_METADATA_FILE_EXTENSION = "kotlin_class"
|
||||
private val PACKAGE_FILE_NAME = ".kotlin_package"
|
||||
private val STRING_TABLE_FILE_NAME = ".kotlin_string_table"
|
||||
private val PACKAGE_FILE_EXTENSION = "kotlin_package"
|
||||
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() +
|
||||
"." + CLASS_METADATA_FILE_EXTENSION
|
||||
}
|
||||
|
||||
platformStatic public fun getPackageFilePath(fqName: FqName): String =
|
||||
packageFqNameToPath(fqName) + "/" + PACKAGE_FILE_NAME
|
||||
public fun getPackageFilePath(fqName: FqName): String =
|
||||
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 =
|
||||
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?
|
||||
) : 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()
|
||||
|
||||
@@ -46,7 +49,8 @@ public class BuiltinsPackageFragment(
|
||||
}
|
||||
|
||||
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)
|
||||
DeserializedPackageMemberScope(this, proto, nameResolver, components, classNames = {
|
||||
proto.getExtension(BuiltInsProtoBuf.className)?.map { id -> nameResolver.getName(id) } ?: listOf()
|
||||
|
||||
Reference in New Issue
Block a user