Drop DebugJsAstProtoBuf

This commit is contained in:
Roman Artemev
2019-02-25 19:26:22 +03:00
committed by romanart
parent cae800b24e
commit 52baf90518
3 changed files with 22 additions and 53741 deletions
@@ -34,7 +34,7 @@ import java.util.regex.Pattern
// You may need to provide custom path to protoc executable, just modify this constant:
private const val PROTOC_EXE = "protoc"
class ProtoPath(val file: String) {
class ProtoPath(val file: String, val generateDebug: Boolean = true) {
val outPath: String = File(file).parent
val packageName: String = findFirst(Pattern.compile("package (.+);"))
val className: String = findFirst(Pattern.compile("option java_outer_classname = \"(.+)\";"))
@@ -53,7 +53,7 @@ val PROTO_PATHS: List<ProtoPath> = listOf(
ProtoPath("core/metadata/src/metadata.proto"),
ProtoPath("core/metadata/src/builtins.proto"),
ProtoPath("js/js.serializer/src/js.proto"),
ProtoPath("js/js.serializer/src/js-ast.proto"),
ProtoPath("js/js.serializer/src/js-ast.proto", false),
ProtoPath("konan/library-reader/src/konan.proto"),
ProtoPath("core/metadata.jvm/src/jvm_metadata.proto"),
ProtoPath("core/metadata.jvm/src/jvm_module.proto"),
@@ -142,13 +142,15 @@ private fun renamePackages(protoPath: String, outPath: String) {
}
private fun modifyAndExecProtoc(protoPath: ProtoPath) {
val debugProtoFile = File(protoPath.file.replace(".proto", ".debug.proto"))
debugProtoFile.writeText(modifyForDebug(protoPath))
debugProtoFile.deleteOnExit()
if (protoPath.generateDebug) {
val debugProtoFile = File(protoPath.file.replace(".proto", ".debug.proto"))
debugProtoFile.writeText(modifyForDebug(protoPath))
debugProtoFile.deleteOnExit()
val outPath = "build-common/test"
execProtoc(debugProtoFile.path, outPath)
renamePackages(debugProtoFile.path, outPath)
val outPath = "build-common/test"
execProtoc(debugProtoFile.path, outPath)
renamePackages(debugProtoFile.path, outPath)
}
}
private fun modifyForDebug(protoPath: ProtoPath): String {
@@ -30,16 +30,18 @@ class ProtoBufConsistencyTest : TestCase() {
val extensions = LinkedHashMultimap.create<Key, Descriptors.FieldDescriptor>()
for (protoPath in PROTO_PATHS) {
val classFqName = protoPath.packageName + "." + protoPath.debugClassName
val klass = this::class.java.classLoader.loadClass(classFqName) ?: error("Class not found: $classFqName")
for (field in klass.declaredFields) {
if (Modifier.isStatic(field.modifiers) && field.type == GeneratedExtension::class.java) {
// The only place where type information for an extension is stored is the field's declared generic type.
// The message type which this extension extends is the first argument to GeneratedExtension<*, *>
val containingType = (field.genericType as ParameterizedType).actualTypeArguments.first() as Class<*>
val value = field.get(null) as GeneratedExtension<*, *>
val desc = value.descriptor
extensions.put(Key(containingType, desc.number), desc)
if (protoPath.generateDebug) {
val classFqName = protoPath.packageName + "." + protoPath.debugClassName
val klass = this::class.java.classLoader.loadClass(classFqName) ?: error("Class not found: $classFqName")
for (field in klass.declaredFields) {
if (Modifier.isStatic(field.modifiers) && field.type == GeneratedExtension::class.java) {
// The only place where type information for an extension is stored is the field's declared generic type.
// The message type which this extension extends is the first argument to GeneratedExtension<*, *>
val containingType = (field.genericType as ParameterizedType).actualTypeArguments.first() as Class<*>
val value = field.get(null) as GeneratedExtension<*, *>
val desc = value.descriptor
extensions.put(Key(containingType, desc.number), desc)
}
}
}
}