Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support generating code from proto in src/test/protobuf #642

Open
lacarvalho91 opened this issue Jun 15, 2023 · 2 comments · Fixed by #643
Open

Support generating code from proto in src/test/protobuf #642

lacarvalho91 opened this issue Jun 15, 2023 · 2 comments · Fixed by #643

Comments

@lacarvalho91
Copy link
Contributor

We have proto files in src/test/protobuf which doesn't seem to be supported out of the box. To get it to work I've had to copy paste some settings from

override def projectSettings: Seq[Def.Setting[_]] =
.

inConfig(Test)(
  Seq(
    PB.targets := Fs2GrpcPlugin.autoImport.scalapbCodeGenerators.value,
    PB.protoSources := Seq(sourceDirectory.value / "protobuf"),
    fs2GrpcServiceSuffix := "Fs2Grpc",
    fs2GrpcOutputPath := sourceManaged.value / "fs2-grpc",
    scalapbCodeGeneratorOptions := Seq(CodeGeneratorOption.Grpc, CodeGeneratorOption.Fs2Grpc),
    scalapbCodeGenerators := {
      val options = scalapbCodeGeneratorOptions.value.toSet
      Target(
        scalapb.gen(
          flatPackage = options(CodeGeneratorOption.FlatPackage),
          javaConversions = options(CodeGeneratorOption.JavaConversions),
          grpc = options(CodeGeneratorOption.Grpc),
          singleLineToProtoString = options(CodeGeneratorOption.SingleLineToProtoString),
          asciiFormatToString = options(CodeGeneratorOption.AsciiFormatToString)
        ),
        sourceManaged.value / "scalapb"
      ) ::
        Option(
          Target(
            (
              SandboxedJvmGenerator.forModule(
                "scala-fs2-grpc",
                Artifact(
                  BuildInfo.organization,
                  s"${BuildInfo.codeGeneratorName}_${CrossVersion.binaryScalaVersion(BuildInfo.scalaVersion)}",
                  BuildInfo.version
                ),
                BuildInfo.codeGeneratorFullName + "$",
                Nil
              ),
              scalapbCodeGeneratorOptions.value.filterNot(_ == CodeGeneratorOption.Fs2Grpc).map(_.toString) :+
                s"serviceSuffix=${fs2GrpcServiceSuffix.value}"
            ),
            fs2GrpcOutputPath.value
          )
        ).filter(_ => scalapbCodeGeneratorOptions.value.contains(CodeGeneratorOption.Fs2Grpc)).toList
    }
  )
)

It would be good if we supported this out of the box like Akka gRPC does here.

@ahjohannessen
Copy link
Collaborator

I had to revert your PR that I merged as the changes are breaking the build of downstream projects. I need to look into it.

@lacarvalho91
Copy link
Contributor Author

Got a link to those builds? I couldn't really work out how to confidently test the changes so maybe those builds will give me some inspiration

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants