Skip to content

Commit

Permalink
Allow to disable Bloop file content comparison (#666)
Browse files Browse the repository at this point in the history
Use --strict-bloop-json-check=false

This can potentially save several 100 ms if the Bloop files are already
on disk.
  • Loading branch information
alexarchambault authored Feb 21, 2022
1 parent 3f7a047 commit c52d375
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 9 deletions.
7 changes: 6 additions & 1 deletion modules/build/src/main/scala/scala/build/Build.scala
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,8 @@ object Build {
def diagnostics: None.type = None
}

def defaultStrictBloopJsonCheck = true

def updateInputs(
inputs: Inputs,
options: BuildOptions,
Expand Down Expand Up @@ -724,7 +726,10 @@ object Build {

val project = value(buildProject(inputs, sources, generatedSources, options, scope, logger))

val updatedBloopConfig = project.writeBloopFile(logger)
val updatedBloopConfig = project.writeBloopFile(
options.internal.strictBloopJsonCheck.getOrElse(defaultStrictBloopJsonCheck),
logger
)

if (updatedBloopConfig && os.isDir(classesDir0)) {
logger.debug(s"Clearing $classesDir0")
Expand Down
14 changes: 9 additions & 5 deletions modules/build/src/main/scala/scala/build/Project.scala
Original file line number Diff line number Diff line change
Expand Up @@ -68,12 +68,16 @@ final case class Project(
def bloopFile: BloopConfig.File =
BloopConfig.File(BloopConfig.File.LatestVersion, bloopProject)

def writeBloopFile(logger: Logger): Boolean = {
val bloopFileContent = writeAsJsonToArray(bloopFile)(BloopCodecs.codecFile)
val dest = directory / ".bloop" / s"$projectName.json"
def writeBloopFile(strictCheck: Boolean, logger: Logger): Boolean = {
lazy val bloopFileContent =
writeAsJsonToArray(bloopFile)(BloopCodecs.codecFile)
val dest = directory / ".bloop" / s"$projectName.json"
val doWrite = !os.isFile(dest) || {
val currentContent = os.read.bytes(dest)
!Arrays.equals(currentContent, bloopFileContent)
strictCheck && {
logger.debug(s"Checking Bloop project in $dest")
val currentContent = os.read.bytes(dest)
!Arrays.equals(currentContent, bloopFileContent)
}
}
if (doWrite) {
logger.debug(s"Writing bloop project in $dest")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ final case class InternalOptions(
keepDiagnostics: Boolean = false,
cache: Option[FileCache[Task]] = None,
localRepository: Option[String] = None,
verbosity: Option[Int] = None
verbosity: Option[Int] = None,
strictBloopJsonCheck: Option[Boolean] = None
)

object InternalOptions {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,10 @@ final case class SharedOptions(
@Hidden
forbid: List[String] = Nil,
@Recurse
helpGroups: HelpGroupOptions = HelpGroupOptions()
helpGroups: HelpGroupOptions = HelpGroupOptions(),

@Hidden
strictBloopJsonCheck: Option[Boolean] = None
) {
// format: on

Expand Down Expand Up @@ -171,7 +174,8 @@ final case class SharedOptions(
internal = bo.InternalOptions(
cache = Some(coursierCache),
localRepository = LocalRepo.localRepo(directories.directories.localRepoDir),
verbosity = Some(logging.verbosity)
verbosity = Some(logging.verbosity),
strictBloopJsonCheck = strictBloopJsonCheck
)
)
}
Expand Down
2 changes: 2 additions & 0 deletions website/docs/reference/cli-options.md
Original file line number Diff line number Diff line change
Expand Up @@ -1043,6 +1043,8 @@ Generate SemanticDBs

#### `--forbid`

#### `--strict-bloop-json-check`

## Test options

Available in commands:
Expand Down

0 comments on commit c52d375

Please sign in to comment.