scalafx-utils/project/BasicSettings.scala

179 lines
5.5 KiB
Scala
Raw Normal View History

/* Note: This file is shared among many projects. Avoid putting project-specific things here. */
2016-09-25 04:06:36 +00:00
import sbt._
import sbt.Keys._
2016-09-25 04:06:36 +00:00
import Helpers._
object BasicSettings extends AutoPlugin with BasicSettings {
override def projectSettings = basicSettings
2016-09-25 04:06:36 +00:00
}
trait BasicSettings extends ProjectSettings { st: SettingTemplate =>
/* Overridable flags */
lazy val optimize = boolFlag("OPTIMIZE") orElse boolFlag("OPTIMISE") getOrElse defaultOptimize
lazy val optimizeGlobal = boolFlag("OPTIMIZE_GLOBAL") getOrElse defaultOptimizeGlobal
lazy val optimizeWarn = boolFlag("OPTIMIZE_WARNINGS") getOrElse false
2017-12-20 06:08:05 +00:00
lazy val disableAsserts = boolFlag("DISABLE_ASSERTIONS") getOrElse defaultDisableAssertions
lazy val noFatalWarn = boolFlag("NO_FATAL_WARNINGS") getOrElse false
lazy val deprecation = boolFlag("NO_DEPRECATION") map (!_) getOrElse true
2017-12-20 06:08:05 +00:00
lazy val inlineWarn = boolFlag("INLINE_WARNINGS") getOrElse defaultWarnInline
lazy val debug = boolFlag("DEBUGGER") getOrElse false
lazy val debugPort = intFlag("DEBUGGER_PORT", 5050)
lazy val debugSuspend = boolFlag("DEBUGGER_SUSPEND") getOrElse true
2017-12-20 06:08:05 +00:00
lazy val unusedWarn = boolFlag("UNUSED_WARNINGS") getOrElse defaultWarnUnused
lazy val importWarn = boolFlag("IMPORT_WARNINGS") getOrElse defaultWarnImport
lazy val findbugsHtml = boolFlag("FINDBUGS_HTML") getOrElse !isJenkins
lazy val newBackend = boolFlag("NEW_BCODE_BACKEND") getOrElse defaultNewBackend
lazy val noBuildDocs = boolFlag("NO_SBT_DOCS").getOrElse(false) && !isJenkins
2016-09-25 04:06:36 +00:00
lazy val basicSettings = new Def.SettingList(
2016-09-25 04:06:36 +00:00
buildMetadata ++
Seq (
organization := buildOrganization,
organizationName := buildOrganizationName,
organizationHomepage := buildOrganizationUrl.orElse(if (githubOrgPageFallback) Some(githubOrgPage) else None),
2016-09-25 04:06:36 +00:00
scalaVersion := buildScalaVersion,
crossScalaVersions := buildScalaVersions,
autoAPIMappings := true,
updateOptions := updateOptions.value.withCachedResolution(cachedResolution),
parallelExecution := parallelBuild,
evictionWarningOptions in update :=
EvictionWarningOptions.default.withWarnTransitiveEvictions(false).withWarnDirectEvictions(false).withWarnScalaVersionEviction(false)
) ++ (
if (noBuildDocs) {
Seq(sources in (Compile, doc) := Seq.empty)
} else {
Seq.empty
}
) ++ (
if (autoAddCompileOptions) {
addScalacOptions() ++ addJavacOptions()
} else {
Seq.empty
}
) ++ (
if (sonatypeResolver) {
/* Many OSS projects push here and then appear in Maven Central later */
Seq(resolvers += Resolver.sonatypeRepo("releases"))
} else {
Seq.empty
}
2016-09-25 04:06:36 +00:00
)
)
lazy val buildScalaVersions = buildScalaVersion +: extraScalaVersions
2016-09-26 00:54:31 +00:00
def basicScalacOptions = Def.derive {
2016-12-07 07:25:12 +00:00
scalacOptions ++= {
var options = Seq.empty[String]
val sv = sver.value
2016-12-07 07:25:12 +00:00
options :+= "-unchecked"
options :+= "-feature"
if (deprecation) {
options :+= "-deprecation"
}
if (unusedWarn) {
options :+= "-Ywarn-unused"
}
if (importWarn) {
options :+= "-Ywarn-unused-import"
}
if (!sv.requireJava8) {
options :+= "-target:jvm-" + minimumJavaVersion
}
if (sv.backend == SupportsNewBackend && newBackend) {
options :+= "-Ybackend:GenBCode"
}
2017-12-20 06:08:05 +00:00
if (disableAsserts) {
options :+= "-Xdisable-assertions"
}
options
}
}
def optimizationScalacOptions(optim: Boolean = optimize) = Def.derive {
scalacOptions ++= {
var options = Seq.empty[String]
val sv = sver.value
val fos = forceOldInlineSyntax.value
2016-12-07 07:25:12 +00:00
if (optim) {
def doNewWarn(): Unit = {
if (optimizeWarn) {
options :+= "-opt-warnings:_"
}
}
if (sv.backend == NewBackend && !fos) {
options :+= "-opt:l:inline"
val inlineFrom = {
var patterns = Seq.empty[String]
if (optimizeGlobal) {
patterns :+= "**"
} else {
patterns :+= "<sources>"
}
patterns ++= inlinePatterns
patterns
}
options :+= inlineFrom.mkString("-opt-inline-from:", ":", "")
doNewWarn()
} else if (sv.backend == NewBackend && fos || sv.backend == SupportsNewBackend && newBackend) {
if (optimizeGlobal) {
options :+= "-opt:l:classpath"
} else {
options :+= "-opt:l:project"
}
doNewWarn()
} else {
2016-12-07 07:25:12 +00:00
options :+= "-optimize"
if (optimizeWarn) {
options :+= "-Yinline-warnings"
}
2016-12-07 07:25:12 +00:00
}
}
options
}
}
2016-09-25 04:06:36 +00:00
def addScalacOptions(optim: Boolean = optimize) = new Def.SettingList(Seq(
basicScalacOptions,
2017-12-20 06:08:05 +00:00
optimizationScalacOptions(optim),
scalacOptions ++= extraScalacOptions
))
2016-12-07 07:25:12 +00:00
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
}
}
2016-09-25 04:06:36 +00:00
private[this] lazy val githubOrgPage = url(s"https://github.com/${githubOrganization}")
}