in maven-plugin/src/main/scala/org/apache/pekko/grpc/maven/AbstractGenerateMojo.scala [243:297]
private[this] def compile(
protocCommand: Seq[String] => Int,
schemas: Set[File],
protoDir: File,
protocOptions: Seq[String],
targets: Seq[Target]): Unit = {
// Sort by the length of path names to ensure that we have parent directories before sub directories
val generatedTargets = targets
.map { t =>
if (!t.outputPath.isAbsolute()) {
t.copy(outputPath = new File(t.outputPath.getAbsolutePath).toPath().normalize().toFile())
} else {
t
}
}
.sortBy(_.outputPath.getAbsolutePath.length)
generatedTargets.foreach(_.outputPath.mkdirs())
if (schemas.nonEmpty && generatedTargets.nonEmpty) {
getLog.info(
"Compiling %d protobuf files to %s".format(schemas.size, generatedTargets.map(_.outputPath).mkString(",")))
schemas.foreach { schema => buildContext.removeMessages(schema) }
getLog.debug("Compiling schemas [%s]".format(schemas.mkString(",")))
getLog.debug("protoc options: %s".format(protocOptions.mkString(",")))
getLog.info("Compiling protobuf")
val (out, err, exitCode) = captureStdOutAndErr {
executeProtoc(protocCommand, schemas, protoDir, protocOptions, generatedTargets)
}
if (exitCode != 0) {
err.split("\n\r").map(_.trim).map(parseError).foreach {
case Left(ProtocError(file, line, pos, message)) =>
buildContext.addMessage(
new File(protoDir, file),
line,
pos,
message,
BuildContext.SEVERITY_ERROR,
new RuntimeException("protoc compilation failed") with NoStackTrace)
case Right(otherError) =>
sys.error(s"protoc exit code $exitCode: $otherError")
}
} else {
if (getLog.isDebugEnabled) {
getLog.debug("protoc output: " + out)
getLog.debug("protoc stderr: " + err)
}
generatedTargets.foreach { dir =>
getLog.info("Protoc target directory: %s".format(dir.outputPath.getAbsolutePath))
buildContext.refresh(dir.outputPath)
}
}
} else if (schemas.nonEmpty && generatedTargets.isEmpty) {
getLog.info("Protobufs files found, but PB.targets is empty.")
}
}