Skip to content
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

Remove automatic installation of semanticdb-scalac #666

Merged
merged 4 commits into from
Apr 9, 2018
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
3 changes: 2 additions & 1 deletion bin/ci-publish.sh
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ if [[ "$TRAVIS_SECURE_ENV_VARS" == true && "$CI_PUBLISH" == true ]]; then
fi
set-up-ssh
set-up-jekyll
sbt website/publishMicrosite
# TODO(olafur): Re-enable doc publishing once 0.6 final is out.
# sbt website/publishMicrosite
else
echo "Skipping publish, branch=$TRAVIS_BRANCH"
fi
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,7 @@ object ScalafixEnable {
scalaVersion.in(p) := fullVersion,
scalacOptions.in(p) ++= List(
"-Yrangepos",
s"-Xplugin-require:semanticdb",
s"-P:semanticdb:sourceroot:${scalafixSourceroot.value.getAbsolutePath}"
s"-Xplugin-require:semanticdb"
),
libraryDependencies.in(p) += compilerPlugin(
"org.scalameta" % "semanticdb-scalac" %
Expand Down
86 changes: 36 additions & 50 deletions scalafix-sbt/src/main/scala/scalafix/sbt/ScalafixPlugin.scala
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ object ScalafixPlugin extends AutoPlugin {
val scalafixCli: InputKey[Unit] =
inputKey[Unit]("Run scalafix rule.")
val scalafixTest: InputKey[Unit] =
inputKey[Unit]("Run scalafix as a test(without modifying sources).")
inputKey[Unit](
"Runs scalafix failing the build if sources would change. Does not modify files.")
val scalafixAutoSuppressLinterErrors: InputKey[Unit] =
inputKey[Unit](
"Run scalafix and automatically suppress linter errors " +
Expand All @@ -30,82 +31,73 @@ object ScalafixPlugin extends AutoPlugin {
"Run syntactic scalafix rule on build sources. Note, semantic rewrites are not supported.")
val sbtfixTest: InputKey[Unit] =
inputKey[Unit](
"Run syntactic scalafix rule on build sources as a test(without modifying sources).")
"Run scalafix on build sources failing the build if source would change. Does not modify files.")
val scalafixConfig: SettingKey[Option[File]] =
settingKey[Option[File]](
".scalafix.conf file to specify which scalafix rules should run.")
val scalafixSourceroot: SettingKey[File] = settingKey[File](
s"Which sourceroot should be used for .semanticdb files.")
val scalafixVersion: SettingKey[String] = settingKey[String](
s"Which scalafix version to run. Default is ${Versions.version}.")
val scalafixScalaVersion: SettingKey[String] = settingKey[String](
s"Which scala version to run scalafix from. Default is ${Versions.scala212}.")
val scalafixSemanticdbVersion: SettingKey[String] = settingKey[String](
s"Which version of semanticdb to use. Default is ${Versions.scalameta}.")
val scalafixSemanticdb =
"org.scalameta" % "semanticdb-scalac" % Versions.scalameta cross CrossVersion.full
val scalafixVerbose: SettingKey[Boolean] =
settingKey[Boolean]("pass --verbose to scalafix")

/** Add -Yrangepos and semanticdb sourceroot to scalacOptions. */
lazy val scalafixConfigSettings: Seq[Def.Setting[_]] = Seq(
scalafix := scalafixTaskImpl(
scalafixParserCompat,
compat = true,
Seq("--format", "sbt")).evaluated,
scalafixTest := scalafixTaskImpl(
scalafixParserCompat,
compat = true,
Seq("--test", "--format", "sbt")).evaluated,
scalafixCli := scalafixTaskImpl(
scalafixParser,
compat = false,
Seq("--format", "sbt")).evaluated,
scalafixAutoSuppressLinterErrors := scalafixTaskImpl(
scalafixParser,
compat = true,
Seq("--auto-suppress-linter-errors", "--format", "sbt")).evaluated
)

@deprecated("This setting is no longer used", "0.6.0")
val scalafixSourceroot: SettingKey[File] = settingKey[File]("Unused")
@deprecated("Use scalacOptions += -Yrangepos instead", "0.6.0")
def scalafixScalacOptions: Def.Initialize[Seq[String]] =
ScalafixPlugin.scalafixScalacOptions

/** Add semanticdb-scalac compiler plugin to libraryDependencies. */
@deprecated("Use addCompilerPlugin(semanticdb-scalac) instead", "0.6.0")
def scalafixLibraryDependencies: Def.Initialize[List[ModuleID]] =
ScalafixPlugin.scalafixLibraryDependencies

@deprecated("This setting is no longer used", "0.6.0")
def sbtfixSettings: Seq[Def.Setting[_]] = Nil

/** Settings that must appear after scalacOptions and libraryDependencies */
@deprecated(
"Use addCompilerPlugin(scalafixSemanticdb) and scalacOptions += \"-Yrangepos\" instead",
"0.6.0")
def scalafixSettings: Seq[Def.Setting[_]] = List(
scalacOptions ++= scalafixScalacOptions.value,
libraryDependencies ++= scalafixLibraryDependencies.value
)

// TODO(olafur) remove this in 0.6.0, replaced
val scalafixEnabled: SettingKey[Boolean] =
settingKey[Boolean](
"No longer used. Use the scalafixEnable command or manually configure " +
"scalacOptions/libraryDependecies/scalaVersion")

lazy val scalafixConfigSettings: Seq[Def.Setting[_]] = scalafixSettings ++
Seq(
scalafix := scalafixTaskImpl(
scalafixParserCompat,
compat = true,
Seq("--format", "sbt")).evaluated,
scalafixTest := scalafixTaskImpl(
scalafixParserCompat,
compat = true,
Seq("--test", "--format", "sbt")).evaluated,
scalafixCli := scalafixTaskImpl(
scalafixParser,
compat = false,
Seq("--format", "sbt")).evaluated,
scalafixAutoSuppressLinterErrors := scalafixTaskImpl(
scalafixParser,
compat = true,
Seq("--auto-suppress-linter-errors", "--format", "sbt")).evaluated
)
}
import scalafix.internal.sbt.CliWrapperPlugin.autoImport._
import autoImport._

override def projectSettings: Seq[Def.Setting[_]] =
scalafixSettings ++
Seq(Compile, Test).flatMap(inConfig(_)(scalafixConfigSettings))
Seq(Compile, Test).flatMap(inConfig(_)(scalafixConfigSettings))

override def globalSettings: Seq[Def.Setting[_]] = Seq(
scalafixConfig := Option(file(".scalafix.conf")).filter(_.isFile),
cliWrapperMainClass := "scalafix.cli.Cli$",
scalafixEnabled := true,
scalafixVerbose := false,
commands += ScalafixEnable.command,
sbtfix := sbtfixImpl(compat = true).evaluated,
sbtfixTest := sbtfixImpl(compat = true, extraOptions = Seq("--test")).evaluated,
aggregate.in(sbtfix) := false,
aggregate.in(sbtfixTest) := false,
scalafixSourceroot := baseDirectory.in(ThisBuild).value,
scalafixVersion := Versions.version,
scalafixSemanticdbVersion := Versions.scalameta,
scalafixScalaVersion := Versions.scala212,
Expand Down Expand Up @@ -162,18 +154,17 @@ object ScalafixPlugin extends AutoPlugin {

lazy val scalafixLibraryDependencies: Def.Initialize[List[ModuleID]] =
Def.setting {
if (scalafixEnabled.value && isSupportedScalaVersion.value) {
if (isSupportedScalaVersion.value) {
compilerPlugin(
"org.scalameta" % "semanticdb-scalac" % scalafixSemanticdbVersion.value cross CrossVersion.full
) :: Nil
} else Nil
}
lazy val scalafixScalacOptions: Def.Initialize[Seq[String]] = Def.setting {
if (scalafixEnabled.value && isSupportedScalaVersion.value) {
if (isSupportedScalaVersion.value) {
Seq(
"-Yrangepos",
s"-Xplugin-require:semanticdb",
s"-P:semanticdb:sourceroot:${scalafixSourceroot.value.getAbsolutePath}"
s"-Xplugin-require:semanticdb"
)
} else Nil
}
Expand Down Expand Up @@ -249,17 +240,12 @@ object ScalafixPlugin extends AutoPlugin {
if (compat && inputArgs.nonEmpty) "--rules" +: inputArgs
else inputArgs

val sourceroot = scalafixSourceroot.value.getAbsolutePath
// only fix unmanaged sources, skip code generated files.
verbose ++
config ++
inputArgs0 ++
baseArgs ++
options ++
List(
"--sourceroot",
sourceroot
)
options
}
val finalArgs = args ++ files.map(_.getAbsolutePath)
val nonBaseArgs = args.filterNot(baseArgs).mkString(" ")
Expand Down
22 changes: 13 additions & 9 deletions scalafix-sbt/src/sbt-test/sbt-scalafix/cross-build/build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,16 @@ inThisBuild(
resolvers += Resolver.sonatypeRepo("releases")
)
)

lazy val scalafixSettings = List(
addCompilerPlugin(scalafixSemanticdb),
scalacOptions += "-Yrangepos"
)

lazy val root = project
.in(file("."))
.aggregate(
javaProject,
customSourceroot,
scala211,
scala210,
scala212
Expand All @@ -20,7 +25,8 @@ lazy val scala210 = project.settings(
scalaVersion := "2.10.5"
)
lazy val scala211 = project.settings(
scalaVersion := Versions.scala211
scalaVersion := Versions.scala211,
scalafixSettings
)
lazy val scala212 = project
.configs(IntegrationTest)
Expand All @@ -32,14 +38,12 @@ lazy val scala212 = project
.in(Compile)
.value
.filterNot(_.getAbsolutePath.contains("IgnoreMe")),
scalaVersion := Versions.scala212
scalaVersion := Versions.scala212,
scalafixSettings
)
lazy val customSourceroot = project.settings(
scalaVersion := Versions.scala212,
scalafixSourceroot := sourceDirectory.value
)
lazy val javaProject = project.settings(
scalaVersion := Versions.scala212
scalaVersion := Versions.scala212,
scalafixSettings
)

TaskKey[Unit]("check") := {
Expand Down Expand Up @@ -77,7 +81,7 @@ TaskKey[Unit]("check") := {
"scala212/src/it/scala/Main.scala",
expected
) +:
Seq(scala210, scala211, scala212, customSourceroot).flatMap { project =>
Seq(scala210, scala211, scala212).flatMap { project =>
val prefix = project.id
Seq(
assertContentMatches(
Expand Down

This file was deleted.

This file was deleted.

1 change: 1 addition & 0 deletions scalafix-sbt/src/sbt-test/sbt-scalafix/suppress/test
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
> scalafixEnable
-> compile:scalafixTest
> compile:scalafixAutoSuppressLinterErrors
> compile:scalafixTest
Expand Down
22 changes: 10 additions & 12 deletions website/src/main/tut/docs/users/installation.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,20 +32,20 @@ addSbtPlugin("ch.epfl.scala" % "sbt-scalafix" % "{{ site.stableVersion }}")
> scalafixCli --test // Make sure no files needs to be fixed


// (optional, to avoid need for scalafixEnable) permanently enable scalafix in build.sbt
// (optional) to avoid running scalafixEnable every time, permanently enable scalafix in build.sbt
// ===> build.sbt
scalaVersion := "{{ site.scala212 }}" // {{ site.scala211 }} is also supported.

// If you get "-Yrangepos is required" error or "Missing compiler plugin semanticdb",
// This setting must appear after scalacOptions and libraryDependencies.
scalafixSettings
// or scalafixLibraryDependencies (Add semanticdb-scalac compiler plugin to libraryDependencies.)
// & scalacOptions bellow

// To configure for custom configurations like IntegrationTest
scalafixConfigure(Compile, Test, IntegrationTest)
addCompilerPlugin(scalafixSemanticdb)
scalacOptions += "-Yrangepos"
```

Notes.
* The `semanticdb-scalac` compiler plugin is required to run semantic Scalafix rules like {% rule_ref Disable %}.
* The `semanticdb-scalac` compiler plugin is not required to run syntactic rules like {% rule_ref DisableSyntax %}.
* The `semanticdb-scalac` compiler plugin produces `*.semanticdb` files in the target `META-INF/semanticdb/` directory.
* The compilation overhead of `semanticdb-scalac` depends on the compiler settings used, but by default it is around 30%
over regular compilation.

### Verify installation

To verify the installation, check that scalacOptions and libraryDependecies
Expand All @@ -54,8 +54,6 @@ contain the values below.
```scala
> show scalacOptions
[info] * -Yrangepos // required
[info] * -Xplugin-require:semanticdb // recommended
[info] * -P:semanticdb:sourceroot:/x // recommended
> show libraryDependencies
[info] * org.scalameta:semanticdb-scalac:{{ site.scalametaVersion }}:plugin->default(compile)
```
Expand Down