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

[1.x] Generate AbstractZincFile during -sourcepath workflow #1309

Merged
merged 1 commit into from
Oct 11, 2024
Merged
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

package xsbt

import xsbti.{ AnalysisCallback, Severity }
import xsbti.{ AnalysisCallback, AnalysisCallback3, Severity }
import xsbti.compile._

import scala.tools.nsc._
Expand All @@ -20,6 +20,7 @@ import java.nio.file.{ Files, Path }

import scala.reflect.io.PlainFile
import scala.reflect.ReflectAccess._
import scala.reflect.internal.util.BatchSourceFile

/** Defines the interface of the incremental compiler hiding implementation details. */
sealed abstract class CallbackGlobal(
Expand Down Expand Up @@ -78,6 +79,15 @@ sealed class ZincCompiler(settings: Settings, dreporter: DelegatingReporter, out
extends CallbackGlobal(settings, dreporter, output)
with ZincGlobalCompat {

override def getSourceFile(f: AbstractFile): BatchSourceFile = {
val file = (f, callback) match {
case (plainFile: PlainFile, callback3: AnalysisCallback3) =>
AbstractZincFile(callback3.toVirtualFile(plainFile.file.toPath))
case _ => f
}
super.getSourceFile(file)
}

final class ZincRun(compileProgress: CompileProgress) extends Run {
override def informUnitStarting(phase: Phase, unit: CompilationUnit): Unit = {
compileProgress.startUnit(phase.name, unit.source.path)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,17 @@
*/

package xsbti;

import xsbti.compile.analysis.ReadSourceInfos;

import java.nio.file.Path;

/**
* Extension to {@link AnalysisCallback2}.
* Similar to {@link AnalysisCallback2}, it serves as compatibility layer for Scala compilers.
*/
public interface AnalysisCallback3 extends AnalysisCallback2 {
VirtualFile toVirtualFile(Path path);

ReadSourceInfos getSourceInfos();
}
Original file line number Diff line number Diff line change
Expand Up @@ -674,6 +674,8 @@ private final class AnalysisCallback(
()
}

override def toVirtualFile(path: Path): VirtualFile = converter.toVirtualFile(path)

override def problem2(
category: String,
pos: Position,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -795,7 +795,10 @@ case class ProjectStructure(
}
val scalacOptions: List[String] =
Option(map.get("scalac.options")).toList
.flatMap(_.toString.split(" +").toList) ++
.flatMap(_.toString.split(" +").toList.map(_.replace(
"[basedir]",
baseDirectory.toAbsolutePath.toString
))) ++
// for now assume export pipelining for all pipelining subprojects
(if (incOptions.pipelining) List("-Ypickle-java", "-Ypickle-write", earlyOutput.toString)
else Nil)
Expand Down
4 changes: 4 additions & 0 deletions internal/zinc-testing/src/main/scala/xsbti/TestCallback.scala
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,10 @@ class TestCallback extends AnalysisCallback3 {

override def getPickleJarPair = Optional.empty()

override def toVirtualFile(path: Path): VirtualFile = {
throw new UnsupportedOperationException("This method should not be called in tests")
}

override def getSourceInfos: ReadSourceInfos = new TestSourceInfos
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
class B {
def f: A = new A()
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
scalac.options = -sourcepath [basedir]/src/main/scala
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
class A
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
class B {
def f = new A()
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
> compile

$ copy-file changes/B.scala src/main/scala/B.scala
$ touch src/main/scala/A.scala

> compile