Skip to content

Commit 7253523

Browse files
bishaboshaKordyjan
authored andcommitted
use compiler impl of protobuf for presentation compiler
zinc 1.4 removes the dependency on protobuf-java, so fails to compile mtags-shared due to the now missing transitive dependency. The compiler implements protobuf streams for semanticdb, so reuse it in the source generator for mtags-shared. [Cherry-picked 34a5e45]
1 parent 5c6b6de commit 7253523

File tree

1 file changed

+29
-1
lines changed

1 file changed

+29
-1
lines changed

project/Build.scala

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -525,6 +525,33 @@ object Build {
525525
recur(lines, false)
526526
}
527527

528+
/** replace imports of `com.google.protobuf.*` with compiler implemented version */
529+
def replaceProtobuf(lines: List[String]): List[String] = {
530+
def recur(ls: List[String]): List[String] = ls match {
531+
case l :: rest =>
532+
val lt = l.trim()
533+
if (lt.isEmpty || lt.startsWith("package ") || lt.startsWith("import ")) {
534+
val newLine =
535+
if (lt.startsWith("import com.google.protobuf.")) {
536+
if (lt == "import com.google.protobuf.CodedInputStream") {
537+
"import dotty.tools.dotc.semanticdb.internal.SemanticdbInputStream as CodedInputStream"
538+
} else if (lt == "import com.google.protobuf.CodedOutputStream") {
539+
"import dotty.tools.dotc.semanticdb.internal.SemanticdbOutputStream as CodedOutputStream"
540+
} else {
541+
l
542+
}
543+
} else {
544+
l
545+
}
546+
newLine :: recur(rest)
547+
} else {
548+
ls // don't check rest of file
549+
}
550+
case _ => ls
551+
}
552+
recur(lines)
553+
}
554+
528555
// Settings shared between scala3-compiler and scala3-compiler-bootstrapped
529556
lazy val commonDottyCompilerSettings = Seq(
530557
// Generate compiler.properties, used by sbt
@@ -1135,7 +1162,8 @@ object Build {
11351162
val mtagsSharedSources = (targetDir ** "*.scala").get.toSet
11361163
mtagsSharedSources.foreach(f => {
11371164
val lines = IO.readLines(f)
1138-
IO.writeLines(f, insertUnsafeNullsImport(lines))
1165+
val substitutions = (replaceProtobuf(_)) andThen (insertUnsafeNullsImport(_))
1166+
IO.writeLines(f, substitutions(lines))
11391167
})
11401168
mtagsSharedSources
11411169
} (Set(mtagsSharedSourceJar)).toSeq

0 commit comments

Comments
 (0)