Skip to content

Commit

Permalink
[BACKPORT] Separate resolvedRunIvyDeps and transitiveLocalClasspath i…
Browse files Browse the repository at this point in the history
…nto two stages when build assembly jar (#4566)

Backport of #4565
  • Loading branch information
lihaoyi authored Feb 15, 2025
1 parent 2930015 commit 5a3eabd
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 2 deletions.
33 changes: 31 additions & 2 deletions scalalib/src/mill/scalalib/AssemblyModule.scala
Original file line number Diff line number Diff line change
Expand Up @@ -63,15 +63,44 @@ trait AssemblyModule extends mill.Module {

private[mill] def assemblyRules0: Seq[Assembly.Rule] = Assembly.defaultRules

/**
* Upstream classfiles and resources from third-party libraries
* necessary to build an executable assembly
*/
def upstreamIvyAssemblyClasspath: T[Agg[PathRef]] = Agg.empty[PathRef]

/**
* Upstream classfiles and resources from locally-built modules
* necessary to build an executable assembly, but without this module's contribution
*/
def upstreamLocalAssemblyClasspath: T[Agg[PathRef]] = upstreamAssemblyClasspath()

def upstreamAssemblyClasspath: T[Agg[PathRef]]

def localClasspath: T[Seq[PathRef]]

/**
* Build the assembly for third-party dependencies separate from the current
* classpath
*
* This should allow much faster assembly creation in the common case where
* third-party dependencies do not change
*/
def resolvedIvyAssembly: T[Assembly] = Task {
Assembly.create(
destJar = Task.dest / "out.jar",
inputPaths = upstreamIvyAssemblyClasspath().map(_.path),
manifest = manifest(),
assemblyRules = assemblyRules
)
}

private[mill] def upstreamAssembly2_0: T[Assembly] = Task {
Assembly.create(
destJar = Task.dest / "out.jar",
inputPaths = upstreamAssemblyClasspath().map(_.path),
inputPaths = upstreamLocalAssemblyClasspath().map(_.path),
manifest = manifest(),
base = Some(resolvedIvyAssembly().pathRef.path),
assemblyRules = assemblyRules
)
}
Expand Down Expand Up @@ -112,7 +141,7 @@ trait AssemblyModule extends mill.Module {
val problematicEntryCount = 65535
if (
prependScript.isDefined &&
(upstream.addedEntries + created.addedEntries) > problematicEntryCount
(resolvedIvyAssembly().addedEntries + upstream.addedEntries + created.addedEntries) > problematicEntryCount
) {
Result.Failure(
s"""The created assembly jar contains more than ${problematicEntryCount} ZIP entries.
Expand Down
8 changes: 8 additions & 0 deletions scalalib/src/mill/scalalib/JavaModule.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1015,6 +1015,14 @@ trait JavaModule
)
}

def upstreamIvyAssemblyClasspath: T[Agg[PathRef]] = Task {
resolvedRunIvyDeps()
}

def upstreamLocalAssemblyClasspath: T[Agg[PathRef]] = Task {
transitiveLocalClasspath()
}

/**
* All upstream classfiles and resources necessary to build and executable
* assembly, but without this module's contribution
Expand Down

0 comments on commit 5a3eabd

Please sign in to comment.