Skip to content

Commit

Permalink
support repeated native plugins with different options
Browse files Browse the repository at this point in the history
  • Loading branch information
github-brice-jaglin committed Jan 28, 2021
1 parent ffe8132 commit 8275bbe
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 5 deletions.
2 changes: 1 addition & 1 deletion build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ scalaVersion := "2.12.13"
addSbtPlugin("org.portable-scala" % "sbt-platform-deps" % "1.0.0")

libraryDependencies ++= Seq(
"com.thesamet.scalapb" %% "protoc-bridge" % "0.9.1"
"com.thesamet.scalapb" %% "protoc-bridge" % "0.9.1+4-8a125376-SNAPSHOT"
)

enablePlugins(SbtPlugin)
Expand Down
14 changes: 10 additions & 4 deletions src/main/scala/sbtprotoc/ProtocPlugin.scala
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import org.portablescala.sbtplatformdeps.PlatformDepsPlugin.autoImport.platformD
import java.net.URLClassLoader
import sbt.librarymanagement.DependencyResolution
import protocbridge.{Artifact => BridgeArtifact}
import protocbridge.{SystemDetector => BridgeSystemDetector, FileCache}
import protocbridge.{SystemDetector => BridgeSystemDetector, FileCache, PluginGenerator}
import scala.concurrent.{Future, blocking}
import scala.concurrent.ExecutionContext.Implicits.global

Expand Down Expand Up @@ -503,9 +503,9 @@ object ProtocPlugin extends AutoPlugin {
// Ensure all plugins are executable
nativePlugins.foreach { dep => dep.data.setExecutable(true) }

val nativePluginsArgs = nativePlugins.map { a =>
val nativePluginsArgs = nativePlugins.flatMap { a =>
val dep = a.get(artifact.key).get
val pluginPath =
val pluginPath = {
maybeNixDynamicLinker.filterNot(_ => a.data.getName.endsWith(".sh")) match {
case None => a.data.absolutePath
case Some(linker) =>
Expand All @@ -516,7 +516,13 @@ object ProtocPlugin extends AutoPlugin {
f.getAbsolutePath()
}
}
s"--plugin=${dep.name}=${pluginPath}"
}
val targetCount = PB.targets.value.count {
case Target(PluginGenerator(name, _, _), _, _) => s"protoc-gen-$name" == dep.name
case _ => false
}
if (targetCount == 1) Seq(s"--plugin=${dep.name}=${pluginPath}")
else Seq.range(0, targetCount).map(i => s"--plugin=${dep.name}_$i=${pluginPath}")
}

val classLoader: BridgeArtifact => ClassLoader =
Expand Down
24 changes: 24 additions & 0 deletions src/sbt-test/settings/native/build.sbt
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
Compile / PB.targets := Seq(
(
PB.gens.plugin("scala"),
Seq()
) -> (Compile / sourceManaged).value,
(
PB.gens.plugin("scala"),
Seq("flat_package")
) -> (Compile / sourceManaged).value
)

val scalapbcClassifier =
if (protocbridge.SystemDetector.detectedClassifier().startsWith("windows")) "windows"
else "unix"

libraryDependencies += "com.thesamet.scalapb" %% "scalapb-runtime" % "0.10.10"
libraryDependencies += "com.thesamet.scalapb" % "protoc-gen-scala" % "0.10.10" % "protobuf" artifacts (
Artifact(
"protoc-gen-scala",
PB.ProtocPlugin,
"sh",
scalapbcClassifier
)
)
7 changes: 7 additions & 0 deletions src/sbt-test/settings/native/project/plugins.sbt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
val pluginVersion = System.getProperty("plugin.version")
if(pluginVersion == null)
throw new RuntimeException("""|The system property 'plugin.version' is not defined.
|Specify this property using the scriptedLaunchOpts -D.""".stripMargin)
else addSbtPlugin("com.thesamet" % "sbt-protoc" % pluginVersion)
}
7 changes: 7 additions & 0 deletions src/sbt-test/settings/native/src/main/protobuf/test1.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
syntax = "proto3";

package test;

message msg {
int32 thing = 1;
}
6 changes: 6 additions & 0 deletions src/sbt-test/settings/native/test
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
> compile

$ exists target/scala-2.12/src_managed/main/test/test1/Test1Proto.scala
$ exists target/scala-2.12/src_managed/main/test/test1/msg.scala
$ exists target/scala-2.12/src_managed/main/test/Test1Proto.scala
$ exists target/scala-2.12/src_managed/main/test/msg.scala

0 comments on commit 8275bbe

Please sign in to comment.