Skip to content

Commit

Permalink
Machine-independent args cache
Browse files Browse the repository at this point in the history
Stamps scalafix arguments using a hash of the files instead of
relying on the lastMofified property in order to produce a
machine-independent "args" cache.
  • Loading branch information
github-sebastien-boulet committed Feb 18, 2021
1 parent 6edff05 commit 8ff37a3
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions src/main/scala/scalafix/sbt/ScalafixPlugin.scala
Original file line number Diff line number Diff line change
Expand Up @@ -492,7 +492,7 @@ object ScalafixPlugin extends AutoPlugin {
case jar =>
Seq(jar)
}
write(files.map(FileInfo.lastModified.apply))
write(files.map(stampFile))
write(customDependencies.map(_.toString))
case Arg.Rules(rules) =>
rules.foreach {
Expand All @@ -509,10 +509,10 @@ object ScalafixPlugin extends AutoPlugin {
case Arg.Config(maybeFile) =>
maybeFile match {
case Some(path) =>
write(FileInfo.lastModified(path.toFile))
write(stampFile(path.toFile))
case None =>
val defaultConfigFile = file(".scalafix.conf")
write(FileInfo.lastModified(defaultConfigFile))
write(stampFile(defaultConfigFile))
}
case Arg.ParsedArgs(args) =>
val cacheKeys = args.filter {
Expand All @@ -535,6 +535,14 @@ object ScalafixPlugin extends AutoPlugin {
case Arg.NoCache =>
throw StampingImpossible
}

def stampFile(file: File): Array[Byte] = {
// ensure the file exists and is not a directory
if (file.isFile)
Hash(file)
else
Array.empty[Byte]
}
}

def diffWithPreviousRuns[T](f: (Boolean, Set[File]) => T): T = {
Expand Down

0 comments on commit 8ff37a3

Please sign in to comment.