Skip to content

Commit

Permalink
Check if rt.jar is still necessary (#4206)
Browse files Browse the repository at this point in the history
Fixes #4164

It's been around since we used to use Ammonite to compile scripts, and
IIRC was necessary to make the in-memory Scala compiler work. We no
longer go through that code path, so maybe we can get rid of it? AFAIK
we now only use the Scala compiler through Zinc which manages this stuff
itself
  • Loading branch information
lihaoyi authored Dec 30, 2024
1 parent a3a9457 commit 609720f
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 47 deletions.
37 changes: 1 addition & 36 deletions main/api/src/mill/api/ClassLoader.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,6 @@ package mill.api

import java.net.{URL, URLClassLoader}

import java.nio.file.{FileAlreadyExistsException, FileSystemException}

import mill.java9rtexport.Export
import scala.util.Properties

/**
* Utilities for creating classloaders for running compiled Java/Scala code in
* isolated classpaths.
Expand All @@ -22,10 +17,7 @@ object ClassLoader {
sharedPrefixes: Seq[String] = Seq(),
logger: Option[mill.api.Logger] = None
)(implicit ctx: Ctx.Home): URLClassLoader = {
new URLClassLoader(
makeUrls(urls).toArray,
refinePlatformParent(parent)
) {
new URLClassLoader(urls.toArray, refinePlatformParent(parent)) {
override def findClass(name: String): Class[?] = {
if (sharedPrefixes.exists(name.startsWith)) {
logger.foreach(
Expand Down Expand Up @@ -73,31 +65,4 @@ object ClassLoader {
appClassLoader.getParent()
}
}

private def makeUrls(urls: Seq[URL])(implicit ctx: Ctx.Home): Seq[URL] = {
if (java9OrAbove) {
val java90rtJar = ctx.home / Export.rtJarName
if (!os.exists(java90rtJar)) {
// Time between retries should go from 100 ms to around 10s, which should
// leave plenty of time for another process to write fully this 50+ MB file
val retry = Retry(
count = 7,
backoffMillis = 100,
filter = {
case (_, _: FileSystemException) if Properties.isWin => true
case _ => false
}
)
retry {
try os.copy(os.Path(Export.rt()), java90rtJar, createFolders = true)
catch {
case e: FileAlreadyExistsException => /* someone else already did this */
}
}
}
urls :+ java90rtJar.toIO.toURI().toURL()
} else {
urls
}
}
}
11 changes: 0 additions & 11 deletions runner/src/mill/runner/MillMain.scala
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import java.nio.file.StandardOpenOption
import java.util.Locale
import scala.jdk.CollectionConverters.*
import scala.util.Properties
import mill.java9rtexport.Export
import mill.api.{MillException, SystemStreams, WorkspaceRoot, internal}
import mill.bsp.{BspContext, BspServerResult}
import mill.main.BuildInfo
Expand Down Expand Up @@ -195,16 +194,6 @@ object MillMain {

val threadCount = Some(maybeThreadCount.toOption.get)

if (mill.main.client.Util.isJava9OrAbove) {
val rt = config.home / Export.rtJarName
if (!os.exists(rt)) {
streams.err.println(
s"Preparing Java ${System.getProperty("java.version")} runtime; this may take a minute or two ..."
)
Export.rtTo(rt.toIO, false)
}
}

val bspContext =
if (bspMode) Some(new BspContext(streams, bspLog, config.home)) else None

Expand Down

0 comments on commit 609720f

Please sign in to comment.