diff --git a/build.sc b/build.sc index 4f54108..8f3da75 100644 --- a/build.sc +++ b/build.sc @@ -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) + ), ) } diff --git a/itest/src/not-publish-module/build.sc b/itest/src/not-publish-module/build.sc new file mode 100644 index 0000000..f4c78b2 --- /dev/null +++ b/itest/src/not-publish-module/build.sc @@ -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()() + () +} diff --git a/itest/src/not-publish-module/curr/src/Main.scala b/itest/src/not-publish-module/curr/src/Main.scala new file mode 100644 index 0000000..b63e92b --- /dev/null +++ b/itest/src/not-publish-module/curr/src/Main.scala @@ -0,0 +1 @@ +object Main {} diff --git a/itest/src/not-publish-module/prev/src/Main.scala b/itest/src/not-publish-module/prev/src/Main.scala new file mode 100644 index 0000000..2fc00f7 --- /dev/null +++ b/itest/src/not-publish-module/prev/src/Main.scala @@ -0,0 +1,3 @@ +object Main { + def hello(): String = "Hello world!" +} diff --git a/mill-mima-worker-api/src/com/github/lolgab/mill/mima/worker/api/MimaWorkerApi.scala b/mill-mima-worker-api/src/com/github/lolgab/mill/mima/worker/api/MimaWorkerApi.scala index 3d644a3..99c2ecd 100644 --- a/mill-mima-worker-api/src/com/github/lolgab/mill/mima/worker/api/MimaWorkerApi.scala +++ b/mill-mima-worker-api/src/com/github/lolgab/mill/mima/worker/api/MimaWorkerApi.scala @@ -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] } diff --git a/mill-mima-worker-impl/src/com/github/lolgab/mill/mima/worker/MimaWorkerImpl.scala b/mill-mima-worker-impl/src/com/github/lolgab/mill/mima/worker/MimaWorkerImpl.scala index c4adb95..45045f7 100644 --- a/mill-mima-worker-impl/src/com/github/lolgab/mill/mima/worker/MimaWorkerImpl.scala +++ b/mill-mima-worker-impl/src/com/github/lolgab/mill/mima/worker/MimaWorkerImpl.scala @@ -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) diff --git a/mill-mima-worker-impl/src/com/typesafe/tools/mima/core/MyProblemReporting.scala b/mill-mima-worker-impl/src/com/typesafe/tools/mima/core/MyProblemReporting.scala new file mode 100644 index 0000000..93e917a --- /dev/null +++ b/mill-mima-worker-impl/src/com/typesafe/tools/mima/core/MyProblemReporting.scala @@ -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) + } +} diff --git a/mill-mima-worker-impl/src/com/typesafe/tools/mima/core/ProblemReportingExport.scala b/mill-mima-worker-impl/src/com/typesafe/tools/mima/core/ProblemReportingExport.scala deleted file mode 100644 index 243c930..0000000 --- a/mill-mima-worker-impl/src/com/typesafe/tools/mima/core/ProblemReportingExport.scala +++ /dev/null @@ -1,5 +0,0 @@ -package com.typesafe.tools.mima.core - -private[com] object MyProblemReporting { - val isReported = ProblemReporting.isReported _ -} diff --git a/mill-mima/src/com/github/lolgab/mill/mima/MimaBase.scala b/mill-mima/src/com/github/lolgab/mill/mima/MimaBase.scala index 9790af6..567fc87 100644 --- a/mill-mima/src/com/github/lolgab/mill/mima/MimaBase.scala +++ b/mill-mima/src/com/github/lolgab/mill/mima/MimaBase.scala @@ -13,10 +13,20 @@ 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] } @@ -24,6 +34,7 @@ private[mima] trait MimaBase * derived from [[mimaPreviousVersions]]. */ def mimaPreviousArtifacts: Target[Agg[Dep]] = T { + val publishData = publishDataTask() val versions = mimaPreviousVersions().distinct if (versions.isEmpty) Result.Failure( @@ -31,13 +42,19 @@ private[mima] trait MimaBase 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 { @@ -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 @@ -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(), @@ -169,7 +187,7 @@ private[mima] trait MimaBase backwardFilters, forwardFilters, mimaExcludeAnnotations(), - publishVersion() + publishVersion ) match { case Some(error) => Result.Failure(error) case None => Result.Success(())