File tree Expand file tree Collapse file tree 4 files changed +18
-13
lines changed Expand file tree Collapse file tree 4 files changed +18
-13
lines changed Original file line number Diff line number Diff line change @@ -42,6 +42,9 @@ class GenBCode extends Phase {
4242 superCallsMap.update(sym, old + calls)
4343 }
4444
45+ private val entryPoints = new mutable.HashSet [String ]()
46+ def registerEntryPoint (s : String ): Unit = entryPoints += s
47+
4548 private var myOutput : AbstractFile = _
4649
4750 private def outputDir (using Context ): AbstractFile = {
@@ -63,7 +66,7 @@ class GenBCode extends Phase {
6366 override def runOn (units : List [CompilationUnit ])(using Context ): List [CompilationUnit ] = {
6467 outputDir match
6568 case jar : JarArchive =>
66- updateJarManifestWithMainClass(jar)
69+ updateJarManifestWithMainClass(jar, entryPoints.toList )
6770 case _ =>
6871 try super .runOn(units)
6972 finally outputDir match {
@@ -78,9 +81,9 @@ class GenBCode extends Phase {
7881 }
7982 }
8083
81- private def updateJarManifestWithMainClass (jarArchive : JarArchive )(using Context ): Unit =
84+ private def updateJarManifestWithMainClass (jarArchive : JarArchive , entryPoints : List [ String ] )(using Context ): Unit =
8285 val mainClass = Option .when(! ctx.settings.XmainClass .isDefault)(ctx.settings.XmainClass .value).orElse {
83- ctx. entryPoints.toList. match
86+ entryPoints match
8487 case List (mainClass) =>
8588 Some (mainClass)
8689 case Nil =>
Original file line number Diff line number Diff line change @@ -52,9 +52,8 @@ object Contexts {
5252 private val (notNullInfosLoc, store8) = store7.newLocation[List [NotNullInfo ]]()
5353 private val (importInfoLoc, store9) = store8.newLocation[ImportInfo ]()
5454 private val (typeAssignerLoc, store10) = store9.newLocation[TypeAssigner ](TypeAssigner )
55- private val (entryPointsLoc, store11) = store10.newLocation[EntryPoints ](new EntryPoints )
5655
57- private val initialStore = store11
56+ private val initialStore = store10
5857
5958 /** The current context */
6059 inline def ctx (using ctx : Context ): Context = ctx
@@ -240,9 +239,6 @@ object Contexts {
240239 /** The current type assigner or typer */
241240 def typeAssigner : TypeAssigner = store(typeAssignerLoc)
242241
243- /** The current entry points */
244- def entryPoints : EntryPoints = store(entryPointsLoc)
245-
246242 /** The new implicit references that are introduced by this scope */
247243 protected var implicitsCache : ContextualImplicits = null
248244 def implicits : ContextualImplicits = {
Load Diff This file was deleted.
Original file line number Diff line number Diff line change @@ -4,18 +4,19 @@ import dotty.tools.dotc.ast.tpd
44import dotty .tools .dotc .core .Contexts .Context
55import dotty .tools .dotc .core .Types
66import dotty .tools .dotc .transform .MegaPhase ._
7- import dotty .tools .dotc .ast .tpd
87import java .io .{File => _ }
98
109import dotty .tools .dotc .core ._
1110import SymDenotations ._
1211import Contexts ._
1312import Types ._
1413import Symbols ._
14+ import Phases ._
1515import dotty .tools .dotc .util .SourcePosition
1616import Decorators ._
1717import StdNames .nme
1818import dotty .tools .io .JarArchive
19+ import dotty .tools .backend .jvm .GenBCode
1920
2021/**
2122 * Small phase to be run to collect main classes and store them in the context.
@@ -40,11 +41,19 @@ class CollectEntryPoints extends MiniPhase:
4041
4142
4243 override def transformTypeDef (tree : tpd.TypeDef )(using Context ): tpd.Tree =
43- ctx.entryPoints ++= getEntryPoint(tree)
44+ getEntryPoint(tree).map(registerEntryPoint )
4445 tree
4546
4647 private def getEntryPoint (tree : tpd.TypeDef )(using Context ): Option [String ] =
4748 val sym = tree.symbol
4849 import dotty .tools .dotc .core .NameOps .stripModuleClassSuffix
4950 val name = sym.fullName.stripModuleClassSuffix.toString
5051 Option .when(sym.isStatic && ! sym.is(Flags .Trait ) && ctx.platform.hasMainMethod(sym))(name)
52+
53+ private def registerEntryPoint (s : String )(using Context ) = {
54+ genBCodePhase match {
55+ case genBCodePhase : GenBCode =>
56+ genBCodePhase.registerEntryPoint(s)
57+ case _ =>
58+ }
59+ }
You can’t perform that action at this time.
0 commit comments