Skip to content

Commit 4b5c077

Browse files
committed
Don't create semanticdb files when writing to JAR
1 parent f20b840 commit 4b5c077

File tree

1 file changed

+13
-8
lines changed

1 file changed

+13
-8
lines changed

compiler/src/dotty/tools/dotc/semanticdb/ExtractSemanticDB.scala

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import scala.annotation.{ threadUnsafe => tu, tailrec }
2424
import scala.PartialFunction.condOpt
2525

2626
import dotty.tools.dotc.{semanticdb => s}
27+
import dotty.tools.io.JarArchive
2728

2829
/** Extract symbol references and uses to semanticdb files.
2930
* See https://scalameta.org/docs/semanticdb/specification.html#symbol-1
@@ -38,7 +39,10 @@ class ExtractSemanticDB extends Phase:
3839
override val description: String = ExtractSemanticDB.description
3940

4041
override def isRunnable(using Context) =
41-
super.isRunnable && ctx.settings.Xsemanticdb.value
42+
def writesToOutputJar =
43+
ExtractSemanticDB.semanticdbTarget.isEmpty &&
44+
ExtractSemanticDB.outputDirectory.isInstanceOf[JarArchive]
45+
super.isRunnable && ctx.settings.Xsemanticdb.value && !writesToOutputJar
4246

4347
// Check not needed since it does not transform trees
4448
override def isCheckable: Boolean = false
@@ -473,21 +477,22 @@ object ExtractSemanticDB:
473477
val name: String = "extractSemanticDB"
474478
val description: String = "extract info into .semanticdb files"
475479

480+
private def semanticdbTarget(using Context): Option[Path] =
481+
Option(ctx.settings.semanticdbTarget.value)
482+
.filterNot(_.isEmpty)
483+
.map(Paths.get(_))
484+
485+
private def outputDirectory(using Context) = ctx.settings.outputDir.value
486+
476487
def write(
477488
source: SourceFile,
478489
occurrences: List[SymbolOccurrence],
479490
symbolInfos: List[SymbolInformation],
480491
synthetics: List[Synthetic],
481492
)(using Context): Unit =
482493
def absolutePath(path: Path): Path = path.toAbsolutePath.normalize
483-
val semanticdbTarget =
484-
val semanticdbTargetSetting = ctx.settings.semanticdbTarget.value
485-
absolutePath(
486-
if semanticdbTargetSetting.isEmpty then ctx.settings.outputDir.value.jpath
487-
else Paths.get(semanticdbTargetSetting)
488-
)
489494
val relPath = SourceFile.relativePath(source, ctx.settings.sourceroot.value)
490-
val outpath = semanticdbTarget
495+
val outpath = absolutePath(semanticdbTarget.getOrElse(outputDirectory.jpath))
491496
.resolve("META-INF")
492497
.resolve("semanticdb")
493498
.resolve(relPath)

0 commit comments

Comments
 (0)