Skip to content
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

SBT: add methods to check if scala 2.12 or 2.13 #4797

Merged
merged 1 commit into from
Feb 8, 2025
Merged
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
41 changes: 20 additions & 21 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ def isCI = System.getenv("CI") != null
def scala212 = "2.12.20"
def scala213 = "2.13.16"

def isScalaVer(ver: String) = Def.setting(scalaBinaryVersion.value == ver)
def isScala212 = isScalaVer("2.12")
def isScala213 = isScalaVer("2.13")

inThisBuild {
List(
version ~= { dynVer =>
Expand Down Expand Up @@ -62,8 +66,7 @@ addCommandAlias(

commands ++= Seq(
Command.command("ci-test-jvm") { s =>
val docsTest =
if (scalaBinaryVersion.value == "2.12") "docs/run" else "version"
val docsTest = if (isScala212.value) "docs/run" else "version"
"tests/test" :: "cli/test" :: "publishLocal" :: docsTest :: s
},
Command.command("ci-test-native")(s =>
Expand Down Expand Up @@ -112,15 +115,10 @@ lazy val sysops = crossProject(JVMPlatform, NativePlatform)
description := "Scalafmt systems operations",
scalacOptions ++= scalacJvmOptions.value,
libraryDependencies ++= {
CrossVersion.partialVersion(scalaVersion.value) match {
case Some((2, 12)) =>
Seq("com.github.bigwheel" %% "util-backports" % "2.1")
case Some((2, 13)) => Seq(
"org.scala-lang.modules" %%% "scala-parallel-collections" % "1.2.0",
)
case _ => Seq()
}
if (!isScala212.value) Nil
else Seq("com.github.bigwheel" %% "util-backports" % "2.1")
},
parallelCollections,
sharedTestSettings,
)

Expand All @@ -145,12 +143,10 @@ lazy val core = crossProject(JVMPlatform, NativePlatform)
scalacOptions ++= scalacJvmOptions.value,
libraryDependencies ++= Seq("org.scalameta" %%% "mdoc-parser" % mdocV),
libraryDependencies ++= {
CrossVersion.partialVersion(scalaVersion.value) match {
case Some((2, 13)) => Seq()
case _ => Seq(compilerPlugin(
"org.scalamacros" % "paradise" % "2.1.1" cross CrossVersion.full,
))
}
if (!isScala212.value) Nil
else Seq(compilerPlugin(
"org.scalamacros" % "paradise" % "2.1.1" cross CrossVersion.full,
))
},
)
// .jsSettings(
Expand All @@ -177,11 +173,9 @@ lazy val macros = crossProject(JVMPlatform, NativePlatform)
import sbtassembly.AssemblyPlugin.defaultUniversalScript

val scalacJvmOptions = Def.setting {
val cross = CrossVersion.partialVersion(scalaVersion.value) match {
case Some((2, 13)) =>
Seq("-Ymacro-annotations", "-Xfatal-warnings", "-deprecation:false")
case _ => Seq.empty
}
val cross =
if (!isScala213.value) Nil
else Seq("-Ymacro-annotations", "-Xfatal-warnings", "-deprecation:false")

val unused = Seq("imports", "privates", "locals", "patvars", "implicits")
.map(x => s"-Ywarn-unused:$x")
Expand Down Expand Up @@ -345,3 +339,8 @@ lazy val communityTestsSettings: Seq[Def.Setting[_]] = Seq(
)

lazy val scalaNativeConfig = nativeConfig ~= { _.withMode(Mode.releaseFull) }

def parallelCollections = libraryDependencies ++= {
if (!isScala213.value) Nil
else Seq("org.scala-lang.modules" %%% "scala-parallel-collections" % "1.2.0")
}