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 {
42
42
superCallsMap.update(sym, old + calls)
43
43
}
44
44
45
+ private val entryPoints = new mutable.HashSet [String ]()
46
+ def registerEntryPoint (s : String ): Unit = entryPoints += s
47
+
45
48
private var myOutput : AbstractFile = _
46
49
47
50
private def outputDir (using Context ): AbstractFile = {
@@ -63,7 +66,7 @@ class GenBCode extends Phase {
63
66
override def runOn (units : List [CompilationUnit ])(using Context ): List [CompilationUnit ] = {
64
67
outputDir match
65
68
case jar : JarArchive =>
66
- updateJarManifestWithMainClass(jar)
69
+ updateJarManifestWithMainClass(jar, entryPoints.toList )
67
70
case _ =>
68
71
try super .runOn(units)
69
72
finally outputDir match {
@@ -78,9 +81,9 @@ class GenBCode extends Phase {
78
81
}
79
82
}
80
83
81
- private def updateJarManifestWithMainClass (jarArchive : JarArchive )(using Context ): Unit =
84
+ private def updateJarManifestWithMainClass (jarArchive : JarArchive , entryPoints : List [ String ] )(using Context ): Unit =
82
85
val mainClass = Option .when(! ctx.settings.XmainClass .isDefault)(ctx.settings.XmainClass .value).orElse {
83
- ctx. entryPoints.toList. match
86
+ entryPoints match
84
87
case List (mainClass) =>
85
88
Some (mainClass)
86
89
case Nil =>
Original file line number Diff line number Diff line change @@ -52,9 +52,8 @@ object Contexts {
52
52
private val (notNullInfosLoc, store8) = store7.newLocation[List [NotNullInfo ]]()
53
53
private val (importInfoLoc, store9) = store8.newLocation[ImportInfo ]()
54
54
private val (typeAssignerLoc, store10) = store9.newLocation[TypeAssigner ](TypeAssigner )
55
- private val (entryPointsLoc, store11) = store10.newLocation[EntryPoints ](new EntryPoints )
56
55
57
- private val initialStore = store11
56
+ private val initialStore = store10
58
57
59
58
/** The current context */
60
59
inline def ctx (using ctx : Context ): Context = ctx
@@ -240,9 +239,6 @@ object Contexts {
240
239
/** The current type assigner or typer */
241
240
def typeAssigner : TypeAssigner = store(typeAssignerLoc)
242
241
243
- /** The current entry points */
244
- def entryPoints : EntryPoints = store(entryPointsLoc)
245
-
246
242
/** The new implicit references that are introduced by this scope */
247
243
protected var implicitsCache : ContextualImplicits = null
248
244
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
4
4
import dotty .tools .dotc .core .Contexts .Context
5
5
import dotty .tools .dotc .core .Types
6
6
import dotty .tools .dotc .transform .MegaPhase ._
7
- import dotty .tools .dotc .ast .tpd
8
7
import java .io .{File => _ }
9
8
10
9
import dotty .tools .dotc .core ._
11
10
import SymDenotations ._
12
11
import Contexts ._
13
12
import Types ._
14
13
import Symbols ._
14
+ import Phases ._
15
15
import dotty .tools .dotc .util .SourcePosition
16
16
import Decorators ._
17
17
import StdNames .nme
18
18
import dotty .tools .io .JarArchive
19
+ import dotty .tools .backend .jvm .GenBCode
19
20
20
21
/**
21
22
* Small phase to be run to collect main classes and store them in the context.
@@ -40,11 +41,19 @@ class CollectEntryPoints extends MiniPhase:
40
41
41
42
42
43
override def transformTypeDef (tree : tpd.TypeDef )(using Context ): tpd.Tree =
43
- ctx.entryPoints ++= getEntryPoint(tree)
44
+ getEntryPoint(tree).map(registerEntryPoint )
44
45
tree
45
46
46
47
private def getEntryPoint (tree : tpd.TypeDef )(using Context ): Option [String ] =
47
48
val sym = tree.symbol
48
49
import dotty .tools .dotc .core .NameOps .stripModuleClassSuffix
49
50
val name = sym.fullName.stripModuleClassSuffix.toString
50
51
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