diff --git a/internal/compiler-bridge-test/src/test/scala/sbt/internal/inc/CompilingSpecification.scala b/internal/compiler-bridge-test/src/test/scala/sbt/internal/inc/CompilingSpecification.scala index fa420b77a5..6ae5315879 100644 --- a/internal/compiler-bridge-test/src/test/scala/sbt/internal/inc/CompilingSpecification.scala +++ b/internal/compiler-bridge-test/src/test/scala/sbt/internal/inc/CompilingSpecification.scala @@ -39,7 +39,7 @@ trait CompilingSpecification extends AbstractBridgeProviderTestkit { def scalaCompiler(instance: xsbti.compile.ScalaInstance, bridgeJar: Path): AnalyzingCompiler = { val bridgeProvider = ZincUtil.constantBridgeProvider(instance, bridgeJar) - val classpath = ClasspathOptionsUtil.boot + val classpath = ClasspathOptionsUtil.noboot(instance.version) val cache = Some(new ClassLoaderCache(new URLClassLoader(Array()))) new AnalyzingCompiler(instance, bridgeProvider, classpath, _ => (), cache) } diff --git a/internal/compiler-interface/src/main/contraband-java/xsbti/compile/ClasspathOptions.java b/internal/compiler-interface/src/main/contraband-java/xsbti/compile/ClasspathOptions.java index f7228fd26f..3fac455fc5 100644 --- a/internal/compiler-interface/src/main/contraband-java/xsbti/compile/ClasspathOptions.java +++ b/internal/compiler-interface/src/main/contraband-java/xsbti/compile/ClasspathOptions.java @@ -32,7 +32,7 @@ protected ClasspathOptions(boolean _bootLibrary, boolean _compiler, boolean _ext } /** * If true, includes the Scala library on the boot classpath. - * This should usually be true. + * This should usually be false. */ public boolean bootLibrary() { return this.bootLibrary; @@ -53,14 +53,14 @@ public boolean extra() { } /** * If true, automatically configures the boot classpath. - * This should usually be true. + * This should usually be false. */ public boolean autoBoot() { return this.autoBoot; } /** * If true, the Scala library jar is filtered from the standard classpath. - * This should usually be true because the library should be included on the boot + * This should usually be false unless the library is included on the boot * classpath of the Scala compiler and not the standard classpath. */ public boolean filterLibrary() { diff --git a/internal/compiler-interface/src/main/contraband/incremental.contra b/internal/compiler-interface/src/main/contraband/incremental.contra index 09842b2ede..a0617698ce 100644 --- a/internal/compiler-interface/src/main/contraband/incremental.contra +++ b/internal/compiler-interface/src/main/contraband/incremental.contra @@ -377,7 +377,7 @@ type Compilers { ## compiler-related parameters. Usually, values are all false for Java compilation. type ClasspathOptions { ## If true, includes the Scala library on the boot classpath. - ## This should usually be true. + ## This should usually be false. bootLibrary: Boolean! ## If true, includes the Scala compiler on the standard classpath. @@ -389,11 +389,11 @@ type ClasspathOptions { extra: Boolean! ## If true, automatically configures the boot classpath. - ## This should usually be true. + ## This should usually be false. autoBoot: Boolean! ## If true, the Scala library jar is filtered from the standard classpath. - ## This should usually be true because the library should be included on the boot + ## This should usually be false unless the library is included on the boot ## classpath of the Scala compiler and not the standard classpath. filterLibrary: Boolean! } diff --git a/internal/zinc-compile-core/src/main/java/xsbti/compile/ClasspathOptionsUtil.java b/internal/zinc-compile-core/src/main/java/xsbti/compile/ClasspathOptionsUtil.java index 1f65c17c5a..2a5e1cf2ef 100644 --- a/internal/zinc-compile-core/src/main/java/xsbti/compile/ClasspathOptionsUtil.java +++ b/internal/zinc-compile-core/src/main/java/xsbti/compile/ClasspathOptionsUtil.java @@ -16,7 +16,6 @@ * that create typical classpath options based on the desired use-case. */ public interface ClasspathOptionsUtil { - /** * Define a manual {@link ClasspathOptions} where the client manages everything. */ @@ -34,6 +33,16 @@ public static ClasspathOptions boot() { return ClasspathOptions.of(true, false, false, true, true); } + /** + * Define {@link ClasspathOptions} where the Scala standard library is present in the classpath. + */ + public static ClasspathOptions noboot(String scalaVersion) { + if (scalaVersion.startsWith("3.") || scalaVersion.startsWith("2.13.")) + return ClasspathOptions.of(false, false, false, false, false); + else + return boot(); + } + /** * Define auto {@link ClasspathOptions} where: * 1. the Scala standard library is present in the classpath; @@ -46,6 +55,19 @@ public static ClasspathOptions auto() { return ClasspathOptions.of(true, true, true, true, true); } + /** + * Define auto {@link ClasspathOptions} where: + * 1. the Scala standard library is present in the classpath; + * 2. the Compiler JAR is present in the classpath; + * 3. the extra JARs present in the Scala instance are added to the classpath. + */ + public static ClasspathOptions autoNoboot(String scalaVersion) { + if (scalaVersion.startsWith("3.") || scalaVersion.startsWith("2.13.")) + return ClasspathOptions.of(false, true, true, false, false); + else + return auto(); + } + /** * Define javac {@link ClasspathOptions} where the Compiler JAR may or may not * be present in the classpath. Note that the classpath won't be @@ -69,4 +91,14 @@ public static ClasspathOptions javac(Boolean compilerInClasspath) { public static ClasspathOptions repl() { return auto(); } + + /** + * Define repl {@link ClasspathOptions} where: + * 1. the Scala standard library is present in the classpath; + * 2. the Compiler JAR is present in the classpath; + * 3. the extra JARs present in the Scala instance are added to the classpath. + */ + public static ClasspathOptions replNoboot(String scalaVersion) { + return autoNoboot(scalaVersion); + } } diff --git a/internal/zinc-compile-core/src/main/scala/sbt/internal/inc/CompilerArguments.scala b/internal/zinc-compile-core/src/main/scala/sbt/internal/inc/CompilerArguments.scala index f490e91508..8b3f4c3dc9 100644 --- a/internal/zinc-compile-core/src/main/scala/sbt/internal/inc/CompilerArguments.scala +++ b/internal/zinc-compile-core/src/main/scala/sbt/internal/inc/CompilerArguments.scala @@ -76,7 +76,7 @@ final class CompilerArguments( if (compilerClasspath.isEmpty) dummy else absString(compilerClasspath) val classpathOption = Seq("-classpath", stringClasspath) - val bootClasspath = bootClasspathOption(hasLibrary(classpath)) + val bootClasspath = bootClasspathOption(hasLibrary(classpath), classpath) options ++ bootClasspath ++ classpathOption ++ abs(sources) } @@ -95,13 +95,13 @@ final class CompilerArguments( } def createBootClasspathFor(classpath: Seq[Path]): String = - createBootClasspath(hasLibrary(classpath) || cpOptions.compiler || cpOptions.extra) + createBootClasspath(hasLibrary(classpath) || cpOptions.compiler || cpOptions.extra, classpath) /** * Return the Scala library to the boot classpath if `addLibrary` is true. * @param addLibrary Flag to return the Scala library. */ - def createBootClasspath(addLibrary: Boolean): String = { + def createBootClasspath(addLibrary: Boolean, classpath: Seq[Path]): String = { def findBoot: String = { import scala.collection.JavaConverters._ System.getProperties.asScala.iterator @@ -115,7 +115,14 @@ final class CompilerArguments( val newBootPrefix = if (originalBoot.isEmpty) "" else originalBoot + java.io.File.pathSeparator - newBootPrefix + absString(scalaInstance.libraryJars.map(_.toPath)) + val useInstanceLibrary = { + val v = scalaInstance.version + v.startsWith("3.") || v.startsWith("2.13.") + } + val library: String = + if (useInstanceLibrary) absString(scalaInstance.libraryJars.map(_.toPath)) + else absString(classpath.filter(isScalaLibrary)) + newBootPrefix + library } else originalBoot } @@ -125,16 +132,16 @@ final class CompilerArguments( def hasLibrary(classpath: Seq[Path]) = classpath.exists(isScalaLibrary) - def bootClasspathOption(addLibrary: Boolean): Seq[String] = + def bootClasspathOption(addLibrary: Boolean, classpath: Seq[Path]): Seq[String] = if (!cpOptions.autoBoot) Nil - else Seq(BootClasspathOption, createBootClasspath(addLibrary)) + else Seq(BootClasspathOption, createBootClasspath(addLibrary, classpath)) - def bootClasspath(addLibrary: Boolean): Seq[Path] = + def bootClasspath(addLibrary: Boolean, classpath: Seq[Path]): Seq[Path] = if (!cpOptions.autoBoot) Nil - else IO.parseClasspath(createBootClasspath(addLibrary)).map(_.toPath) + else IO.parseClasspath(createBootClasspath(addLibrary, classpath)).map(_.toPath) def bootClasspathFor(classpath: Seq[Path]) = - bootClasspath(hasLibrary(classpath)) + bootClasspath(hasLibrary(classpath), classpath) def extClasspath: Seq[Path] = List("java.ext.dirs", "scala.ext.dirs").flatMap(k => diff --git a/internal/zinc-compile-core/src/main/scala/sbt/internal/inc/javac/JavaCompiler.scala b/internal/zinc-compile-core/src/main/scala/sbt/internal/inc/javac/JavaCompiler.scala index 610c36354c..2c357a00f2 100644 --- a/internal/zinc-compile-core/src/main/scala/sbt/internal/inc/javac/JavaCompiler.scala +++ b/internal/zinc-compile-core/src/main/scala/sbt/internal/inc/javac/JavaCompiler.scala @@ -93,6 +93,7 @@ object JavaCompiler { cpOptions: ClasspathOptions ): Seq[String] = { val cp = classpath.map(converter.toPath) + // this seems to duplicate scala-library val augmentedClasspath: Seq[Path] = if (!cpOptions.autoBoot) cp else cp ++ scalaInstance.libraryJars.map(_.toPath) diff --git a/internal/zinc-scripted/src/test/scala/sbt/internal/inc/IncHandler.scala b/internal/zinc-scripted/src/test/scala/sbt/internal/inc/IncHandler.scala index 29305fb7cb..b3c22d9691 100644 --- a/internal/zinc-scripted/src/test/scala/sbt/internal/inc/IncHandler.scala +++ b/internal/zinc-scripted/src/test/scala/sbt/internal/inc/IncHandler.scala @@ -196,7 +196,7 @@ class IncHandler(directory: Path, cacheDir: Path, scriptedLog: ManagedLogger, co toCache } val analyzingCompiler = scalaCompiler(si, compilerBridge) - val cs = incrementalCompiler.compilers(si, ClasspathOptionsUtil.boot, None, analyzingCompiler) + val cs = incrementalCompiler.compilers(si, ClasspathOptionsUtil.noboot(si.version), None, analyzingCompiler) IncState(si, cs, 0) } @@ -204,7 +204,7 @@ class IncHandler(directory: Path, cacheDir: Path, scriptedLog: ManagedLogger, co def scalaCompiler(instance: XScalaInstance, bridgeJar: Path): AnalyzingCompiler = { val bridgeProvider = ZincUtil.constantBridgeProvider(instance, bridgeJar) - val classpath = ClasspathOptionsUtil.boot + val classpath = ClasspathOptionsUtil.noboot(instance.version) new AnalyzingCompiler(instance, bridgeProvider, classpath, unit, IncHandler.classLoaderCache) } diff --git a/zinc/src/main/scala/sbt/internal/inc/ZincUtil.scala b/zinc/src/main/scala/sbt/internal/inc/ZincUtil.scala index d433085e00..4a3ddec802 100644 --- a/zinc/src/main/scala/sbt/internal/inc/ZincUtil.scala +++ b/zinc/src/main/scala/sbt/internal/inc/ZincUtil.scala @@ -82,7 +82,11 @@ object ZincUtil { * @return A Scala compiler ready to be used. */ def scalaCompiler(scalaInstance: ScalaInstance, compilerBridgeJar: Path): AnalyzingCompiler = { - scalaCompiler(scalaInstance, compilerBridgeJar, ClasspathOptionsUtil.boot) + scalaCompiler( + scalaInstance, + compilerBridgeJar, + ClasspathOptionsUtil.noboot(scalaInstance.version) + ) } /** @@ -98,7 +102,11 @@ object ZincUtil { * @return A Scala compiler ready to be used. */ def scalaCompiler(scalaInstance: ScalaInstance, compilerBridgeJar: File): AnalyzingCompiler = { - scalaCompiler(scalaInstance, compilerBridgeJar.toPath, ClasspathOptionsUtil.boot) + scalaCompiler( + scalaInstance, + compilerBridgeJar.toPath, + ClasspathOptionsUtil.noboot(scalaInstance.version) + ) } // def compilers(