Skip to content

Commit

Permalink
Use scalaVersion semantic selector (#3022)
Browse files Browse the repository at this point in the history
  • Loading branch information
regadas authored Jun 3, 2020
1 parent c66075f commit 8b20c3f
Show file tree
Hide file tree
Showing 2 changed files with 88 additions and 88 deletions.
36 changes: 13 additions & 23 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -105,10 +105,6 @@ val tensorFlowVersion = "1.15.0"
val zoltarVersion = "0.5.6"
val scalaCollectionCompatVersion = "2.1.6"

def isScala213x = Def.setting {
scalaBinaryVersion.value == "2.13"
}

lazy val mimaSettings = Seq(
mimaPreviousArtifacts :=
previousVersion(version.value)
Expand Down Expand Up @@ -161,15 +157,8 @@ val commonSettings = Sonatype.sonatypeSettings ++ assemblySettings ++ Seq(
scalaVersion := "2.13.2",
crossScalaVersions := Seq("2.12.11", scalaVersion.value),
scalacOptions ++= Scalac.commonsOptions.value,
scalacOptions ++= {
if (isScala213x.value) {
Seq("-Ymacro-annotations", "-Ywarn-unused")
} else {
Seq()
}
},
Compile / doc / scalacOptions --= Seq("-release", "8"),
scalacOptions in (Compile, doc) ++= Scalac.compileDocOptions.value,
Compile / doc / scalacOptions ++= Scalac.compileDocOptions.value,
javacOptions ++= Seq("-source", "1.8", "-target", "1.8", "-Xlint:unchecked"),
javacOptions in (Compile, doc) := Seq("-source", "1.8"),
// protobuf-lite is an older subset of protobuf-java and causes issues
Expand Down Expand Up @@ -336,14 +325,14 @@ lazy val assemblySettings = Seq(
lazy val macroSettings = Def.settings(
libraryDependencies += "org.scala-lang" % "scala-reflect" % scalaVersion.value,
libraryDependencies ++= {
if (isScala213x.value) {
Seq()
} else {
Seq(
compilerPlugin(
("org.scalamacros" % "paradise" % scalaMacrosVersion).cross(CrossVersion.full)
VersionNumber(scalaVersion.value) match {
case v if v.matchesSemVer(SemanticSelector("2.12.x")) =>
Seq(
compilerPlugin(
("org.scalamacros" % "paradise" % scalaMacrosVersion).cross(CrossVersion.full)
)
)
)
case _ => Nil
}
},
// see MacroSettings.scala
Expand Down Expand Up @@ -1091,10 +1080,11 @@ lazy val `scio-repl`: Project = project
beamSDKIODependencies,
beamSDKGoogleCloudCoreDependencies,
libraryDependencies ++= {
if (isScala213x.value) {
Seq()
} else {
Seq("org.scalamacros" % "paradise" % scalaMacrosVersion cross CrossVersion.full)
VersionNumber(scalaVersion.value) match {
case v if v.matchesSemVer(SemanticSelector("2.12.x")) =>
Seq("org.scalamacros" % "paradise" % scalaMacrosVersion cross CrossVersion.full)
case _ =>
Nil
}
},
assemblyJarName in assembly := s"scio-repl-${version.value}.jar"
Expand Down
140 changes: 75 additions & 65 deletions project/ScalacOptions.scala
Original file line number Diff line number Diff line change
Expand Up @@ -16,78 +16,88 @@
*/

import sbt._, Keys._
import sbt.librarymanagement.{SemanticSelector, VersionNumber}

object Scalac {
// see: https://tpolecat.github.io/2017/04/25/scalac-flags.html
val baseOptions = List(
"-release",
"8",
"-target:jvm-1.8",
"-deprecation", // Emit warning and location for usages of deprecated APIs.
"-feature", // Emit warning and location for usages of features that should be imported explicitly.
"-unchecked", // Enable additional warnings where generated code depends on assumptions.
"-encoding",
"utf-8", // Specify character encoding used by source files.
"-explaintypes", // Explain type errors in more detail.
// "-language:existentials", // Existential types (besides wildcard types) can be written and inferred
"-language:experimental.macros", // Allow macro definition (besides implementation and application)
"-language:higherKinds", // Allow higher-kinded types
"-language:implicitConversions", // Allow definition of implicit functions called views
"-Xcheckinit", // Wrap field accessors to throw an exception on uninitialized access.
// "-Xfatal-warnings", // Fail the compilation if there are any warnings.
// "-Xfuture", // Turn on future language features.
"-Xlint:adapted-args", // Warn if an argument list is modified to match the receiver.
// "-Xlint:delayedinit-select", // Selecting member of DelayedInit.
"-Xlint:doc-detached", // A Scaladoc comment appears to be detached from its element.
"-Xlint:inaccessible", // Warn about inaccessible types in method signatures.
"-Xlint:infer-any", // Warn when a type argument is inferred to be `Any`.
"-Xlint:missing-interpolator", // A string literal appears to be missing an interpolator id.
"-Xlint:nullary-override", // Warn when non-nullary `def f()' overrides nullary `def f'.
"-Xlint:nullary-unit", // Warn when nullary methods return Unit.
"-Xlint:option-implicit", // Option.apply used implicit view.
// "-Xlint:package-object-classes", // Class or object defined in package object.
"-Xlint:poly-implicit-overload", // Parameterized overloaded implicit methods are not visible as view bounds.
"-Xlint:private-shadow", // A private field (or class parameter) shadows a superclass field.
"-Xlint:stars-align", // Pattern sequence wildcard must align with sequence component.
"-Xlint:type-parameter-shadow", // A local type parameter shadows a type already in scope.
// "-Ywarn-dead-code", // Warn when dead code is identified.
// "-Ywarn-numeric-widen", // Warn when numerics are widened.
// "-Ywarn-unused:implicits", // Warn if an implicit parameter is unused.
// "-Ywarn-unused:locals", // Warn if a local definition is unused.
// "-Ywarn-unused:params", // Warn if a value parameter is unused.
// "-Ywarn-unused:patvars", // Warn if a variable bound in a pattern is unused.
// "-Ywarn-unused:privates", // Warn if a private member is unused.
"-Ywarn-value-discard", // Warn when non-Unit expression results are unused.
"-Xmacro-settings:show-coder-fallback=true",
"-Ydelambdafy:inline", // Set the strategy used for translating lambdas into JVM code to "inline"
"-Ybackend-parallelism",
"8"
)

def scala212settings = Def.setting {
List(
"-Xmax-classfile-name",
"100",
"-Xlint:constant", // Evaluation of a constant arithmetic expression results in an error.
"-Xlint:by-name-right-associative", // By-name parameter of right associative operator.
"-Xlint:unsound-match", // Pattern match may not be typesafe.
"-Ypartial-unification", // Enable partial unification in type constructor inference
"-Ywarn-unused:imports", // Warn if an import selector is not referenced.
"-Ywarn-extra-implicit", // Warn when more than one implicit parameter section is defined.,
"-Ywarn-inaccessible", // Warn about inaccessible types in method signatures.
"-Ywarn-infer-any" // Warn when a type argument is inferred to be `Any`.
val baseOptions = Def.setting {
val base = List(
"-target:jvm-1.8",
"-deprecation", // Emit warning and location for usages of deprecated APIs.
"-feature", // Emit warning and location for usages of features that should be imported explicitly.
"-unchecked", // Enable additional warnings where generated code depends on assumptions.
"-encoding",
"utf-8", // Specify character encoding used by source files.
"-explaintypes", // Explain type errors in more detail.
// "-language:existentials", // Existential types (besides wildcard types) can be written and inferred
"-language:experimental.macros", // Allow macro definition (besides implementation and application)
"-language:higherKinds", // Allow higher-kinded types
"-language:implicitConversions", // Allow definition of implicit functions called views
"-Xcheckinit", // Wrap field accessors to throw an exception on uninitialized access.
// "-Xfatal-warnings", // Fail the compilation if there are any warnings.
// "-Xfuture", // Turn on future language features.
"-Xlint:adapted-args", // Warn if an argument list is modified to match the receiver.
// "-Xlint:delayedinit-select", // Selecting member of DelayedInit.
"-Xlint:doc-detached", // A Scaladoc comment appears to be detached from its element.
"-Xlint:inaccessible", // Warn about inaccessible types in method signatures.
"-Xlint:infer-any", // Warn when a type argument is inferred to be `Any`.
"-Xlint:missing-interpolator", // A string literal appears to be missing an interpolator id.
"-Xlint:nullary-override", // Warn when non-nullary `def f()' overrides nullary `def f'.
"-Xlint:nullary-unit", // Warn when nullary methods return Unit.
"-Xlint:option-implicit", // Option.apply used implicit view.
// "-Xlint:package-object-classes", // Class or object defined in package object.
"-Xlint:poly-implicit-overload", // Parameterized overloaded implicit methods are not visible as view bounds.
"-Xlint:private-shadow", // A private field (or class parameter) shadows a superclass field.
"-Xlint:stars-align", // Pattern sequence wildcard must align with sequence component.
"-Xlint:type-parameter-shadow", // A local type parameter shadows a type already in scope.
// "-Ywarn-dead-code", // Warn when dead code is identified.
// "-Ywarn-numeric-widen", // Warn when numerics are widened.
// "-Ywarn-unused:implicits", // Warn if an implicit parameter is unused.
// "-Ywarn-unused:locals", // Warn if a local definition is unused.
// "-Ywarn-unused:params", // Warn if a value parameter is unused.
// "-Ywarn-unused:patvars", // Warn if a variable bound in a pattern is unused.
// "-Ywarn-unused:privates", // Warn if a private member is unused.
"-Ywarn-value-discard", // Warn when non-Unit expression results are unused.
"-Xmacro-settings:show-coder-fallback=true",
"-Ydelambdafy:inline" // Set the strategy used for translating lambdas into JVM code to "inline"
)

VersionNumber(sys.props("java.version")) match {
case v if v.matchesSemVer(SemanticSelector(">1.8")) => base ++ List("-release", "8")
case _ => base
}
}

def commonsOptions = Def.setting {
baseOptions ++ (if (scalaBinaryVersion.value == "2.12")
scala212settings.value
else Nil)
val scalaVersionOptions = Def.setting {
VersionNumber(scalaVersion.value) match {
case v if v.matchesSemVer(SemanticSelector("2.12.x")) =>
List(
"-Xmax-classfile-name",
"100",
"-Xlint:constant", // Evaluation of a constant arithmetic expression results in an error.
"-Xlint:by-name-right-associative", // By-name parameter of right associative operator.
"-Xlint:unsound-match", // Pattern match may not be typesafe.
"-Ypartial-unification", // Enable partial unification in type constructor inference
"-Ywarn-unused:imports", // Warn if an import selector is not referenced.
"-Ywarn-extra-implicit", // Warn when more than one implicit parameter section is defined.,
"-Ywarn-inaccessible", // Warn about inaccessible types in method signatures.
"-Ywarn-infer-any" // Warn when a type argument is inferred to be `Any`.
)
case v if v.matchesSemVer(SemanticSelector(">=2.13")) =>
List("-Ymacro-annotations", "-Ywarn-unused")
case _ =>
Nil
}
}

def compileDocOptions = Def.setting {
List("-skip-packages", "org.apache") ++
(if (scalaBinaryVersion.value == "2.12") List("-no-java-comments")
else Nil)
val commonsOptions = Def.setting(baseOptions.value ++ scalaVersionOptions.value)

val compileDocOptions = Def.setting {
val base = List("-skip-packages", "org.apache")

VersionNumber(scalaVersion.value) match {
case v if v.matchesSemVer(SemanticSelector("2.12.x")) => base ++ List("-no-java-comments")
case _ => base
}
}
}

0 comments on commit 8b20c3f

Please sign in to comment.