Skip to content

Commit

Permalink
Merge pull request #458 from eed3si9n/wip/cache_fix
Browse files Browse the repository at this point in the history
Fix pattern matching in classpath hash caching
  • Loading branch information
jvican authored Nov 25, 2017
2 parents d6d6988 + bc64515 commit 4fa347a
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 11 deletions.
7 changes: 5 additions & 2 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,10 @@ def commonSettings: Seq[Setting[_]] = Seq(
crossScalaVersions := Seq(scala211, scala212),
publishArtifact in Test := false,
commands ++= Seq(publishBridgesAndTest, publishBridgesAndSet, crossTestBridges),
scalacOptions += "-YdisableFlatCpCaching"
scalacOptions ++= Seq(
"-YdisableFlatCpCaching",
"-target:jvm-1.8",
)
)

def relaxNon212: Seq[Setting[_]] = Seq(
Expand All @@ -44,7 +47,7 @@ def relaxNon212: Seq[Setting[_]] = Seq(
"-deprecation",
"-Ywarn-unused",
"-Ywarn-unused-import",
"-YdisableFlatCpCaching"
"-YdisableFlatCpCaching",
)
}
}
Expand Down
12 changes: 6 additions & 6 deletions project/Dependencies.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@ import sbt._, Keys._
import sbt.contraband.ContrabandPlugin.autoImport._

object Dependencies {
val scala210 = "2.10.6"
val scala211 = "2.11.11"
val scala212 = "2.12.3"
val scala210 = "2.10.7"
val scala211 = "2.11.12"
val scala212 = "2.12.4"
val scala213 = "2.13.0-M2"

private val ioVersion = "1.0.0"
private val utilVersion = "1.0.0"
private val lmVersion = "1.0.0"
private val ioVersion = "1.0.2"
private val utilVersion = "1.0.3"
private val lmVersion = "1.0.4"

private val sbtIO = "org.scala-sbt" %% "io" % ioVersion

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ object ClasspathCache {
val currentMetadata = (attrs.lastModifiedTime(), attrs.size())
Option(cacheMetadataJar.get(file)) match {
case Some((metadata, hashHit)) if metadata == currentMetadata => hashHit
case None => genFileHash(file, currentMetadata)
case _ => genFileHash(file, currentMetadata)
}
}
}
Expand Down
56 changes: 54 additions & 2 deletions zinc/src/test/scala/sbt/inc/cached/CachedHashingSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@

package sbt.inc.cached

import java.nio.file.Paths

import java.nio.file.{ Path, Paths }
import java.io.File
import sbt.inc.{ BaseCompilerSpec, SourceFiles }
import sbt.internal.inc.{ Analysis, CompileOutput, MixedAnalyzingCompiler }
import sbt.io.IO
Expand Down Expand Up @@ -62,4 +62,56 @@ class CachedHashingSpec extends BaseCompilerSpec {
s"Cache jar didn't work: $cachedHashingTime is >= than 20% of $hashingTime.")
}
}

it should "fall back when the JAR metadata is changed" in {
IO.withTemporaryDirectory { tempDir =>
val classes = Seq(SourceFiles.Good)
val sources0 = Map(Paths.get("src") -> classes.map(path => Paths.get(path)))
val projectSetup = ProjectSetup(tempDir.toPath(), sources0, Nil)
val compiler = projectSetup.createCompiler()

import compiler.in.{ setup, options, compilers, previousResult }
import sbt.internal.inc.JavaInterfaceUtil._
import sbt.io.syntax._

val javac = compilers.javaTools.javac
val scalac = compilers.scalac
val fakeLibraryJar = tempDir / "lib" / "foo.jar"

def genConfig = MixedAnalyzingCompiler.makeConfig(
scalac,
javac,
options.sources,
List(fakeLibraryJar),
CompileOutput(options.classesDirectory),
setup.cache,
setup.progress.toOption,
options.scalacOptions,
options.javacOptions,
Analysis.empty,
previousResult.setup.toOption,
setup.perClasspathEntryLookup,
setup.reporter,
options.order,
setup.skip,
setup.incrementalCompilerOptions,
setup.extra.toList.map(_.toScalaTuple)
)

IO.copyFile(fromResource(Paths.get("jar1.jar")), fakeLibraryJar)
genConfig

// This mimics changing dependency like -SNAPSHOT
IO.copyFile(fromResource(Paths.get("classesDep1.zip")), fakeLibraryJar)
genConfig
}
}

private def fromResource(path: Path): File = {
val prefix = Paths.get("bin")
val fullPath = prefix.resolve(path).toString()
Option(getClass.getClassLoader.getResource(fullPath))
.map(url => new File(url.toURI))
.getOrElse(throw new NoSuchElementException(s"Missing resource $fullPath"))
}
}

0 comments on commit 4fa347a

Please sign in to comment.