Fix MatchError when using cross version patch with sbt 1.0

This commit is contained in:
Alexandre Archambault 2017-09-19 23:23:32 +02:00
parent ce1ebc0124
commit d077a82341
6 changed files with 26 additions and 25 deletions

View File

@ -18,10 +18,6 @@ object SbtCompatibility {
type IvySbt = sbt.IvySbt
type Binary = sbt.CrossVersion.Binary
type Disabled = sbt.CrossVersion.Disabled.type
type Full = sbt.CrossVersion.Full
implicit class ModuleIDOps(val id: sbt.ModuleID) extends AnyVal {
def withConfigurations(configurations: Option[String]): sbt.ModuleID =
id.copy(configurations = configurations)

View File

@ -16,20 +16,6 @@ object SbtCompatibility {
type IvySbt = sbt.internal.librarymanagement.IvySbt
type Binary = sbt.librarymanagement.Binary
type Disabled = sbt.librarymanagement.Disabled
type Full = sbt.librarymanagement.Full
implicit class BinaryOps(private val binary: Binary) extends AnyVal {
def remapVersion(scalaBinaryVersion: String): String =
binary.prefix + scalaBinaryVersion + binary.suffix
}
implicit class FullOps(private val full: Full) extends AnyVal {
def remapVersion(scalaVersion: String): String =
full.prefix + scalaVersion + full.suffix
}
def needsIvyXmlLocal = sbt.Keys.publishLocalConfiguration
def needsIvyXml = sbt.Keys.publishConfiguration

View File

@ -25,11 +25,9 @@ object FromSbt {
crossVersion: CrossVersion,
scalaVersion: => String,
scalaBinaryVersion: => String
): String = crossVersion match {
case _: Disabled => name
case f: Full => name + "_" + f.remapVersion(scalaVersion)
case b: Binary => name + "_" + b.remapVersion(scalaBinaryVersion)
}
): String =
CrossVersion(crossVersion, scalaVersion, scalaBinaryVersion)
.fold(name)(_(name))
def attributes(attr: Map[String, String]): Map[String, String] =
attr.map { case (k, v) =>

View File

@ -1,9 +1,10 @@
import Compatibility._
scalaVersion := "2.12.2-bin-typelevel-4"
scalaOrganization := "org.typelevel"
scalacOptions += "-Yinduction-heuristics"
libraryDependencies ++= Seq(
"com.47deg" %% "freestyle" % "0.1.0",
// CrossVersion.patch not available in sbt 0.13.8
compilerPlugin("org.scalamacros" % "paradise_2.12.2" % "2.1.0")
compilerPlugin("org.scalamacros" %% "paradise" % "2.1.0" cross CrossVersion.patch)
)

View File

@ -0,0 +1,19 @@
object Compatibility {
// patch method not available in sbt 0.13.8
implicit class CrossVersionOps(val companion: sbt.CrossVersion.type) extends AnyVal {
def patch: sbt.CrossVersion = new sbt.CrossVersion.Full(patchFun)
}
// adapted from sbt.CrossVersion from the sbt 0.13.16 sources
private val BinCompatV = """(\d+)\.(\d+)\.(\d+)(-\w+)??-bin(-.*)?""".r
private def patchFun(fullVersion: String): String =
fullVersion match {
case BinCompatV(x, y, z, w, _) => s"""$x.$y.$z${if (w == null) "" else w}"""
case other => other
}
}