Skip to content

Commit

Permalink
Split jvm-specific settings into scalaModuleSettingsJVM
Browse files Browse the repository at this point in the history
Move jvm-specific settings from scalaModuleSettings to a new
scalaModuleSettingsJVM setting. This means that JVM projects in
scala modules now have to add bot `scalaModuleSettings` and
`scalaModuleSettingsJVM`.

Adding sbt-osgi settings in a scala-js project caused the published
jar to be empty (scala/scala-parser-combinators#119).
  • Loading branch information
lrytz committed Jul 6, 2017
1 parent 040871b commit 4bd144f
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 17 deletions.
6 changes: 1 addition & 5 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,6 @@ bintrayRepository := "sbt-plugins"

bintrayOrganization := None

// this plugin depends on the sbt-osgi plugin -- 2-for-1!
// TODO update to 0.8.0
// this might require us to modify the downstream project to enable the AutoPlugin
// See code changes and docs: https://github.com/sbt/sbt-osgi/commit/e3625e685b8d1784938ec66067d629251811a9d1
addSbtPlugin("com.typesafe.sbt" % "sbt-osgi" % "0.7.0")
addSbtPlugin("com.typesafe.sbt" % "sbt-osgi" % "0.9.1")

addSbtPlugin("com.typesafe" % "sbt-mima-plugin" % "0.1.14")
30 changes: 18 additions & 12 deletions src/main/scala/ScalaModulePlugin.scala
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
import sbt._
import Keys._
import com.typesafe.sbt.osgi.{OsgiKeys, SbtOsgi}
import com.typesafe.tools.mima.plugin.{MimaPlugin, MimaKeys}, MimaKeys._
import com.typesafe.tools.mima.plugin.MimaKeys._
import com.typesafe.tools.mima.plugin.MimaPlugin
import sbt.Keys._
import sbt.{Def, _}

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.")

// Settings applied to the entire build when the plugin is loaded.

// See https://github.com/sbt/sbt/issues/2082
override def requires = plugins.JvmPlugin

override def trigger = allRequirements

// Settings in here are implicitly `in ThisBuild`
Expand Down Expand Up @@ -54,11 +54,15 @@ object ScalaModulePlugin extends AutoPlugin {
)

/**
* Enable `-opt:l:classpath` or `-optimize`, depending on the scala version.
* Enable `-opt:l:inline`, `-opt:l:classpath` or `-optimize`, depending on the scala version.
*/
lazy val enableOptimizer: Setting[_] = scalacOptions in (Compile, compile) += {
val Some((2, maj)) = CrossVersion.partialVersion(scalaVersion.value)
if (maj >= 12) "-opt:l:classpath" else "-optimize"
lazy val enableOptimizer: Setting[_] = scalacOptions in (Compile, compile) ++= {
val v = scalaVersion.value
val Some((2, maj)) = CrossVersion.partialVersion(v)
if (maj >= 12) {
if (v.startsWith("2.12.3")) Seq("-opt:l:inline", "-opt-inline-from", "scala.**")
else Seq("-opt:l:classpath")
} else Seq("-optimize")
}

/**
Expand All @@ -78,8 +82,6 @@ object ScalaModulePlugin extends AutoPlugin {
lazy val scalaModuleSettings: Seq[Setting[_]] = Seq(
repoName := name.value,

mimaPreviousVersion := None,

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

// don't use for doc scope, scaladoc warnings are not to be reckoned with
Expand Down Expand Up @@ -140,6 +142,10 @@ object ScalaModulePlugin extends AutoPlugin {
</developer>
</developers>
)
)

lazy val scalaModuleSettingsJVM: Seq[Setting[_]] = Seq(
mimaPreviousVersion := None
) ++ mimaSettings ++ scalaModuleOsgiSettings

// adapted from https://github.com/typesafehub/migration-manager/blob/0.1.6/sbtplugin/src/main/scala/com/typesafe/tools/mima/plugin/SbtMima.scala#L69
Expand Down Expand Up @@ -200,7 +206,7 @@ object ScalaModulePlugin extends AutoPlugin {
// a setting-transform to turn the regular version into something osgi can deal with
private val osgiVersion = version(_.replace('-', '.'))

private lazy val scalaModuleOsgiSettings = SbtOsgi.osgiSettings ++ Seq(
private lazy val scalaModuleOsgiSettings = SbtOsgi.projectSettings ++ SbtOsgi.autoImport.osgiSettings ++ Seq(
OsgiKeys.bundleSymbolicName := s"${organization.value}.${name.value}",
OsgiKeys.bundleVersion := osgiVersion.value,

Expand Down

0 comments on commit 4bd144f

Please sign in to comment.