Skip to content

Commit

Permalink
Add support for -Xshow-phases (#1314)
Browse files Browse the repository at this point in the history
Fix & Unit Test
  • Loading branch information
Friendseeker authored Dec 24, 2023
1 parent 1c809a6 commit c68a4c2
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,8 @@ 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 @@ -116,6 +118,8 @@ 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 @@ -136,13 +140,18 @@ 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
Original file line number Diff line number Diff line change
Expand Up @@ -152,14 +152,14 @@ private final class CachedCompiler0(
// cast down to AnalysisCallback2
val callback2 = callback.asInstanceOf[xsbti.AnalysisCallback2]

compiler.set(callback, underlyingReporter)
if (command.shouldStopWithInfo) {
underlyingReporter.info(null, command.getInfoMessage(compiler), true)
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
14 changes: 14 additions & 0 deletions zinc/src/test/scala/sbt/inc/IncrementalCompilerSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -211,4 +211,18 @@ class IncrementalCompilerSpec extends BaseCompilerSpec {
comp.close()
}
}

it should "not throw NullPointerException when passing -Xshow-phases to scalac" in withTmpDir {
tmp =>
val comp = ProjectSetup.simple(
tmp.toPath,
Seq(SourceFiles.Good),
Seq("-Xshow-phases")
).createCompiler()
try {
assertThrows[CompileFailed] {
comp.doCompile()
}
} finally comp.close()
}
}
8 changes: 6 additions & 2 deletions zinc/src/test/scala/sbt/inc/TestProjectSetup.scala
Original file line number Diff line number Diff line change
Expand Up @@ -148,9 +148,13 @@ case class CompilerSetup(
case class ProjectPaths(baseDir: Path) {}

object ProjectSetup {
def simple(baseDir: Path, classes: Seq[String]): ProjectSetup = {
def simple(
baseDir: Path,
classes: Seq[String],
scalacOptions: Seq[String] = Nil
): ProjectSetup = {
val sources = Map(Paths.get("src") -> classes.map(Paths.get(_)))
ProjectSetup(VirtualSubproject(baseDir), sources, Nil, Map.empty)
ProjectSetup(VirtualSubproject(baseDir), sources, Nil, Map.empty, scalacOptions = scalacOptions)
}
}

Expand Down

0 comments on commit c68a4c2

Please sign in to comment.