Skip to content

Commit cce1d81

Browse files
committed
Use Phase::isRunnable infrastructure in sbt phases
1 parent bc98d79 commit cce1d81

File tree

2 files changed

+14
-10
lines changed

2 files changed

+14
-10
lines changed

compiler/src/dotty/tools/dotc/sbt/ExtractAPI.scala

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,11 @@ import scala.collection.mutable
4141
class ExtractAPI extends Phase {
4242
override def phaseName: String = "sbt-api"
4343

44+
override def isRunnable(implicit ctx: Context): Boolean = {
45+
def forceRun = ctx.settings.YdumpSbtInc.value || ctx.settings.YforceSbtPhases.value
46+
super.isRunnable && (ctx.sbtCallback != null || forceRun)
47+
}
48+
4449
// SuperAccessors need to be part of the API (see the scripted test
4550
// `trait-super` for an example where this matters), this is only the case
4651
// after `PostTyper` (unlike `ExtractDependencies`, the simplication to trees
@@ -50,9 +55,7 @@ class ExtractAPI extends Phase {
5055

5156
override def run(implicit ctx: Context): Unit = {
5257
val unit = ctx.compilationUnit
53-
val dumpInc = ctx.settings.YdumpSbtInc.value
54-
val forceRun = dumpInc || ctx.settings.YforceSbtPhases.value
55-
if ((ctx.sbtCallback != null || forceRun) && !unit.isJava) {
58+
if (!unit.isJava) {
5659
val sourceFile = unit.source.file
5760
if (ctx.sbtCallback != null)
5861
ctx.sbtCallback.startSource(sourceFile.file)
@@ -61,7 +64,7 @@ class ExtractAPI extends Phase {
6164
val classes = apiTraverser.apiSource(unit.tpdTree)
6265
val mainClasses = apiTraverser.mainClasses
6366

64-
if (dumpInc) {
67+
if (ctx.settings.YdumpSbtInc.value) {
6568
// Append to existing file that should have been created by ExtractDependencies
6669
val pw = new PrintWriter(File(sourceFile.jpath).changeExtension("inc").toFile
6770
.bufferedWriter(append = true), true)

compiler/src/dotty/tools/dotc/sbt/ExtractDependencies.scala

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -49,22 +49,23 @@ class ExtractDependencies extends Phase {
4949

5050
override def phaseName: String = "sbt-deps"
5151

52+
override def isRunnable(implicit ctx: Context): Boolean = {
53+
def forceRun = ctx.settings.YdumpSbtInc.value || ctx.settings.YforceSbtPhases.value
54+
super.isRunnable && (ctx.sbtCallback != null || forceRun)
55+
}
56+
5257
// This phase should be run directly after `Frontend`, if it is run after
5358
// `PostTyper`, some dependencies will be lost because trees get simplified.
5459
// See the scripted test `constants` for an example where this matters.
5560
// TODO: Add a `Phase#runsBefore` method ?
5661

5762
override def run(implicit ctx: Context): Unit = {
5863
val unit = ctx.compilationUnit
59-
val dumpInc = ctx.settings.YdumpSbtInc.value
60-
val forceRun = dumpInc || ctx.settings.YforceSbtPhases.value
61-
val shouldRun = !unit.isJava && (ctx.sbtCallback != null || forceRun)
62-
63-
if (shouldRun) {
64+
if (!unit.isJava) {
6465
val collector = new ExtractDependenciesCollector
6566
collector.traverse(unit.tpdTree)
6667

67-
if (dumpInc) {
68+
if (ctx.settings.YdumpSbtInc.value) {
6869
val deps = collector.dependencies.map(_.toString).toArray[Object]
6970
val names = collector.usedNames.map { case (clazz, names) => s"$clazz: $names" }.toArray[Object]
7071
Arrays.sort(deps)

0 commit comments

Comments
 (0)