@@ -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
@@ -392,6 +417,22 @@ object Build {
392417 javaOptions += " -DBENCH_CLASS_PATH=" + Attributed .data((`scala3-library-bootstrapped` / Compile / fullClasspath).value).mkString(" " , File .pathSeparator, " " )
393418 )
394419
420+ lazy val commonMiMaSettings = Def .settings(
421+ mimaPreviousArtifacts += {
422+ val thisProjectID = projectID.value
423+ val crossedName = thisProjectID.crossVersion match {
424+ case cv : Disabled => thisProjectID.name
425+ case cv : Binary => s " ${thisProjectID.name}_ ${cv.prefix}$previousDottyBinaryVersion${cv.suffix}"
426+ }
427+ (thisProjectID.organization % crossedName % previousDottyVersion)
428+ },
429+
430+ mimaCheckDirection := (compatMode match {
431+ case CompatMode .BinaryCompatible => " backward"
432+ case CompatMode .SourceAndBinaryCompatible => " both"
433+ }),
434+ )
435+
395436 /** Projects -------------------------------------------------------------- */
396437
397438 val dottyCompilerBootstrappedRef = LocalProject (" scala3-compiler-bootstrapped" )
@@ -411,7 +452,8 @@ object Build {
411452 lazy val `scala3-bootstrapped` = project.asDottyRoot(Bootstrapped )
412453
413454 lazy val `scala3-interfaces` = project.in(file(" interfaces" )).
414- settings(commonJavaSettings)
455+ settings(commonJavaSettings).
456+ settings(commonMiMaSettings)
415457
416458 /** Find an artifact with the given `name` in `classpath` */
417459 def findArtifact (classpath : Def .Classpath , name : String ): File = classpath
@@ -1636,15 +1678,17 @@ object Build {
16361678 ).
16371679 settings(dottyLibrarySettings)
16381680 if (mode == Bootstrapped ) {
1639- base.settings(Seq (
1681+ base.settings(
16401682 (Compile / doc) := {
16411683 // Workaround for
16421684 // [error] |object IArray cannot have the same name as object IArray in package scala
16431685 // -- cannot define object member with the same name as a object member in self reference _.
16441686 val doWork = (Compile / doc).result.value
16451687 (Compile / doc/ target).value
1646- }
1647- ))
1688+ },
1689+ commonMiMaSettings,
1690+ mimaBinaryIssueFilters ++= MiMaFilters .Library ,
1691+ )
16481692 } else base
16491693 }
16501694
0 commit comments