Skip to content

Provide keys through autoImport #55

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

Merged
merged 2 commits into from
Sep 12, 2019
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
31 changes: 17 additions & 14 deletions src/main/scala/ScalaModulePlugin.scala
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,13 @@ import sbt.librarymanagement.ivy.IvyDependencyResolution
import sbt.librarymanagement.{ UnresolvedWarningConfiguration, UpdateConfiguration }

object ScalaModulePlugin extends AutoPlugin {
val repoName = settingKey[String]("The name of the repository under github.com/scala/.")
val mimaPreviousVersion = settingKey[Option[String]]("The version of this module to compare against when running MiMa.")
val scalaVersionsByJvm = settingKey[Map[Int, List[(String, Boolean)]]]("For a Java major version (6, 8, 9), a list of a Scala version and a flag indicating whether to use this combination for publishing.")
object autoImport {
val scalaModuleRepoName = settingKey[String]("The name of the repository under github.com/scala/.")
val scalaModuleMimaPreviousVersion = settingKey[Option[String]]("The version of this module to compare against when running MiMa.")
val scalaModuleScalaVersionsByJvm = settingKey[Map[Int, List[(String, Boolean)]]]("For a Java major version (6, 8, 9), a list of a Scala version and a flag indicating whether to use this combination for publishing.")
val scalaModuleEnableOptimizerInlineFrom = settingKey[String]("The value passed to -opt-inline-from by `enableOptimizer` on 2.13 and higher.")
}
import autoImport._

// See https://github.com/sbt/sbt/issues/2082
override def requires = plugins.JvmPlugin
Expand All @@ -22,7 +26,7 @@ object ScalaModulePlugin extends AutoPlugin {

// Settings in here are implicitly `in ThisBuild`
override def buildSettings: Seq[Setting[_]] = Seq(
scalaVersionsByJvm := Map.empty,
scalaModuleScalaVersionsByJvm := Map.empty,

crossScalaVersions := {
val OneDot = """1\.(\d).*""".r // 1.6, 1.8
Expand All @@ -36,7 +40,7 @@ object ScalaModulePlugin extends AutoPlugin {
val isTravis = Option(System.getenv("TRAVIS")).exists(_ == "true") // `contains` doesn't exist in Scala 2.10
val isTravisPublishing = Option(System.getenv("TRAVIS_TAG")).exists(_.trim.nonEmpty)

val byJvm = scalaVersionsByJvm.value
val byJvm = scalaModuleScalaVersionsByJvm.value
if (byJvm.isEmpty)
throw new RuntimeException(s"Make sure to define `scalaVersionsByJvm in ThisBuild` in `build.sbt` in the root project, using the `ThisBuild` scope.")

Expand All @@ -55,11 +59,10 @@ object ScalaModulePlugin extends AutoPlugin {
}
scalaVersions
},
enableOptimizerInlineFrom := "<sources>",
scalaModuleEnableOptimizerInlineFrom := "<sources>",
scalaVersion := crossScalaVersions.value.head
)

val enableOptimizerInlineFrom = settingKey[String]("The value passed to -opt-inline-from by `enableOptimizer` on 2.13 and higher")
/**
* Enable `-opt:l:inline`, `-opt:l:classpath` or `-optimize`, depending on the scala version.
*/
Expand All @@ -69,7 +72,7 @@ object ScalaModulePlugin extends AutoPlugin {
(maj.toInt, min.toInt) match {
case (m, _) if m < 12 => Seq("-optimize")
case (12, n) if n < 3 => Seq("-opt:l:project")
case _ => Seq("-opt:l:inline", "-opt-inline-from:" + enableOptimizerInlineFrom.value)
case _ => Seq("-opt:l:inline", "-opt-inline-from:" + scalaModuleEnableOptimizerInlineFrom.value)
}
}

Expand All @@ -88,7 +91,7 @@ object ScalaModulePlugin extends AutoPlugin {
* To be included in the main sbt project of a Scala module.
*/
lazy val scalaModuleSettings: Seq[Setting[_]] = Seq(
repoName := name.value,
scalaModuleRepoName := name.value,

organization := "org.scala-lang.modules",

Expand Down Expand Up @@ -128,7 +131,7 @@ object ScalaModulePlugin extends AutoPlugin {
},

publishMavenStyle := true,
scmInfo := Some(ScmInfo(url(s"https://github.com/scala/${repoName.value}"),s"scm:git:git://github.com/scala/${repoName.value}.git")),
scmInfo := Some(ScmInfo(url(s"https://github.com/scala/${scalaModuleRepoName.value}"),s"scm:git:git://github.com/scala/${scalaModuleRepoName.value}.git")),
homepage := Some(url("http://www.scala-lang.org/")),
organizationHomepage := Some(url("http://www.scala-lang.org/")),
licenses := Seq("Apache-2.0" -> url("https://www.apache.org/licenses/LICENSE-2.0")),
Expand All @@ -137,7 +140,7 @@ object ScalaModulePlugin extends AutoPlugin {
pomExtra := (
<issueManagement>
<system>GitHub</system>
<url>https://github.com/scala/{repoName.value}/issues</url>
<url>https://github.com/scala/{scalaModuleRepoName.value}/issues</url>
</issueManagement>
<developers>
<developer>
Expand Down Expand Up @@ -169,14 +172,14 @@ object ScalaModulePlugin extends AutoPlugin {
private val runMimaIfEnabled = taskKey[Unit]("Run MiMa if mimaPreviousVersion and the module can be resolved against the current scalaBinaryVersion.")

private lazy val mimaSettings: Seq[Setting[_]] = MimaPlugin.mimaDefaultSettings ++ Seq(
mimaPreviousVersion := None,
scalaModuleMimaPreviousVersion := None,

// We're not using `%%` here in order to support both jvm and js projects (cross version `_2.12` / `_sjs0.6_2.12`)
mimaPreviousArtifacts := mimaPreviousVersion.value.map(v => organization.value % moduleName.value % v cross crossVersion.value).toSet,
mimaPreviousArtifacts := scalaModuleMimaPreviousVersion.value.map(v => organization.value % moduleName.value % v cross crossVersion.value).toSet,

canRunMima := {
val log = streams.value.log
mimaPreviousVersion.value match {
scalaModuleMimaPreviousVersion.value match {
case None =>
log.warn("MiMa will NOT run because no mimaPreviousVersion is provided.")
false
Expand Down