Skip to content

Commit

Permalink
Merge pull request #5 from djspiewak/feature/2.13
Browse files Browse the repository at this point in the history
(Hopefully) fixed 2.13 handling with the flag removal in M4
  • Loading branch information
fiadliel authored Jun 19, 2018
2 parents f0149bd + a370b6c commit 824ae13
Showing 1 changed file with 34 additions and 13 deletions.
47 changes: 34 additions & 13 deletions src/main/scala/PartialUnification.scala
Original file line number Diff line number Diff line change
Expand Up @@ -13,24 +13,45 @@ object PartialUnification extends AutoPlugin {

import autoImport._

def pluginOrFlag(scalaVersion: String, pluginModule: ModuleID): Either[ModuleID, String] = {
val pluginDependency = Left(compilerPlugin(pluginModule cross CrossVersion.full))
val flag = Right("-Ypartial-unification")
val VersionNumber((major +: minor +: patch +: _), _, _) = scalaVersion

(major, minor, patch) match {
case (2, 10, p) if p >= 6 => pluginDependency
case (2, 11, 8) => pluginDependency
case (2, 11, p) if p >= 9 => flag
case (2, 12, _) => flag
case (2, 13, _) => flag
def pluginOrFlag(scalaVersion: String, pluginModule: ModuleID): Resolution = {
val pluginDependency = Resolution.Plugin(compilerPlugin(pluginModule cross CrossVersion.full))
val flag = Resolution.Flag("-Ypartial-unification")
val VersionNumber((major +: minor +: patch +: _), tags, _) = scalaVersion

(major, minor, patch, tags) match {
case (2, 10, p, _) if p >= 6 => pluginDependency
case (2, 11, 8, _) => pluginDependency
case (2, 11, p, _) if p >= 9 => flag
case (2, 12, _, _) => flag
case (2, 13, _, milestone +: _) if milestone == "M1" || milestone == "M2" || milestone == "M3" => flag // ignoring the M4 snapshot
case (2, 13, _, _) => Resolution.NothingHappens
case _ => sys.error(s"scala version $scalaVersion is not supported by this plugin.")
}
}

override val projectSettings = Seq(
partialUnificationModule := "com.milessabin" % "si2712fix-plugin" % "1.2.0",
libraryDependencies ++= pluginOrFlag(scalaVersion.value, partialUnificationModule.value).left.toSeq,
scalacOptions ++= pluginOrFlag(scalaVersion.value, partialUnificationModule.value).right.toSeq

libraryDependencies ++= {
pluginOrFlag(scalaVersion.value, partialUnificationModule.value) match {
case Resolution.Plugin(id) => Seq(id)
case _ => Seq.empty
}
},

scalacOptions ++= {
pluginOrFlag(scalaVersion.value, partialUnificationModule.value) match {
case Resolution.Flag(flag) => Seq(flag)
case _ => Seq.empty
}
}
)

sealed trait Resolution extends Product with Serializable

object Resolution {
final case class Plugin(id: ModuleID) extends Resolution
final case class Flag(flag: String) extends Resolution
case object NothingHappens extends Resolution
}
}

0 comments on commit 824ae13

Please sign in to comment.