Skip to content

Commit

Permalink
Merge pull request #10643 from Friendseeker/show-phases-fix
Browse files Browse the repository at this point in the history
Add support for `-Vphases` when incremental compilation is enabled
  • Loading branch information
lrytz committed Jan 5, 2024
2 parents c2a8bba + 9549984 commit fc3c3d5
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 3 deletions.
6 changes: 6 additions & 0 deletions src/sbt-bridge/scala/tools/xsbt/CallbackGlobal.scala
Expand Up @@ -106,6 +106,7 @@ sealed class ZincCompiler(settings: Settings, dreporter: DelegatingReporter, out
val analyzer = new Analyzer(global)
def newPhase(prev: Phase) = analyzer.newPhase(prev)
def name = phaseName
def description = "analyze the generated class files and map them to sources"
}

/** Phase that extracts dependency information */
Expand All @@ -120,6 +121,7 @@ sealed class ZincCompiler(settings: Settings, dreporter: DelegatingReporter, out
val dependency = new Dependency(global)
def newPhase(prev: Phase) = dependency.newPhase(prev)
def name = phaseName
def description = "extract dependency information"
}

/**
Expand All @@ -140,13 +142,17 @@ sealed class ZincCompiler(settings: Settings, dreporter: DelegatingReporter, out
val api = new API(global)
def newPhase(prev: Phase) = api.newPhase(prev)
def name = phaseName
def description = "construct a representation of the public API"
}

override lazy val phaseDescriptors = {
phasesSet += sbtAnalyzer
phasesDescMap(sbtAnalyzer) = sbtAnalyzer.description
if (callback.enabled()) {
phasesSet += sbtDependency
phasesDescMap(sbtDependency) = sbtDependency.description
phasesSet += apiExtractor
phasesDescMap(apiExtractor) = apiExtractor.description
}
this.computePhaseDescriptors
}
Expand Down
2 changes: 1 addition & 1 deletion src/sbt-bridge/scala/tools/xsbt/CompilerBridge.scala
Expand Up @@ -163,14 +163,14 @@ private final class CachedCompiler0(
if (callback2 != null) callback2.problem2(p.category, p.position, p.message, p.severity, true, p.rendered, p.diagnosticCode, p.diagnosticRelatedInformation, p.actions)
else callback.problem(p.category, p.position, p.message, p.severity, true)

compiler.set(callback, underlyingReporter)
if (command.shouldStopWithInfo) {
underlyingReporter.echo(command.getInfoMessage(compiler))
throw new InterfaceCompileFailed(args, Array(), StopInfoError)
}

if (noErrors(underlyingReporter)) {
debug(log, prettyPrintCompilationArguments(args))
compiler.set(callback, underlyingReporter)
val run = new compiler.ZincRun(compileProgress)

run.compileFiles(sources)
Expand Down
19 changes: 19 additions & 0 deletions test/junit/scala/tools/xsbt/BasicBridgeTest.scala
@@ -1,6 +1,9 @@
package scala.tools.xsbt

import org.junit.Test
import xsbti.CompileFailed

import scala.tools.testkit.AssertUtil.assertThrown

class BasicBridgeTest extends BridgeTesting {
@Test
Expand All @@ -20,4 +23,20 @@ class BasicBridgeTest extends BridgeTesting {
assert(t.exists)
}
}

@Test
def noNPEonVphases(): Unit = withTemporaryDirectory { tempDir =>
val compiler = mkCompiler
assertThrown[CompileFailed](
_.toString.contains("Compiler option supplied that disabled Zinc compilation"))(
compiler.run(
sources = Array.empty,
changes = emptyChanges,
options = Array("-usejavacp", "-Vphases"),
output = new TestOutput(tempDir),
callback = new TestCallback,
delegate = mkReporter,
progress = ignoreProgress,
log = TestLogger))
}
}
4 changes: 2 additions & 2 deletions test/junit/scala/tools/xsbt/BridgeTesting.scala
Expand Up @@ -30,14 +30,14 @@ class BridgeTesting {

def mkScaladoc: ScaladocBridge = new ScaladocBridge()

private val emptyChanges: DependencyChanges = new DependencyChanges {
val emptyChanges: DependencyChanges = new DependencyChanges {
override val modifiedLibraries = new Array[VirtualFileRef](0)
override val modifiedBinaries = new Array[File](0)
override val modifiedClasses = new Array[String](0)
override def isEmpty = true
}

private val ignoreProgress = new CompileProgress { }
val ignoreProgress = new CompileProgress { }

def compileSrcs(baseDir: Path, srcs: String*): (Seq[VirtualFile], TestCallback) =
compileSrcs(baseDir, mkReporter, srcs: _*)
Expand Down

0 comments on commit fc3c3d5

Please sign in to comment.