Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Disable ExtractSemanticDB phase when writing to output directory defined as JAR. #16790

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 12 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.{AbstractFile, JarArchive}

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

override def isRunnable(using Context) =
super.isRunnable && ctx.settings.Xsemanticdb.value
import ExtractSemanticDB.{semanticdbTarget, outputDirectory}
def writesToOutputJar = semanticdbTarget.isEmpty && 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 @@ -475,21 +478,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): AbstractFile = 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