Skip to content
Open
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
27 changes: 24 additions & 3 deletions project/ScalaLibraryPlugin.scala
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import java.nio.file.Files
import xsbti.VirtualFileRef
import sbt.internal.inc.Stamper
import org.scalajs.sbtplugin.ScalaJSPlugin.autoImport.scalaJSVersion
import org.objectweb.asm.*

object ScalaLibraryPlugin extends AutoPlugin {

Expand Down Expand Up @@ -55,8 +56,8 @@ object ScalaLibraryPlugin extends AutoPlugin {
dest = target / (id.toString)
ref <- dest.relativeTo((LocalRootProject / baseDirectory).value)
} {
// Copy the files to the classDirectory
IO.copyFile(file, dest)
// Read -> Strip Scala 2 Pickles -> Write
IO.write(dest, unpickler(IO.readBytes(file)))
// Update the timestamp in the analysis
stamps = stamps.markProduct(
VirtualFileRef.of(s"$${BASE}/$ref"),
Expand All @@ -76,7 +77,8 @@ object ScalaLibraryPlugin extends AutoPlugin {
// Copy all the specialized classes in the stdlib
// no need to update any stamps as these classes exist nowhere in the analysis
for (orig <- diff; dest <- orig.relativeTo(reference)) {
IO.copyFile(orig, ((Compile / classDirectory).value / dest.toString()))
// Read -> Strip Scala 2 Pickles -> Write
IO.write((Compile / classDirectory).value / dest.toString, unpickler(IO.readBytes(orig)))
}
}

Expand All @@ -102,6 +104,25 @@ object ScalaLibraryPlugin extends AutoPlugin {
} (Set(jar)), target)
}

/* Remove Scala 2 Pickles from Classfiles */
private def unpickler(bytes: Array[Byte]): Array[Byte] = {
Copy link
Member

Choose a reason for hiding this comment

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

This is a very confusing name, as the "unpickler" in the compiler is the thing that actually decodes things. Consider

Suggested change
private def unpickler(bytes: Array[Byte]): Array[Byte] = {
private def removeScala2Pickles(bytes: Array[Byte]): Array[Byte] = {

val reader = new ClassReader(bytes)
val writer = new ClassWriter(0)
val visitor = new ClassVisitor(Opcodes.ASM9, writer) {
override def visitAttribute(attr: Attribute): Unit = attr.`type` match {
case "ScalaSig" | "ScalaInlineInfo" => ()
case _ => super.visitAttribute(attr)
}

override def visitAnnotation(desc: String, visible: Boolean): AnnotationVisitor =
if (desc == "Lscala/reflect/ScalaSignature;" || desc == "Lscala/reflect/ScalaLongSignature;") null
else super.visitAnnotation(desc, visible)

}
reader.accept(visitor, 0)
writer.toByteArray
}

private lazy val filesToCopy = Set(
"scala/Tuple1",
"scala/Tuple2",
Expand Down
1 change: 1 addition & 0 deletions project/build.sbt
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// Used by VersionUtil to get gitHash and commitDate
libraryDependencies += "org.eclipse.jgit" % "org.eclipse.jgit" % "4.11.0.201803080745-r"
libraryDependencies += "org.ow2.asm" % "asm" % "9.9"

libraryDependencies += Dependencies.`jackson-databind`
Loading