@@ -49,52 +49,51 @@ 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- val collector = new ExtractDependenciesCollector
65- collector.traverse(unit.tpdTree)
66-
67- if (dumpInc) {
68- val deps = collector.dependencies.map(_.toString).toArray[Object ]
69- val names = collector.usedNames.map { case (clazz, names) => s " $clazz: $names" }.toArray[Object ]
70- Arrays .sort(deps)
71- Arrays .sort(names)
72-
73- val pw = io.File (unit.source.file.jpath).changeExtension(" inc" ).toFile.printWriter()
74- // val pw = Console.out
75- try {
76- pw.println(" Used Names:" )
77- pw.println(" ===========" )
78- names.foreach(pw.println)
79- pw.println()
80- pw.println(" Dependencies:" )
81- pw.println(" =============" )
82- deps.foreach(pw.println)
83- } finally pw.close()
84- }
85-
86- if (ctx.sbtCallback != null ) {
87- collector.usedNames.foreach {
88- case (clazz, usedNames) =>
89- val className = classNameAsString(clazz)
90- usedNames.names.foreach {
91- case (usedName, scopes) =>
92- ctx.sbtCallback.usedName(className, usedName.toString, scopes)
93- }
94- }
64+ val collector = new ExtractDependenciesCollector
65+ collector.traverse(unit.tpdTree)
66+
67+ if (ctx.settings.YdumpSbtInc .value) {
68+ val deps = collector.dependencies.map(_.toString).toArray[Object ]
69+ val names = collector.usedNames.map { case (clazz, names) => s " $clazz: $names" }.toArray[Object ]
70+ Arrays .sort(deps)
71+ Arrays .sort(names)
72+
73+ val pw = io.File (unit.source.file.jpath).changeExtension(" inc" ).toFile.printWriter()
74+ // val pw = Console.out
75+ try {
76+ pw.println(" Used Names:" )
77+ pw.println(" ===========" )
78+ names.foreach(pw.println)
79+ pw.println()
80+ pw.println(" Dependencies:" )
81+ pw.println(" =============" )
82+ deps.foreach(pw.println)
83+ } finally pw.close()
84+ }
9585
96- collector.dependencies.foreach(recordDependency)
86+ if (ctx.sbtCallback != null ) {
87+ collector.usedNames.foreach {
88+ case (clazz, usedNames) =>
89+ val className = classNameAsString(clazz)
90+ usedNames.names.foreach {
91+ case (usedName, scopes) =>
92+ ctx.sbtCallback.usedName(className, usedName.toString, scopes)
93+ }
9794 }
95+
96+ collector.dependencies.foreach(recordDependency)
9897 }
9998 }
10099
0 commit comments