Skip to content
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

Add support for multi-release Jar files #2724

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 10 additions & 10 deletions .github/workflows/actions.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ name: CI
#
# To maximize bug-catching changes while keeping CI times reasonable, we run:
# - All tests on Linux/Java17
# - Fewer tests on Linux/Java8 and Windows/Java17
# - Fewest tests on Windows/Java8
# - Fewer tests on Linux/Java11 and Windows/Java17
# - Fewest tests on Windows/Java11

on:
push:
Expand All @@ -35,7 +35,7 @@ jobs:
matrix:
include:
# bootstrap tests
- java-version: 8
- java-version: 11
buildcmd: ci/test-mill-release.sh
- java-version: 17
buildcmd: ci/test-mill-release.sh
Expand All @@ -48,7 +48,7 @@ jobs:
- java-version: 20
buildcmd: ci/test-mill-bootstrap.sh
# Just some reporting to enable reasoning about library upgrades
- java-version: 8
- java-version: 11
buildcmd: |
./mill -i -k __.ivyDepsTree
./mill -i -k __.ivyDepsTree --withRuntime
Expand All @@ -63,7 +63,7 @@ jobs:
strategy:
fail-fast: false
matrix:
java-version: [8, 17]
java-version: [11, 17]
millargs:
# unit and module tests
- '"{main,scalalib,testrunner,bsp}.__.test"'
Expand Down Expand Up @@ -94,21 +94,21 @@ jobs:
format-check:
uses: ./.github/workflows/run-mill-action.yml
with:
java-version: '8'
java-version: '11'
millargs: mill.scalalib.scalafmt.ScalafmtModule/checkFormatAll __.sources

bincompat-check:
uses: ./.github/workflows/run-mill-action.yml
with:
java-version: '8'
java-version: '11'
millargs: __.mimaReportBinaryIssues
continue-on-error: true

windows:
strategy:
fail-fast: false
matrix:
java-version: [8, 17]
java-version: [11, 17]
millargs:
# Run a stripped down build matrix on Windows, to avoid taking too long
- '"{__.publishLocal,dev.assembly,__.compile}"'
Expand Down Expand Up @@ -165,7 +165,7 @@ jobs:

- uses: actions/setup-java@v3
with:
java-version: 8
java-version: 11
distribution: temurin

- run: ci/release-maven.sh
Expand All @@ -188,7 +188,7 @@ jobs:

- uses: actions/setup-java@v3
with:
java-version: 8
java-version: 11
distribution: temurin

- run: ./mill -i uploadToGithub $REPO_ACCESS_TOKEN
2 changes: 1 addition & 1 deletion .github/workflows/publish-bridges.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ jobs:

- uses: actions/setup-java@v3
with:
java-version: 8
java-version: 11
distribution: temurin

- run: ci/release-bridge-maven.sh
2 changes: 1 addition & 1 deletion .github/workflows/publishDocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:

- uses: actions/setup-java@v3
with:
java-version: 8
java-version: 11
distribution: temurin

- run: ci/publish-docs.sh
20 changes: 15 additions & 5 deletions scalalib/src/mill/scalalib/Assembly.scala
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,8 @@ object Assembly {

def loadShadedClasspath(
inputPaths: Agg[os.Path],
assemblyRules: Seq[Assembly.Rule]
assemblyRules: Seq[Assembly.Rule],
runtimeVersion: Option[Runtime.Version]
): (Generator[(String, UnopenedInputStream)], ResourceCloser) = {
val shadeRules = assemblyRules.collect {
case Rule.Relocate(from, to) => ShadePattern.Rename(List(from -> to)).inAll
Expand All @@ -148,13 +149,20 @@ object Assembly {
}

val pathsWithResources = inputPaths.filter(os.exists).map { path =>
if (os.isFile(path)) path -> Some(new JarFile(path.toIO))
if (os.isFile(path)) path -> {
val file = path.toIO
val jarFile = runtimeVersion match {
case Some(version) => new JarFile(file, true, java.util.zip.ZipFile.OPEN_READ, version)
case None => new JarFile(file)
}
Some(jarFile)
}
else path -> None
}

val generators = Generator.from(pathsWithResources).flatMap {
case (path, Some(jarFile)) =>
Generator.from(jarFile.entries().asScala.filterNot(_.isDirectory))
Generator.from(jarFile.versionedStream().iterator().asScala.filterNot(_.isDirectory))
.flatMap(entry => shader(entry.getName, () => jarFile.getInputStream(entry)))
case (path, None) =>
os.walk
Expand Down Expand Up @@ -193,7 +201,8 @@ object Assembly {
manifest: mill.api.JarManifest = mill.api.JarManifest.MillDefault,
prependShellScript: String = "",
base: Option[os.Path] = None,
assemblyRules: Seq[Assembly.Rule] = Assembly.defaultRules
assemblyRules: Seq[Assembly.Rule] = Assembly.defaultRules,
runtimeVersion: Option[Runtime.Version]
)(implicit ctx: Ctx.Dest with Ctx.Log): PathRef = {
val tmp = ctx.dest / "out-tmp.jar"

Expand All @@ -213,7 +222,8 @@ object Assembly {
manifest.build.write(manifestOut)
manifestOut.close()

val (mappings, resourceCleaner) = Assembly.loadShadedClasspath(inputPaths, assemblyRules)
val (mappings, resourceCleaner) =
Assembly.loadShadedClasspath(inputPaths, assemblyRules, runtimeVersion)
try {
Assembly.groupAssemblyEntries(mappings, assemblyRules).foreach {
case (mapping, entry) =>
Expand Down
17 changes: 15 additions & 2 deletions scalalib/src/mill/scalalib/JavaModule.scala
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,17 @@ trait JavaModule
*/
def javacOptions: T[Seq[String]] = T { Seq.empty[String] }

private def extractRuntimeVersion(javacOptions: Seq[String]): Option[Runtime.Version] = {
val releaseOptIndex = javacOptions.indexOf("--release")
val releaseOptValueIndex = releaseOptIndex + 1
if (releaseOptIndex >= 0 && javacOptions.length >= releaseOptValueIndex) {
val runtimeVersionString = javacOptions(releaseOptValueIndex)
val runtimeVersion = Runtime.Version.parse(runtimeVersionString)
println(s"Extracted javac --release version $runtimeVersion")
Some(runtimeVersion)
} else None
}

/** The direct dependencies of this module */
def moduleDeps: Seq[JavaModule] = Seq.empty

Expand Down Expand Up @@ -447,7 +458,8 @@ trait JavaModule
Assembly.createAssembly(
upstreamAssemblyClasspath().map(_.path),
manifest(),
assemblyRules = assemblyRules
assemblyRules = assemblyRules,
runtimeVersion = extractRuntimeVersion(javacOptions())
)
}

Expand All @@ -461,7 +473,8 @@ trait JavaModule
manifest(),
prependShellScript(),
Some(upstreamAssembly().path),
assemblyRules
assemblyRules,
runtimeVersion = extractRuntimeVersion(javacOptions())
)
}

Expand Down
Loading