Skip to content

Commit 16b91ba

Browse files
committed
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.
1 parent c074a0e commit 16b91ba

File tree

1 file changed

+29
-1
lines changed

1 file changed

+29
-1
lines changed

project/Build.scala

+29-1
Original file line numberDiff line numberDiff line change
@@ -527,6 +527,33 @@ object Build {
527527
recur(lines, false)
528528
}
529529

530+
/** replace imports of `com.google.protobuf.*` with compiler implemented version */
531+
def replaceProtobuf(lines: List[String]): List[String] = {
532+
def recur(ls: List[String]): List[String] = ls match {
533+
case l :: rest =>
534+
val lt = l.trim()
535+
if (lt.isEmpty || lt.startsWith("package ") || lt.startsWith("import ")) {
536+
val newLine =
537+
if (lt.startsWith("import com.google.protobuf.")) {
538+
if (lt == "import com.google.protobuf.CodedInputStream") {
539+
"import dotty.tools.dotc.semanticdb.internal.SemanticdbInputStream as CodedInputStream"
540+
} else if (lt == "import com.google.protobuf.CodedOutputStream") {
541+
"import dotty.tools.dotc.semanticdb.internal.SemanticdbOutputStream as CodedOutputStream"
542+
} else {
543+
l
544+
}
545+
} else {
546+
l
547+
}
548+
newLine :: recur(rest)
549+
} else {
550+
ls // don't check rest of file
551+
}
552+
case _ => ls
553+
}
554+
recur(lines)
555+
}
556+
530557
// Settings shared between scala3-compiler and scala3-compiler-bootstrapped
531558
lazy val commonDottyCompilerSettings = Seq(
532559
// Note: bench/profiles/projects.yml should be updated accordingly.
@@ -1224,7 +1251,8 @@ object Build {
12241251
val mtagsSharedSources = (targetDir ** "*.scala").get.toSet
12251252
mtagsSharedSources.foreach(f => {
12261253
val lines = IO.readLines(f)
1227-
IO.writeLines(f, insertUnsafeNullsImport(lines))
1254+
val substitutions = (replaceProtobuf(_)) andThen (insertUnsafeNullsImport(_))
1255+
IO.writeLines(f, substitutions(lines))
12281256
})
12291257
mtagsSharedSources
12301258
} (Set(mtagsSharedSourceJar)).toSeq

0 commit comments

Comments
 (0)