Skip to content

Commit e29e82a

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 3858a23 commit e29e82a

File tree

2 files changed

+32
-6
lines changed

2 files changed

+32
-6
lines changed

project/Build.scala

+31-4
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.
@@ -556,7 +583,7 @@ object Build {
556583
// get libraries onboard
557584
libraryDependencies ++= Seq(
558585
"org.scala-lang.modules" % "scala-asm" % "9.5.0-scala-1", // used by the backend
559-
Dependencies.newCompilerInterface, // we stick to the old version to avoid deprecation warnings
586+
Dependencies.compilerInterface,
560587
"org.jline" % "jline-reader" % "3.19.0", // used by the REPL
561588
"org.jline" % "jline-terminal" % "3.19.0",
562589
"org.jline" % "jline-terminal-jna" % "3.19.0", // needed for Windows
@@ -1140,8 +1167,7 @@ object Build {
11401167
// when sbt reads the settings.
11411168
Test / test := (LocalProject("scala3-sbt-bridge-tests") / Test / test).value,
11421169

1143-
// The `newCompilerInterface` is backward compatible with the `oldCompilerInterface`
1144-
libraryDependencies += Dependencies.newCompilerInterface % Provided
1170+
libraryDependencies += Dependencies.compilerInterface % Provided
11451171
)
11461172

11471173
// We use a separate project for the bridge tests since they can only be run
@@ -1225,7 +1251,8 @@ object Build {
12251251
val mtagsSharedSources = (targetDir ** "*.scala").get.toSet
12261252
mtagsSharedSources.foreach(f => {
12271253
val lines = IO.readLines(f)
1228-
IO.writeLines(f, insertUnsafeNullsImport(lines))
1254+
val substitutions = (replaceProtobuf(_)) andThen (insertUnsafeNullsImport(_))
1255+
IO.writeLines(f, substitutions(lines))
12291256
})
12301257
mtagsSharedSources
12311258
} (Set(mtagsSharedSourceJar)).toSeq

project/Dependencies.scala

+1-2
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,5 @@ object Dependencies {
2828
"com.vladsch.flexmark" % "flexmark-ext-yaml-front-matter" % flexmarkVersion,
2929
)
3030

31-
val newCompilerInterface = "org.scala-sbt" % "compiler-interface" % "1.9.0"
32-
// val oldCompilerInterface = "org.scala-sbt" % "compiler-interface" % "1.3.5"
31+
val compilerInterface = "org.scala-sbt" % "compiler-interface" % "1.9.0"
3332
}

0 commit comments

Comments
 (0)