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

Forward port sbt/sbt#3701, JDK9/Scala 2.{10,11} overcompilation #450

Merged
merged 1 commit into from
Nov 6, 2017
Merged
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
5 changes: 3 additions & 2 deletions internal/compiler-bridge/src/main/scala/xsbt/Dependency.scala
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,9 @@ final class Dependency(val global: CallbackGlobal) extends LocateClassFile with
// The dependency comes from a JAR
for {
zip <- zipEntry.underlyingSource
classFile <- Option(zip.file)
} binaryDependency(classFile, binaryClassName)
jarFile <- Option(zip.file)
if !jarFile.isDirectory // workaround for JDK9 and Scala 2.10/2.11, see https://github.com/sbt/sbt/pull/3701
} binaryDependency(jarFile, binaryClassName)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the only change that fixes an observable bug. I didn't figure out why the bug in SBT 0.13 fixed by -Dscala.ext.dirs was not necessary here.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you elaborate why Scalac reports the underlying source to be a directory under JDK9? I'm curious.

Copy link
Member Author

@retronym retronym Nov 3, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To integrate the JEP-220 support into Scala 2.10/2.11, I made the jrt:// virtual file system appear as a ZipFile. This was done by subclassing, but the superclass had inadvertently overriden override val underlyingSource = Some(jarFile). I could not override this to return None without making a binary compatible change to the method I was overriding (widening to Option).

So I return Some($JAVA_HOME) instead, but that messed up Zinc.

Rocks and hard places, all around. Filtering here in Zinc seemed the least bad option for now, but we might need to revisit it to make Zinc properly invalidate after the JDK is upgraded.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great to know this, thanks for the explanation.

case pf: PlainFile =>
// The dependency comes from a class file
binaryDependency(pf.file, binaryClassName)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,15 @@ final class CompilerArguments(
* @param addLibrary Flag to return the Scala library.
*/
def createBootClasspath(addLibrary: Boolean): String = {
val originalBoot = System.getProperty("sun.boot.class.path", "")
def findBoot: String = {
import scala.collection.JavaConverters._
System.getProperties.asScala.iterator
.collectFirst {
case (k, v) if k.endsWith(".boot.class.path") => v
}
.getOrElse("")
}
val originalBoot = Option(System.getProperty("sun.boot.class.path")).getOrElse(findBoot)
if (addLibrary) {
val newBootPrefix =
if (originalBoot.isEmpty) ""
Expand All @@ -109,7 +117,8 @@ final class CompilerArguments(
bootClasspath(hasLibrary(classpath))

def extClasspath: Seq[File] =
(IO.parseClasspath(System.getProperty("java.ext.dirs", "")) * "*.jar").get
List("java.ext.dirs", "scala.ext.dirs").flatMap(k =>
(IO.parseClasspath(System.getProperty(k, "")) * "*.jar").get)

private[this] def include(flag: Boolean, jars: File*) =
if (flag || ScalaInstance.isDotty(scalaInstance.version)) jars
Expand Down