Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## [1.0.8]
* Add option `PB.importRoot` (defaults to `PB.protoSources`) that allows you to set the directory
that protobuf `import`s will be evaluated in.

## [1.0.7]
* Update default protoc to 3.21.7

Expand Down
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,9 @@ libraryDependencies ++= Seq(
// Changing where to look for protos to compile (default src/main/protobuf):
Compile / PB.protoSources := Seq(sourceDirectory.value / "somewhere")

// Changing where to look for relative `import`s (defaults to `PB.protoSources`):
Compile / PB.importRoot := (Compile / baseDirectory).value / "protos"

// Additional options to pass to protoc:
Compile / PB.protocOptions := Seq("-xyz")

Expand Down
10 changes: 9 additions & 1 deletion src/main/scala/sbtprotoc/ProtocPlugin.scala
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,11 @@ object ProtocPlugin extends AutoPlugin {
)
val recompile = TaskKey[Boolean]("protoc-recompile")

val importRoot = SettingKey[File](
"protobuf-import-root",
"Directory to use when resolving .proto import directives."
)

val Target = protocbridge.Target
val gens = protocbridge.gens
val ProtocPlugin = "protoc-plugin"
Expand Down Expand Up @@ -313,7 +318,10 @@ object ProtocPlugin extends AutoPlugin {
PB.manifestProcessing := true,
PB.includePaths := (
PB.includePaths.?.value.getOrElse(Nil) ++
PB.protoSources.value ++
(PB.importRoot.?.value match {
case None => PB.protoSources.value
case Some(root) => Seq(root)
}) ++
Seq(PB.externalIncludePath.value, PB.externalSourcePath.value) ++
protocIncludeDependencies.value,
).distinct,
Expand Down