From 26bc1f14cad26d2e2c1d93d71fa7ce806ff225c8 Mon Sep 17 00:00:00 2001 From: Sarah Gerweck Date: Tue, 6 Dec 2016 23:25:12 -0800 Subject: [PATCH] Updates to build for 2.12 --- CHANGELOG.md | 5 +++ project/BasicSettings.scala | 84 +++++++++++++++++++++++++------------ project/Helpers.scala | 34 +++++---------- 3 files changed, 73 insertions(+), 50 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 770fcf1..6baafe0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -49,3 +49,8 @@ end users will be listed here. #### 0.11.1 * Update to Akka 2.4.11. + +#### 0.11.2 + + * Update to Akka 2.4.14. + * Add support for Scala 2.12 diff --git a/project/BasicSettings.scala b/project/BasicSettings.scala index 4396317..7209f8d 100644 --- a/project/BasicSettings.scala +++ b/project/BasicSettings.scala @@ -62,8 +62,8 @@ object BasicSettings extends AutoPlugin with Basics { scalaVersion := buildScalaVersion, crossScalaVersions := buildScalaVersions, - scalacOptions ++= buildScalacOptions, - javacOptions ++= buildJavacOptions, + addScalacOptions(), + addJavacOptions(), autoAPIMappings := true, updateOptions := updateOptions.value.withCachedResolution(cachedResolution), @@ -88,30 +88,62 @@ object BasicSettings extends AutoPlugin with Basics { lazy val buildScalaVersions = buildScalaVersion +: extraScalaVersions - val buildScalacOptions = Seq ( - "-unchecked", - "-feature", - "-target:jvm-" + minimumJavaVersion - ) ++ ( - if (deprecation) Seq("-deprecation") else Seq.empty - ) ++ ( - if (optimize) Seq("-optimize") else Seq.empty - ) ++ ( - if (inlineWarn) Seq("-Yinline-warnings") else Seq.empty - ) ++ ( - if (unusedWarn) Seq("-Ywarn-unused") else Seq.empty - ) ++ ( - if (importWarn) Seq("-Ywarn-unused-import") else Seq.empty - ) ++ ( - if (newBackend) Seq("-Ybackend:GenBCode", "-Yopt:l:classpath") else Seq.empty - ) + def addScalacOptions(optim: Boolean = optimize) = Def.derive { + scalacOptions ++= { + val sv = SVer(scalaBinaryVersion.value) + var options = Seq.empty[String] - /* Java build setup */ - val buildJavacOptions = Seq( - "-target", minimumJavaVersion, - "-source", minimumJavaVersion - ) ++ ( - if (deprecation) Seq("-Xlint:deprecation") else Seq.empty - ) + options :+= "-unchecked" + options :+= "-feature" + if (deprecation) { + options :+= "-deprecation" + } + if (inlineWarn) { + options :+= "-Yinline-warnings" + } + if (unusedWarn) { + options :+= "-Ywarn-unused" + } + if (importWarn) { + options :+= "-Ywarn-unused-import" + } + if (!sv.requireJava8) { + options :+= "-target:jvm-" + minimumJavaVersion + } + if (optim) { + if (sv.newOptimize || sv.supportsNewBackend && newBackend) { + options :+= "-opt:l:project" + } else if (!sv.requireJava8) { + options :+= "-optimize" + } + } + if (sv.supportsNewBackend && newBackend && !sv.requireJava8) { + options :+= "-Ybackend:GenBCode" + } + + options + } + } + + def addJavacOptions() = Def.derive { + javacOptions ++= { + val sv = SVer(scalaBinaryVersion.value) + var options = Seq.empty[String] + + if (sv.requireJava8) { + options ++= Seq[String]( + "-target", "1.8", + "-source", "1.8" + ) + } else { + options ++= Seq[String]( + "-target", minimumJavaVersion, + "-source", minimumJavaVersion + ) + } + + options + } + } } diff --git a/project/Helpers.scala b/project/Helpers.scala index 1d74259..4478066 100644 --- a/project/Helpers.scala +++ b/project/Helpers.scala @@ -20,41 +20,27 @@ object Helpers { } sealed trait SVer { - def requireJava8: Boolean + val supportsNewBackend: Boolean = false + val requireJava8: Boolean = true + val newOptimize: Boolean = false } object SVer { def apply(scalaVersion: String): SVer = { scalaVersion match { - case "2.10" => SVer2_10 - case "2.11" => SVer2_11 - case "2.12.0-M1" => SVer2_12M1 - case "2.12.0-M2" => SVer2_12M2 - case "2.12.0-M3" => SVer2_12M3 - case "2.12.0-M4" => SVer2_12M4 - case "2.12" => SVer2_12 + case "2.10" => SVer2_10 + case "2.11" => SVer2_11 + case "2.12" => SVer2_12 } } } case object SVer2_10 extends SVer { - def requireJava8 = false + override val requireJava8 = false } case object SVer2_11 extends SVer { - def requireJava8 = false - } - case object SVer2_12M1 extends SVer { - def requireJava8 = true - } - case object SVer2_12M2 extends SVer { - def requireJava8 = true - } - case object SVer2_12M3 extends SVer { - def requireJava8 = true - } - case object SVer2_12M4 extends SVer { - def requireJava8 = true + override val supportsNewBackend = true + override val requireJava8 = false } case object SVer2_12 extends SVer { - def requireJava8 = true + override val newOptimize = true } } -