From 4e3bcc9eeb8e3b6b13f29cb63360a512c0f6ed9b Mon Sep 17 00:00:00 2001 From: Guillaume R Date: Thu, 25 Jul 2019 01:14:09 +0200 Subject: Use the binary version of the compiler bridge when available (#659) * Use the binary version of the compiler bridge when available, fix #591 This also eliminates #389 for Dotty 0.13.0-RC1 and more recent * Add test for Dotty 0.16 --- scalalib/src/ZincWorkerModule.scala | 32 ++++++++++++++++++-------------- 1 file changed, 18 insertions(+), 14 deletions(-) (limited to 'scalalib/src/ZincWorkerModule.scala') diff --git a/scalalib/src/ZincWorkerModule.scala b/scalalib/src/ZincWorkerModule.scala index 4c94102c..81bfbb46 100644 --- a/scalalib/src/ZincWorkerModule.scala +++ b/scalalib/src/ZincWorkerModule.scala @@ -7,15 +7,15 @@ import mill.T import mill.api.KeyedLockedCache import mill.define.{Discover, Worker} import mill.scalalib.Lib.resolveDependencies -import mill.scalalib.api.Util.isDotty +import mill.scalalib.api.Util.{isDotty, isBinaryBridgeAvailable} import mill.scalalib.api.ZincWorkerApi import mill.api.Loose import mill.util.JsonFormatters._ -object ZincWorkerModule extends mill.define.ExternalModule with ZincWorkerModule{ +object ZincWorkerModule extends mill.define.ExternalModule with ZincWorkerModule { lazy val millDiscover = Discover[this.type] } -trait ZincWorkerModule extends mill.Module{ +trait ZincWorkerModule extends mill.Module { def repositories = Seq( coursier.LocalRepositories.ivy2Local, MavenRepository("https://repo1.maven.org/maven2"), @@ -37,7 +37,8 @@ trait ZincWorkerModule extends mill.Module{ ) } - def worker: Worker[mill.scalalib.api.ZincWorkerApi] = T.worker{ + def worker: Worker[mill.scalalib.api.ZincWorkerApi] = T.worker { + val cp = compilerInterfaceClasspath() val cl = mill.api.ClassLoader.create( classpath().map(_.path.toNIO.toUri.toURL).toVector, getClass.getClassLoader @@ -46,7 +47,7 @@ trait ZincWorkerModule extends mill.Module{ val instance = cls.getConstructor( classOf[ Either[ - (ZincWorkerApi.Ctx, Array[os.Path], (String, String) => os.Path), + (ZincWorkerApi.Ctx, (String, String) => (Option[Array[os.Path]], os.Path)), String => os.Path ] ], @@ -58,8 +59,7 @@ trait ZincWorkerModule extends mill.Module{ .newInstance( Left(( T.ctx(), - compilerInterfaceClasspath().map(_.path).toArray, - (x: String, y: String) => scalaCompilerBridgeSourceJar(x, y).asSuccess.get.value + (x: String, y: String) => scalaCompilerBridgeJar(x, y, cp).asSuccess.get.value )), mill.scalalib.api.Util.grepJar(_, "scala-library", _, sources = false), mill.scalalib.api.Util.grepJar(_, "scala-compiler", _, sources = false), @@ -69,8 +69,9 @@ trait ZincWorkerModule extends mill.Module{ instance.asInstanceOf[mill.scalalib.api.ZincWorkerApi] } - def scalaCompilerBridgeSourceJar(scalaVersion: String, - scalaOrganization: String) = { + def scalaCompilerBridgeJar(scalaVersion: String, + scalaOrganization: String, + compileClassPath: Agg[mill.eval.PathRef]) = { val (scalaVersion0, scalaBinaryVersion0) = scalaVersion match { case s if s.startsWith("2.13.") => ("2.13.0-M2", "2.13.0-M2") case _ => (scalaVersion, mill.scalalib.api.Util.scalaBinaryVersion(scalaVersion)) @@ -88,15 +89,18 @@ trait ZincWorkerModule extends mill.Module{ val version = Versions.zinc (ivy"$org::$name:$version", s"${name}_$scalaBinaryVersion0", version) } + val useSources = !isBinaryBridgeAvailable(scalaVersion) resolveDependencies( repositories, - Lib.depToDependency(_, scalaVersion0, ""), + Lib.depToDependency(_, scalaVersion0), Seq(bridgeDep), - sources = true - ).map(deps => - mill.scalalib.api.Util.grepJar(deps.map(_.path), bridgeName, bridgeVersion, sources = true) - ) + useSources + ).map{deps => + val cp = if (useSources) Some(compileClassPath.map(_.path).toArray) else None + val res = mill.scalalib.api.Util.grepJar(deps.map(_.path), bridgeName, bridgeVersion, useSources) + (cp, res) + } } def compilerInterfaceClasspath = T{ -- cgit v1.2.3