Skip to content

Commit eabbac3

Browse files
committed
Complete update to protobuf 4.28.2
1 parent f26cec7 commit eabbac3

File tree

23 files changed

+1251
-361
lines changed

23 files changed

+1251
-361
lines changed

CHANGELOG.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
# Change Log
22
## [0.12.0] (Not released)
3-
- Bump protobuf and protoc to 4.26.0. Currently files must specify proto2 and
3+
- Bump protobuf and protoc to 4.28.2. Currently files must specify proto2 and
44
proto3 syntax. Editions are not supported yet.
55
- References to descriptors are fully qualified (#1724)
66
- Oneofs are now generated as sealed abstract class instead of sealed traits (#1694)
7+
- BREAKING CHANGE: As a result of protobuf 4.x change, extensions in proto3 now have presence,
8+
and so are wrapped in an `Option[]`.
79

810
## [0.11.18] (Unreleased)
911
- References to descriptors are fully qualified (#1724)

build.sbt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -352,7 +352,8 @@ lazy val e2eWithJava = (projectMatrix in file("e2e-withjava"))
352352
.settings(
353353
scalacOptions ++= (if (!isScala3.value)
354354
Seq(
355-
"-P:silencer:lineContentFilters=import com.thesamet.pb.MisplacedMapper.weatherMapper"
355+
"-P:silencer:lineContentFilters=import com.thesamet.pb.MisplacedMapper.weatherMapper",
356+
"-P:silencer:pathFilters=custom_options_use"
356357
)
357358
else Nil)
358359
)

compiler-plugin/src/main/scala/scalapb/compiler/DescriptorImplicits.scala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -311,12 +311,13 @@ class DescriptorImplicits private[compiler] (
311311
else collection.empty
312312
}
313313

314-
def scalaTypeName: String =
314+
def scalaTypeName: String = {
315315
if (fd.isMapField) {
316316
s"$collectionType[${mapType.keyType}, ${mapType.valueType}]"
317317
} else if (fd.isRepeated) s"${collectionType}[$singleScalaTypeName]"
318318
else if (supportsPresence) s"${ScalaOption}[$singleScalaTypeName]"
319319
else singleScalaTypeName
320+
}
320321

321322
def fieldOptions: FieldOptions = {
322323
val localOptions = fd.getOptions.getExtension[FieldOptions](Scalapb.field)
Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
syntax = "proto2";
2+
3+
import "custom_options.proto";
4+
import "scalapb/scalapb.proto";
5+
6+
package com.thesamet.proto.e2e;
7+
8+
option (scalapb.options) = {
9+
import: "com.thesamet.pb.{CustomAnnotation, CustomAnnotation1, CustomAnnotation2, CustomFieldAnnotation1, CustomFieldAnnotation2, Base1, Base2}"
10+
};
11+
12+
option (message_a).a = "AAA";
13+
14+
message FooMessage {
15+
option (scalapb.message).annotations = "@CustomAnnotation";
16+
option (scalapb.message).companion_annotations = "@CustomAnnotation1";
17+
option (scalapb.message).companion_annotations = "@CustomAnnotation2";
18+
option (message_b).b = "BBB";
19+
option (message_b).c = "CCC";
20+
option (message_b).d = "D1";
21+
option (message_b).d = "D2";
22+
23+
optional int32 myField1 = 1 [(message_c).c = "CCC", (opt_name).first = "John"];
24+
optional int32 myField2 = 2 [(rep_name) = {last: "Doe"}, (rep_name) = {first: "Moe"}];
25+
26+
oneof my_one_of {
27+
option (scalapb.oneof).extends = "Base1";
28+
option (scalapb.oneof).extends = "Base2";
29+
int32 x = 3;
30+
int32 y = 4;
31+
}
32+
}
33+
34+
message BarMessage {
35+
option (scalapb.message).annotations = "@CustomAnnotation";
36+
option (scalapb.message).annotations = "@CustomAnnotation1";
37+
option (scalapb.message).annotations = "@CustomAnnotation2";
38+
39+
option (rep_int32) = 1;
40+
option (rep_int32) = 2;
41+
option (rep_int32) = -16;
42+
option (rep_int32) = -5;
43+
option (rep_int64) = 3;
44+
option (rep_int64) = 4;
45+
option (rep_int64) = -9;
46+
option (rep_int64) = -11;
47+
option (rep_uint32) = 1;
48+
option (rep_uint32) = 2;
49+
option (rep_uint32) = -16;
50+
option (rep_uint32) = -5;
51+
option (rep_uint64) = 3;
52+
option (rep_uint64) = 4;
53+
option (rep_uint64) = -9;
54+
option (rep_uint64) = -11;
55+
option (rep_sint32) = 5;
56+
option (rep_sint32) = -11;
57+
option (rep_sint64) = 6;
58+
option (rep_sint64) = -1;
59+
option (rep_sint64) = -15;
60+
option (rep_fixed32) = 7;
61+
option (rep_fixed32) = 5;
62+
option (rep_fixed64) = 8;
63+
option (rep_fixed64) = 17;
64+
option (rep_string) = "foo";
65+
option (rep_string) = "bar";
66+
option (rep_bytes) = "foo";
67+
option (rep_bytes) = "bar";
68+
option (rep_float) = 4.17;
69+
option (rep_double) = 5.35;
70+
option (rep_enum) = GOOD;
71+
option (rep_enum) = BAD;
72+
option (rep_enum) = GOOD;
73+
option (rep_bool) = false;
74+
option (rep_bool) = true;
75+
option (rep_bool) = false;
76+
option (rep_message_c) = {
77+
c: "C1"
78+
};
79+
option (rep_message_c) = {
80+
c: "C2"
81+
};
82+
83+
option (opt_int32) = 1;
84+
option (opt_int64) = 3;
85+
option (opt_sint32) = 5;
86+
option (opt_sint64) = 6;
87+
option (opt_fixed32) = 7;
88+
option (opt_fixed64) = 8;
89+
option (opt_string) = "foo";
90+
option (opt_bytes) = "foo";
91+
option (opt_float) = 4.17;
92+
option (opt_double) = 5.35;
93+
option (opt_enum) = GOOD;
94+
option (opt_bool) = true;
95+
}
96+
97+
message FieldAnnotations {
98+
option (scalapb.message).unknown_fields_annotations = "@CustomFieldAnnotation1";
99+
option (scalapb.message).unknown_fields_annotations = "@CustomFieldAnnotation2";
100+
101+
optional string x = 1 [(scalapb.field).annotations = '@deprecated("Will be gone", "1.0")'];
102+
103+
optional string y = 2 [
104+
(scalapb.field) = {
105+
annotations: '@deprecated("Will be removed", "0.1")',
106+
annotations: '@unchecked'
107+
}
108+
];
109+
110+
optional string z = 3 [
111+
(scalapb.field) = {
112+
annotations: [
113+
'@deprecated("Will be removed", "0.1")',
114+
'@unchecked'
115+
]
116+
}
117+
];
118+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
package com.thesamet.pb
2+
3+
trait Base1
4+
5+
trait Base2
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package com.thesamet.pb
2+
3+
import scala.annotation.StaticAnnotation
4+
import scala.annotation.meta.{beanGetter, beanSetter, field, getter, setter}
5+
6+
class CustomAnnotation() extends StaticAnnotation
7+
8+
class CustomAnnotation1() extends StaticAnnotation
9+
10+
class CustomAnnotation2() extends StaticAnnotation
11+
12+
class CustomAnnotation3() extends StaticAnnotation
13+
14+
@getter @setter @beanGetter @beanSetter @field
15+
final class CustomFieldAnnotation1 extends StaticAnnotation
16+
17+
@getter @setter @beanGetter @beanSetter @field
18+
final class CustomFieldAnnotation2 extends StaticAnnotation

e2e/src/test/scala/CustomOptionsSpec.scala

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -138,33 +138,33 @@ class CustomOptionsSpec extends AnyFlatSpec with Matchers with OptionValues {
138138
}
139139

140140
"proto3 primitives" should "work" in {
141-
barP3Options.extension(CustomOptionsP3Proto.p3OptInt32) must be(1)
142-
barP3Options.extension(CustomOptionsP3Proto.p3OptInt64) must be(3)
143-
barP3Options.extension(CustomOptionsP3Proto.p3OptSint32) must be(5)
144-
barP3Options.extension(CustomOptionsP3Proto.p3OptSint64) must be(6)
145-
barP3Options.extension(CustomOptionsP3Proto.p3OptFixed32) must be(7)
146-
barP3Options.extension(CustomOptionsP3Proto.p3OptFixed64) must be(8)
147-
barP3Options.extension(CustomOptionsP3Proto.p3OptFloat) must be(4.17f)
148-
barP3Options.extension(CustomOptionsP3Proto.p3OptDouble) must be(5.35)
149-
barP3Options.extension(CustomOptionsP3Proto.p3OptEnum) must be(GOOD_P3)
150-
barP3Options.extension(CustomOptionsP3Proto.p3OptBool) must be(true)
151-
barP3Options.extension(CustomOptionsP3Proto.p3OptString) must be("foo")
152-
barP3Options.extension(CustomOptionsP3Proto.p3OptBytes) must be(ByteString.copyFromUtf8("foo"))
141+
barP3Options.extension(CustomOptionsP3Proto.p3OptInt32).value must be(1)
142+
barP3Options.extension(CustomOptionsP3Proto.p3OptInt64).value must be(3)
143+
barP3Options.extension(CustomOptionsP3Proto.p3OptSint32).value must be(5)
144+
barP3Options.extension(CustomOptionsP3Proto.p3OptSint64).value must be(6)
145+
barP3Options.extension(CustomOptionsP3Proto.p3OptFixed32).value must be(7)
146+
barP3Options.extension(CustomOptionsP3Proto.p3OptFixed64).value must be(8)
147+
barP3Options.extension(CustomOptionsP3Proto.p3OptFloat).value must be(4.17f)
148+
barP3Options.extension(CustomOptionsP3Proto.p3OptDouble).value must be(5.35)
149+
barP3Options.extension(CustomOptionsP3Proto.p3OptEnum).value must be(GOOD_P3)
150+
barP3Options.extension(CustomOptionsP3Proto.p3OptBool).value must be(true)
151+
barP3Options.extension(CustomOptionsP3Proto.p3OptString).value must be("foo")
152+
barP3Options.extension(CustomOptionsP3Proto.p3OptBytes).value must be(ByteString.copyFromUtf8("foo"))
153153
}
154154

155155
"setting proto3 primitives" should "work" in {
156-
validateSetter(CustomOptionsP3Proto.p3OptInt32)(1)
157-
validateSetter(CustomOptionsP3Proto.p3OptInt64)(3)
158-
validateSetter(CustomOptionsP3Proto.p3OptSint32)(5)
159-
validateSetter(CustomOptionsP3Proto.p3OptSint64)(6)
160-
validateSetter(CustomOptionsP3Proto.p3OptFixed32)(7)
161-
validateSetter(CustomOptionsP3Proto.p3OptFixed64)(8)
162-
validateSetter(CustomOptionsP3Proto.p3OptFloat)(4.17f)
163-
validateSetter(CustomOptionsP3Proto.p3OptDouble)(5.35)
164-
validateSetter(CustomOptionsP3Proto.p3OptEnum)(GOOD_P3)
165-
validateSetter(CustomOptionsP3Proto.p3OptBool)(true)
166-
validateSetter(CustomOptionsP3Proto.p3OptString)("foo")
167-
validateSetter(CustomOptionsP3Proto.p3OptBytes)(ByteString.copyFromUtf8("foo"))
156+
validateSetter(CustomOptionsP3Proto.p3OptInt32)(Some(1))
157+
validateSetter(CustomOptionsP3Proto.p3OptInt64)(Some(3))
158+
validateSetter(CustomOptionsP3Proto.p3OptSint32)(Some(5))
159+
validateSetter(CustomOptionsP3Proto.p3OptSint64)(Some(6))
160+
validateSetter(CustomOptionsP3Proto.p3OptFixed32)(Some(7))
161+
validateSetter(CustomOptionsP3Proto.p3OptFixed64)(Some(8))
162+
validateSetter(CustomOptionsP3Proto.p3OptFloat)(Some(4.17f))
163+
validateSetter(CustomOptionsP3Proto.p3OptDouble)(Some(5.35))
164+
validateSetter(CustomOptionsP3Proto.p3OptEnum)(Some(GOOD_P3))
165+
validateSetter(CustomOptionsP3Proto.p3OptBool)(Some(true))
166+
validateSetter(CustomOptionsP3Proto.p3OptString)(Some("foo"))
167+
validateSetter(CustomOptionsP3Proto.p3OptBytes)(Some(ByteString.copyFromUtf8("foo")))
168168
}
169169

170170
"Custom name on field descriptor" should "translate to custom type" in {

project/Dependencies.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import Keys._
55
object Dependencies {
66
object versions {
77
val grpc = "1.68.0"
8-
val protobuf = "4.26.0"
8+
val protobuf = "4.28.2"
99
val silencer = "1.7.17"
1010
val collectionCompat = "2.12.0"
1111
val coursier = "2.1.13"

0 commit comments

Comments
 (0)