summaryrefslogtreecommitdiff
path: root/scalaplugin
diff options
context:
space:
mode:
authorLi Haoyi <haoyi.sg@gmail.com>2017-11-27 09:02:05 -0800
committerLi Haoyi <haoyi.sg@gmail.com>2017-11-27 09:02:05 -0800
commit77bef2c92936ec7ba0603a0470380906f247e482 (patch)
tree076d3f213eeec9ca3f222fc6cd02cc89f1408364 /scalaplugin
parentc6d95ab024831bd5f12d9aff2cacc361b9acfa1c (diff)
downloadmill-77bef2c92936ec7ba0603a0470380906f247e482.tar.gz
mill-77bef2c92936ec7ba0603a0470380906f247e482.tar.bz2
mill-77bef2c92936ec7ba0603a0470380906f247e482.zip
Acyclic cross-version tests are running
Diffstat (limited to 'scalaplugin')
-rw-r--r--scalaplugin/src/main/scala/mill/scalaplugin/ScalaModule.scala29
-rw-r--r--scalaplugin/src/test/scala/mill/scalaplugin/AcyclicTests.scala18
2 files changed, 38 insertions, 9 deletions
diff --git a/scalaplugin/src/main/scala/mill/scalaplugin/ScalaModule.scala b/scalaplugin/src/main/scala/mill/scalaplugin/ScalaModule.scala
index 766bdd36..861d0717 100644
--- a/scalaplugin/src/main/scala/mill/scalaplugin/ScalaModule.scala
+++ b/scalaplugin/src/main/scala/mill/scalaplugin/ScalaModule.scala
@@ -44,18 +44,33 @@ object ScalaModule{
.getOrElse(throw new Exception("Cannot find " + s))
.toIO
}
+
+ val outerClassLoader = getClass.getClassLoader
+
+ val compilerBridgeJar = grepJar(s"compiler-bridge_$binaryScalaVersion-1.0.5.jar")
+ val zincClassLoader = new URLClassLoader(
+ compileClasspathFiles.filter(_ != compilerBridgeJar).map(_.toURI.toURL),
+ ClassLoader.getSystemClassLoader.getParent
+ ){
+ override def loadClass(name: String): Class[_] = {
+ Option(findLoadedClass(name)) orElse
+ (try Some(findClass(name)) catch {case e: ClassNotFoundException => None}) getOrElse {
+ // Try to limit `outerClassLoader` to only stuff from the compiler-bridge jar
+ if (name.startsWith("xsbt.")) outerClassLoader.loadClass(name)
+ else super.loadClass(name)
+ }
+ }
+ }
val scalaInstance = new ScalaInstance(
version = scalaVersion,
- loader = getClass.getClassLoader,
+ loader = zincClassLoader,
libraryJar = grepJar(s"scala-library-$scalaVersion.jar"),
compilerJar = grepJar(s"scala-compiler-$scalaVersion.jar"),
allJars = compileClasspathFiles,
explicitActual = None
)
- val scalac = ZincUtil.scalaCompiler(
- scalaInstance,
- grepJar(s"compiler-bridge_$binaryScalaVersion-1.0.5.jar")
- )
+
+ val scalac = ZincUtil.scalaCompiler(scalaInstance, compilerBridgeJar)
mkdir(outputPath)
@@ -78,7 +93,6 @@ object ScalaModule{
val reporter = new ManagedLoggedReporter(10, logger)
val extra = Array(InterfaceUtil.t2(("key", "value")))
- var lastCompiledUnits: Set[String] = Set.empty
val ignoreProgress = new CompileProgress {
override def advance(current: Int, total: Int): Boolean = true
override def startUnit(phase: String, unitPath: String): Unit = ()
@@ -102,7 +116,7 @@ object ScalaModule{
lookup,
skip = false,
zincFile,
- compilerCache,
+ new FreshCompilerCache(),
IncOptions.of(),
reporter,
Some(ignoreProgress),
@@ -122,6 +136,7 @@ object ScalaModule{
newResult.setup()
)
)
+ zincClassLoader.close()
PathRef(outputPath/'classes)
}
diff --git a/scalaplugin/src/test/scala/mill/scalaplugin/AcyclicTests.scala b/scalaplugin/src/test/scala/mill/scalaplugin/AcyclicTests.scala
index 1f0bbd7e..5537037f 100644
--- a/scalaplugin/src/test/scala/mill/scalaplugin/AcyclicTests.scala
+++ b/scalaplugin/src/test/scala/mill/scalaplugin/AcyclicTests.scala
@@ -61,8 +61,22 @@ object AcyclicTests extends TestSuite{
}
val packageScala = workspacePath/'src/'main/'scala/'acyclic/"package.scala"
- 'acyclic - {
- val scalaVersion = "2.12.4"
+ 'scala210 - check("2.10.6")
+ 'scala211 - check("2.11.8")
+ 'scala212 - check("2.12.4")
+
+ val allBinaryVersions = Seq("2.10", "2.11", "2.12")
+ def check(scalaVersion: String) = {
+ // Dependencies are right; make sure every dependency is of the correct
+ // binary Scala version, except for the compiler-bridge which is of the
+ // same version as the host classpath.
+ val Right((compileDepClasspath, _)) = eval(AcyclicBuild.acyclic(scalaVersion).compileDepClasspath)
+ val binaryScalaVersion = scalaVersion.split('.').dropRight(1).mkString(".")
+ val compileDeps = compileDepClasspath.map(_.path.toString())
+ val offBinaryVersions = allBinaryVersions.filter(_ != binaryScalaVersion)
+ val offVersionedDeps = compileDeps.filter(p => offBinaryVersions.exists(p.contains))
+ assert(offVersionedDeps.forall(_.contains("compiler-bridge")))
+
// We can compile
val Right((pathRef, evalCount)) = eval(AcyclicBuild.acyclic(scalaVersion).compile)
val outputPath = pathRef.path