diff options
-rw-r--r-- | build.sbt | 71 | ||||
-rwxr-xr-x | build.sc | 38 | ||||
-rw-r--r-- | core/src/mill/modules/Util.scala | 47 | ||||
-rw-r--r-- | integration/test/resources/jawn/build.sc | 4 | ||||
-rw-r--r-- | scalajslib/src/mill/scalajslib/ScalaJSModule.scala | 2 | ||||
-rw-r--r-- | scalajslib/test/src/mill/scalajslib/HelloJSWorldTests.scala | 7 | ||||
-rw-r--r-- | scalalib/src/mill/scalalib/GenIdea.scala | 1 | ||||
-rw-r--r-- | scalalib/src/mill/scalalib/Lib.scala | 5 | ||||
-rw-r--r-- | scalalib/src/mill/scalalib/PublishModule.scala | 4 | ||||
-rw-r--r-- | scalalib/src/mill/scalalib/ScalaModule.scala | 42 | ||||
-rw-r--r-- | scalalib/src/mill/scalalib/ScalaWorkerApi.scala | 19 | ||||
-rw-r--r-- | scalalib/test/src/mill/scalalib/ResolveDepsTests.scala | 2 | ||||
-rw-r--r-- | scalaworker/src/mill/scalaworker/ScalaWorker.scala | 47 | ||||
-rw-r--r-- | shared.sc | 9 |
14 files changed, 151 insertions, 147 deletions
@@ -64,36 +64,36 @@ def ammoniteRun(hole: SettingKey[File], args: String => List[String], suffix: St } -def bridge(bridgeVersion: String) = Project( - id = "bridge" + bridgeVersion.replace('.', '_'), - base = file("target/bridge/" + bridgeVersion.replace('.', '_')), - settings = Seq( - organization := "com.lihaoyi", - scalaVersion := bridgeVersion, - name := "mill-bridge", - target := baseDirectory.value, - crossVersion := CrossVersion.full, - libraryDependencies ++= Seq( - "org.scala-lang" % "scala-compiler" % scalaVersion.value, - "org.scala-sbt" % "compiler-interface" % "1.0.5" - ), - (sourceGenerators in Compile) += ammoniteRun( - sourceManaged in Compile, - List("shared.sc", "downloadBridgeSource", _, bridgeVersion) - ).taskValue.map(x => (x ** "*.scala").get) - ) -) - -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") +//def bridge(bridgeVersion: String) = Project( +// id = "bridge" + bridgeVersion.replace('.', '_'), +// base = file("target/bridge/" + bridgeVersion.replace('.', '_')), +// settings = Seq( +// organization := "com.lihaoyi", +// scalaVersion := bridgeVersion, +// name := "mill-bridge", +// target := baseDirectory.value, +// crossVersion := CrossVersion.full, +// libraryDependencies ++= Seq( +// "org.scala-lang" % "scala-compiler" % scalaVersion.value, +// "org.scala-sbt" % "compiler-interface" % "1.0.5" +// ), +// (sourceGenerators in Compile) += ammoniteRun( +// sourceManaged in Compile, +// List("shared.sc", "downloadBridgeSource", _, bridgeVersion) +// ).taskValue.map(x => (x ** "*.scala").get) +// ) +//) +// +//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 .dependsOn(moduledefs) @@ -131,16 +131,6 @@ lazy val moduledefs = project publishArtifact in Compile := false ) -val bridgeProps = Def.task{ - val mapping = Map( - "MILL_COMPILER_BRIDGE_2_10_6" -> (packageBin in (bridge2_10_6, Compile)).value.absolutePath, - "MILL_COMPILER_BRIDGE_2_11_8" -> (packageBin in (bridge2_11_8, Compile)).value.absolutePath, - "MILL_COMPILER_BRIDGE_2_11_11" -> (packageBin in (bridge2_11_11, Compile)).value.absolutePath, - "MILL_COMPILER_BRIDGE_2_12_3" -> (packageBin in (bridge2_12_3, Compile)).value.absolutePath, - "MILL_COMPILER_BRIDGE_2_12_4" -> (packageBin in (bridge2_12_4, Compile)).value.absolutePath - ) - for((k, v) <- mapping) yield s"-D$k=$v" -} lazy val scalaWorkerProps = Def.task{ Seq("-DMILL_SCALA_WORKER=" + (fullClasspath in (scalaworker, Compile)).value.map(_.data).mkString(",")) } @@ -176,7 +166,6 @@ def genTask(m: Project) = Def.task{ } (javaOptions in scalalib) := { - bridgeProps.value.toSeq ++ scalaWorkerProps.value ++ Seq("-DMILL_BUILD_LIBRARIES=" + ( @@ -86,34 +86,6 @@ object core extends MillModule { } } -val bridgeVersions = Seq("2.10.6", "2.11.8", "2.11.11", "2.12.3", "2.12.4") - -object bridges extends Cross[BridgeModule](bridgeVersions:_*) -class BridgeModule(crossVersion: String) extends PublishModule { - def publishName = "mill-bridge" - def publishVersion = "0.1" - - def scalaVersion = crossVersion - def allSources = T{ - Agg(PathRef(shared.downloadBridgeSource(T.ctx().dest, crossVersion))) - } - def ivyDeps = Agg( - ivy"org.scala-lang:scala-compiler:$crossVersion", - ivy"org.scala-sbt:compiler-interface:1.0.5" - ) - - def publishWithFullScalaVersion = true - - def pomSettings = PomSettings( - organization = "com.lihaoyi", - description = artifactId(), - developers = Seq(Developer("lihaoyi", "Li Haoyi", "https://github.com/lihaoyi/mill")), - licenses = Seq(License("MIT License", "https://spdx.org/licenses/MIT.html#licenseText")), - scm = SCM("https://github.com/lihaoyi/mill", "scm:git:https://github.com/lihaoyi/mill.git"), - url = "https://github.com/lihaoyi/mill" - ) -} - object scalaworker extends MillModule{ def moduleDeps = Seq(core, scalalib) @@ -134,8 +106,6 @@ object scalalib extends MillModule { ivy"org.scala-sbt:test-interface:1.0" ) - def bridgeCompiles = mill.define.Task.traverse(bridges.items)(_._2.compile) - def genTask(m: ScalaModule) = T.task{ Seq(m.jar(), m.sourcesJar()) ++ m.externalCompileDepClasspath() ++ @@ -143,13 +113,6 @@ object scalalib extends MillModule { } def testArgs = T{ - val bridgeVersions = bridges.items.map(_._1.head.toString) - - val bridgeArgs = - for((version, compile) <- bridgeVersions.zip(bridgeCompiles())) - yield s"-DMILL_COMPILER_BRIDGE_${version.replace('.', '_')}=${compile.classes.path}" - - val genIdeaArgs = genTask(moduledefs)() ++ genTask(core)() ++ @@ -157,7 +120,6 @@ object scalalib extends MillModule { genTask(scalajslib)() scalaworker.testArgs() ++ - bridgeArgs ++ Seq("-DMILL_BUILD_LIBRARIES=" + genIdeaArgs.map(_.path).mkString(",")) } } diff --git a/core/src/mill/modules/Util.scala b/core/src/mill/modules/Util.scala index d53cfcc9..542f58d1 100644 --- a/core/src/mill/modules/Util.scala +++ b/core/src/mill/modules/Util.scala @@ -1,11 +1,12 @@ package mill.modules -import ammonite.ops.{Path, RelPath} + +import ammonite.ops.{Path, RelPath, empty, mkdir, read} import mill.eval.PathRef import mill.util.Ctx object Util { - def download(url: String, dest: RelPath)(implicit ctx: Ctx.DestCtx) = { + def download(url: String, dest: RelPath = "download")(implicit ctx: Ctx.DestCtx) = { ammonite.ops.mkdir(ctx.dest) val out = ctx.dest / dest @@ -23,4 +24,46 @@ object Util { rbc.close() } } + + def downloadUnpackZip(url: String, dest: RelPath = "unpacked") + (implicit ctx: Ctx.DestCtx) = { + ctx.dest + mkdir(ctx.dest) + + val tmpName = if (dest == empty / "tmp.zip") "tmp2.zip" else "tmp.zip" + val downloaded = download(url, tmpName) + unpackZip(downloaded.path, dest) + } + + def unpackZip(src: Path, dest: RelPath = "unpacked") + (implicit ctx: Ctx.DestCtx) = { + mkdir(ctx.dest) + + val byteStream = read.getInputStream(src) + val zipStream = new java.util.zip.ZipInputStream(byteStream) + while({ + zipStream.getNextEntry match{ + case null => false + case entry => + if (!entry.isDirectory) { + val entryDest = ctx.dest / dest / RelPath(entry.getName) + mkdir(entryDest / ammonite.ops.up) + val fileOut = new java.io.FileOutputStream(entryDest.toString) + val buffer = new Array[Byte](4096) + while ( { + zipStream.read(buffer) match { + case -1 => false + case n => + fileOut.write(buffer, 0, n) + true + } + }) () + fileOut.close() + } + zipStream.closeEntry() + true + } + })() + PathRef(ctx.dest / dest) + } } diff --git a/integration/test/resources/jawn/build.sc b/integration/test/resources/jawn/build.sc index 0c4bdfca..ac9de195 100644 --- a/integration/test/resources/jawn/build.sc +++ b/integration/test/resources/jawn/build.sc @@ -1,6 +1,6 @@ import mill.scalalib import mill.Cross -import mill.scalalib.{Dep, TestModule, DepSyntax} +import mill.scalalib.{Dep, TestModule, DepSyntax, Lib} import ammonite.ops.up object jawn extends Cross[JawnModule]("2.10.6", "2.11.11", "2.12.3") class JawnModule(crossVersion: String) extends mill.Module{ @@ -43,7 +43,7 @@ class JawnModule(crossVersion: String) extends mill.Module{ object play extends Support(){ def ivyDeps = mill.T{ - scalaBinaryVersion() match{ + Lib.scalaBinaryVersion(scalaVersion()) match{ case "2.10" => Agg(ivy"com.typesafe.play::play-json:2.4.11") case "2.11" => Agg(ivy"com.typesafe.play::play-json:2.5.15") case _ => Agg(ivy"com.typesafe.play::play-json:2.6.0") diff --git a/scalajslib/src/mill/scalajslib/ScalaJSModule.scala b/scalajslib/src/mill/scalajslib/ScalaJSModule.scala index 82000c6e..6f50de53 100644 --- a/scalajslib/src/mill/scalajslib/ScalaJSModule.scala +++ b/scalajslib/src/mill/scalajslib/ScalaJSModule.scala @@ -41,7 +41,6 @@ trait ScalaJSModule extends scalalib.ScalaModule { outer => ) else resolveDependencies( Seq(Cache.ivy2Local, MavenRepository("https://repo1.maven.org/maven2")), "2.12.4", - "2.12", Seq(Dep( "com.lihaoyi", s"mill-jsbridge_${scalaJSBridgeVersion().replace('.', '_')}", @@ -62,7 +61,6 @@ trait ScalaJSModule extends scalalib.ScalaModule { outer => resolveDependencies( repositories, "2.12.4", - "2.12", commonDeps :+ envDep ) } diff --git a/scalajslib/test/src/mill/scalajslib/HelloJSWorldTests.scala b/scalajslib/test/src/mill/scalajslib/HelloJSWorldTests.scala index 88792366..5ba4343f 100644 --- a/scalajslib/test/src/mill/scalajslib/HelloJSWorldTests.scala +++ b/scalajslib/test/src/mill/scalajslib/HelloJSWorldTests.scala @@ -7,11 +7,12 @@ import javax.script.{ScriptContext, ScriptEngineManager} import ammonite.ops._ import mill._ import mill.define.Discover -import mill.scalalib.{DepSyntax, PublishModule, TestRunner} +import mill.scalalib.{DepSyntax, Lib, PublishModule, TestRunner} import mill.scalalib.publish.{Developer, License, PomSettings, SCM} import mill.util.{TestEvaluator, TestUtil} import utest._ import mill.util.TestEvaluator.implicitDisover + import scala.collection.JavaConverters._ @@ -38,7 +39,7 @@ object HelloJSWorldTests extends TestSuite { override def sources = T.input{ Agg(PathRef(basePath / 'src / 'utest)) } def testFramework: T[String] = "utest.runner.Framework" override def ivyDeps = Agg( - ivy"com.lihaoyi:utest_sjs${scalaJSBinaryVersion()}_${scalaBinaryVersion()}:0.6.3" + ivy"com.lihaoyi:utest_sjs${scalaJSBinaryVersion()}_${Lib.scalaBinaryVersion(scalaVersion())}:0.6.3" ) } } @@ -50,7 +51,7 @@ object HelloJSWorldTests extends TestSuite { override def sources = T.input{ Agg(PathRef(basePath / 'src / 'scalatest)) } def testFramework: T[String] = "org.scalatest.tools.Framework" override def ivyDeps = Agg( - ivy"org.scalatest:scalatest_sjs${scalaJSBinaryVersion()}_${scalaBinaryVersion()}:3.0.4" + ivy"org.scalatest:scalatest_sjs${scalaJSBinaryVersion()}_${Lib.scalaBinaryVersion(scalaVersion())}:3.0.4" ) } } diff --git a/scalalib/src/mill/scalalib/GenIdea.scala b/scalalib/src/mill/scalalib/GenIdea.scala index ea401b04..6511ee25 100644 --- a/scalalib/src/mill/scalalib/GenIdea.scala +++ b/scalalib/src/mill/scalalib/GenIdea.scala @@ -45,7 +45,6 @@ object GenIdea { val Result.Success(res) = scalalib.Lib.resolveDependencies( Seq(Cache.ivy2Local, MavenRepository("https://repo1.maven.org/maven2")), "2.12.4", - "2.12", for(name <- artifactNames) yield Dep("com.lihaoyi", s"mill-${name}", "0.0.1-SNAPSHOT") ) diff --git a/scalalib/src/mill/scalalib/Lib.scala b/scalalib/src/mill/scalalib/Lib.scala index 8fbbfc0f..ae10bd00 100644 --- a/scalalib/src/mill/scalalib/Lib.scala +++ b/scalalib/src/mill/scalalib/Lib.scala @@ -18,6 +18,8 @@ case class CompilationResult(analysisFile: Path, classes: PathRef) object Lib{ + def scalaBinaryVersion(scalaVersion: String) = scalaVersion.split('.').dropRight(1).mkString(".") + def grepJar(classPath: Agg[Path], s: String) = { classPath .find(_.toString.endsWith(s)) @@ -34,13 +36,12 @@ object Lib{ */ def resolveDependencies(repositories: Seq[Repository], scalaVersion: String, - scalaBinaryVersion: String, deps: TraversableOnce[Dep], sources: Boolean = false): Result[Agg[PathRef]] = { val flattened = deps.map{ case Dep.Java(dep) => dep case Dep.Scala(dep) => - dep.copy(module = dep.module.copy(name = dep.module.name + "_" + scalaBinaryVersion)) + dep.copy(module = dep.module.copy(name = dep.module.name + "_" + scalaBinaryVersion(scalaVersion))) case Dep.Point(dep) => dep.copy(module = dep.module.copy(name = dep.module.name + "_" + scalaVersion)) }.toSet diff --git a/scalalib/src/mill/scalalib/PublishModule.scala b/scalalib/src/mill/scalalib/PublishModule.scala index 64efce77..cedcdf8a 100644 --- a/scalalib/src/mill/scalalib/PublishModule.scala +++ b/scalalib/src/mill/scalalib/PublishModule.scala @@ -15,7 +15,7 @@ trait PublishModule extends ScalaModule { outer => def pom = T { val dependencies = - ivyDeps().map(Artifact.fromDep(_, scalaVersion(), scalaBinaryVersion())) + ivyDeps().map(Artifact.fromDep(_, scalaVersion(), Lib.scalaBinaryVersion(scalaVersion()))) val pom = Pom(artifact(), dependencies, artifactName(), pomSettings()) val pomPath = T.ctx().dest / s"${artifactId()}-${publishVersion()}.pom" @@ -25,7 +25,7 @@ trait PublishModule extends ScalaModule { outer => def ivy = T { val dependencies = - ivyDeps().map(Artifact.fromDep(_, scalaVersion(), scalaBinaryVersion())) + ivyDeps().map(Artifact.fromDep(_, scalaVersion(), Lib.scalaBinaryVersion(scalaVersion()))) val ivy = Ivy(artifact(), dependencies) val ivyPath = T.ctx().dest / "ivy.xml" write.over(ivyPath, ivy) diff --git a/scalalib/src/mill/scalalib/ScalaModule.scala b/scalalib/src/mill/scalalib/ScalaModule.scala index 8f635906..47326c6c 100644 --- a/scalalib/src/mill/scalalib/ScalaModule.scala +++ b/scalalib/src/mill/scalalib/ScalaModule.scala @@ -7,10 +7,12 @@ import mill.define.{Cross, Task} import mill.define.TaskModule import mill.eval.{PathRef, Result} import mill.modules.Jvm -import mill.modules.Jvm.{createAssembly, createJar, interactiveSubprocess, subprocess, runLocal} +import mill.modules.Jvm.{createAssembly, createJar, interactiveSubprocess, runLocal, subprocess} import Lib._ import mill.define.Cross.Resolver import mill.util.Loose.Agg +import mill.util.Strict + /** * Core configuration required to compile a single Scala compilation target */ @@ -23,7 +25,6 @@ trait ScalaModule extends mill.Module with TaskModule { outer => def scalaVersion: T[String] def mainClass: T[Option[String]] = None - def scalaBinaryVersion = T{ scalaVersion().split('.').dropRight(1).mkString(".") } def ivyDeps = T{ Agg.empty[Dep] } def compileIvyDeps = T{ Agg.empty[Dep] } def scalacPluginIvyDeps = T{ Agg.empty[Dep] } @@ -60,7 +61,6 @@ trait ScalaModule extends mill.Module with TaskModule { outer => resolveDependencies( repositories, scalaVersion(), - scalaBinaryVersion(), deps(), sources ) @@ -90,31 +90,13 @@ trait ScalaModule extends mill.Module with TaskModule { outer => depClasspath() } - /** - * Strange compiler-bridge jar that the Zinc incremental compile needs - */ - def compilerBridge: T[PathRef] = T{ - val compilerBridgeKey = "MILL_COMPILER_BRIDGE_" + scalaVersion().replace('.', '_') - val compilerBridgePath = sys.props(compilerBridgeKey) - if (compilerBridgePath != null) PathRef(Path(compilerBridgePath), quick = true) - else { - val dep = compilerBridgeIvyDep(scalaVersion()) - val classpath = resolveDependencies( - repositories, - scalaVersion(), - scalaBinaryVersion(), - Seq(dep) - ) - classpath match { - case Result.Success(resolved) => - resolved.filter(_.path.ext != "pom").toSeq match { - case Seq(single) => PathRef(single.path, quick = true) - case Seq() => throw new Exception(dep + " resolution failed") // TODO: find out, is it possible? - case _ => throw new Exception(dep + " resolution resulted in more than one file") - } - case f: Result.Failure => throw new Exception(dep + s" resolution failed.\n + ${f.msg}") // TODO: remove, resolveDependencies will take care of this. - } - } + def compilerBridgeSources = T{ + resolveDependencies( + repositories, + scalaVersion(), + Seq(ivy"org.scala-sbt::compiler-bridge:1.1.0"), + sources = true + ) } def scalacPluginClasspath: T[Agg[PathRef]] = @@ -153,10 +135,10 @@ trait ScalaModule extends mill.Module with TaskModule { outer => mill.scalalib.ScalaWorkerApi.scalaWorker().compileScala( scalaVersion(), allSources().map(_.path), + compilerBridgeSources().map(_.path), compileDepClasspath().map(_.path), scalaCompilerClasspath().map(_.path), scalacPluginClasspath().map(_.path), - compilerBridge().path, scalacOptions(), scalacPluginClasspath().map(_.path), javacOptions(), @@ -270,7 +252,7 @@ trait ScalaModule extends mill.Module with TaskModule { outer => def artifactName: T[String] = basePath.last.toString def artifactScalaVersion: T[String] = T { if (crossFullScalaVersion()) scalaVersion() - else scalaBinaryVersion() + else Lib.scalaBinaryVersion(scalaVersion()) } def artifactId: T[String] = T { s"${artifactName()}_${artifactScalaVersion()}" } diff --git a/scalalib/src/mill/scalalib/ScalaWorkerApi.scala b/scalalib/src/mill/scalalib/ScalaWorkerApi.scala index 7db48a41..4f9c527c 100644 --- a/scalalib/src/mill/scalalib/ScalaWorkerApi.scala +++ b/scalalib/src/mill/scalalib/ScalaWorkerApi.scala @@ -1,7 +1,5 @@ package mill.scalalib -import java.lang.reflect.{InvocationHandler, Method} -import java.net.URI import ammonite.ops.Path import coursier.Cache @@ -9,8 +7,7 @@ import coursier.maven.MavenRepository import mill.Agg import mill.scalalib.TestRunner.Result import mill.T -import mill.define.{Task, Worker} -import mill.eval.PathRef +import mill.define.Worker import mill.scalalib.Lib.resolveDependencies import mill.util.Loose import mill.util.JsonFormatters._ @@ -22,7 +19,6 @@ object ScalaWorkerApi extends mill.define.ExternalModule { val mill.eval.Result.Success(v) = resolveDependencies( Seq(Cache.ivy2Local, MavenRepository("https://repo1.maven.org/maven2")), "2.12.4", - "2.12", Seq(ivy"com.lihaoyi::mill-scalaworker:0.0.1-SNAPSHOT") ) v.map(_.path) @@ -34,18 +30,27 @@ object ScalaWorkerApi extends mill.define.ExternalModule { getClass.getClassLoader ) val cls = cl.loadClass("mill.scalaworker.ScalaWorker") - val instance = cls.getConstructor(classOf[mill.util.Ctx]).newInstance(T.ctx()) + val instance = cls.getConstructor(classOf[mill.util.Ctx], classOf[Array[String]]) + .newInstance(T.ctx(), compilerInterfaceClasspath().map(_.path.toString).toArray[String]) instance.asInstanceOf[ScalaWorkerApi] } + + def compilerInterfaceClasspath = T{ + resolveDependencies( + Seq(Cache.ivy2Local, MavenRepository("https://repo1.maven.org/maven2")), + "2.12.4", + Seq(ivy"org.scala-sbt:compiler-interface:1.1.0") + ) + } } trait ScalaWorkerApi { def compileScala(scalaVersion: String, sources: Agg[Path], + compileBridgeSources: Agg[Path], compileClasspath: Agg[Path], compilerClasspath: Agg[Path], pluginClasspath: Agg[Path], - compilerBridge: Path, scalacOptions: Seq[String], scalacPluginClasspath: Agg[Path], javacOptions: Seq[String], diff --git a/scalalib/test/src/mill/scalalib/ResolveDepsTests.scala b/scalalib/test/src/mill/scalalib/ResolveDepsTests.scala index d1ddde20..f697127c 100644 --- a/scalalib/test/src/mill/scalalib/ResolveDepsTests.scala +++ b/scalalib/test/src/mill/scalalib/ResolveDepsTests.scala @@ -10,7 +10,7 @@ import utest._ object ResolveDepsTests extends TestSuite { val repos = Seq(Cache.ivy2Local, MavenRepository("https://repo1.maven.org/maven2")) - def evalDeps(deps: Agg[Dep]): Result[Agg[PathRef]] = Lib.resolveDependencies(repos, "2.12.4", "2.12", deps) + def evalDeps(deps: Agg[Dep]): Result[Agg[PathRef]] = Lib.resolveDependencies(repos, "2.12.4", deps) val tests = Tests { 'resolveValidDeps - { diff --git a/scalaworker/src/mill/scalaworker/ScalaWorker.scala b/scalaworker/src/mill/scalaworker/ScalaWorker.scala index 70cfb604..45b2b927 100644 --- a/scalaworker/src/mill/scalaworker/ScalaWorker.scala +++ b/scalaworker/src/mill/scalaworker/ScalaWorker.scala @@ -6,13 +6,13 @@ import java.net.URLClassLoader import java.util.Optional import java.util.zip.ZipInputStream -import ammonite.ops.{Path, exists, ls, mkdir} +import ammonite.ops.{Path, exists, ls, mkdir, rm, up} import ammonite.util.Colors import mill.Agg import mill.define.Worker import mill.eval.PathRef import mill.modules.Jvm -import mill.scalalib.{CompilationResult, TestRunner} +import mill.scalalib.{CompilationResult, Lib, TestRunner} import xsbti.compile.{CompilerCache => _, FileAnalysisStore => _, ScalaInstance => _, _} import mill.scalalib.Lib.grepJar import mill.scalalib.TestRunner.Result @@ -36,7 +36,7 @@ object ScalaWorker{ def main(args: Array[String]): Unit = { try{ - val result = new ScalaWorker(null).apply( + val result = new ScalaWorker(null, null).apply( frameworkInstance = TestRunner.framework(args(0)), entireClasspath = Agg.from(args(1).split(" ").map(Path(_))), testClassfilePath = Agg.from(args(2).split(" ").map(Path(_))), @@ -61,26 +61,59 @@ object ScalaWorker{ // results from the outputPath System.exit(0) } - } -class ScalaWorker(ctx0: mill.util.Ctx) extends mill.scalalib.ScalaWorkerApi{ + +class ScalaWorker(ctx0: mill.util.Ctx, + compilerBridgeClasspath: Array[String]) extends mill.scalalib.ScalaWorkerApi{ @volatile var scalaClassloaderCache = Option.empty[(Long, ClassLoader)] @volatile var scalaInstanceCache = Option.empty[(Long, ScalaInstance)] + def compileZincBridge(scalaVersion: String, + compileBridgeSources: Agg[Path], + compilerJars: Array[File]) = { + val workingDir = ctx0.dest / scalaVersion + val compiledDest = workingDir / 'compiled + if (!exists(workingDir)) { + + mkdir(workingDir) + mkdir(compiledDest) + + val sourceJar = compileBridgeSources + .find(_.last == s"compiler-bridge_${Lib.scalaBinaryVersion(scalaVersion)}-1.1.0-sources.jar") + .get + + val sourceFolder = mill.modules.Util.unpackZip(sourceJar)(workingDir) + val classloader = new URLClassLoader(compilerJars.map(_.toURI.toURL), null) + val scalacMain = classloader.loadClass("scala.tools.nsc.Main") + val argsArray = Array[String]( + "-d", compiledDest.toString, + "-classpath", (compilerJars ++ compilerBridgeClasspath).mkString(":") + ) ++ ls.rec(sourceFolder.path).filter(_.ext == "scala").map(_.toString) + + scalacMain.getMethods + .find(_.getName == "process") + .get + .invoke(null, argsArray) + } + compiledDest + } + def compileScala(scalaVersion: String, sources: Agg[Path], + compileBridgeSources: Agg[Path], compileClasspath: Agg[Path], compilerClasspath: Agg[Path], pluginClasspath: Agg[Path], - compilerBridge: Path, scalacOptions: Seq[String], scalacPluginClasspath: Agg[Path], javacOptions: Seq[String], upstreamCompileOutput: Seq[CompilationResult]) (implicit ctx: mill.util.Ctx): CompilationResult = { val compileClasspathFiles = compileClasspath.map(_.toIO).toArray - val compilerJars = compilerClasspath.toArray.map(_.toIO) + + val compilerBridge = compileZincBridge(scalaVersion, compileBridgeSources, compilerJars) + val pluginJars = pluginClasspath.toArray.map(_.toIO) val compilerClassloaderSig = compilerClasspath.map(p => p.toString().hashCode + p.mtime.toMillis).sum @@ -144,15 +144,6 @@ def generateCoreTestSources(p: Path) = { generateApplicativeTest(p) } -@main -def downloadBridgeSource(curlDest: Path, crossVersion: String) = { - val v = crossVersion.split('.').dropRight(1).mkString(".") - unpackZip( - curlDest, - s"http://repo1.maven.org/maven2/org/scala-sbt/compiler-bridge_$v/1.0.5/compiler-bridge_$v-1.0.5-sources.jar" - ) - curlDest -} @main def downloadTestRepo(label: String, commit: String, dest: Path) = { |