From 07724ac968ccdf67f71a6110ac25d45628abe2ee Mon Sep 17 00:00:00 2001 From: Alexandre Archambault Date: Thu, 10 Mar 2022 11:54:12 +0100 Subject: [PATCH 1/3] Tweak --strict-bloop-json-check option When --strict-bloop-json-check=false was passed, it seems we were not updating Bloop files when new sources we added (or former ones removed). This should fix that. --- .../src/main/scala/scala/build/Project.scala | 45 ++++++++++++++++--- 1 file changed, 38 insertions(+), 7 deletions(-) diff --git a/modules/build/src/main/scala/scala/build/Project.scala b/modules/build/src/main/scala/scala/build/Project.scala index 5917100ba2..162213d55f 100644 --- a/modules/build/src/main/scala/scala/build/Project.scala +++ b/modules/build/src/main/scala/scala/build/Project.scala @@ -5,6 +5,8 @@ import _root_.coursier.{Dependency => CsDependency, core => csCore, util => csUt import com.github.plokhotnyuk.jsoniter_scala.core.{writeToArray => writeAsJsonToArray} import coursier.core.Classifier +import java.io.ByteArrayOutputStream +import java.nio.charset.StandardCharsets import java.nio.file.Path import java.util.Arrays @@ -68,17 +70,46 @@ final case class Project( def bloopFile: BloopConfig.File = BloopConfig.File(BloopConfig.File.LatestVersion, bloopProject) + private def maybeUpdateInputs(logger: Logger): Boolean = { + val dest = directory / ".bloop" / s"$projectName.inputs.txt" + val onDiskOpt = + if (os.exists(dest)) Some(os.read.bytes(dest)) + else None + val newContent = { + val linesIt = + if (sources.forall(_.startsWith(workspace))) + sources.iterator.map(_.relativeTo(workspace).toString) + else + sources.iterator.map(_.toString) + val it = linesIt.map(_ + System.lineSeparator()).map(_.getBytes(StandardCharsets.UTF_8)) + val b = new ByteArrayOutputStream + for (elem <- it) + b.write(elem) + b.toByteArray() + } + val doWrite = onDiskOpt.forall(onDisk => !Arrays.equals(onDisk, newContent)) + if (doWrite) { + logger.debug(s"Writing source file list in $dest") + os.write.over(dest, newContent, createFolders = true) + } + else + logger.debug(s"Source file list in $dest doesn't need updating") + doWrite + } + 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) || { - strictCheck && { - logger.debug(s"Checking Bloop project in $dest") - val currentContent = os.read.bytes(dest) - !Arrays.equals(currentContent, bloopFileContent) - } - } + val doWrite = + if (strictCheck) + !os.isFile(dest) || { + logger.debug(s"Checking Bloop project in $dest") + val currentContent = os.read.bytes(dest) + !Arrays.equals(currentContent, bloopFileContent) + } + else + maybeUpdateInputs(logger) || !os.isFile(dest) if (doWrite) { logger.debug(s"Writing bloop project in $dest") os.write.over(dest, bloopFileContent, createFolders = true) From 95fb465bedbf92b703fdd94e822e0e222e6ded7c Mon Sep 17 00:00:00 2001 From: Alexandre Archambault Date: Thu, 10 Mar 2022 11:56:26 +0100 Subject: [PATCH 2/3] Temporarily disable --strict-bloop-json-check=false in build This option should speed up compilation, by short-circuiting costly Bloop file generation when the build is apparently the same. As of now, this option doesn't overwrite the Bloop files when new sources are created, which is a problem. --- project/settings.sc | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/project/settings.sc b/project/settings.sc index 152602d7f4..5b418114e1 100644 --- a/project/settings.sc +++ b/project/settings.sc @@ -783,7 +783,8 @@ trait ScalaCliCompile extends ScalaModule { asOpt("--jar", compileClasspath().map(_.path)), asOpt("-O", scalacPluginClasspath().map(p => s"-Xplugin:${p.path}")), Seq("--jvm", "zulu:17"), - "--strict-bloop-json-check=false", // don't check Bloop JSON files at each run + // re-enable this when switching to Scala CLI > 0.1.2 + // "--strict-bloop-json-check=false", // don't check Bloop JSON files at each run workspace, sourceFiles ) From e3f7e1dd31d8971c6f1d0cf9a7b02dbe95b61c12 Mon Sep 17 00:00:00 2001 From: Alexandre Archambault Date: Thu, 10 Mar 2022 13:41:29 +0100 Subject: [PATCH 3/3] Sort files when reading them from directories just in case --- modules/build/src/main/scala/scala/build/Inputs.scala | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/modules/build/src/main/scala/scala/build/Inputs.scala b/modules/build/src/main/scala/scala/build/Inputs.scala index 62cc86bc63..5522d35921 100644 --- a/modules/build/src/main/scala/scala/build/Inputs.scala +++ b/modules/build/src/main/scala/scala/build/Inputs.scala @@ -128,7 +128,8 @@ final case class Inputs( String.format(s"%040x", calculatedSum) } - private def singleFilesFromDirectory(d: Inputs.Directory): Seq[Inputs.SingleFile] = + private def singleFilesFromDirectory(d: Inputs.Directory): Seq[Inputs.SingleFile] = { + import Ordering.Implicits.seqOrdering os.walk.stream(d.path, skip = _.last.startsWith(".")) .filter(os.isFile(_)) .collect { @@ -140,6 +141,8 @@ final case class Inputs( Inputs.Script(d.path, p.subRelativeTo(d.path)) } .toVector + .sortBy(_.subPath.segments) + } } object Inputs { @@ -175,8 +178,10 @@ object Inputs { ScopePath(Left(source), subPath) } - sealed trait SingleFile extends OnDisk with SingleElement - sealed trait SourceFile extends SingleFile + sealed trait SingleFile extends OnDisk with SingleElement + sealed trait SourceFile extends SingleFile { + def subPath: os.SubPath + } sealed trait Compiled extends Element sealed trait AnyScalaFile extends Compiled