@@ -15,6 +15,8 @@ import xerial.sbt.pack.PackPlugin
1515import xerial .sbt .pack .PackPlugin .autoImport ._
1616import xerial .sbt .Sonatype .autoImport ._
1717
18+ import com .typesafe .tools .mima .plugin .MimaPlugin .autoImport ._
19+
1820import dotty .tools .sbtplugin .DottyIDEPlugin .{ installCodeExtension , prepareCommand , runProcess }
1921import dotty .tools .sbtplugin .DottyIDEPlugin .autoImport ._
2022
@@ -72,6 +74,29 @@ object Build {
7274 val publishedDottyVersion = referenceVersion
7375 val sbtDottyVersion = " 0.5.5"
7476
77+ /** Version against which we check binary compatibility.
78+ *
79+ * This must be the latest published release in the same versioning line.
80+ * For example, if the next version is going to be 3.1.4, then this must be
81+ * set to 3.1.3. If it is going to be 3.1.0, it must be set to the latest
82+ * 3.0.x release.
83+ */
84+ val previousDottyVersion = " 3.0.0-RC3"
85+ val previousDottyBinaryVersion = " 3.0.0-RC3"
86+
87+ object CompatMode {
88+ final val BinaryCompatible = 0
89+ final val SourceAndBinaryCompatible = 1
90+ }
91+
92+ val compatMode = {
93+ val VersionRE = """ ^\d+\.(\d+).(\d+).*""" .r
94+ baseVersion match {
95+ case VersionRE (_, " 0" ) => CompatMode .BinaryCompatible
96+ case _ => CompatMode .SourceAndBinaryCompatible
97+ }
98+ }
99+
75100 /** scala-library version required to compile Dotty.
76101 *
77102 * Both the non-bootstrapped and bootstrapped version should match, unless
@@ -397,6 +422,22 @@ object Build {
397422 javaOptions += " -DBENCH_CLASS_PATH=" + Attributed .data((`scala3-library-bootstrapped` / Compile / fullClasspath).value).mkString(" " , File .pathSeparator, " " )
398423 )
399424
425+ lazy val commonMiMaSettings = Def .settings(
426+ mimaPreviousArtifacts += {
427+ val thisProjectID = projectID.value
428+ val crossedName = thisProjectID.crossVersion match {
429+ case cv : Disabled => thisProjectID.name
430+ case cv : Binary => s " ${thisProjectID.name}_ ${cv.prefix}$previousDottyBinaryVersion${cv.suffix}"
431+ }
432+ (thisProjectID.organization % crossedName % previousDottyVersion)
433+ },
434+
435+ mimaCheckDirection := (compatMode match {
436+ case CompatMode .BinaryCompatible => " backward"
437+ case CompatMode .SourceAndBinaryCompatible => " both"
438+ }),
439+ )
440+
400441 /** Projects -------------------------------------------------------------- */
401442
402443 val dottyCompilerBootstrappedRef = LocalProject (" scala3-compiler-bootstrapped" )
@@ -416,7 +457,8 @@ object Build {
416457 lazy val `scala3-bootstrapped` = project.asDottyRoot(Bootstrapped )
417458
418459 lazy val `scala3-interfaces` = project.in(file(" interfaces" )).
419- settings(commonJavaSettings)
460+ settings(commonJavaSettings).
461+ settings(commonMiMaSettings)
420462
421463 /** Find an artifact with the given `name` in `classpath` */
422464 def findArtifact (classpath : Def .Classpath , name : String ): File = classpath
@@ -1641,15 +1683,17 @@ object Build {
16411683 ).
16421684 settings(dottyLibrarySettings)
16431685 if (mode == Bootstrapped ) {
1644- base.settings(Seq (
1686+ base.settings(
16451687 (Compile / doc) := {
16461688 // Workaround for
16471689 // [error] |object IArray cannot have the same name as object IArray in package scala
16481690 // -- cannot define object member with the same name as a object member in self reference _.
16491691 val doWork = (Compile / doc).result.value
16501692 (Compile / doc/ target).value
1651- }
1652- ))
1693+ },
1694+ commonMiMaSettings,
1695+ mimaBinaryIssueFilters ++= MiMaFilters .Library ,
1696+ )
16531697 } else base
16541698 }
16551699
0 commit comments