-
Notifications
You must be signed in to change notification settings - Fork 44
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
fix false positive cache invalidation caused by unscoped lookup #192
Conversation
021a9a7
to
d545657
Compare
@@ -393,15 +388,12 @@ object ScalafmtPlugin extends AutoPlugin { | |||
|
|||
private def scalafmtTask(sources: Seq[File], session: FormatSession) = | |||
Def.task { | |||
session.formatTrackedSources(streams.value.cacheStoreFactory, sources) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
would changing this to (scalafmt / streams).value.cacheStoreFactory
be an equivalent single-line fix? if not, can you explain how this change actually works?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i tested this, doesn't work. mystery...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It wouldn't since we would still be missing the configuration axis (not propagated from the taskDyn, see #192 (comment)) when resolving the .value
lookup.
However, an equivalent fix would be to pass the config as an argument of the method, and use (config / scalafmt / streams).value.cacheStoreFactory
, but I felt like capturing the cache directory in the session was simpler.
i am not an expert (in fact, could barely navigate through |
@kitbellew here is an attempt at clarifying what's going on (based on my own understanding obviously). This assumes the reader is familiar with the task graph & scopes. # build.sbt
lazy val taskLookup = taskKey[File]("")
lazy val taskDynLookup = taskKey[File]("")
inConfig(Compile)(
Seq(
taskLookup := Def.task(streams.value.cacheDirectory).value,
taskDynLookup := Def.taskDyn(Def.task(streams.value.cacheDirectory)).value,
)
) -$ sbt "show taskLookup" | tail -n2 | head -n1
+$ sbt "show taskDynLookup" | tail -n2 | head -n1
-[info] /tmp/sbt/target/streams/compile/taskLookup/_global/streams
+[info] /tmp/sbt/target/streams/_global/_global/_global/streams We can see that the cache directory is not resolved in the same scope depending on where the lookup happens.
|
It seems that keys are not scoped when looked up from Def.Initialize[] referenced within Def.taskDyn(), resulting in streams.value.cacheStoreFactory defaulting to a directory shared across configurations.
d545657
to
b18ce32
Compare
thank you for the explanation, Brice. while bug in the macro is a more palatable explanation for the regression, it is true that i am more of a bull in a china shop when it comes to sbt/scopes. |
Fix regression introduced in bb36031, effectively disabling the cache for projects with files in several configuration. This is particularly annoying with
scalafmtOnCompile := true
.The problem is visible by looking at a stamp file on a project with 4 configurations after running
sbt clean scalafixAll