Skip to content

Commit

Permalink
Merge pull request #1331 from lrytz/noboot
Browse files Browse the repository at this point in the history
Don't use autoBoot / filterLibrary for 2.13 and 3
  • Loading branch information
eed3si9n authored Jan 27, 2024
2 parents ed976ea + 8e4186a commit c4f4ec0
Show file tree
Hide file tree
Showing 7 changed files with 53 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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!
}
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand All @@ -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("2.") || 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;
Expand All @@ -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("2.") || 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
Expand All @@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -196,15 +196,15 @@ 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)
}

private final val unit = (_: Seq[String]) => ()

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)
}

Expand Down
12 changes: 10 additions & 2 deletions zinc/src/main/scala/sbt/internal/inc/ZincUtil.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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)
)
}

/**
Expand All @@ -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(
Expand Down

0 comments on commit c4f4ec0

Please sign in to comment.