Skip to content

Split jvm-specific settings into scalaModuleSettingsJVM #27

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 1 commit into from
Jul 7, 2017
Merged
Show file tree
Hide file tree
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
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")
31 changes: 19 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,16 @@ 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 Ver = """(\d+)\.(\d+)\.(\d+).*""".r
val Ver("2", maj, min) = scalaVersion.value
(maj.toInt, min.toInt) match {
case (m, _) if m < 12 => Seq("-optimize")
case (12, n) if n < 3 => Seq("-opt:l:classpath")
case _ => Seq("-opt:l:inline", "-opt-inline-from:scala/**")
}
}

/**
Expand All @@ -78,8 +83,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 +143,10 @@ object ScalaModulePlugin extends AutoPlugin {
</developer>
</developers>
)
)

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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hum I just realized that this means you've deactivated MiMa for Scala.js, doesn't it?

Scala.js artifacts can very well be checked by MiMa, and should be. We have an (almost) guarantee that "JVM binary compatible" implies "SJSIR binary compatible". So if MiMa says OK for the .class files in a Scala.js artifact, it also means OK for the .sjsir files. It's very useful. We check our own artifacts with MiMa.

Copy link
Member Author

@lrytz lrytz Jul 7, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, good to know. I thought that MiMa probably doesn't support scala-js jars because it was already deactivated for Scala.js in the build, as the "previous version" is only set for the JVM project (https://github.com/scala/scala-parser-combinators/blob/1.0.x/build.sbt#L62-L64).

I guess the additional value is to also test classfiles compiled from platform-specific sources?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In fact, running MiMa would have probably caught scala/scala-parser-combinators#119 :-)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess the additional value is to also test classfiles compiled from platform-specific sources?

Yes indeed.

In fact, running MiMa would have probably caught scala/scala-parser-combinators#119 :-)

Ah ah, probably!


// 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 +207,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