Skip to content

Commit

Permalink
Merge pull request #471 from dwijnand/make-signature-problems-opt-in
Browse files Browse the repository at this point in the history
Make signature problems opt-in
  • Loading branch information
dwijnand authored Feb 18, 2020
2 parents 4943295 + 9ed6a88 commit c07be2a
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 11 deletions.
11 changes: 8 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,13 +88,18 @@ mimaBinaryIssueFilters ++= Seq(

Most MiMa checks (`DirectMissingMethod`, `IncompatibleResultType`,
`IncompatibleMethType`, etc) are against the method `descriptor`, which
includes the signature without information about generic parameters.
is the "raw" type signature, without any information about generic parameters.

The `IncompatibleSignature` check compares the `Signature`, which includes the
full signature including generic parameters. This can catch real
incompatibilities, but also sometimes triggers for a change in generics that
would not in fact cause problems at run time. To opt-out of this check you can
filter them like this:
would not in fact cause problems at run time. Opt-in to this check by setting:

```scala
ThisBuild / mimaReportSignatureProblems := true
```

Prior to MiMa 0.7 this check was always on, and you could opt-out like this:

```scala
mimaBinaryIssueFilters ++= Seq(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,12 @@ object MimaKeys extends MimaKeys

class MimaKeys {

final val mimaPreviousArtifacts = settingKey[Set[ModuleID]]("Previous released artifacts used to test binary compatibility.")
final val mimaReportBinaryIssues = taskKey[Unit]("Logs all binary incompatibilities to the sbt console/logs.")
final val mimaBinaryIssueFilters = taskKey[Seq[ProblemFilter]]("Filters to apply to binary issues found. Applies both to backward and forward binary compatibility checking.")
final val mimaFailOnProblem = settingKey[Boolean]("if true, fail the build on binary incompatibility detection.")
final val mimaFailOnNoPrevious = settingKey[Boolean]("if true, fail the build if no previous artifacts are set.")
final val mimaPreviousArtifacts = settingKey[Set[ModuleID]]("Previous released artifacts used to test binary compatibility.")
final val mimaReportBinaryIssues = taskKey[Unit]("Logs all binary incompatibilities to the sbt console/logs.")
final val mimaBinaryIssueFilters = taskKey[Seq[ProblemFilter]]("Filters to apply to binary issues found. Applies both to backward and forward binary compatibility checking.")
final val mimaFailOnProblem = settingKey[Boolean]("if true, fail the build on binary incompatibility detection.")
final val mimaFailOnNoPrevious = settingKey[Boolean]("if true, fail the build if no previous artifacts are set.")
final val mimaReportSignatureProblems = settingKey[Boolean]("if true, report `IncompatibleSignatureProblem`s.")

final val mimaPreviousClassfiles = taskKey[Map[ModuleID, File]]("Directories or jars containing the previous class files used to test compatibility with a given module.")
final val mimaCurrentClassfiles = taskKey[File]("Directory or jar containing the current class files used to test compatibility.")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package plugin

import sbt._
import sbt.Keys._
import com.typesafe.tools.mima.core.{ IncompatibleSignatureProblem, ProblemFilters }

/** MiMa's sbt plugin. */
object MimaPlugin extends AutoPlugin {
Expand All @@ -17,6 +18,7 @@ object MimaPlugin extends AutoPlugin {
mimaBinaryIssueFilters := Nil,
mimaFailOnProblem := true,
mimaFailOnNoPrevious := true,
mimaReportSignatureProblems := false,
mimaCheckDirection := "backward",
)

Expand All @@ -29,7 +31,7 @@ object MimaPlugin extends AutoPlugin {
problems._1,
problems._2,
mimaFailOnProblem.value,
mimaBinaryIssueFilters.value,
binaryIssueFilters.value,
mimaBackwardIssueFilters.value,
mimaForwardIssueFilters.value,
log,
Expand Down Expand Up @@ -63,6 +65,11 @@ object MimaPlugin extends AutoPlugin {
@deprecated("Switch to enablePlugins(MimaPlugin)", "0.7.0")
def mimaDefaultSettings: Seq[Setting[_]] = globalSettings ++ buildSettings ++ projectSettings

private def binaryIssueFilters = Def.task {
val noSigs = ProblemFilters.exclude[IncompatibleSignatureProblem]("*")
mimaBinaryIssueFilters.value ++ (if (mimaReportSignatureProblems.value) Nil else Seq(noSigs))
}

// Allows reuse between mimaFindBinaryIssues and mimaReportBinaryIssues
// without blowing up the Akka build's heap
private def binaryIssuesIterator = Def.task {
Expand Down
4 changes: 4 additions & 0 deletions sbtplugin/src/sbt-test/sbt-mima-plugin/build-level-keys/test
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,7 @@
> set ThisBuild / mimaPreviousArtifacts := Set(organization.value %% name.value % s"0.0.1-SNAPSHOT")
> set ThisBuild / mimaBinaryIssueFilters := Seq(com.typesafe.tools.mima.core.ProblemFilters.exclude(s"MissingMethodProblem", s"A.bar"))
> mimaReportBinaryIssues

# fail, because mimaReportSignatureProblems was set
> set ThisBuild / mimaReportSignatureProblems := true
-> mimaReportBinaryIssues
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
class A {
def foo = 1
def foo = Option(1)
def bar = foo
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
class A {
def foo = 1
def foo = Option("one")
}

0 comments on commit c07be2a

Please sign in to comment.