diff --git a/src/main/scala/scalafix/sbt/ScalafixPlugin.scala b/src/main/scala/scalafix/sbt/ScalafixPlugin.scala index 720a2d4d..ba43c226 100644 --- a/src/main/scala/scalafix/sbt/ScalafixPlugin.scala +++ b/src/main/scala/scalafix/sbt/ScalafixPlugin.scala @@ -107,6 +107,7 @@ object ScalafixPlugin extends AutoPlugin { .map(_ => oldCompile) else Def.task(oldCompile) }.value, + scalafix / compile := Defaults.compileTask.value, // In some cases (I haven't been able to understand when/why, but this also happens for bgRunMain while // fgRunMain is fine), there is no specific streams attached to InputTasks, so we they end up sharing the // global streams, causing issues for cache storage. This does not happen for Tasks, so we define a dummy one @@ -505,8 +506,9 @@ object ScalafixPlugin extends AutoPlugin { (config / scalafix / streams).value ) } - // sub-task of compile after which bytecode should not be modified - task.dependsOn(config / manipulateBytecode) + // no need to trigger compilation if the invocation comes from there + if (shellArgs.extra.contains("--triggered")) task + else task.dependsOn(config / scalafix / compile) } else { Def.task { if (errors.length == 1) { @@ -583,7 +585,7 @@ object ScalafixPlugin extends AutoPlugin { case "--stdout" => // --stdout cannot be cached as we don't capture the output to replay it throw StampingImpossible - case "--tool-classpath" => + case tcp if tcp.startsWith("--tool-classpath") => // custom tool classpaths might contain directories for which we would need to stamp all files, so // just disable caching for now to keep it simple and to be safe throw StampingImpossible @@ -743,16 +745,6 @@ object ScalafixPlugin extends AutoPlugin { options.ignoredScalacOptions() ++ scalacOptionsToRelax.map(_.pattern()) ) - }, - manipulateBytecode := { - val analysis = manipulateBytecode.value - if (!scalafixInvoked.value) analysis - else { - // prevent storage of the analysis with relaxed scalacOptions - despite not depending explicitly on compile, - // it is being triggered for parent configs/projects through evaluation of dependencyClasspath (TrackAlways) - // in the scope where scalafix is invoked - analysis.withHasModified(false) - } } ) diff --git a/src/sbt-test/sbt-scalafix/relax-scalacOptions/build.sbt b/src/sbt-test/sbt-1.4/relax-scalacOptions/build.sbt similarity index 79% rename from src/sbt-test/sbt-scalafix/relax-scalacOptions/build.sbt rename to src/sbt-test/sbt-1.4/relax-scalacOptions/build.sbt index cc0547a4..1bfde9f8 100644 --- a/src/sbt-test/sbt-scalafix/relax-scalacOptions/build.sbt +++ b/src/sbt-test/sbt-1.4/relax-scalacOptions/build.sbt @@ -1,14 +1,8 @@ val V = _root_.scalafix.sbt.BuildInfo addCompilerPlugin(scalafixSemanticdb) -scalacOptions ++= Seq("-Yrangepos") - +scalacOptions ++= Seq("-Yrangepos", "-Ywarn-unused") scalaVersion := V.scala212 -scalacOptions ++= Seq( - // generate errors on unused imports - "-Xfatal-warnings", - "-Ywarn-unused" -) Compile / compile / scalacOptions ++= Seq( // generate errors on procedure syntax "-Wconf:cat=deprecation:e", @@ -38,11 +32,6 @@ TaskKey[Unit]("checkLastCompilationCached") := { } } -TaskKey[Unit]("checkZincAnalysisPresent") := { - val isPresent = (Compile / previousCompile).value.analysis.isPresent() - assert(isPresent, "zinc analysis not found") -} - // https://github.com/sbt/sbt/commit/dbb47b3ce822ff7ec25881dadd71a3b29e202273 // must be outside a macro to workaround "Illegal dynamic reference: Def" def streamScopedKey(scope: Scope) = Def.ScopedKey(scope, Keys.streams.key) diff --git a/src/sbt-test/sbt-1.4/relax-scalacOptions/project/build.properties b/src/sbt-test/sbt-1.4/relax-scalacOptions/project/build.properties new file mode 100644 index 00000000..dbae93bc --- /dev/null +++ b/src/sbt-test/sbt-1.4/relax-scalacOptions/project/build.properties @@ -0,0 +1 @@ +sbt.version=1.4.9 diff --git a/src/sbt-test/sbt-scalafix/relax-scalacOptions/project/plugins.sbt b/src/sbt-test/sbt-1.4/relax-scalacOptions/project/plugins.sbt similarity index 100% rename from src/sbt-test/sbt-scalafix/relax-scalacOptions/project/plugins.sbt rename to src/sbt-test/sbt-1.4/relax-scalacOptions/project/plugins.sbt diff --git a/src/sbt-test/sbt-scalafix/relax-scalacOptions/src/main/scala/IgnoreWarning.scala b/src/sbt-test/sbt-1.4/relax-scalacOptions/src/main/scala/IgnoreWarning.scala similarity index 100% rename from src/sbt-test/sbt-scalafix/relax-scalacOptions/src/main/scala/IgnoreWarning.scala rename to src/sbt-test/sbt-1.4/relax-scalacOptions/src/main/scala/IgnoreWarning.scala diff --git a/src/sbt-test/sbt-scalafix/relax-scalacOptions/src/main/scala/UnusedImportAndProcedureSyntax.scala b/src/sbt-test/sbt-1.4/relax-scalacOptions/src/main/scala/UnusedImportAndProcedureSyntax.scala similarity index 100% rename from src/sbt-test/sbt-scalafix/relax-scalacOptions/src/main/scala/UnusedImportAndProcedureSyntax.scala rename to src/sbt-test/sbt-1.4/relax-scalacOptions/src/main/scala/UnusedImportAndProcedureSyntax.scala diff --git a/src/sbt-test/sbt-1.4/relax-scalacOptions/test b/src/sbt-test/sbt-1.4/relax-scalacOptions/test new file mode 100644 index 00000000..678f60ff --- /dev/null +++ b/src/sbt-test/sbt-1.4/relax-scalacOptions/test @@ -0,0 +1,45 @@ +# when the build does not contain any flag relaxed on scalafix invocation +# check that regular compilation benefits froma prior direct scalafix invocation ... +-> scalafix --check RemoveUnused +-> checkLastCompilationCached +> compile +> checkLastCompilationCached + +# ... and indirect scalafix invocation +> clean +> test:scalafix --check RemoveUnused +-> checkLastCompilationCached +> compile +> checkLastCompilationCached + +# we now have 2 fatal warnings preventing compilation +> set scalacOptions ++= Seq("-Xfatal-warnings") +-> compile + +# ensure that a semantic rule can be ran despite warnings, to fix one of the warning +> scalafix RemoveUnused + +# confirm that the rule was applied and that triggered compilation is cached once the updated file recompiled +> scalafix --check RemoveUnused +-> checkLastCompilationCached +> scalafix --check RemoveUnused +> checkLastCompilationCached + +# and that -Xfatal-warnings remains honored for regular compilation +-> compile + +# confirm that regular compilation succeeds after fixing the last warning +> scalafix ProcedureSyntax +> compile + +# check that regular compilation is cached as usual +> compile +> checkLastCompilationCached + +# check that there is no recompilation when running a semantic rule after a regular compilation ... +> scalafix RemoveUnused +> checkLastCompilationCached + +# nor when compiling after running a semantic rule +> compile +> checkLastCompilationCached \ No newline at end of file diff --git a/src/sbt-test/sbt-scalafix/relax-scalacOptions/test b/src/sbt-test/sbt-scalafix/relax-scalacOptions/test deleted file mode 100644 index 0b61661c..00000000 --- a/src/sbt-test/sbt-scalafix/relax-scalacOptions/test +++ /dev/null @@ -1,22 +0,0 @@ -# we have 2 fatal warnings preventing compilation --> compile - -# ensure that a semantic rule can be ran despite warnings, to fix one of the warning -> scalafixAll RemoveUnused - -# but that the zinc analysis file has not been persisted, otherwise the run with relax scalacOptions would -# cause the next compile to be full (non-incremental) no matter if there was a previous successful compilation --> checkZincAnalysisPresent - -# and that -Xfatal-warnings remains honored for regular compilation --> compile - -# confirm that compilation succeeds after fixing the last warning -> scalafix ProcedureSyntax -> compile -> checkZincAnalysisPresent - -# check that there is no recompilation when running a semantic rule after a successful compilation --> checkLastCompilationCached -> scalafixAll RemoveUnused -> checkLastCompilationCached