Skip to content

Commit

Permalink
Make MiMa not extend PublishModule (#158)
Browse files Browse the repository at this point in the history
* Make MiMa not extend `PublishModule`

Functionality for `PublishModule` is still supported but it is required
only at runtime, to allow checking on modules that don't extend `PublishModule`

* Simplify MyProblemReporting.isReported
  • Loading branch information
lolgab authored May 30, 2024
1 parent 95c8b15 commit 8d8f63b
Show file tree
Hide file tree
Showing 9 changed files with 77 additions and 17 deletions.
4 changes: 4 additions & 0 deletions build.sc
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,10 @@ trait itestCross extends MillIntegrationTestModule with Cross.Module[String] {
TestInvocation.Targets(Seq("prepare")),
TestInvocation.Targets(Seq("verify"), expectedExitCode = 1)
),
PathRef(testBase / "not-publish-module") -> Seq(
TestInvocation.Targets(Seq("prepare")),
TestInvocation.Targets(Seq("verify"), expectedExitCode = 1)
),

)
}
Expand Down
26 changes: 26 additions & 0 deletions itest/src/not-publish-module/build.sc
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import mill._

import mill.scalalib._
import mill.scalalib.publish._
import $file.plugins
import com.github.lolgab.mill.mima._

object prev extends ScalaModule with PublishModule {
def scalaVersion = "2.13.4"
def publishVersion = "0.0.1"
def pomSettings =
PomSettings("", organization = "org", "", Seq(), VersionControl(), Seq())
}
object curr extends ScalaModule with Mima {
def scalaVersion = "2.13.4"
override def mimaPreviousArtifacts = T(Agg(ivy"org::prev:0.0.1"))
}

def prepare() = T.command {
prev.publishLocal(sys.props("ivy.home") + "/local")()
}

def verify() = T.command {
curr.mimaReportBinaryIssues()()
()
}
1 change: 1 addition & 0 deletions itest/src/not-publish-module/curr/src/Main.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
object Main {}
3 changes: 3 additions & 0 deletions itest/src/not-publish-module/prev/src/Main.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
object Main {
def hello(): String = "Hello world!"
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ trait MimaWorkerApi {
backwardFilters: Map[String, Seq[ProblemFilter]],
forwardFilters: Map[String, Seq[ProblemFilter]],
excludeAnnos: Seq[String],
publishVersion: String
publishVersion: Option[String]
): Option[String]
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class MimaWorkerImpl extends MimaWorkerApi {
backwardFilters: Map[String, Seq[ProblemFilter]],
forwardFilters: Map[String, Seq[ProblemFilter]],
excludeAnnos: Seq[String],
publishVersion: String
publishVersion: Option[String]
): Option[String] = {
sanityCheckScalaBinaryVersion(scalaBinaryVersion)

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.typesafe.tools.mima.core

private[com] object MyProblemReporting {
def isReported(
versionOpt: Option[String],
filters: Seq[ProblemFilter],
versionedFilters: Map[String, Seq[ProblemFilter]]
)(problem: Problem): Boolean = versionOpt match {
case None => filters.forall(_(problem))
case Some(version) =>
ProblemReporting.isReported(version, filters, versionedFilters)(problem)
}
}

This file was deleted.

38 changes: 28 additions & 10 deletions mill-mima/src/com/github/lolgab/mill/mima/MimaBase.scala
Original file line number Diff line number Diff line change
Expand Up @@ -13,31 +13,48 @@ import scala.util.chaining._

private[mima] trait MimaBase
extends JavaModule
with PublishModule
with ExtraCoursierSupport
with VersionSpecific {

private def publishDataTask: Task[Option[(String, String, String)]] =
this match {
case m: PublishModule =>
T.task {
Some(
(m.pomSettings().organization, m.artifactId(), m.publishVersion())
)
}
case _ => T.task { None }
}

/** Set of versions to check binary compatibility against. */
def mimaPreviousVersions: Target[Seq[String]] = T { Seq.empty[String] }

/** Set of artifacts to check binary compatibility against. By default this is
* derived from [[mimaPreviousVersions]].
*/
def mimaPreviousArtifacts: Target[Agg[Dep]] = T {
val publishData = publishDataTask()
val versions = mimaPreviousVersions().distinct
if (versions.isEmpty)
Result.Failure(
"No previous artifacts configured. Please override mimaPreviousVersions or mimaPreviousArtifacts.",
Some(Agg.empty[Dep])
)
else
Result.Success(
Agg.from(
versions.map(version =>
ivy"${pomSettings().organization}:${artifactId()}:${version}"
publishData match {
case Some((organization, artifactId, _)) =>
Result.Success(
Agg.from(
versions.map(version => ivy"$organization:$artifactId:$version")
)
)
)
)
case None =>
Result.Failure(
"The module is not a PublishModule so it requires setting mimaPreviousArtifacts manually. Please override mimaPreviousArtifacts or extend PublishModule.",
Some(Agg.empty[Dep])
)
}
}

private def mimaCheckDirectionInput = T.input {
Expand Down Expand Up @@ -125,13 +142,13 @@ private[mima] trait MimaBase
val log = T.ctx().log

val runClasspathIO =
runClasspath().view.map(_.path).filter(os.exists).map(_.toIO).toArray
runClasspath().iterator.map(_.path).filter(os.exists).map(_.toIO).toSeq
val current = mimaCurrentArtifact().path.pipe {
case p if os.exists(p) => p
case _ => (T.dest / "emptyClasses").tap(os.makeDir)
}.toIO

val previous = resolvedMimaPreviousArtifacts().map {
val previous = resolvedMimaPreviousArtifacts().iterator.map {
case (dep, artifact) =>
worker.api.Artifact(prettyDep(dep), artifact.path.toIO)
}.toSeq
Expand All @@ -155,6 +172,7 @@ private[mima] trait MimaBase
mimaBackwardIssueFilters().view.mapValues(_.map(toWorkerApi)).toMap
val forwardFilters =
mimaForwardIssueFilters().view.mapValues(_.map(toWorkerApi)).toMap
val publishVersion = publishDataTask().map(_._3)

mimaWorker().reportBinaryIssues(
scalaBinVersionTask(),
Expand All @@ -169,7 +187,7 @@ private[mima] trait MimaBase
backwardFilters,
forwardFilters,
mimaExcludeAnnotations(),
publishVersion()
publishVersion
) match {
case Some(error) => Result.Failure(error)
case None => Result.Success(())
Expand Down

0 comments on commit 8d8f63b

Please sign in to comment.