From aaf471dd36447f52ead4f334a10eb2a79cdc1914 Mon Sep 17 00:00:00 2001 From: Guillaume Martres Date: Fri, 23 Jun 2017 16:24:47 +0200 Subject: [PATCH 1/2] Add constant CrossVersion sbt 1 removes CrossVersion.binaryMapped which was used in the sbt-dotty plugin to provide a way to depend on Scala 2.x artifacts in a project that cross-compiles between Scala 2.x and Dotty (see `withDottyCompat()` in https://github.com/lampepfl/dotty/blob/master/sbt-dotty/src/dotty/tools/sbtplugin/DottyPlugin.scala). Using `binaryWith` is not enough because it only allows the user to specify a prefix and a suffix for the binary version which will always be set to `scalaBinaryVersion`. This commit introduces a new `Constant` kind of CrossVersion which allows the user to specify any string he wants as a cross-version, thus making it possible to port `withDottyCompat()` to sbt 1. --- .../src/main/contraband/librarymanagement.json | 12 ++++++++++++ .../sbt/librarymanagement/CrossVersionExtra.scala | 4 ++++ 2 files changed, 16 insertions(+) diff --git a/librarymanagement/src/main/contraband/librarymanagement.json b/librarymanagement/src/main/contraband/librarymanagement.json index 1ea41015e..71b18d691 100644 --- a/librarymanagement/src/main/contraband/librarymanagement.json +++ b/librarymanagement/src/main/contraband/librarymanagement.json @@ -150,6 +150,18 @@ { "name": "suffix", "type": "String", "default": "\"\"", "since": "0.0.1" } ] }, + { + "name": "Constant", + "namespace": "sbt.librarymanagement", + "target": "Scala", + "doc": [ + "Cross-versions a module using the string `value`." + ], + "type": "record", + "fields": [ + { "name": "value", "type": "String", "default": "\"\"", "since": "0.0.2" } + ] + }, { "name": "Patch", "namespace": "sbt.librarymanagement", diff --git a/librarymanagement/src/main/scala/sbt/librarymanagement/CrossVersionExtra.scala b/librarymanagement/src/main/scala/sbt/librarymanagement/CrossVersionExtra.scala index c7e8fecc8..b556a8a50 100644 --- a/librarymanagement/src/main/scala/sbt/librarymanagement/CrossVersionExtra.scala +++ b/librarymanagement/src/main/scala/sbt/librarymanagement/CrossVersionExtra.scala @@ -24,6 +24,9 @@ abstract class CrossVersionFunctions { /** Cross-versions a module with the binary version (typically the binary Scala version). */ def binary: CrossVersion = Binary() + /** Cross-versions a module with a constant string (typically the binary Scala version). */ + def constant(value: String): CrossVersion = Constant(value) + /** * Cross-versions a module with the result of prepending `prefix` and appending `suffix` to the binary version * (typically the binary Scala version). See also [[sbt.librarymanagement.Binary]]. @@ -58,6 +61,7 @@ abstract class CrossVersionFunctions { cross match { case _: Disabled => None case b: Binary => append(b.prefix + binaryVersion + b.suffix) + case c: Constant => append(c.value) case _: Patch => append(patchFun(fullVersion)) case f: Full => append(f.prefix + fullVersion + f.suffix) } From f325d466deada6f114e6ff056f47952481bca84f Mon Sep 17 00:00:00 2001 From: Guillaume Martres Date: Fri, 23 Jun 2017 16:49:10 +0200 Subject: [PATCH 2/2] Add tests for CrossVersion.constant --- .../src/test/scala/CrossVersionTest.scala | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/librarymanagement/src/test/scala/CrossVersionTest.scala b/librarymanagement/src/test/scala/CrossVersionTest.scala index b65c9a11b..376a17cb1 100644 --- a/librarymanagement/src/test/scala/CrossVersionTest.scala +++ b/librarymanagement/src/test/scala/CrossVersionTest.scala @@ -230,6 +230,13 @@ class CrossVersionTest extends UnitSpec { patchVersion("2.11.8-RC1-bin-extra") shouldBe Some("artefact_2.11.8-RC1") } + private def constantVersion(value: String) = + CrossVersion(CrossVersion.constant(value), "dummy1", "dummy2") map (fn => fn("artefact")) + + "CrossVersion.constant" should "add a constant to the version" in { + constantVersion("duck") shouldBe Some("artefact_duck") + } + "Disabled" should "have structural equality" in { Disabled() shouldBe Disabled() } @@ -239,4 +246,7 @@ class CrossVersionTest extends UnitSpec { "CrossVersion.binary" should "have structural equality" in { CrossVersion.binary shouldBe CrossVersion.binary } + "CrossVersion.constant" should "have structural equality" in { + CrossVersion.constant("duck") shouldBe CrossVersion.constant("duck") + } }