Skip to content

Commit

Permalink
Don't create semanticdb files when writing to JAR
Browse files Browse the repository at this point in the history
  • Loading branch information
WojciechMazur committed Aug 1, 2022
1 parent 6aa7ee0 commit cc4acd3
Showing 1 changed file with 13 additions and 8 deletions.
21 changes: 13 additions & 8 deletions compiler/src/dotty/tools/dotc/semanticdb/ExtractSemanticDB.scala
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import scala.annotation.{ threadUnsafe => tu, tailrec }
import scala.PartialFunction.condOpt

import dotty.tools.dotc.{semanticdb => s}
import dotty.tools.io.JarArchive

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

override def isRunnable(using Context) =
super.isRunnable && ctx.settings.Xsemanticdb.value
def writesToOutputJar =
ExtractSemanticDB.semanticdbTarget.isEmpty &&
ExtractSemanticDB.outputDirectory.isInstanceOf[JarArchive]
super.isRunnable && ctx.settings.Xsemanticdb.value && !writesToOutputJar

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

private def semanticdbTarget(using Context): Option[Path] =
Option(ctx.settings.semanticdbTarget.value)
.filterNot(_.isEmpty)
.map(Paths.get(_))

private def outputDirectory(using Context) = ctx.settings.outputDir.value

def write(
source: SourceFile,
occurrences: List[SymbolOccurrence],
symbolInfos: List[SymbolInformation],
synthetics: List[Synthetic],
)(using Context): Unit =
def absolutePath(path: Path): Path = path.toAbsolutePath.normalize
val semanticdbTarget =
val semanticdbTargetSetting = ctx.settings.semanticdbTarget.value
absolutePath(
if semanticdbTargetSetting.isEmpty then ctx.settings.outputDir.value.jpath
else Paths.get(semanticdbTargetSetting)
)
val relPath = SourceFile.relativePath(source, ctx.settings.sourceroot.value)
val outpath = semanticdbTarget
val outpath = absolutePath(semanticdbTarget.getOrElse(outputDirectory.jpath))
.resolve("META-INF")
.resolve("semanticdb")
.resolve(relPath)
Expand Down

0 comments on commit cc4acd3

Please sign in to comment.