-
-
Notifications
You must be signed in to change notification settings - Fork 377
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
Break out AssemblyModule
from JavaModule
, move launcher
into RunModule
#4301
Merged
Merged
Changes from all commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
e2fbb11
wip
lihaoyi 499a527
.
lihaoyi 9078540
.
lihaoyi af95bae
wip
lihaoyi 73aa6ac
wip
lihaoyi 253f3e0
wip
lihaoyi d7053c8
Merge branch 'main' into assembly-module
lihaoyi 91f4a54
wip
lihaoyi c81c83b
wip
lihaoyi 311bc2f
mergbe
lihaoyi b029e37
.
lihaoyi 7a01060
.
lihaoyi 1e997cf
fix-test
lihaoyi 34d2130
.
lihaoyi d192697
add -XX:+HeapDumpOnOutOfMemoryError
lihaoyi 7adf383
.
lihaoyi aefbe9e
Merge branch 'simple-test-bootstrap' into assembly-module
lihaoyi 75af694
.
lihaoyi 44dbc37
Merge branch 'main' into assembly-module
lihaoyi 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 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
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,136 @@ | ||
package mill.scalalib | ||
|
||
import mill.api.Loose.Agg | ||
import mill.api.{JarManifest, PathRef, Result} | ||
import mill.define.{Target => T, _} | ||
import mill.util.Jvm | ||
|
||
import scala.annotation.nowarn | ||
|
||
/** | ||
* Core configuration required to compile a single Java compilation target | ||
*/ | ||
trait AssemblyModule extends mill.Module { | ||
outer => | ||
|
||
def finalMainClassOpt: T[Either[String, String]] | ||
|
||
def forkArgs: T[Seq[String]] | ||
|
||
/** | ||
* Creates a manifest representation which can be modified or replaced | ||
* The default implementation just adds the `Manifest-Version`, `Main-Class` and `Created-By` attributes | ||
*/ | ||
def manifest: T[JarManifest] = Task { manifest0() } | ||
|
||
private[mill] def manifest0: T[JarManifest] = Task { | ||
Jvm.createManifest(finalMainClassOpt().toOption) | ||
} | ||
|
||
/** | ||
* What shell script to use to launch the executable generated by `assembly`. | ||
* Defaults to a generic "universal" launcher that should work for Windows, | ||
* OS-X and Linux | ||
*/ | ||
def prependShellScript: T[String] = Task { | ||
prependShellScript0() | ||
} | ||
private[mill] def prependShellScript0: T[String] = Task { | ||
finalMainClassOpt().toOption match { | ||
case None => "" | ||
case Some(cls) => | ||
mill.util.Jvm.launcherUniversalScript( | ||
mainClass = cls, | ||
shellClassPath = Agg("$0"), | ||
cmdClassPath = Agg("%~dpnx0"), | ||
jvmArgs = forkArgs() | ||
) | ||
} | ||
} | ||
|
||
def assemblyRules: Seq[Assembly.Rule] = assemblyRules0 | ||
|
||
private[mill] def assemblyRules0: Seq[Assembly.Rule] = Assembly.defaultRules | ||
|
||
def upstreamAssemblyClasspath: T[Agg[PathRef]] | ||
|
||
def localClasspath: T[Seq[PathRef]] | ||
|
||
private[mill] def upstreamAssembly2_0: T[Assembly] = Task { | ||
Assembly.create( | ||
destJar = T.dest / "out.jar", | ||
inputPaths = upstreamAssemblyClasspath().map(_.path), | ||
manifest = manifest(), | ||
assemblyRules = assemblyRules | ||
) | ||
} | ||
|
||
/** | ||
* Build the assembly for upstream dependencies separate from the current | ||
* classpath | ||
* | ||
* This should allow much faster assembly creation in the common case where | ||
* upstream dependencies do not change | ||
*/ | ||
def upstreamAssembly2: T[Assembly] = Task { | ||
upstreamAssembly2_0() | ||
} | ||
|
||
def upstreamAssembly: T[PathRef] = Task { | ||
T.log.error( | ||
s"upstreamAssembly target is deprecated and should no longer used." + | ||
s" Please make sure to use upstreamAssembly2 instead." | ||
) | ||
upstreamAssembly2().pathRef | ||
} | ||
|
||
private[mill] def assembly0: Task[PathRef] = Task.Anon { | ||
// detect potential inconsistencies due to `upstreamAssembly` deprecation after 0.11.7 | ||
if ( | ||
(upstreamAssembly.ctx.enclosing: @nowarn) != s"${classOf[AssemblyModule].getName}#upstreamAssembly" | ||
) { | ||
T.log.error( | ||
s"${upstreamAssembly.ctx.enclosing: @nowarn} is overriding a deprecated target which is no longer used." + | ||
s" Please make sure to override upstreamAssembly2 instead." | ||
) | ||
} | ||
|
||
val prependScript = Option(prependShellScript()).filter(_ != "") | ||
val upstream = upstreamAssembly2() | ||
|
||
val created = Assembly.create( | ||
destJar = T.dest / "out.jar", | ||
Agg.from(localClasspath().map(_.path)), | ||
manifest(), | ||
prependScript, | ||
Some(upstream.pathRef.path), | ||
assemblyRules | ||
) | ||
// See https://github.com/com-lihaoyi/mill/pull/2655#issuecomment-1672468284 | ||
val problematicEntryCount = 65535 | ||
if ( | ||
prependScript.isDefined && | ||
(upstream.addedEntries + created.addedEntries) > problematicEntryCount | ||
) { | ||
Result.Failure( | ||
s"""The created assembly jar contains more than ${problematicEntryCount} ZIP entries. | ||
|JARs of that size are known to not work correctly with a prepended shell script. | ||
|Either reduce the entries count of the assembly or disable the prepended shell script with: | ||
| | ||
| def prependShellScript = "" | ||
|""".stripMargin, | ||
Some(created.pathRef) | ||
) | ||
} else { | ||
Result.Success(created.pathRef) | ||
} | ||
} | ||
|
||
/** | ||
* An executable uber-jar/assembly containing all the resources and compiled | ||
* classfiles from this module and all it's upstream modules and dependencies | ||
*/ | ||
def assembly: T[PathRef] = T { | ||
assembly0() | ||
} | ||
} |
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
Oops, something went wrong.
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.
This comment doesn't seem right.