Prepend scala instance jars to sbt classpath

When using the launcher's classpath for the metabuild, the
scala-compiler jar can be missing. This is because the managedJars only
method returns the scala-library jar and not the rest of the scala
instance. To fix this, we can always prepend the scala instance jars to
the classpath.

In order to simulate the issue in scripted, I had to manually remove the
scala-compiler.jar from the scripted classpath or else the scripted test
that I added doesn't actually do anything because the scala-compiler.jar
would end up on the app.provider.mainClasspath.

Fixes #4452
This commit is contained in:
Ethan Atkins 2020-11-20 12:17:59 -08:00
parent da30c65aec
commit 6a9965c263
4 changed files with 12 additions and 4 deletions

View File

@ -1362,7 +1362,9 @@ def scriptedTask(launch: Boolean): Def.Initialize[InputTask[Unit]] = Def.inputTa
scriptedLaunchOpts.value ++ (if (launch) Some(launchJar) else None),
scalaVersion.value,
version.value,
(scriptedSbtReduxProj / Test / fullClasspathAsJars).value.map(_.data),
(scriptedSbtReduxProj / Test / fullClasspathAsJars).value
.map(_.data)
.filterNot(_.getName.contains("scala-compiler")),
streams.value.log
)
}

View File

@ -2497,14 +2497,15 @@ object Classpaths {
val isMeta = isMetaBuild.value
val force = reresolveSbtArtifacts.value
val app = appConfiguration.value
val sbtCp0 = app.provider.mainClasspath.toList
val sbtCp = sbtCp0 map { Attributed.blank(_) }
def isJansiOrJLine(f: File) = f.getName.contains("jline") || f.getName.contains("jansi")
val scalaInstanceJars = app.provider.scalaProvider.jars.filterNot(isJansiOrJLine)
val sbtCp = (scalaInstanceJars ++ app.provider.mainClasspath).map(Attributed.blank)
val mjars = managedJars(
classpathConfiguration.value,
classpathTypes.value,
update.value
)
if (isMeta && !force) mjars ++ sbtCp
if (isMeta && !force) (mjars ++ sbtCp).distinct
else mjars
},
exportedProducts := ClasspathImpl.trackedExportedProducts(TrackLevel.TrackAlways).value,

View File

@ -0,0 +1,3 @@
import scala.tools.nsc
object Plugin

View File

@ -0,0 +1,2 @@
> show sbtVersion
# we just want to test that the project loads