Skip to content

Commit

Permalink
SI-8345 support both scalap 2.11.0-M8 and 2.11.0-RC1
Browse files Browse the repository at this point in the history
Once scala#3588 is merged, the ByteCode module will go back to
scala.tools.scalap.scalax.rules.scalasig from its current (M8) package:
scala.tools.scalap.scalasig
  • Loading branch information
adriaanm authored and lrytz committed May 9, 2018
1 parent 8f3b000 commit 6169dca
Showing 1 changed file with 28 additions and 6 deletions.
34 changes: 28 additions & 6 deletions src/partest/scala/tools/partest/nest/Runner.scala
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@ import scala.tools.nsc.{ Settings, CompilerCommand, Global }
import scala.tools.nsc.io.{ AbstractFile }
import scala.tools.nsc.reporters.ConsoleReporter
import scala.tools.nsc.util.{ Exceptional, stackTraceString }
import scala.tools.scalap.Main.decompileScala
import scala.tools.scalap.scalasig.ByteCode
import scala.util.{ Try, Success, Failure }
import ClassPath.{ join, split }
import TestState.{ Pass, Fail, Crash, Uninitialized, Updated }
Expand Down Expand Up @@ -683,16 +681,40 @@ class Runner(val testFile: File, val suiteRunner: SuiteRunner) {
lastState
}

private def decompileClass(clazz: Class[_], isPackageObject: Boolean): String = {
import scala.tools.scalap

// TODO: remove use of reflection once Scala 2.11.0-RC1 is out
// have to use reflection to work on both 2.11.0-M8 and 2.11.0-RC1.
// Once we require only 2.11.0-RC1, replace the following block by:
// import scalap.scalax.rules.scalasig.ByteCode
// ByteCode forClass clazz bytes
val bytes = {
import scala.language.{reflectiveCalls, existentials}
type ByteCode = { def bytes: Array[Byte] }
type ByteCodeModule = { def forClass(clazz: Class[_]): ByteCode }
val ByteCode = {
val ByteCodeModuleCls =
// RC1 package structure -- see: scala/scala#3588 and https://issues.scala-lang.org/browse/SI-8345
(util.Try { Class.forName("scala.tools.scalap.scalax.rules.scalasig.ByteCode$") }
// M8 package structure
getOrElse Class.forName("scala.tools.scalap.scalasig.ByteCode$"))
ByteCodeModuleCls.getDeclaredFields()(0).get(null).asInstanceOf[ByteCodeModule]
}
ByteCode forClass clazz bytes
}

scalap.Main.decompileScala(bytes, isPackageObject)
}

def runScalapTest() = runTestCommon {
val isPackageObject = testFile.getName startsWith "package"
val className = testFile.getName.stripSuffix(".scala").capitalize + (if (!isPackageObject) "" else ".package")
val loader = ScalaClassLoader.fromURLs(List(outDir.toURI.toURL), this.getClass.getClassLoader)
val byteCode = ByteCode forClass (loader loadClass className)
val result = decompileScala(byteCode.bytes, isPackageObject)

logFile writeAll result
logFile writeAll decompileClass(loader loadClass className, isPackageObject)
diffIsOk
}

def runScriptTest() = {
import scala.sys.process._
val (swr, wr) = newTestWriters()
Expand Down

0 comments on commit 6169dca

Please sign in to comment.