diff --git a/CHANGELOG.md b/CHANGELOG.md index 57b049d8..b752fb53 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/README.md b/README.md index 6e60436a..dc9929f9 100644 --- a/README.md +++ b/README.md @@ -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") diff --git a/src/main/scala/sbtprotoc/ProtocPlugin.scala b/src/main/scala/sbtprotoc/ProtocPlugin.scala index 77f942ca..6f18d0cc 100644 --- a/src/main/scala/sbtprotoc/ProtocPlugin.scala +++ b/src/main/scala/sbtprotoc/ProtocPlugin.scala @@ -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" @@ -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,