Skip to content

Cross compile to Scala 3.0.0-M3 #146

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 14 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ See also the [CHANGELOG](https://github.com/cucumber/cucumber-jvm/blob/master/CH

### Added

- [Build] Cross compilation with Scala 3.0.0-M3
- TODO DOCUMENT BREAKING CHANGES

### Changed

### Deprecated
Expand Down
24 changes: 18 additions & 6 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ ThisBuild / homepage := Some(
val scala211 = "2.11.12"
val scala212 = "2.12.12"
val scala213 = "2.13.3"
val scala3 = "3.0.0-M3"

scalaVersion := scala213

Expand All @@ -52,6 +53,7 @@ lazy val commonSettings = Seq(
case Some((2, 11)) => ScalacOptions.scalacOptions211
case Some((2, 12)) => ScalacOptions.scalacOptions212
case Some((2, 13)) => ScalacOptions.scalacOptions213
case Some((3, 0)) => ScalacOptions.scalacOptions3
case _ => Seq()
}
}
Expand All @@ -75,23 +77,33 @@ lazy val cucumberScala = (projectMatrix in file("cucumber-scala"))
libraryDependencies ++= Seq(
"io.cucumber" % "cucumber-core" % cucumberVersion,
// Users have to provide it (for JacksonDefaultDataTableTransformer)
"com.fasterxml.jackson.module" %% "jackson-module-scala" % jacksonVersion % Provided,
("com.fasterxml.jackson.module" %% "jackson-module-scala" % jacksonVersion % Provided)
.withDottyCompat(scalaVersion.value),
"junit" % "junit" % junitVersion % Test,
"io.cucumber" % "cucumber-junit" % cucumberVersion % Test,
"org.mockito" %% "mockito-scala" % mockitoScalaVersion % Test
("org.mockito" %% "mockito-scala" % mockitoScalaVersion % Test)
.withDottyCompat(scalaVersion.value)
),
libraryDependencies ++= {
CrossVersion.partialVersion(scalaVersion.value) match {
case Some((2, n)) if n <= 12 =>
List("org.scala-lang.modules" %% "scala-collection-compat" % "2.3.1")
case Some((3, 0)) =>
List("dev.zio" %% "izumi-reflect" % "1.0.0-M12")
case _ => Nil
}
},
unmanagedSourceDirectories in Compile ++= {
val sourceDir = (sourceDirectory in Compile).value
CrossVersion.partialVersion(scalaVersion.value) match {
case Some((2, n)) if n <= 11 => Seq(sourceDir / "scala-2.11")
case _ => Seq()
case Some((2, n)) if n > 11 =>
Seq(sourceDir / "scala-2")
case Some((2, n)) if n <= 11 =>
Seq(sourceDir / "scala-2", sourceDir / "scala-2.11")
case Some((3, 0)) =>
Seq(sourceDir / "scala-3.0")
case _ =>
Seq()
}
},
// Generate I18n traits
Expand All @@ -102,7 +114,7 @@ lazy val cucumberScala = (projectMatrix in file("cucumber-scala"))
Seq(file)
}.taskValue
)
.jvmPlatform(scalaVersions = Seq(scala213, scala212, scala211))
.jvmPlatform(scalaVersions = Seq(scala3, scala213, scala212, scala211))

// Examples project
lazy val examples = (projectMatrix in file("examples"))
Expand All @@ -116,7 +128,7 @@ lazy val examples = (projectMatrix in file("examples"))
publishArtifact := false
)
.dependsOn(cucumberScala % Test)
.jvmPlatform(scalaVersions = Seq(scala213, scala212))
.jvmPlatform(scalaVersions = Seq(scala3, scala213, scala212))

// Release & Publish

Expand Down
64 changes: 63 additions & 1 deletion cucumber-scala/src/main/codegen/gen.scala
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,30 @@ for (i <- 1 to 22) {
println(p1 + p2 + ": Unit = { " + register + pf + otherwise + closeRegister + "\n")
}

/*
* Generates the evil looking apply methods in ScalaDsl#StepBody for Function1 to Function22
* For Scala 3
*/
for (i <- 1 to 22) {
val ts = (1 to i).map(n => s"T$n").mkString(", ")
val ltt = (1 to i).map(n => s"LTT[T$n]").mkString(", ")
val pf = " case List(" + (1 to i).map("a" + _ + ":AnyRef").mkString(", ") + ") => \n f(" + (1 to i).map(n => "a" + n + ".asInstanceOf[T" + n + "]").mkString(",\n ") + ")\n"

val template =
s"""
|inline def apply[$ts](f: ($ts) => Any): Unit = {
| val types = Seq($ltt)
| register(types) {
| $pf
| case _ =>
| throw new IncorrectStepDefinitionException()
| }
|}
|""".stripMargin

println(template)
}

/*
* Generates the apply methods in ParameterTypeDsl for Function1 to Function22
*/
Expand All @@ -35,4 +59,42 @@ for (i <- 1 to 22) {
|""".stripMargin

println(template)
}
}

/*
* Generates the macros parameterTypes.
* For Scala 3
*/
for (i <- 1 to 22) {

val ts = (1 to i).map("T".+).mkString(", ")

val template =
s"""
|inline def parameterTypes[$ts](): Seq[MyType] = {
| $${ getTypes[$ts]() }
|}
|""".stripMargin

println(template)
}

/*
* Generates the macros method getTypes.
* For Scala 3
*/
for (i <- 1 to 22) {
val ts = (1 to i).map(n => s"T$n").mkString(", ")
val usings = (1 to i).map(n => s"Type[T$n]").mkString(", ")
val reprs = (1 to i).map(n => s"TypeRepr.of[T$n]").mkString(", ")

val template =
s"""
|private def getTypes[$ts]()(using $usings, Quotes): Expr[Seq[MyType]] = {
| import quotes.reflect._
| getTypesFromRepr(Seq($reprs))
|}
|""".stripMargin

println(template)
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,13 @@ object ScalaTypeHelper {

class ScalaParameterizedType(manifest: Manifest[_]) extends ParameterizedType {

override def getActualTypeArguments: Array[Type] =
private val typeArgs =
manifest.typeArguments.map(ScalaTypeHelper.asJavaType).toArray
private val rawType = manifest.runtimeClass

override def getRawType: Type = manifest.runtimeClass
override def getActualTypeArguments: Array[Type] = typeArgs

override def getRawType: Type = rawType

override def getOwnerType: Type = null

Expand Down
Loading