Skip to content

Commit

Permalink
Test 2.12 support
Browse files Browse the repository at this point in the history
  • Loading branch information
olafurpg committed Dec 9, 2016
1 parent a63f495 commit 7d9e6e7
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 24 deletions.
8 changes: 6 additions & 2 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ lazy val root = project
`scalafix-nsc`,
`scalafix-tests`,
core,
cli,
// cli, // superseded by sbt plugin
readme,
`scalafix-sbt`
)
Expand All @@ -104,7 +104,7 @@ lazy val core = project
addCompilerPlugin(
"org.scalamacros" % "paradise" % "2.1.0" cross CrossVersion.full),
libraryDependencies ++= Seq(
"com.lihaoyi" %% "sourcecode" % "0.1.2",
"com.lihaoyi" %% "sourcecode" % "0.1.3",
"org.scalameta" %% "scalameta" % Build.metaV,
"org.scala-lang" % "scala-reflect" % scalaVersion.value,
// Test dependencies
Expand Down Expand Up @@ -202,6 +202,10 @@ lazy val `scalafix-tests` = project
.settings(
allSettings,
noPublish,
test := {
if (scalaVersion.value.startsWith("2.11")) (test in Compile).value
else Def.task(()).value
},
parallelExecution in Test := true,
compileInputs in (Compile, compile) :=
(compileInputs in (Compile, compile))
Expand Down
48 changes: 28 additions & 20 deletions scalafix-sbt/src/main/scala/scalafix/sbt/ScalafixPlugin.scala
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ trait ScalafixKeys {
settingKey[Seq[String]]("Which scalafix rules should run?")
val scalafixEnabled: SettingKey[Boolean] =
settingKey[Boolean]("Is scalafix enabled?")
val scalafixInternalJar: TaskKey[File] =
taskKey[File]("Path to scalafix-nsc compiler plugin jar.")
val scalafixInternalJar: TaskKey[Option[File]] =
taskKey[Option[File]]("Path to scalafix-nsc compiler plugin jar.")
}

object rewrite {
Expand All @@ -22,20 +22,27 @@ object rewrite {

object ScalafixPlugin extends AutoPlugin with ScalafixKeys {
object autoImport extends ScalafixKeys
private val Version = "2\\.(\\d\\d)\\.".r
private val nightlyVersion = _root_.scalafix.Versions.nightly
private val disabled = sys.props.contains("scalafix.disable")
private val scalafixStub =
private def jar(report: UpdateReport): Option[File] =
report.allFiles.find(
_.getAbsolutePath.matches(s".*scalafix-nsc_2.[12].jar$$"))
private def stub(version: String) =
Project(id = "scalafix-stub", base = file("project/scalafix")).settings(
description :=
"""Serves as a caching layer for extracting the jar location of the
|scalafix-nsc compiler plugin. If the dependecy was added to all
|projects, the (slow) update task will be re-run for every project.""".stripMargin,
scalaVersion := "2.11.8", // TODO(olafur) 2.12 support
libraryDependencies +=
"ch.epfl.scala" %% "scalafix-nsc" % nightlyVersion % Compile
scalaVersion := version,
libraryDependencies ++= Seq(
"ch.epfl.scala" %% "scalafix-nsc" % nightlyVersion
)
)
private val scalafix211 = stub("2.11.8")
private val scalafix212 = stub("2.12.1")

override def extraProjects: Seq[Project] = Seq(scalafixStub)
override def extraProjects: Seq[Project] = Seq(scalafix211, scalafix212)

override def requires = JvmPlugin
override def trigger: PluginTrigger = AllRequirements
Expand All @@ -48,21 +55,21 @@ object ScalafixPlugin extends AutoPlugin with ScalafixKeys {
state
}

override def projectSettings: Seq[Def.Setting[_]] =
override def globalSettings: Seq[Def.Setting[_]] =
Seq(
commands += scalafix,
scalafixRewrites := Seq(
rewrite.ExplicitImplicit,
rewrite.ProcedureSyntax
),
scalafixInternalJar in Global := {
// TODO(olafur) 2.12 support
(update in scalafixStub).value.allFiles
.find(_.getAbsolutePath.matches(".*scalafix-nsc[^-]*.jar$"))
.getOrElse {
throw new IllegalStateException(
"Unable to find scalafix-nsc in library dependencies!")
}
scalaVersion.value match {
case Version("11") =>
jar((update in scalafix211).value)
case Version("12") =>
jar((update in scalafix212).value)
case _ => None
}
},
scalafixEnabled in Global := false,
scalacOptions ++= {
Expand All @@ -79,11 +86,12 @@ object ScalafixPlugin extends AutoPlugin with ScalafixKeys {
val prefixed = rewrites.map(x => s"scalafix:$x")
Some(s"-P:${prefixed.mkString(",")}")
}
val jar = (scalafixInternalJar in Global).value.getAbsolutePath
Seq(
Some(s"-Xplugin:$jar"),
config
).flatten
(scalafixInternalJar in Global).value.map { jar =>
Seq(
Some(s"-Xplugin:${jar.getAbsolutePath}"),
config
).flatten
}.getOrElse(Nil)
}
}
)
Expand Down
9 changes: 7 additions & 2 deletions scalafix-sbt/src/sbt-test/sbt-scalafix/basic/build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ lazy val root = project
.settings(commonSettings)
.aggregate(
p1,
p2
p2,
p3
)

lazy val p1 = project.settings(
Expand All @@ -16,6 +17,10 @@ lazy val p2 = project.settings(
scalaVersion := "2.10.5"
)

lazy val p3 = project.settings(
scalaVersion := "2.12.1"
)

TaskKey[Unit]("check") := {
def assertContentMatches(file: String, expectedUntrimmed: String): Unit = {
val expected = expectedUntrimmed.trim
Expand Down Expand Up @@ -52,7 +57,7 @@ TaskKey[Unit]("check") := {
| }
|}""".stripMargin
val testExpected = expected.replaceFirst("Main", "TestMain")
Seq("", "p1/").foreach { prefix =>
Seq("", "p1/", "p3/").foreach { prefix =>
assertContentMatches(
prefix + "src/test/scala/Test.scala",
testExpected
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
object Main {
implicit val x = 2
lazy val y = 2
def main(args: Array[String]) {
println("hello")
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
object TestMain {
implicit val x = 2
lazy val y = 2
def main(args: Array[String]) {
println("hello")
}
}

0 comments on commit 7d9e6e7

Please sign in to comment.