Skip to content

Commit

Permalink
Update generateWellKnownTypes task to use the automatically downloade…
Browse files Browse the repository at this point in the history
…d proto files

Now that we're bundling the well-known type proto files, we no longer
need to read them from the copy of protobuf installed on the build
system.

This update also pulled in a newer version of `descriptor.proto` with an
added field.
  • Loading branch information
garyp committed Apr 29, 2021
1 parent 1c92f2a commit 8bfd99b
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 12 deletions.
12 changes: 7 additions & 5 deletions runtime/api/runtime.api
Original file line number Diff line number Diff line change
Expand Up @@ -1210,11 +1210,12 @@ public final class pbandk/wkt/Field$Kind$UNRECOGNIZED : pbandk/wkt/Field$Kind {
public final class pbandk/wkt/FieldDescriptorProto : pbandk/Message {
public static final field Companion Lpbandk/wkt/FieldDescriptorProto$Companion;
public fun <init> ()V
public fun <init> (Ljava/lang/String;Ljava/lang/Integer;Lpbandk/wkt/FieldDescriptorProto$Label;Lpbandk/wkt/FieldDescriptorProto$Type;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/Integer;Ljava/lang/String;Lpbandk/wkt/FieldOptions;Ljava/util/Map;)V
public synthetic fun <init> (Ljava/lang/String;Ljava/lang/Integer;Lpbandk/wkt/FieldDescriptorProto$Label;Lpbandk/wkt/FieldDescriptorProto$Type;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/Integer;Ljava/lang/String;Lpbandk/wkt/FieldOptions;Ljava/util/Map;ILkotlin/jvm/internal/DefaultConstructorMarker;)V
public fun <init> (Ljava/lang/String;Ljava/lang/Integer;Lpbandk/wkt/FieldDescriptorProto$Label;Lpbandk/wkt/FieldDescriptorProto$Type;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/Integer;Ljava/lang/String;Lpbandk/wkt/FieldOptions;Ljava/lang/Boolean;Ljava/util/Map;)V
public synthetic fun <init> (Ljava/lang/String;Ljava/lang/Integer;Lpbandk/wkt/FieldDescriptorProto$Label;Lpbandk/wkt/FieldDescriptorProto$Type;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/Integer;Ljava/lang/String;Lpbandk/wkt/FieldOptions;Ljava/lang/Boolean;Ljava/util/Map;ILkotlin/jvm/internal/DefaultConstructorMarker;)V
public final fun component1 ()Ljava/lang/String;
public final fun component10 ()Lpbandk/wkt/FieldOptions;
public final fun component11 ()Ljava/util/Map;
public final fun component11 ()Ljava/lang/Boolean;
public final fun component12 ()Ljava/util/Map;
public final fun component2 ()Ljava/lang/Integer;
public final fun component3 ()Lpbandk/wkt/FieldDescriptorProto$Label;
public final fun component4 ()Lpbandk/wkt/FieldDescriptorProto$Type;
Expand All @@ -1223,8 +1224,8 @@ public final class pbandk/wkt/FieldDescriptorProto : pbandk/Message {
public final fun component7 ()Ljava/lang/String;
public final fun component8 ()Ljava/lang/Integer;
public final fun component9 ()Ljava/lang/String;
public final fun copy (Ljava/lang/String;Ljava/lang/Integer;Lpbandk/wkt/FieldDescriptorProto$Label;Lpbandk/wkt/FieldDescriptorProto$Type;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/Integer;Ljava/lang/String;Lpbandk/wkt/FieldOptions;Ljava/util/Map;)Lpbandk/wkt/FieldDescriptorProto;
public static synthetic fun copy$default (Lpbandk/wkt/FieldDescriptorProto;Ljava/lang/String;Ljava/lang/Integer;Lpbandk/wkt/FieldDescriptorProto$Label;Lpbandk/wkt/FieldDescriptorProto$Type;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/Integer;Ljava/lang/String;Lpbandk/wkt/FieldOptions;Ljava/util/Map;ILjava/lang/Object;)Lpbandk/wkt/FieldDescriptorProto;
public final fun copy (Ljava/lang/String;Ljava/lang/Integer;Lpbandk/wkt/FieldDescriptorProto$Label;Lpbandk/wkt/FieldDescriptorProto$Type;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/Integer;Ljava/lang/String;Lpbandk/wkt/FieldOptions;Ljava/lang/Boolean;Ljava/util/Map;)Lpbandk/wkt/FieldDescriptorProto;
public static synthetic fun copy$default (Lpbandk/wkt/FieldDescriptorProto;Ljava/lang/String;Ljava/lang/Integer;Lpbandk/wkt/FieldDescriptorProto$Label;Lpbandk/wkt/FieldDescriptorProto$Type;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/Integer;Ljava/lang/String;Lpbandk/wkt/FieldOptions;Ljava/lang/Boolean;Ljava/util/Map;ILjava/lang/Object;)Lpbandk/wkt/FieldDescriptorProto;
public fun equals (Ljava/lang/Object;)Z
public final fun getDefaultValue ()Ljava/lang/String;
public fun getDescriptor ()Lpbandk/MessageDescriptor;
Expand All @@ -1235,6 +1236,7 @@ public final class pbandk/wkt/FieldDescriptorProto : pbandk/Message {
public final fun getNumber ()Ljava/lang/Integer;
public final fun getOneofIndex ()Ljava/lang/Integer;
public final fun getOptions ()Lpbandk/wkt/FieldOptions;
public final fun getProto3Optional ()Ljava/lang/Boolean;
public fun getProtoSize ()I
public final fun getType ()Lpbandk/wkt/FieldDescriptorProto$Type;
public final fun getTypeName ()Ljava/lang/String;
Expand Down
6 changes: 1 addition & 5 deletions runtime/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -142,11 +142,7 @@ android {

tasks {
val generateWellKnownTypes by registering(KotlinProtocTask::class) {
val protocPath = provider {
System.getProperty("protoc.path")
?: throw InvalidUserDataException("System property protoc.path must be set")
}.map { rootProject.layout.projectDirectory.dir(it) }
includeDir.set(protocPath.map { it.dir("include") })
includeDir.set(layout.dir(extractWellKnownTypeProtos.map { it.destinationDir }))
outputDir.set(project.file("src/commonMain/kotlin"))
kotlinPackage.set("pbandk.wkt")
logLevel.set("debug")
Expand Down
18 changes: 16 additions & 2 deletions runtime/src/commonMain/kotlin/pbandk/wkt/descriptor.kt
Original file line number Diff line number Diff line change
Expand Up @@ -472,6 +472,7 @@ data class FieldDescriptorProto(
val oneofIndex: Int? = null,
val jsonName: String? = null,
val options: pbandk.wkt.FieldOptions? = null,
val proto3Optional: Boolean? = null,
override val unknownFields: Map<Int, pbandk.UnknownField> = emptyMap()
) : pbandk.Message {
override operator fun plus(other: pbandk.Message?) = protoMergeImpl(other)
Expand All @@ -482,7 +483,7 @@ data class FieldDescriptorProto(
override fun decodeWith(u: pbandk.MessageDecoder) = pbandk.wkt.FieldDescriptorProto.decodeWithImpl(u)

override val descriptor: pbandk.MessageDescriptor<pbandk.wkt.FieldDescriptorProto> by lazy {
val fieldsList = ArrayList<pbandk.FieldDescriptor<pbandk.wkt.FieldDescriptorProto, *>>(10)
val fieldsList = ArrayList<pbandk.FieldDescriptor<pbandk.wkt.FieldDescriptorProto, *>>(11)
fieldsList.apply {
add(
pbandk.FieldDescriptor(
Expand Down Expand Up @@ -584,6 +585,16 @@ data class FieldDescriptorProto(
value = pbandk.wkt.FieldDescriptorProto::jsonName
)
)
add(
pbandk.FieldDescriptor(
messageDescriptor = this@Companion::descriptor,
name = "proto3_optional",
number = 17,
type = pbandk.FieldDescriptor.Type.Primitive.Bool(hasPresence = true),
jsonName = "proto3Optional",
value = pbandk.wkt.FieldDescriptorProto::proto3Optional
)
)
}
pbandk.MessageDescriptor(
messageClass = pbandk.wkt.FieldDescriptorProto::class,
Expand Down Expand Up @@ -2338,6 +2349,7 @@ private fun FieldDescriptorProto.protoMergeImpl(plus: pbandk.Message?): FieldDes
oneofIndex = plus.oneofIndex ?: oneofIndex,
jsonName = plus.jsonName ?: jsonName,
options = options?.plus(plus.options) ?: plus.options,
proto3Optional = plus.proto3Optional ?: proto3Optional,
unknownFields = unknownFields + plus.unknownFields
)
} ?: this
Expand All @@ -2354,6 +2366,7 @@ private fun FieldDescriptorProto.Companion.decodeWithImpl(u: pbandk.MessageDecod
var oneofIndex: Int? = null
var jsonName: String? = null
var options: pbandk.wkt.FieldOptions? = null
var proto3Optional: Boolean? = null

val unknownFields = u.readMessage(this) { _fieldNumber, _fieldValue ->
when (_fieldNumber) {
Expand All @@ -2367,11 +2380,12 @@ private fun FieldDescriptorProto.Companion.decodeWithImpl(u: pbandk.MessageDecod
8 -> options = _fieldValue as pbandk.wkt.FieldOptions
9 -> oneofIndex = _fieldValue as Int
10 -> jsonName = _fieldValue as String
17 -> proto3Optional = _fieldValue as Boolean
}
}
return FieldDescriptorProto(name, number, label, type,
typeName, extendee, defaultValue, oneofIndex,
jsonName, options, unknownFields)
jsonName, options, proto3Optional, unknownFields)
}

fun OneofDescriptorProto?.orDefault() = this ?: OneofDescriptorProto.defaultInstance
Expand Down

0 comments on commit 8bfd99b

Please sign in to comment.