These are chat archives for trueaccord/ScalaPB

8th
Feb 2018
erinmez
@erinmez
Feb 08 14:38
Hi there, how can I enable preserveUnknownFields in my build.sbt for 0.7.0-rc7 ?
erinmez
@erinmez
Feb 08 15:24
@thesamet
Hi @thesamet , specifying preserve_unknown_fields: true in the proto file works, but is there perhaps a global way as in scalapb.gen(flatPackage=true,.... ?
Nadav Samet
@thesamet
Feb 08 16:49
No, there's currently no global way to do it.
erinmez
@erinmez
Feb 08 16:57
ok thanks! I have read somewhere that it's the intention for proto3 (I think it was from 3.5 onwards) spec to switch back and make the preserving the default. Is this the intention with scalapb in the 0.7.0 final as well? Right now, I can live with it but it generates some 50+ scala files for the protobuf & scalapb options which I would love to avoid.
Nadav Samet
@thesamet
Feb 08 18:29
Generally, ScalaPB tries to be consistent with the semantics of the official spec and with the Java implementation in particular. Can you clarify what you mean by the 50+ scala files? I am not sure I understand how having this option would result in having less files
codeexplorer
@codeexplorer
Feb 08 20:22
I am having issues doing sbt build with scalapb: I get this error : object gen is not a member of package scalapb
scalapb.gen() -> (sourceManaged in Compile).value hen I add the following to build.sbt: PB.targets in Compile := Seq(
scalapb.gen() -> (sourceManaged in Compile).value
)
I have added the plugin and dependencies as follows :
libraryDependencies += "com.trueaccord.scalapb" %% "compilerplugin" % "0.6.7"
addSbtPlugin("com.thesamet" % "sbt-protoc" % "0.99.13")
erinmez
@erinmez
Feb 08 21:23

@thesamet
Only a few scala source files are generated with the following proto def:

syntax = "proto3";
package mypackage.v100;
message MyMessage {
  string foo = 1;
}

and this build.sbt:

libraryDependencies += "sampleorg" % "_sample_api" % "0.1-SNAPSHOT" % "protobuf"
PB.targets in Compile := Seq(
  scalapb.gen() -> (sourceManaged in Compile).value
)
PB.protoSources in Compile += target.value / "protobuf_external"

However, in order to enable the "preserve mode", I'm forced to import additional defs into my proto def:

syntax = "proto3";
package mypackage.v100;
import "scalapb/scalapb.proto";
option (scalapb.options) = {
  preserve_unknown_fields: true
};
message MyMessage {
  string foo = 1;
}

and add the scalapb protobuf dependency in this build.sbt:

libraryDependencies += "com.thesamet.scalapb" %% "scalapb-runtime" % scalapb.compiler.Version.scalapbVersion % "protobuf"
libraryDependencies += "sampleorg" % "_sample_api" % "0.1-SNAPSHOT" % "protobuf"
PB.targets in Compile := Seq(
  scalapb.gen() -> (sourceManaged in Compile).value
)
PB.protoSources in Compile += target.value / "protobuf_external"

which then also generates scala files for all those scalapb and google protobuf defs. I tried to add an includeFilter, however, my generated message scala files depend on types from those other scala files.

Basically, what would be nice is something like this:

scalapb.gen(preserveUnknownFields=true) -> (sourceManaged in Compile).value

which I guess would avoid the inclusion described above (disclaimer, I'm a real beginner with ScalaPB :smile:

Nadav Samet
@thesamet
Feb 08 21:53
You don't need to generate and recompile ScalaPB runtime. You can include in PB.protoSources only the directories you care about, by using something like this: https://github.com/thesamet/sbt-protoc/blob/master/examples/multi-with-external-jar/build.sbt#L16
The problem with having global parameters that affect compilation is that it can results with source code incpompatibilies.
What is likely to happen is that in a future release we will have this flag set to true by default.
erinmez
@erinmez
Feb 08 22:07
thanks for the pointer, I will try that. Is there perhaps an ETA for a final release?
Nadav Samet
@thesamet
Feb 08 23:17
I think we need about a week or two. Not anticipating any breaking changes, so changes from 0.7.0-rc7 are going to be minimal