-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move finding Main classes to external sbt run
- Loading branch information
1 parent
f074726
commit f118982
Showing
7 changed files
with
68 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
package dotty.tools.dotc.core | ||
|
||
type EntryPoints = scala.collection.mutable.HashSet[String] | ||
This comment has been minimized.
Sorry, something went wrong. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
50 changes: 50 additions & 0 deletions
50
compiler/src/dotty/tools/dotc/transform/CollectEntryPoints.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package dotty.tools.dotc.transform | ||
|
||
import dotty.tools.dotc.ast.tpd | ||
import dotty.tools.dotc.core.Contexts.Context | ||
import dotty.tools.dotc.core.Types | ||
import dotty.tools.dotc.transform.MegaPhase._ | ||
import dotty.tools.dotc.ast.tpd | ||
import java.io.{File => _} | ||
|
||
import dotty.tools.dotc.core._ | ||
import SymDenotations._ | ||
import Contexts._ | ||
import Types._ | ||
import Symbols._ | ||
import dotty.tools.dotc.util.SourcePosition | ||
import Decorators._ | ||
import StdNames.nme | ||
import dotty.tools.io.JarArchive | ||
|
||
/** | ||
* Small phase to be run to collect main classes and store them in the context. | ||
* The general rule to run this phase is either: | ||
* - The output of compilation is JarArchive and there is no `-Xmain-class` defined | ||
* - The compiler is run from sbt and is forced by flags forcing `ExtractorAPI` | ||
* | ||
* The following flags affect this phase: | ||
* -d path.jar | ||
* -Xmain-class | ||
* -Yforce-sbt-phases | ||
* -Ydump-sbt-inc | ||
*/ | ||
class CollectEntryPoints extends MiniPhase: | ||
def phaseName: String = "Collect entry points" | ||
|
||
override def isRunnable(using Context): Boolean = | ||
def forceRun = (ctx.settings.XmainClass.isDefault && ctx.settings.outputDir.value.isInstanceOf[JarArchive]) || | ||
ctx.settings.YdumpSbtInc.value || | ||
ctx.settings.YforceSbtPhases.value | ||
super.isRunnable && (ctx.sbtCallback != null || forceRun) | ||
|
||
|
||
override def transformTypeDef(tree: tpd.TypeDef)(using Context): tpd.Tree = | ||
ctx.entryPoints ++= getEntryPoint(tree) | ||
tree | ||
|
||
private def getEntryPoint(tree: tpd.TypeDef)(using Context): Option[String] = | ||
val sym = tree.symbol | ||
import dotty.tools.dotc.core.NameOps.stripModuleClassSuffix | ||
val name = sym.fullName.stripModuleClassSuffix.toString | ||
Option.when(sym.isStatic && !sym.is(Flags.Trait) && ctx.platform.hasMainMethod(sym))(name) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
I recommend using an immutable collection, otherwise one needs to be very careful about not reusing the same EntryPoints instance in multiple contexts.