Skip to content

Commit

Permalink
Merge pull request #1309 from Friendseeker/plainfile-match-fail
Browse files Browse the repository at this point in the history
[1.x] Generate `AbstractZincFile` during `-sourcepath` workflow
  • Loading branch information
eed3si9n authored Oct 11, 2024
2 parents 7aa92cb + 7696f6c commit f42f7d6
Show file tree
Hide file tree
Showing 10 changed files with 40 additions and 2 deletions.
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

0 comments on commit f42f7d6

Please sign in to comment.