From dd6884399e6f8715741105c9341b0763a97accf3 Mon Sep 17 00:00:00 2001 From: Tomasz Godzik Date: Thu, 11 Jul 2024 18:05:23 +0200 Subject: [PATCH] refactor: Switch to original fork of Bloop --- build.sc | 8 ++++++++ gcbenchmark/gcbenchmark.scala | 2 +- .../src/main/scala/scala/build/Bloop.scala | 19 +++++++++---------- .../scala/scala/build/bsp/BspServer.scala | 2 +- .../scala/scala/build/tests/TestLogger.scala | 3 +++ .../scala/cli/commands/bloop/Bloop.scala | 2 +- .../scala/cli/commands/bloop/BloopStart.scala | 4 ++-- .../cli/commands/setupide/SetupIde.scala | 2 +- .../SharedCompilationServerOptions.scala | 4 ++-- .../scala/scala/cli/internal/CliLogger.scala | 2 ++ .../scala/cli/integration/BloopTests.scala | 2 +- project/deps.sc | 4 ++-- 12 files changed, 33 insertions(+), 21 deletions(-) diff --git a/build.sc b/build.sc index f81dd0e23d..1104ff17bb 100644 --- a/build.sc +++ b/build.sc @@ -349,6 +349,14 @@ trait Core extends ScalaCliCrossSbtModule super.scalacOptions() ++ asyncScalacOptions(crossScalaVersion) } + import coursier.maven.MavenRepository + + def repositoriesTask = T.task { + super.repositoriesTask() ++ Seq( + MavenRepository("https://oss.sonatype.org/content/repositories/snapshots") + ) + } + def ivyDeps = super.ivyDeps() ++ Agg( Deps.bloopRifle.exclude(("org.scala-lang.modules", "scala-collection-compat_2.13")), Deps.collectionCompat, diff --git a/gcbenchmark/gcbenchmark.scala b/gcbenchmark/gcbenchmark.scala index eadaded756..6280d4c374 100644 --- a/gcbenchmark/gcbenchmark.scala +++ b/gcbenchmark/gcbenchmark.scala @@ -44,7 +44,7 @@ object Main { def bloopPid: Option[Int] = { val processes = os.proc("jps", "-l").call().out.text() - "(\\d+) bloop[.]Bloop".r + "(\\d+) bloop[.]Server".r .findFirstMatchIn(processes) .map(_.group(1).toInt) } diff --git a/modules/build/src/main/scala/scala/build/Bloop.scala b/modules/build/src/main/scala/scala/build/Bloop.scala index bdad7cf5ed..dab467458e 100644 --- a/modules/build/src/main/scala/scala/build/Bloop.scala +++ b/modules/build/src/main/scala/scala/build/Bloop.scala @@ -73,7 +73,8 @@ object Bloop { val res = value { Artifacts.artifacts( Seq(Positioned.none(dep)), - Nil, + // TODO remove after bloop available on maven central + Seq(coursier.Repositories.sonatype("snapshots")), Some(params), logger, cache.withMessage(s"Downloading compilation server ${dep.version}") @@ -85,25 +86,23 @@ object Bloop { def bloopClassPath( logger: Logger, cache: FileCache[Task] - ): Either[BuildException, (Seq[File], Boolean)] = + ): Either[BuildException, Seq[File]] = bloopClassPath(logger, cache, BloopRifleConfig.defaultVersion) def bloopClassPath( logger: Logger, cache: FileCache[Task], bloopVersion: String - ): Either[BuildException, (Seq[File], Boolean)] = either { + ): Either[BuildException, Seq[File]] = either { val moduleStr = BloopRifleConfig.defaultModule val mod = value { ModuleParser.parse(moduleStr) .left.map(err => new ModuleFormatError(moduleStr, err, Some("Bloop"))) } - val dep = DependencyLike(mod, bloopVersion) - val sv = BloopRifleConfig.defaultScalaVersion - val sbv = ScalaVersion.binary(sv) - val params = ScalaParameters(sv, sbv) - val cp = value(bloopClassPath(dep, params, logger, cache)) - val isScalaCliBloop = moduleStr.startsWith(BloopRifleConfig.scalaCliBloopOrg + ":") - (cp, isScalaCliBloop) + val dep = DependencyLike(mod, bloopVersion) + val sv = BloopRifleConfig.defaultScalaVersion + val sbv = ScalaVersion.binary(sv) + val params = ScalaParameters(sv, sbv) + value(bloopClassPath(dep, params, logger, cache)) } } diff --git a/modules/build/src/main/scala/scala/build/bsp/BspServer.scala b/modules/build/src/main/scala/scala/build/bsp/BspServer.scala index e4f2bcdd2e..375dd555f2 100644 --- a/modules/build/src/main/scala/scala/build/bsp/BspServer.scala +++ b/modules/build/src/main/scala/scala/build/bsp/BspServer.scala @@ -183,7 +183,7 @@ class BspServer( val res = new b.InitializeBuildResult( "scala-cli", Constants.version, - bloop.rifle.internal.Constants.bspVersion, + bloop.rifle.internal.BuildInfo.bspVersion, capabilities ) val buildComesFromIntelliJ = params.getDisplayName.toLowerCase.contains("intellij") diff --git a/modules/build/src/test/scala/scala/build/tests/TestLogger.scala b/modules/build/src/test/scala/scala/build/tests/TestLogger.scala index 7a7033b5bf..8d984f4a0e 100644 --- a/modules/build/src/test/scala/scala/build/tests/TestLogger.scala +++ b/modules/build/src/test/scala/scala/build/tests/TestLogger.scala @@ -53,6 +53,9 @@ case class TestLogger(info: Boolean = true, debug: Boolean = false) extends Logg def bloopBspStdout: Option[java.io.OutputStream] = Some(System.out) def bloopCliInheritStderr: Boolean = true def bloopCliInheritStdout: Boolean = true + def debug(msg: => String): Unit = { + System.err.println(msg) + } def debug(msg: => String, ex: Throwable): Unit = { System.err.println(msg) if (ex != null) ex.printStackTrace(System.err) diff --git a/modules/cli/src/main/scala/scala/cli/commands/bloop/Bloop.scala b/modules/cli/src/main/scala/scala/cli/commands/bloop/Bloop.scala index 781dd63004..b558586f2e 100644 --- a/modules/cli/src/main/scala/scala/cli/commands/bloop/Bloop.scala +++ b/modules/cli/src/main/scala/scala/cli/commands/bloop/Bloop.scala @@ -1,6 +1,6 @@ package scala.cli.commands.bloop -import bloop.rifle.internal.{Constants, Operations} +import bloop.rifle.internal.Operations import bloop.rifle.{BloopRifle, BloopRifleConfig, BloopThreads} import caseapp.core.RemainingArgs diff --git a/modules/cli/src/main/scala/scala/cli/commands/bloop/BloopStart.scala b/modules/cli/src/main/scala/scala/cli/commands/bloop/BloopStart.scala index 967b6fb74f..c68a51411f 100644 --- a/modules/cli/src/main/scala/scala/cli/commands/bloop/BloopStart.scala +++ b/modules/cli/src/main/scala/scala/cli/commands/bloop/BloopStart.scala @@ -1,6 +1,6 @@ package scala.cli.commands.bloop -import bloop.rifle.internal.Constants +import bloop.rifle.internal.BuildInfo import bloop.rifle.{BloopRifle, BloopRifleConfig, BloopThreads} import caseapp.* @@ -64,7 +64,7 @@ object BloopStart extends ScalaCommand[BloopStartOptions] { bloopRifleConfig, threads.startServerChecks, logger.bloopRifleLogger, - Constants.bloopVersion, + BuildInfo.version, bloopRifleConfig.javaPath ) Await.result(f, Duration.Inf) diff --git a/modules/cli/src/main/scala/scala/cli/commands/setupide/SetupIde.scala b/modules/cli/src/main/scala/scala/cli/commands/setupide/SetupIde.scala index 0774b018af..2c18057a4c 100644 --- a/modules/cli/src/main/scala/scala/cli/commands/setupide/SetupIde.scala +++ b/modules/cli/src/main/scala/scala/cli/commands/setupide/SetupIde.scala @@ -166,7 +166,7 @@ object SetupIde extends ScalaCommand[SetupIdeOptions] { bspName, bspArgs.asJava, Constants.version, - bloop.rifle.internal.Constants.bspVersion, + bloop.rifle.internal.BuildInfo.bspVersion, List("scala", "java").asJava ) diff --git a/modules/cli/src/main/scala/scala/cli/commands/shared/SharedCompilationServerOptions.scala b/modules/cli/src/main/scala/scala/cli/commands/shared/SharedCompilationServerOptions.scala index f9d9826d66..221c2e8bd1 100644 --- a/modules/cli/src/main/scala/scala/cli/commands/shared/SharedCompilationServerOptions.scala +++ b/modules/cli/src/main/scala/scala/cli/commands/shared/SharedCompilationServerOptions.scala @@ -1,6 +1,6 @@ package scala.cli.commands.shared -import bloop.rifle.internal.Constants +import bloop.rifle.internal.BuildInfo import bloop.rifle.{BloopRifleConfig, BloopVersion, BspConnectionAddress} import caseapp.* import com.github.plokhotnyuk.jsoniter_scala.core.* @@ -192,7 +192,7 @@ final case class SharedCompilationServerOptions( .map(_.trim) .filter(_.nonEmpty) .fold[BloopRifleConfig.BloopVersionConstraint](BloopRifleConfig.AtLeast( - BloopVersion(Constants.bloopVersion) + BloopVersion(BuildInfo.version) ))(v => BloopRifleConfig.Strict(BloopVersion(v))) def bloopDefaultJvmOptions(logger: Logger): Option[List[String]] = { diff --git a/modules/cli/src/main/scala/scala/cli/internal/CliLogger.scala b/modules/cli/src/main/scala/scala/cli/internal/CliLogger.scala index 6335b83664..fe91c52944 100644 --- a/modules/cli/src/main/scala/scala/cli/internal/CliLogger.scala +++ b/modules/cli/src/main/scala/scala/cli/internal/CliLogger.scala @@ -160,6 +160,8 @@ class CliLogger( def bloopRifleLogger = new BloopRifleLogger { def info(msg: => String) = logger.message(msg) + def debug(msg: => String) = + if (verbosity >= 3) logger.debug(msg) def debug(msg: => String, ex: Throwable) = if (verbosity >= 3) { logger.debug(msg) diff --git a/modules/integration/src/test/scala/scala/cli/integration/BloopTests.scala b/modules/integration/src/test/scala/scala/cli/integration/BloopTests.scala index 7bdcf0a4b0..baa55160f6 100644 --- a/modules/integration/src/test/scala/scala/cli/integration/BloopTests.scala +++ b/modules/integration/src/test/scala/scala/cli/integration/BloopTests.scala @@ -83,7 +83,7 @@ class BloopTests extends ScalaCliSuite { test("bloop exit works") { def bloopRunning(): Boolean = { val javaProcesses = os.proc("jps", "-l").call().out.text() - javaProcesses.contains("bloop.Bloop") + javaProcesses.contains("bloop.Server") } val inputs = TestInputs.empty diff --git a/project/deps.sc b/project/deps.sc index 7357e881d1..995b3cd7c0 100644 --- a/project/deps.sc +++ b/project/deps.sc @@ -109,7 +109,7 @@ object Deps { def signingCli = "0.2.3" def signingCliJvmVersion = 17 def javaClassName = "0.1.3" - def bloop = "1.5.17-sc-2" + def bloop = "1.6.0-11-8092d595-SNAPSHOT" } // DO NOT hardcode a Scala version in this dependency string // This dependency is used to ensure that Ammonite is available for Scala versions @@ -120,7 +120,7 @@ object Deps { // Force using of 2.13 - is there a better way? def bloopConfig = ivy"ch.epfl.scala:bloop-config_2.13:2.0.2" .exclude(("com.github.plokhotnyuk.jsoniter-scala", "jsoniter-scala-core_2.13")) - def bloopRifle = ivy"io.github.alexarchambault.bleep:bloop-rifle_2.13:${Versions.bloop}" + def bloopRifle = ivy"ch.epfl.scala:bloop-rifle_2.13:${Versions.bloop}" def bsp4j = ivy"ch.epfl.scala:bsp4j:2.1.1" def caseApp = ivy"com.github.alexarchambault::case-app:2.1.0-M28" def collectionCompat = ivy"org.scala-lang.modules::scala-collection-compat:2.12.0"