-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Fix executable jars #13263
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Fix executable jars #13263
Changes from 6 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
0421117
Add generating jars with Manifest for scalac
BarkingBad f074726
Fix making executable JARs from scala compiler output
BarkingBad f118982
Move finding Main classes to external sbt run
BarkingBad 7044a61
Restore changes for ExtractAPI. Move miniphase to transformers batch.
BarkingBad 418a84c
Fix unapply for arrays after erasure
BarkingBad 50486af
Refactor collecting entry points. Remove them from context and pass t…
BarkingBad 9cde003
Remove spare checks from CollectEntryPoints
BarkingBad File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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
59 changes: 59 additions & 0 deletions
59
compiler/src/dotty/tools/dotc/transform/CollectEntryPoints.scala
This file contains hidden or 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,59 @@ | ||
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 java.io.{File => _} | ||
|
||
import dotty.tools.dotc.core._ | ||
import SymDenotations._ | ||
import Contexts._ | ||
import Types._ | ||
import Symbols._ | ||
import Phases._ | ||
import dotty.tools.dotc.util.SourcePosition | ||
import Decorators._ | ||
import StdNames.nme | ||
import dotty.tools.io.JarArchive | ||
import dotty.tools.backend.jvm.GenBCode | ||
|
||
/** | ||
* 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 = | ||
getEntryPoint(tree).map(registerEntryPoint) | ||
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) | ||
|
||
private def registerEntryPoint(s: String)(using Context) = { | ||
genBCodePhase match { | ||
case genBCodePhase: GenBCode => | ||
genBCodePhase.registerEntryPoint(s) | ||
case _ => | ||
} | ||
} |
This file contains hidden or 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 hidden or 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like this should be removed along with any code related to sbt in this phase since it no longer occurs before ExtractAPI.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed