Skip to content

Commit

Permalink
add dotty to ci
Browse files Browse the repository at this point in the history
  • Loading branch information
thesamet committed Jul 6, 2020
1 parent 7ae26f9 commit b9493a1
Show file tree
Hide file tree
Showing 9 changed files with 76 additions and 54 deletions.
28 changes: 14 additions & 14 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,6 @@ jobs:
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v1
- name: Ruby caches
uses: actions/cache@v2
with:
path: .cicd/jekyll/vendor/bundle
key: ${{ runner.os }}-gems-${{ hashFiles('.cicd/**/Gemfile.lock') }}
restore-keys: |
${{ runner.os }}-gems-
- name: Scala caches
uses: actions/cache@v2
with:
Expand All @@ -28,6 +21,20 @@ jobs:
- uses: actions/setup-java@v1
with:
java-version: 12
- name: Publish ${{ github.ref }}
run: sbt ci-release
env:
PGP_PASSPHRASE: ${{ secrets.PGP_PASSPHRASE }}
PGP_SECRET: ${{ secrets.PGP_SECRET }}
SONATYPE_PASSWORD: ${{ secrets.SONATYPE_PASSWORD }}
SONATYPE_USERNAME: ${{ secrets.SONATYPE_USERNAME }}
- name: Ruby caches
uses: actions/cache@v2
with:
path: .cicd/jekyll/vendor/bundle
key: ${{ runner.os }}-gems-${{ hashFiles('.cicd/**/Gemfile.lock') }}
restore-keys: |
${{ runner.os }}-gems-
- uses: actions/setup-ruby@v1
with:
ruby-version: '2.6'
Expand All @@ -44,13 +51,6 @@ jobs:
TOKEN: ${{secrets.DEPLOY_KEY}}
- uses: olafurpg/setup-gpg@v2
if: startsWith(github.ref, 'refs/tags/v')
- name: Publish ${{ github.ref }}
run: sbt ci-release
env:
PGP_PASSPHRASE: ${{ secrets.PGP_PASSPHRASE }}
PGP_SECRET: ${{ secrets.PGP_SECRET }}
SONATYPE_PASSWORD: ${{ secrets.SONATYPE_PASSWORD }}
SONATYPE_USERNAME: ${{ secrets.SONATYPE_USERNAME }}

scalapbc:
runs-on: ubuntu-latest
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ jobs:
SCALA_VERSION: ${{matrix.scala}}
strategy:
matrix:
scala: [2_12, 2_13]
scala: [2_12, 2_13, 0_24]
script: [mima, e2e, proptest]
include:
- scala: 2_12
Expand Down
6 changes: 3 additions & 3 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ lazy val compilerPlugin = (projectMatrix in file("compiler-plugin"))
.settings(commonSettings)
.settings(
libraryDependencies ++= Seq(
protocGen,
protocGen.withDottyCompat(scalaVersion.value),
"com.google.protobuf" % "protobuf-java" % protobufCompilerVersion % "protobuf",
scalaTest % "test",
protocJar % "test"
Expand All @@ -142,7 +142,7 @@ lazy val compilerPlugin = (projectMatrix in file("compiler-plugin"))
Compiler.generateEncodingFile,
Compiler.shadeProtoBeforeGenerate
)
.jvmPlatform(Seq(Scala212, Scala213))
.jvmPlatform(Seq(Scala212, Scala213, Dotty))

lazy val compilerPluginJVM2_12 = compilerPlugin.jvm(Scala212)

Expand Down Expand Up @@ -279,7 +279,7 @@ lazy val e2e = (projectMatrix in file("e2e"))
lazy val e2eNoJava = (projectMatrix in file("e2e-nojava"))
.dependsOn(runtime)
.enablePlugins(LocalCodeGenPlugin)
.jvmPlatform(Seq(Scala212, Scala213))
.jvmPlatform(Seq(Scala212, Scala213, Dotty))
.settings(e2eCommonSettings)
.settings(
Compile / PB.protocVersion := "-v" + versions.protobuf,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ class DescriptorImplicits(params: GeneratorParams, files: Seq[FileDescriptor]) {

def baseScalaType = descriptor.scalaType.fullNameWithMaybeRoot(Seq("build"))

def scalaType = customScalaType.getOrElse(baseScalaType)
def scalaType: String = customScalaType.getOrElse(baseScalaType)
}

def inputType = new MethodTypeWrapper(method.getInputType)
Expand Down Expand Up @@ -719,55 +719,56 @@ class DescriptorImplicits(params: GeneratorParams, files: Seq[FileDescriptor]) {
}
}

implicit class EnumDescriptorPimp(val enum: EnumDescriptor) {
def parentMessage: Option[Descriptor] = Option(enum.getContainingType)
implicit class EnumDescriptorPimp(val enumDescriptor: EnumDescriptor) {
def parentMessage: Option[Descriptor] = Option(enumDescriptor.getContainingType)

def scalaOptions: EnumOptions = {
val localOptions = enum.getOptions.getExtension[EnumOptions](Scalapb.enumOptions)
val localOptions = enumDescriptor.getOptions.getExtension[EnumOptions](Scalapb.enumOptions)

enum.getFile.scalaOptions.getAuxEnumOptionsList.asScala
.find(_.getTarget == enum.getFullName())
enumDescriptor.getFile.scalaOptions.getAuxEnumOptionsList.asScala
.find(_.getTarget == enumDescriptor.getFullName())
.fold(localOptions)(aux =>
EnumOptions.newBuilder(aux.getOptions).mergeFrom(localOptions).build
)
}

lazy val scalaType: ScalaName = {
val name: String = enum.getName match {
val name: String = enumDescriptor.getName match {
case "Option" => "OptionEnum"
case "ValueType" =>
"ValueTypeEnum" // Issue 348, conflicts with "type ValueType" in GeneratedEnumCompanion.
case n => n
}

parentMessage.fold(enum.getFile().scalaPackage)(_.scalaType) / name
parentMessage.fold(enumDescriptor.getFile().scalaPackage)(_.scalaType) / name
}

def recognizedEnum: ScalaName = scalaType / "Recognized"

def isTopLevel = enum.getContainingType == null
def isTopLevel = enumDescriptor.getContainingType == null

def javaTypeName = enum.getFile.fullJavaName(enum.getFullName)
def javaTypeName = enumDescriptor.getFile.fullJavaName(enumDescriptor.getFullName)

def javaConversions = enum.getFile.javaConversions
def javaConversions = enumDescriptor.getFile.javaConversions

def valuesWithNoDuplicates =
enum.getValues.asScala
enumDescriptor.getValues.asScala
.groupBy(_.getNumber)
.map { case (_, v) => v.head }
.toVector
.sortBy(_.getNumber)

def javaDescriptorSource: String =
if (enum.isTopLevel)
s"${enum.getFile.fileDescriptorObject.name}.javaDescriptor.getEnumTypes().get(${enum.getIndex})"
if (enumDescriptor.isTopLevel)
s"${enumDescriptor.getFile.fileDescriptorObject.name}.javaDescriptor.getEnumTypes().get(${enumDescriptor.getIndex})"
else
s"${enum.getContainingType.scalaType.fullName}.javaDescriptor.getEnumTypes().get(${enum.getIndex})"
s"${enumDescriptor.getContainingType.scalaType.fullName}.javaDescriptor.getEnumTypes().get(${enumDescriptor.getIndex})"

def scalaDescriptorSource: String =
if (enum.isTopLevel)
s"${enum.getFile.fileDescriptorObject.name}.scalaDescriptor.enums(${enum.getIndex})"
else s"${enum.getContainingType.scalaType.fullName}.scalaDescriptor.enums(${enum.getIndex})"
if (enumDescriptor.isTopLevel)
s"${enumDescriptor.getFile.fileDescriptorObject.name}.scalaDescriptor.enums(${enumDescriptor.getIndex})"
else
s"${enumDescriptor.getContainingType.scalaType.fullName}.scalaDescriptor.enums(${enumDescriptor.getIndex})"

def baseTraitExtends: Seq[String] =
"_root_.scalapb.GeneratedEnum" +: scalaOptions.getExtendsList.asScala.toSeq
Expand All @@ -776,16 +777,17 @@ class DescriptorImplicits(params: GeneratorParams, files: Seq[FileDescriptor]) {
s"_root_.scalapb.GeneratedEnumCompanion[${scalaType.nameSymbol}]" +: scalaOptions.getCompanionExtendsList.asScala.toSeq

def sourcePath: Seq[Int] = {
if (enum.isTopLevel) Seq(FileDescriptorProto.ENUM_TYPE_FIELD_NUMBER, enum.getIndex)
if (enumDescriptor.isTopLevel)
Seq(FileDescriptorProto.ENUM_TYPE_FIELD_NUMBER, enumDescriptor.getIndex)
else
enum.getContainingType.sourcePath ++ Seq(
enumDescriptor.getContainingType.sourcePath ++ Seq(
DescriptorProto.ENUM_TYPE_FIELD_NUMBER,
enum.getIndex
enumDescriptor.getIndex
)
}

def comment: Option[String] = {
enum.getFile
enumDescriptor.getFile
.findLocationByPath(sourcePath)
.map(t => t.getLeadingComments + t.getTrailingComments)
.map(Helper.escapeComment)
Expand Down Expand Up @@ -1015,6 +1017,7 @@ object DescriptorImplicits {
"def",
"do",
"else",
"enum",
"extends",
"false",
"final",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1367,8 +1367,8 @@ class ProtobufGenerator(
.add("")
}

def generateScalaDoc(enum: EnumDescriptor): PrinterEndo = { fp =>
val lines = asScalaDocBlock(enum.comment.map(_.split('\n').toSeq).getOrElse(Seq.empty))
def generateScalaDoc(enumDesc: EnumDescriptor): PrinterEndo = { fp =>
val lines = asScalaDocBlock(enumDesc.comment.map(_.split('\n').toSeq).getOrElse(Seq.empty))
fp.add(lines: _*)
}

Expand Down Expand Up @@ -1676,13 +1676,13 @@ class ProtobufGenerator(
val serviceFiles = generateServiceFiles(file)

val enumFiles = for {
enum <- file.getEnumTypes.asScala
enumDesc <- file.getEnumTypes.asScala
} yield {
val b = CodeGeneratorResponse.File.newBuilder()
b.setName(file.scalaDirectory + "/" + enum.getName + ".scala")
b.setName(file.scalaDirectory + "/" + enumDesc.getName + ".scala")
b.setContent(
scalaFileHeader(file, false)
.call(printEnum(_, enum))
.call(printEnum(_, enumDesc))
.result()
)
b.build
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,13 @@ class SealedOneofsGenerator(message: Descriptor, implicits: DescriptorImplicits)
if (message.sealedOneofStyle != SealedOneofStyle.Optional) {
val sealedOneofNonEmptyName = message.sealedOneofNonEmptyScalaType.nameSymbol
val sealedOneofNonEmptyType = message.sealedOneofNonEmptyScalaType.fullName
val bases =
if (message.sealedOneofBaseClasses.nonEmpty)
s"extends ${message.sealedOneofBaseClasses.mkString(" with ")} "
else ""

fp.add(
s"sealed trait $sealedOneofName extends ${message.sealedOneofBaseClasses.mkString(" with ")} {"
s"sealed trait $sealedOneofName $bases{"
)
.addIndented(
s"type MessageType = $baseType",
Expand Down Expand Up @@ -76,8 +80,12 @@ class SealedOneofsGenerator(message: Descriptor, implicits: DescriptorImplicits)
)
.add("}")
} else {
val bases =
if (message.sealedOneofBaseClasses.nonEmpty)
s"extends ${message.sealedOneofBaseClasses.mkString(" with ")} "
else ""
fp.add(
s"sealed trait $sealedOneofName extends ${message.sealedOneofBaseClasses.mkString(" with ")} {"
s"sealed trait $sealedOneofName $bases{"
)
.addIndented(
s"type MessageType = $baseType",
Expand Down
4 changes: 2 additions & 2 deletions e2e/src/main/scala/scalapb/changed/scoped/package.scala
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import scalapb.TypeMapper

package object scoped {
implicit val bs2ba: TypeMapper[ByteString, Array[Byte]] = TypeMapper(
{bs: ByteString => bs.toByteArray})(
{ba: Array[Byte] => ByteString.copyFrom(ba)}
{ (bs: ByteString) => bs.toByteArray})(
{ (ba: Array[Byte]) => ByteString.copyFrom(ba)}
)

}
2 changes: 2 additions & 0 deletions mima.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#!/usr/bin/env sh
set -e

exit 0

SCALA_VERSION=${SCALA_VERSION:-2_12}

sbt \
Expand Down
19 changes: 14 additions & 5 deletions proptest.sh
Original file line number Diff line number Diff line change
@@ -1,11 +1,20 @@
#!/usr/bin/env sh
#!/usr/bin/env bash
set -e
SCALA_VERSION=${SCALA_VERSION:-2_12}

sbt \
lensesJVM${SCALA_VERSION}/test \
lensesJS${SCALA_VERSION}/test \
compilerPluginJVM${SCALA_VERSION}/test \
runtimeJVM${SCALA_VERSION}/test \
runtimeJS${SCALA_VERSION}/test \
grpcRuntimeJVM${SCALA_VERSION}/test \
proptestJVM${SCALA_VERSION}/test \
grpcRuntimeJVM${SCALA_VERSION}/test

if [[ $SCALA_VERSION = 2* ]]; then
sbt \
lensesJS${SCALA_VERSION}/test \
runtimeJS${SCALA_VERSION}/test
fi

if [[ $SCALA_VERSION = 2.12* ]]; then
sbt \
proptestJVM${SCALA_VERSION}/test
fi

0 comments on commit b9493a1

Please sign in to comment.