Skip to content

Commit

Permalink
improvement: Don't fail on hashing, but use a random one
Browse files Browse the repository at this point in the history
Previously, when hashing would fail the whole compilation would also fail and while this seems incredibly rare let's try to guard ourselves here.

Connected to #2053
  • Loading branch information
tgodzik committed May 25, 2023
1 parent ddd5adc commit 3ed2320
Show file tree
Hide file tree
Showing 3 changed files with 24 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,35 @@ 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 3ed2320

Please sign in to comment.