Skip to content

Commit

Permalink
Merge pull request #2058 from tgodzik/random-hash
Browse files Browse the repository at this point in the history
improvement: Don't fail on hashing, but use a random hash
  • Loading branch information
tgodzik committed May 26, 2023
2 parents cc04a06 + 964a4f8 commit 7a7a913
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ object BloopZincCompiler {
skip: Boolean = false,
incrementalCompilerOptions: IncOptions,
extra: List[(String, String)]
): Task[CompileConfiguration] = Task.now {
)(implicit logger: ObservedLogger[_]): Task[CompileConfiguration] = Task.now {
// Remove directories from classpath hashes, we're only interested in jars
val jarClasspathHashes = BloopLookup.filterOutDirsFromHashedClasspath(classpathHashes)
val compileSetup = MiniSetup.of(
Expand Down Expand Up @@ -284,7 +284,7 @@ object BloopZincCompiler {
earlyOutput = None,
// deals with pipelining, not supported yet
earlyAnalysisStore = None,
stamper = BloopStamps.initial
stamper = BloopStamps.initial(logger)
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ object BloopIncremental {
}
}

val current = BloopStamps.initial
val current = BloopStamps.initial(log)
val externalAPI = getExternalAPI(lookup)
val previous = previous0 match { case a: Analysis => a }
val previousRelations = previous.relations
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,36 @@ import xsbti.VirtualFileRef
import xsbti.compile.FileHash
import xsbti.compile.analysis.ReadStamps
import xsbti.compile.analysis.Stamp
import scala.util.control.NonFatal
import sbt.util.Logger
import sbt.internal.inc.FarmHash

object BloopStamps {
private val converter = PlainVirtualFileConverter.converter

private def underlying = Stamps.initial(
private def underlying(logger: Logger) = Stamps.initial(
BloopStamps.forHash,
// The hash is for the sources
BloopStamps.forHash,
Stamper.forHashInRootPaths(converter)
libraryStamp(logger)
)
def initial: ReadStamps = Stamps.timeWrapBinaryStamps(underlying, converter)

def libraryStamp(logger: Logger): VirtualFileRef => Stamp = { (file: VirtualFileRef) =>
{
val baseStamp = Stamper.forHashInRootPaths(converter)
try {
baseStamp(file)
} catch {
case NonFatal(e) =>
logger.error(s"Could not calculate hash for ${file.id} because of ${e.getMessage}")
FarmHash.fromLong(emptyHash.toLong)
}

}
}

def initial(logger: Logger): ReadStamps =
Stamps.timeWrapBinaryStamps(underlying(logger), converter)

private final val emptyHash = scala.util.Random.nextInt()
private final val directoryHash = scala.util.Random.nextInt()
Expand Down

0 comments on commit 7a7a913

Please sign in to comment.