Skip to content

Commit

Permalink
Support Mill 0.11.0-M1 (#78)
Browse files Browse the repository at this point in the history
* Support Mill 0.11.0-M1

Drop support for 0.9.7 (minimum version is now 0.9.12)

* Support Mill 0.11.0-M1

* Use system links for common files

* Test with Mill 0.10.10

* Avoid directory system link
  • Loading branch information
lolgab authored Dec 21, 2022
1 parent 1d228aa commit ef4ccfc
Show file tree
Hide file tree
Showing 11 changed files with 100 additions and 26 deletions.
8 changes: 4 additions & 4 deletions build.sc
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import $ivy.`com.github.lolgab::mill-mima::0.0.13`
import com.github.lolgab.mill.mima._
import os.Path

val millVersions = Seq("0.9.7", "0.10.0")
val millVersions = Seq("0.9.12", "0.10.0", "0.11.0-M1")
val millBinaryVersions = millVersions.map(scalaNativeBinaryVersion)

def millBinaryVersion(millVersion: String) = scalaNativeBinaryVersion(
Expand Down Expand Up @@ -57,7 +57,7 @@ class MillMimaCross(val millBinaryVersion: String)
ivy"com.github.lolgab::mima_mill$millBinaryVersion:0.0.1"
)
override def sources = T.sources(
super.sources() ++ Seq(millSourcePath / s"src-mill$millBinaryVersion")
super.sources() ++ Seq(millSourcePath / s"src-mill${millVersion(millBinaryVersion).split('.').take(2).mkString(".")}")
.map(PathRef(_))
)
override def compileIvyDeps = super.compileIvyDeps() ++ Agg(
Expand All @@ -80,10 +80,10 @@ object `mill-mima-worker-impl` extends Common {

object itest
extends Cross[itestCross](
"0.9.7",
"0.9.12",
"0.10.0",
"0.10.7"
"0.10.10",
"0.11.0-M1"
)
class itestCross(millVersion: String) extends MillIntegrationTestModule {
override def millSourcePath: Path = super.millSourcePath / os.up
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package com.github.lolgab.mill.mima

import com.github.lolgab.mill.mima.worker.MimaBuildInfo
import mill._
import mill.scalalib._

private[mima] trait VersionSpecific extends CoursierModule {
private[mima] def mimaWorkerClasspath: T[Agg[PathRef]] = T {
Lib
.resolveDependencies(
repositoriesTask(),
resolveCoursierDependency().apply(_),
Agg(
ivy"com.github.lolgab:mill-mima-worker-impl_2.13:${MimaBuildInfo.publishVersion}"
.exclude("com.github.lolgab" -> "mill-mima-worker-api_2.13")
),
ctx = Some(T.log)
)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package com.github.lolgab.mill.mima

import mill.Agg
import mill.PathRef
import mill.T
import mill.api.Result
import mill.define.Task
import mill.scalalib._

import scala.util.chaining._

private[mima] trait ExtraCoursierSupport
extends CoursierModule
with ScalaModule {

/** Resolves each dependency independently.
*
* @param deps
* The dependencies to resolve.
* @param sources
* If `true`, resolved the source jars instead of the binary jars.
* @return
* Tuples containing each dependencies and it's resolved transitive
* artifacts.
*/
protected def resolveSeparateNonTransitiveDeps(
deps: Task[Agg[Dep]]
): Task[Agg[(Dep, Agg[PathRef])]] = T.task {
val pRepositories = repositoriesTask()
val pDeps = deps()
val scalaV = scalaVersion()
pDeps.map { dep =>
val Result.Success(resolved) = Lib.resolveDependencies(
repositories = pRepositories,
deps = Agg(dep).map(dep =>
Lib
.depToBoundDep(dep, scalaV)
.tap(dependency =>
dependency.copy(dep = dependency.dep.withTransitive(false))
)
),
ctx = Some(implicitly[mill.api.Ctx.Log])
)
(dep, resolved)
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package com.github.lolgab.mill.mima

import com.github.lolgab.mill.mima.worker.MimaBuildInfo
import mill._
import mill.scalalib._

private[mima] trait VersionSpecific extends CoursierModule {
private[mima] def mimaWorkerClasspath: T[Agg[PathRef]] = T {
Lib
.resolveDependencies(
repositoriesTask(),
Agg(
ivy"com.github.lolgab:mill-mima-worker-impl_2.13:${MimaBuildInfo.publishVersion}"
.exclude("com.github.lolgab" -> "mill-mima-worker-api_2.13")
).map(Lib.depToBoundDep(_, BuildInfo.scalaVersion)),
ctx = Some(T.log)
)
}
}
18 changes: 2 additions & 16 deletions mill-mima/src/com/github/lolgab/mill/mima/MimaBase.scala
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.github.lolgab.mill.mima

import com.github.lolgab.mill.mima.internal.Utils.scalaBinaryVersion
import com.github.lolgab.mill.mima.worker.MimaBuildInfo
import com.github.lolgab.mill.mima.worker.MimaWorkerExternalModule
import mill._
import mill.api.Result
Expand All @@ -16,7 +15,8 @@ import scala.util.chaining._
private[mima] trait MimaBase
extends ScalaModule
with PublishModule
with ExtraCoursierSupport {
with ExtraCoursierSupport
with VersionSpecific {

/** Set of versions to check binary compatibility against. */
def mimaPreviousVersions: Target[Seq[String]] = T { Seq.empty[String] }
Expand Down Expand Up @@ -85,20 +85,6 @@ private[mima] trait MimaBase
false
}

private def mimaWorkerClasspath: T[Agg[os.Path]] = T {
Lib
.resolveDependencies(
repositoriesTask(),
resolveCoursierDependency().apply(_),
Agg(
ivy"com.github.lolgab:mill-mima-worker-impl_2.13:${MimaBuildInfo.publishVersion}"
.exclude("com.github.lolgab" -> "mill-mima-worker-api_2.13")
),
ctx = Some(T.log)
)
.map(_.map(_.path))
}

private def mimaWorker: Task[worker.api.MimaWorkerApi] = T.task {
val cp = mimaWorkerClasspath()
MimaWorkerExternalModule.mimaWorker().impl(cp)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package com.github.lolgab.mill.mima.worker

import com.github.lolgab.mill.mima.worker.api.MimaWorkerApi
import mill.Agg
import mill.PathRef
import mill.T
import mill.define.Discover
import mill.define.Worker
Expand All @@ -10,17 +11,14 @@ class MimaWorker {
private var scalaInstanceCache = Option.empty[(Long, MimaWorkerApi)]

def impl(
mimaWorkerClasspath: Agg[os.Path]
mimaWorkerClasspath: Agg[PathRef]
)(implicit ctx: mill.api.Ctx.Home): MimaWorkerApi = {
val classloaderSig = mimaWorkerClasspath
.map(p => p.toString().hashCode + os.mtime(p))
.iterator
.sum
val classloaderSig = mimaWorkerClasspath.hashCode
scalaInstanceCache match {
case Some((sig, bridge)) if sig == classloaderSig => bridge
case _ =>
val cl = mill.api.ClassLoader.create(
mimaWorkerClasspath.map(_.toIO.toURI.toURL).iterator.to(Seq),
mimaWorkerClasspath.map(_.path.toIO.toURI.toURL).iterator.to(Seq),
parent = null,
sharedLoader = getClass.getClassLoader,
sharedPrefixes = Seq("com.github.lolgab.mill.mima.worker.api.")
Expand Down

0 comments on commit ef4ccfc

Please sign in to comment.