summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLi Haoyi <haoyi.sg@gmail.com>2017-12-04 07:52:31 -0800
committerLi Haoyi <haoyi.sg@gmail.com>2017-12-04 08:48:17 -0800
commit7238d7340744a5eda74acb6970c2cbf7bedea0e7 (patch)
treea0d2e6cb108779ebb4ca63be03c03ad45e41346e
parent54f2af0a974e28b81026f503eff420fad2869d2f (diff)
downloadmill-7238d7340744a5eda74acb6970c2cbf7bedea0e7.tar.gz
mill-7238d7340744a5eda74acb6970c2cbf7bedea0e7.tar.bz2
mill-7238d7340744a5eda74acb6970c2cbf7bedea0e7.zip
Cross building acyclic now works, using a locally compiled cross-versioned compiler-bridge.jar.
For now just hardcode the Scala versions we want to support as part of the build; we can figure out how to do the runtime download&compile thing later
-rw-r--r--bridge.sc4
-rw-r--r--build.sbt70
-rw-r--r--scalaplugin/src/main/scala/mill/scalaplugin/ScalaModule.scala14
-rw-r--r--scalaplugin/src/test/scala/mill/scalaplugin/AcyclicTests.scala5
4 files changed, 88 insertions, 5 deletions
diff --git a/bridge.sc b/bridge.sc
new file mode 100644
index 00000000..bdfbe26a
--- /dev/null
+++ b/bridge.sc
@@ -0,0 +1,4 @@
+import ammonite.ops._
+val zippedBytes = scalaj.http.Http()
+ .asBytes
+ .body \ No newline at end of file
diff --git a/build.sbt b/build.sbt
index 3031ffef..c1d8719b 100644
--- a/build.sbt
+++ b/build.sbt
@@ -35,6 +35,61 @@ val sharedSettings = Seq(
)
+def bridge(bridgeVersion: String) = Project(
+ id = "bridge" + bridgeVersion.replace('.', '_'),
+ base = file("bridge/" + bridgeVersion.replace('.', '_')),
+ settings = Seq(
+ organization := "com.lihaoyi",
+ scalaVersion := bridgeVersion,
+ name := "mill-bridge",
+ crossVersion := CrossVersion.full,
+ libraryDependencies ++= Seq(
+ "org.scala-lang" % "scala-compiler" % scalaVersion.value,
+ "org.scala-sbt" % "compiler-interface" % "1.0.5"
+ ),
+ (sourceGenerators in Compile) += Def.task{
+ import sys.process._
+ import collection.JavaConverters._
+ val v = scalaBinaryVersion.value
+ val url =
+ s"http://repo1.maven.org/maven2/org/scala-sbt/compiler-bridge_$v/1.0.5/compiler-bridge_$v-1.0.5-sources.jar"
+ val curlDest = java.nio.file.Paths.get(target.value.toString, "sources")
+ if (java.nio.file.Files.exists(curlDest)) {
+ java.nio.file.Files.walk(curlDest)
+ .iterator()
+ .asScala
+ .toSeq
+ .reverse
+ .foreach(java.nio.file.Files.delete)
+ }
+
+ java.nio.file.Files.createDirectories(curlDest)
+
+ Seq("curl", "-L", "-o", curlDest.resolve("bridge.jar").toString, url).!
+ Seq("unzip", curlDest.resolve("bridge.jar").toString, "-d", curlDest.toString).!
+
+ val sources = java.nio.file.Files.walk(curlDest)
+ .iterator
+ .asScala
+ .filter(_.toString.endsWith(".scala"))
+ .map(_.toFile)
+ .toSeq
+
+ sources
+ }.taskValue
+ )
+)
+lazy val bridge2_10_6 = bridge("2.10.6")
+lazy val bridge2_11_8 = bridge("2.11.8")
+//lazy val bridge2_11_9 = bridge("2.11.9")
+//lazy val bridge2_11_10 = bridge("2.11.10")
+lazy val bridge2_11_11 = bridge("2.11.11")
+//lazy val bridge2_12_0 = bridge("2.12.0")
+//lazy val bridge2_12_1 = bridge("2.12.1")
+//lazy val bridge2_12_2 = bridge("2.12.2")
+lazy val bridge2_12_3 = bridge("2.12.3")
+lazy val bridge2_12_4 = bridge("2.12.4")
+
lazy val core = project
.settings(
sharedSettings,
@@ -53,5 +108,18 @@ lazy val scalaplugin = project
.dependsOn(core % "compile->compile;test->test")
.settings(
sharedSettings,
- name := "mill-scalaplugin"
+ name := "mill-scalaplugin",
+ (compile in Test) := {
+ val a = (packageBin in (bridge2_10_6, Compile)).value
+ val b = (packageBin in (bridge2_11_8, Compile)).value
+// val c = (packageBin in (bridge2_11_9, Compile)).value
+// val d = (packageBin in (bridge2_11_10, Compile)).value
+ val e = (packageBin in (bridge2_11_11, Compile)).value
+// val f = (packageBin in (bridge2_12_0, Compile)).value
+// val g = (packageBin in (bridge2_12_1, Compile)).value
+// val h = (packageBin in (bridge2_12_2, Compile)).value
+ val i = (packageBin in (bridge2_12_3, Compile)).value
+ val j = (packageBin in (bridge2_12_4, Compile)).value
+ (compile in Test).value
+ }
)
diff --git a/scalaplugin/src/main/scala/mill/scalaplugin/ScalaModule.scala b/scalaplugin/src/main/scala/mill/scalaplugin/ScalaModule.scala
index 6b67b708..27aefb12 100644
--- a/scalaplugin/src/main/scala/mill/scalaplugin/ScalaModule.scala
+++ b/scalaplugin/src/main/scala/mill/scalaplugin/ScalaModule.scala
@@ -4,6 +4,7 @@ package scalaplugin
import java.io.File
import java.net.URLClassLoader
import java.util.Optional
+import java.util.concurrent.Callable
import ammonite.ops._
import coursier.{Cache, Fetch, MavenRepository, Repository, Resolution}
@@ -17,6 +18,8 @@ import sbt.internal.util.{ConsoleOut, MainAppender}
import sbt.util.{InterfaceUtil, LogExchange}
import xsbti.compile.{CompilerCache => _, FileAnalysisStore => _, ScalaInstance => _, _}
import mill.util.JsonFormatters._
+import sbt.librarymanagement.DependencyResolution
+import xsbti.GlobalLock
@@ -49,7 +52,11 @@ object ScalaModule{
val outerClassLoader = getClass.getClassLoader
val compilerJars = compilerClasspath.toArray.map(_.toIO)
- val compilerBridgeJar = grepJar(compilerBridge, s"compiler-bridge_$binaryScalaVersion-1.0.5.jar")
+
+ val compilerBridgeJar = new java.io.File(
+ s"bridge/${scalaVersion.replace('.', '_')}/target/scala-$binaryScalaVersion/mill-bridge_$scalaVersion-0.1-SNAPSHOT.jar"
+ )
+
val zincClassLoader = new URLClassLoader(compilerJars.map(_.toURI.toURL), null){
override def loadClass(name: String): Class[_] = {
Option(findLoadedClass(name)) orElse
@@ -115,7 +122,8 @@ object ScalaModule{
lookup,
skip = false,
zincFile,
- compilerCache,
+ new FreshCompilerCache,
+// compilerCache,
IncOptions.of(),
reporter,
Some(ignoreProgress),
@@ -129,6 +137,8 @@ object ScalaModule{
logger = logger
)
+ zincClassLoader.close()
+
store.set(
AnalysisContents.create(
newResult.analysis(),
diff --git a/scalaplugin/src/test/scala/mill/scalaplugin/AcyclicTests.scala b/scalaplugin/src/test/scala/mill/scalaplugin/AcyclicTests.scala
index 7ba8b267..124c7a0c 100644
--- a/scalaplugin/src/test/scala/mill/scalaplugin/AcyclicTests.scala
+++ b/scalaplugin/src/test/scala/mill/scalaplugin/AcyclicTests.scala
@@ -9,7 +9,7 @@ import utest._
import mill.util.JsonFormatters._
object AcyclicBuild{
val acyclic =
- for(crossVersion <- Cross("2.10.6", "2.11.8", "2.12.4"))
+ for(crossVersion <- Cross("2.10.6", "2.11.8", "2.12.3", "2.12.4"))
yield new ScalaModule{outer =>
def basePath = AcyclicTests.workspacePath
def organization = "com.lihaoyi"
@@ -46,7 +46,8 @@ object AcyclicTests extends TestSuite{
'scala210 - check("2.10.6")
'scala211 - check("2.11.8")
- 'scala212 - check("2.12.4")
+ 'scala2123 - check("2.12.3")
+ 'scala2124 - check("2.12.4")
val allBinaryVersions = Seq("2.10", "2.11", "2.12")
def check(scalaVersion: String) = {