Skip to content

Commit

Permalink
Merge branch 'master' into update/munit-1.0.0-M10
Browse files Browse the repository at this point in the history
  • Loading branch information
scala-steward committed Nov 8, 2023
2 parents b71c150 + f2f7472 commit 8f38403
Show file tree
Hide file tree
Showing 24 changed files with 301 additions and 91 deletions.
6 changes: 6 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
version: 2
updates:
- package-ecosystem: "github-actions"
directory: "/"
schedule:
interval: "weekly"
10 changes: 5 additions & 5 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ jobs:
publish:
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Scala caches
Expand Down Expand Up @@ -56,7 +56,7 @@ jobs:
scalapbc:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
with:
fetch-depth: 0
- uses: actions/setup-java@v3
Expand All @@ -80,7 +80,7 @@ jobs:
arch: osx-x86_64
runs-on: ${{matrix.os}}
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
with:
fetch-depth: 0
- uses: olafurpg/setup-scala@v13
Expand Down Expand Up @@ -114,7 +114,7 @@ jobs:
runs-on: ubuntu-20.04
needs: [native, scalapbc]
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Download artifacts
Expand All @@ -131,4 +131,4 @@ jobs:
set -x
assets=$(find ./artifacts -name "*.zip" -printf "-a %p ")
RELEASE_NAME=${GITHUB_REF#refs/tags/}
hub release create ${assets} -m "$RELEASE_NAME" "$RELEASE_NAME"
gh release create "$RELEASE_NAME" --generate-notes ${assets}
4 changes: 2 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jobs:
script: scala3_compat_test

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4

- uses: actions/setup-java@v3
with:
Expand All @@ -46,7 +46,7 @@ jobs:
conformance:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- uses: actions/cache@v3
id: conformance-cache
with:
Expand Down
4 changes: 2 additions & 2 deletions .scalafmt.conf
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
version = 3.7.3
version = 3.7.14
style = defaultWithAlign
maxColumn = 100
assumeStandardLibraryStripMargin = true
Expand All @@ -14,4 +14,4 @@ fileOverride {
"glob:**/src/main/scala-3/**" {
runner.dialect = scala3
}
}
}
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@
CollectionAdapter for (#1509)
- Introduced new generator parameter `scala3_sources` (also available via
scalapb.proto) to generate sources that are compatible with Scala 3 (#1576)
- `aux_*_options` now accept `*` in the target field to match all entities in
scope.
- Add `derives` and `sealed_oneof_derives` to the message options that adds a
derived clause to generated messages and sealed oneofs.
- Bump Scala.js to 1.14.0

## [0.11.13]
- Added input and output message type for method descriptor (#1503)
Expand Down
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ Wrapping up your PR
while working on this. Add the exclusions to `build.sbt`. Binary
incompatibilities are expected when modifying `scalapb.proto` and in the
meantime we have some tolerance for certain type of incompatabilities.
* In SBT, run `scalafmt` and `test:scalafmt` to ensure the code compiles
* In SBT, run `scalafmtAll` to ensure the code compiles
cleanly.
* Run `./make_plugin_proto.sh` to re-generate all the generated code that
ships with ScalaPB.
Expand Down
2 changes: 1 addition & 1 deletion build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ inThisBuild(
)
)

addCommandAlias("fmt", "all scalafmtSbt scalafmt test:scalafmt")
addCommandAlias("fmt", "all scalafmtSbt scalafmtAll")

lazy val sharedNativeSettings = List(
nativeLinkStubs := true // for utest
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ class DescriptorImplicits private[compiler] (

(fd.getFile.scalaOptions.getAuxFieldOptionsList.asScala
.collect {
case opt if opt.getTarget == fd.getFullName() => opt.getOptions
case opt if Helper.targetMatches(opt.getTarget(), fd.getFullName()) => opt.getOptions
} :+ localOptions).reduce[FieldOptions]((left, right) =>
left.toBuilder.mergeFrom(right).build()
)
Expand Down Expand Up @@ -532,9 +532,9 @@ class DescriptorImplicits private[compiler] (
val localOptions = message.getOptions.getExtension[MessageOptions](Scalapb.message)

message.getFile.scalaOptions.getAuxMessageOptionsList.asScala
.find(_.getTarget == message.getFullName())
.fold(localOptions)(aux =>
MessageOptions.newBuilder(aux.getOptions).mergeFrom(localOptions).build
.filter(o => Helper.targetMatches(o.getTarget, message.getFullName()))
.foldLeft(localOptions)((local, aux) =>
MessageOptions.newBuilder(aux.getOptions).mergeFrom(local).build
)
}

Expand Down Expand Up @@ -772,9 +772,9 @@ class DescriptorImplicits private[compiler] (
val localOptions = enumDescriptor.getOptions.getExtension[EnumOptions](Scalapb.enumOptions)

enumDescriptor.getFile.scalaOptions.getAuxEnumOptionsList.asScala
.find(_.getTarget == enumDescriptor.getFullName())
.fold(localOptions)(aux =>
EnumOptions.newBuilder(aux.getOptions).mergeFrom(localOptions).build
.filter(o => Helper.targetMatches(o.getTarget, enumDescriptor.getFullName()))
.foldLeft(localOptions)((local, aux) =>
EnumOptions.newBuilder(aux.getOptions).mergeFrom(local).build
)
}

Expand Down Expand Up @@ -862,9 +862,9 @@ class DescriptorImplicits private[compiler] (
val localOptions = enumValue.getOptions.getExtension[EnumValueOptions](Scalapb.enumValue)

enumValue.getFile.scalaOptions.getAuxEnumValueOptionsList.asScala
.find(_.getTarget == enumValue.getFullName())
.fold(localOptions)(aux =>
EnumValueOptions.newBuilder(aux.getOptions).mergeFrom(localOptions).build
.filter(o => Helper.targetMatches(o.getTarget, enumValue.getFullName()))
.foldLeft(localOptions)((local, aux) =>
EnumValueOptions.newBuilder(aux.getOptions).mergeFrom(local).build
)
}

Expand Down Expand Up @@ -1239,4 +1239,11 @@ object Helper {
.replace(">", ">")
.replace("\\", "&92;")
}

// Does the pattern matches the name. If the pattern is "*" the name always matches, otherwise
// must be an exact match. This may evolve in the future.
def targetMatches(pattern: String, name: String): Boolean = pattern match {
case "*" => true
case o => name == o
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class SealedOneofsGenerator(message: Descriptor, implicits: DescriptorImplicits)
val bases =
if (baseClasses.nonEmpty)
s"extends ${baseClasses.mkString(" with ")} $derives"
else ""
else derives

if (message.sealedOneofStyle != SealedOneofStyle.Optional) {
val sealedOneofNonEmptyName = message.sealedOneofNonEmptyScalaType.nameSymbol
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,25 @@ class DescriptorImplicitsSpec extends AnyFlatSpec with Matchers with ProtocInvoc
.find(_.getFullName() == "inside_disable_flat.proto")
.get
.disableOutput must be(false)
}

"Helpers.targetMatches" should "do exact match when not *" in {
Helper.targetMatches("foo", "foo") must be(true)
Helper.targetMatches("foo", "") must be(false)
Helper.targetMatches("foo", "bar") must be(false)
Helper.targetMatches("", "") must be(true)
Helper.targetMatches("", "foo") must be(false)
}

"Helpers.targetMatches" should "return true when *" in {
Helper.targetMatches("*", "foo") must be(true)
Helper.targetMatches("*", "bar") must be(true)
Helper.targetMatches("*", "") must be(true)
Helper.targetMatches("*", "*") must be(true)
}

"Helpers.targetMatches" should "not support * as a generic wildcard" in {
Helper.targetMatches("foo.*", "foo.bar") must be(false)
Helper.targetMatches("foo.*.bar", "bar.giz.bar") must be(false)
}
}
22 changes: 21 additions & 1 deletion docs/src/main/markdown/customizations.md
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,8 @@ option (scalapb.options) = {
};
```

The list `aux_message_options` contains options targeted at different messages define under the same proto package of the package-scoped options. The `target` name needs to be fully-qualified message name in the protobuf namespace. Similar to `aux_message_options`, we also have `aux_enum_options`, `aux_enum_value_options` and `aux_field_options`. See [example usage here](https://github.com/scalapb/ScalaPB/tree/master/e2e/src/main/protobuf/scoped).
The list `aux_message_options` contains options targeted at different messages define under the same proto package of the package-scoped options. The `target` name needs to be fully-qualified message name in the protobuf namespace. Similar to `aux_message_options`, we also have `aux_enum_options`, `aux_enum_value_options` and `aux_field_options`. See [example usage here](https://github.com/scalapb/ScalaPB/tree/master/e2e/src/main/protobuf/scoped). If the target is set `*` then the options will be
applied to all the entities in the file or package (depending on the `scope` option).

## Primitive wrappers

Expand Down Expand Up @@ -806,3 +807,22 @@ enum BarEnum {
BarValue = 1 [(scalapb.enum_value).annotations = "@annotation4"];
}
```

## Adding derives clause

In ScalaPB 0.11.14, it is possible to add a `derives` clause to generated messages and
sealed oneofs:

```protobuf
message Foo {
option (scalapb.message).derives = "yourpkg.Show";
...
}}}
message Expr {
option (scalapb.message).sealed_oneof_derives = "yourpkg.Show";
oneof sealed_value {
...
}
}
```
4 changes: 2 additions & 2 deletions docs/src/main/markdown/getting-started.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ Protocol buffers are the flexible, efficient, automated solution to solve exactl
## Where to Find the Example Code

The example code for this tutorial is under the `examples/basic` directory
in ScalaPB's repo. To get your copy:
in [ScalaPB's repo](https://github.com/scalapb/ScalaPB/tree/master/examples/basic). To get your copy:

```bash
git clone https://github.com/scalapb/ScalaPB.git
Expand Down Expand Up @@ -135,7 +135,7 @@ object PhoneType {
case object HOME extends PhoneType(1) {
val index = 1
val name = "HOME"
override def isMobile: Boolean = true
override def isHome: Boolean = true
}

// ...
Expand Down
26 changes: 26 additions & 0 deletions e2e/src/main/protobuf/scoped/wildcard.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
syntax = "proto3";

package scalapb.e2e.scoped;

import "scalapb/scalapb.proto";

option (scalapb.options) = {
aux_message_options: [
{
target: "scalapb.e2e.scoped.Wild2",
options: {
extends: "scalapb.e2e.scoped.SomeTrait"
}
},
{
target: "*"
options: {
extends: "scalapb.e2e.scoped.WildcardTrait"
}
}
]
};

message Wild1 {}

message Wild2 {}
3 changes: 3 additions & 0 deletions e2e/src/main/scala/scalapb/e2e/scoped/WildcardTrait.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package scalapb.e2e.scoped

trait WildcardTrait
5 changes: 0 additions & 5 deletions e2e/src/test/scala/NoBoxSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,6 @@ class NoBoxSpec extends AnyFlatSpec with Matchers {
scalaCar.tyre1 must be(Tyre.defaultInstance)
}

"Scala message with a no_box field with null value" should "throw exception when being serialized" in {
val car = Car(tyre1 = null)
a[Exception] shouldBe thrownBy(car.toByteArray)
}

"Scala message with a no_box reference" should "generate correct types" in {
val car = Car()
car.dontBoxMeDef mustBe (DontBoxMe.defaultInstance)
Expand Down
11 changes: 11 additions & 0 deletions e2e/src/test/scala/scoped/WildcardSpec.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package scalapb.e2e.scoped

import org.scalatest.flatspec.AnyFlatSpec
import org.scalatest.matchers.must.Matchers
import scalapb.changed.scoped._

class WildcardSpec extends AnyFlatSpec with Matchers {
assert(Wild1().isInstanceOf[WildcardTrait])
assert(Wild2().isInstanceOf[WildcardTrait])
assert(Wild2().isInstanceOf[SomeTrait])
}
6 changes: 6 additions & 0 deletions e2e/src/test/scalajvm/NoBoxWithJavaSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,10 @@ class NoBoxWithJavaSpec extends AnyFlatSpec with Matchers {
val p = Person("", Money(BigDecimal("123.123")))
Person.fromJavaProto(Person.toJavaProto(p)) must be(p)
}

"Scala message with a no_box field with null value" should "throw exception when being serialized" in {
val car = Car(tyre1 = null)
a[Exception] shouldBe thrownBy(car.toByteArray)
}

}
2 changes: 1 addition & 1 deletion examples_and_formatting.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
set -e
./test_generated_code_checked_in.sh
for d in examples/*; do cd "$d" && sbt test && cd ../..; done
sbt -J-Xmx4500M scalafmtCheck test:scalafmtCheck scalafmtSbtCheck
sbt -J-Xmx4500M scalafmtCheckAll scalafmtSbtCheck
4 changes: 2 additions & 2 deletions project/Dependencies.scala
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import Keys._

object Dependencies {
object versions {
val grpc = "1.58.0"
val grpc = "1.59.0"
val protobuf = "3.19.6"
val silencer = "1.7.14"
val collectionCompat = "2.11.0"
Expand All @@ -16,7 +16,7 @@ object Dependencies {
// For testing
val annotationApi = "1.3.2"
val cats = "2.6.1"
val mockito = "5.6.0"
val mockito = "5.7.0"
val munit = "1.0.0-M8"
val scalaTest = "3.2.17"
val scalaTestPlusMockito = "3.1.0.0"
Expand Down
2 changes: 1 addition & 1 deletion project/build.properties
Original file line number Diff line number Diff line change
@@ -1 +1 @@
sbt.version=1.9.6
sbt.version=1.9.7
6 changes: 3 additions & 3 deletions project/plugins.sbt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
val scalaJSVersion = Option(System.getenv("SCALAJS_VERSION")).getOrElse("1.12.0")
val scalaJSVersion = Option(System.getenv("SCALAJS_VERSION")).getOrElse("1.14.0")

addSbtPlugin("com.eed3si9n" % "sbt-assembly" % "0.14.10")

Expand All @@ -8,7 +8,7 @@ addSbtPlugin("com.github.sbt" % "sbt-native-packager" % "1.9.16")

addSbtPlugin("org.scala-js" % "sbt-scalajs" % scalaJSVersion)

addSbtPlugin("org.scala-native" % "sbt-scala-native" % "0.4.15")
addSbtPlugin("org.scala-native" % "sbt-scala-native" % "0.4.16")

addSbtPlugin("com.typesafe" % "sbt-mima-plugin" % "1.1.3")

Expand All @@ -24,6 +24,6 @@ addSbtPlugin("com.thesamet" % "sbt-protoc-gen-project" % "0.1.8")

addSbtPlugin("com.eed3si9n" % "sbt-projectmatrix" % "0.9.1")

addSbtPlugin("org.scalameta" % "sbt-mdoc" % "2.3.7")
addSbtPlugin("org.scalameta" % "sbt-mdoc" % "2.4.0")

addSbtPlugin("org.scalameta" % "sbt-native-image" % "0.3.4")
Loading

0 comments on commit 8f38403

Please sign in to comment.