Skip to content

Commit

Permalink
Complete update to protobuf 4.28.2
Browse files Browse the repository at this point in the history
  • Loading branch information
thesamet committed Sep 29, 2024
1 parent f26cec7 commit eabbac3
Show file tree
Hide file tree
Showing 23 changed files with 1,251 additions and 361 deletions.
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
# Change Log
## [0.12.0] (Not released)
- Bump protobuf and protoc to 4.26.0. Currently files must specify proto2 and
- Bump protobuf and protoc to 4.28.2. Currently files must specify proto2 and
proto3 syntax. Editions are not supported yet.
- References to descriptors are fully qualified (#1724)
- Oneofs are now generated as sealed abstract class instead of sealed traits (#1694)
- BREAKING CHANGE: As a result of protobuf 4.x change, extensions in proto3 now have presence,
and so are wrapped in an `Option[]`.

## [0.11.18] (Unreleased)
- References to descriptors are fully qualified (#1724)
Expand Down
3 changes: 2 additions & 1 deletion build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,8 @@ lazy val e2eWithJava = (projectMatrix in file("e2e-withjava"))
.settings(
scalacOptions ++= (if (!isScala3.value)
Seq(
"-P:silencer:lineContentFilters=import com.thesamet.pb.MisplacedMapper.weatherMapper"
"-P:silencer:lineContentFilters=import com.thesamet.pb.MisplacedMapper.weatherMapper",
"-P:silencer:pathFilters=custom_options_use"
)
else Nil)
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -311,12 +311,13 @@ class DescriptorImplicits private[compiler] (
else collection.empty
}

def scalaTypeName: String =
def scalaTypeName: String = {
if (fd.isMapField) {
s"$collectionType[${mapType.keyType}, ${mapType.valueType}]"
} else if (fd.isRepeated) s"${collectionType}[$singleScalaTypeName]"
else if (supportsPresence) s"${ScalaOption}[$singleScalaTypeName]"
else singleScalaTypeName
}

def fieldOptions: FieldOptions = {
val localOptions = fd.getOptions.getExtension[FieldOptions](Scalapb.field)
Expand Down
File renamed without changes.
118 changes: 118 additions & 0 deletions e2e-withjava/src/main/protobuf/custom_options_use.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
syntax = "proto2";

import "custom_options.proto";
import "scalapb/scalapb.proto";

package com.thesamet.proto.e2e;

option (scalapb.options) = {
import: "com.thesamet.pb.{CustomAnnotation, CustomAnnotation1, CustomAnnotation2, CustomFieldAnnotation1, CustomFieldAnnotation2, Base1, Base2}"
};

option (message_a).a = "AAA";

message FooMessage {
option (scalapb.message).annotations = "@CustomAnnotation";
option (scalapb.message).companion_annotations = "@CustomAnnotation1";
option (scalapb.message).companion_annotations = "@CustomAnnotation2";
option (message_b).b = "BBB";
option (message_b).c = "CCC";
option (message_b).d = "D1";
option (message_b).d = "D2";

optional int32 myField1 = 1 [(message_c).c = "CCC", (opt_name).first = "John"];
optional int32 myField2 = 2 [(rep_name) = {last: "Doe"}, (rep_name) = {first: "Moe"}];

oneof my_one_of {
option (scalapb.oneof).extends = "Base1";
option (scalapb.oneof).extends = "Base2";
int32 x = 3;
int32 y = 4;
}
}

message BarMessage {
option (scalapb.message).annotations = "@CustomAnnotation";
option (scalapb.message).annotations = "@CustomAnnotation1";
option (scalapb.message).annotations = "@CustomAnnotation2";

option (rep_int32) = 1;
option (rep_int32) = 2;
option (rep_int32) = -16;
option (rep_int32) = -5;
option (rep_int64) = 3;
option (rep_int64) = 4;
option (rep_int64) = -9;
option (rep_int64) = -11;
option (rep_uint32) = 1;
option (rep_uint32) = 2;
option (rep_uint32) = -16;
option (rep_uint32) = -5;
option (rep_uint64) = 3;
option (rep_uint64) = 4;
option (rep_uint64) = -9;
option (rep_uint64) = -11;
option (rep_sint32) = 5;
option (rep_sint32) = -11;
option (rep_sint64) = 6;
option (rep_sint64) = -1;
option (rep_sint64) = -15;
option (rep_fixed32) = 7;
option (rep_fixed32) = 5;
option (rep_fixed64) = 8;
option (rep_fixed64) = 17;
option (rep_string) = "foo";
option (rep_string) = "bar";
option (rep_bytes) = "foo";
option (rep_bytes) = "bar";
option (rep_float) = 4.17;
option (rep_double) = 5.35;
option (rep_enum) = GOOD;
option (rep_enum) = BAD;
option (rep_enum) = GOOD;
option (rep_bool) = false;
option (rep_bool) = true;
option (rep_bool) = false;
option (rep_message_c) = {
c: "C1"
};
option (rep_message_c) = {
c: "C2"
};

option (opt_int32) = 1;
option (opt_int64) = 3;
option (opt_sint32) = 5;
option (opt_sint64) = 6;
option (opt_fixed32) = 7;
option (opt_fixed64) = 8;
option (opt_string) = "foo";
option (opt_bytes) = "foo";
option (opt_float) = 4.17;
option (opt_double) = 5.35;
option (opt_enum) = GOOD;
option (opt_bool) = true;
}

message FieldAnnotations {
option (scalapb.message).unknown_fields_annotations = "@CustomFieldAnnotation1";
option (scalapb.message).unknown_fields_annotations = "@CustomFieldAnnotation2";

optional string x = 1 [(scalapb.field).annotations = '@deprecated("Will be gone", "1.0")'];

optional string y = 2 [
(scalapb.field) = {
annotations: '@deprecated("Will be removed", "0.1")',
annotations: '@unchecked'
}
];

optional string z = 3 [
(scalapb.field) = {
annotations: [
'@deprecated("Will be removed", "0.1")',
'@unchecked'
]
}
];
}
5 changes: 5 additions & 0 deletions e2e-withjava/src/main/scala/com/thesamet/pb/Bases.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package com.thesamet.pb

trait Base1

trait Base2
18 changes: 18 additions & 0 deletions e2e-withjava/src/main/scala/com/thesamet/pb/CustomAnnotation.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package com.thesamet.pb

import scala.annotation.StaticAnnotation
import scala.annotation.meta.{beanGetter, beanSetter, field, getter, setter}

class CustomAnnotation() extends StaticAnnotation

class CustomAnnotation1() extends StaticAnnotation

class CustomAnnotation2() extends StaticAnnotation

class CustomAnnotation3() extends StaticAnnotation

@getter @setter @beanGetter @beanSetter @field
final class CustomFieldAnnotation1 extends StaticAnnotation

@getter @setter @beanGetter @beanSetter @field
final class CustomFieldAnnotation2 extends StaticAnnotation
48 changes: 24 additions & 24 deletions e2e/src/test/scala/CustomOptionsSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -138,33 +138,33 @@ class CustomOptionsSpec extends AnyFlatSpec with Matchers with OptionValues {
}

"proto3 primitives" should "work" in {
barP3Options.extension(CustomOptionsP3Proto.p3OptInt32) must be(1)
barP3Options.extension(CustomOptionsP3Proto.p3OptInt64) must be(3)
barP3Options.extension(CustomOptionsP3Proto.p3OptSint32) must be(5)
barP3Options.extension(CustomOptionsP3Proto.p3OptSint64) must be(6)
barP3Options.extension(CustomOptionsP3Proto.p3OptFixed32) must be(7)
barP3Options.extension(CustomOptionsP3Proto.p3OptFixed64) must be(8)
barP3Options.extension(CustomOptionsP3Proto.p3OptFloat) must be(4.17f)
barP3Options.extension(CustomOptionsP3Proto.p3OptDouble) must be(5.35)
barP3Options.extension(CustomOptionsP3Proto.p3OptEnum) must be(GOOD_P3)
barP3Options.extension(CustomOptionsP3Proto.p3OptBool) must be(true)
barP3Options.extension(CustomOptionsP3Proto.p3OptString) must be("foo")
barP3Options.extension(CustomOptionsP3Proto.p3OptBytes) must be(ByteString.copyFromUtf8("foo"))
barP3Options.extension(CustomOptionsP3Proto.p3OptInt32).value must be(1)
barP3Options.extension(CustomOptionsP3Proto.p3OptInt64).value must be(3)
barP3Options.extension(CustomOptionsP3Proto.p3OptSint32).value must be(5)
barP3Options.extension(CustomOptionsP3Proto.p3OptSint64).value must be(6)
barP3Options.extension(CustomOptionsP3Proto.p3OptFixed32).value must be(7)
barP3Options.extension(CustomOptionsP3Proto.p3OptFixed64).value must be(8)
barP3Options.extension(CustomOptionsP3Proto.p3OptFloat).value must be(4.17f)
barP3Options.extension(CustomOptionsP3Proto.p3OptDouble).value must be(5.35)
barP3Options.extension(CustomOptionsP3Proto.p3OptEnum).value must be(GOOD_P3)
barP3Options.extension(CustomOptionsP3Proto.p3OptBool).value must be(true)
barP3Options.extension(CustomOptionsP3Proto.p3OptString).value must be("foo")
barP3Options.extension(CustomOptionsP3Proto.p3OptBytes).value must be(ByteString.copyFromUtf8("foo"))
}

"setting proto3 primitives" should "work" in {
validateSetter(CustomOptionsP3Proto.p3OptInt32)(1)
validateSetter(CustomOptionsP3Proto.p3OptInt64)(3)
validateSetter(CustomOptionsP3Proto.p3OptSint32)(5)
validateSetter(CustomOptionsP3Proto.p3OptSint64)(6)
validateSetter(CustomOptionsP3Proto.p3OptFixed32)(7)
validateSetter(CustomOptionsP3Proto.p3OptFixed64)(8)
validateSetter(CustomOptionsP3Proto.p3OptFloat)(4.17f)
validateSetter(CustomOptionsP3Proto.p3OptDouble)(5.35)
validateSetter(CustomOptionsP3Proto.p3OptEnum)(GOOD_P3)
validateSetter(CustomOptionsP3Proto.p3OptBool)(true)
validateSetter(CustomOptionsP3Proto.p3OptString)("foo")
validateSetter(CustomOptionsP3Proto.p3OptBytes)(ByteString.copyFromUtf8("foo"))
validateSetter(CustomOptionsP3Proto.p3OptInt32)(Some(1))
validateSetter(CustomOptionsP3Proto.p3OptInt64)(Some(3))
validateSetter(CustomOptionsP3Proto.p3OptSint32)(Some(5))
validateSetter(CustomOptionsP3Proto.p3OptSint64)(Some(6))
validateSetter(CustomOptionsP3Proto.p3OptFixed32)(Some(7))
validateSetter(CustomOptionsP3Proto.p3OptFixed64)(Some(8))
validateSetter(CustomOptionsP3Proto.p3OptFloat)(Some(4.17f))
validateSetter(CustomOptionsP3Proto.p3OptDouble)(Some(5.35))
validateSetter(CustomOptionsP3Proto.p3OptEnum)(Some(GOOD_P3))
validateSetter(CustomOptionsP3Proto.p3OptBool)(Some(true))
validateSetter(CustomOptionsP3Proto.p3OptString)(Some("foo"))
validateSetter(CustomOptionsP3Proto.p3OptBytes)(Some(ByteString.copyFromUtf8("foo")))
}

"Custom name on field descriptor" should "translate to custom type" in {
Expand Down
2 changes: 1 addition & 1 deletion project/Dependencies.scala
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import Keys._
object Dependencies {
object versions {
val grpc = "1.68.0"
val protobuf = "4.26.0"
val protobuf = "4.28.2"
val silencer = "1.7.17"
val collectionCompat = "2.12.0"
val coursier = "2.1.13"
Expand Down
Loading

0 comments on commit eabbac3

Please sign in to comment.