From 0dfd40972da795a51a9e4c8a00950e00230d870c Mon Sep 17 00:00:00 2001 From: Miles Sabin Date: Thu, 29 Sep 2016 01:42:59 +0100 Subject: [PATCH] Added CrossVersion.patch which strips off -bin-suffix. (#2757) --- ivy/src/main/scala/sbt/CrossVersion.scala | 13 +++++++++++++ ivy/src/test/scala/CrossVersionTest.scala | 19 +++++++++++++++++++ notes/0.13.13.markdown | 4 ++++ 3 files changed, 36 insertions(+) diff --git a/ivy/src/main/scala/sbt/CrossVersion.scala b/ivy/src/main/scala/sbt/CrossVersion.scala index b17ac525c..cedd6321d 100644 --- a/ivy/src/main/scala/sbt/CrossVersion.scala +++ b/ivy/src/main/scala/sbt/CrossVersion.scala @@ -92,6 +92,19 @@ object CrossVersion { private[this] def idFun[T]: T => T = x => x + /** + * Cross-versions a module with the full Scala version excluding any `-bin` suffix. + */ + def patch: CrossVersion = new Full(patchFun) + + private[this] def patchFun(fullVersion: String): String = { + val BinCompatV = """(\d+)\.(\d+)\.(\d+)(-\w+)??-bin(-.*)?""".r + fullVersion match { + case BinCompatV(x, y, z, w, _) => s"""$x.$y.$z${if (w == null) "" else w}""" + case other => other + } + } + @deprecated("Will be made private.", "0.13.1") def append(s: String): Option[String => String] = Some(x => crossName(x, s)) diff --git a/ivy/src/test/scala/CrossVersionTest.scala b/ivy/src/test/scala/CrossVersionTest.scala index 364d6c67e..0e0e7ed9d 100644 --- a/ivy/src/test/scala/CrossVersionTest.scala +++ b/ivy/src/test/scala/CrossVersionTest.scala @@ -118,5 +118,24 @@ object CrossVersionTest extends Specification { "return binary Scala version for 2.10.1 as 2.10" in { CrossVersion.binaryScalaVersion("2.10.1") must_== "2.10" } + + "return patch Scala version for 2.11.8 as 2.11.8" in { + CrossVersion(CrossVersion.patch, "2.11.8", "dummy").map(_("artefact")) must_== Some("artefact_2.11.8") + } + "return patch Scala version for 2.11.8-M1 as 2.11.8-M1" in { + CrossVersion(CrossVersion.patch, "2.11.8-M1", "dummy").map(_("artefact")) must_== Some("artefact_2.11.8-M1") + } + "return patch Scala version for 2.11.8-RC1 as 2.11.8-RC1" in { + CrossVersion(CrossVersion.patch, "2.11.8-RC1", "dummy").map(_("artefact")) must_== Some("artefact_2.11.8-RC1") + } + "return patch Scala version for 2.11.8-bin-extra as 2.11.8" in { + CrossVersion(CrossVersion.patch, "2.11.8-bin-extra", "dummy").map(_("artefact")) must_== Some("artefact_2.11.8") + } + "return patch Scala version for 2.11.8-M1-bin-extra as 2.11.8-M1" in { + CrossVersion(CrossVersion.patch, "2.11.8-M1-bin-extra", "dummy").map(_("artefact")) must_== Some("artefact_2.11.8-M1") + } + "return patch Scala version for 2.11.8-RC1-bin-extra as 2.11.8-RC1" in { + CrossVersion(CrossVersion.patch, "2.11.8-RC1-bin-extra", "dummy").map(_("artefact")) must_== Some("artefact_2.11.8-RC1") + } } } diff --git a/notes/0.13.13.markdown b/notes/0.13.13.markdown index 9dc2fe46d..faa8e34f0 100644 --- a/notes/0.13.13.markdown +++ b/notes/0.13.13.markdown @@ -19,6 +19,10 @@ - Adds `.jvmopts` support to the launcher script. [sbt/sbt-launcher-package#111][111] by [@fommil][@fommil] - Adds `.java-version` support to the Windows launcher script. [sbt/sbt-launcher-package#111][111] by [@fommil][@fommil] - The startup log level is dropped to `-error` in script mode using `scalas`. [#840][840]/[#2746][2746] by [@eed3si9n][@eed3si9n] +- Adds `CrossVersion.patch` which sits in between `CrossVersion.binary` and `CrossVersion.full` in that it strips off any + trailing `-bin-...` suffix which is used to distinguish variant but binary compatible Scala toolchain builds. Most things + which are currently `CrossVersion.full` (eg. Scala compiler plugins, esp. macro-paradise) would be more appropriately + depended on as `CrossVersion.patch` from this release on. ### Bug fixes