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

Add support for -Xshow-phases #1314

Merged
merged 3 commits into from
Dec 24, 2023
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 @@ -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