Skip to content

Commit

Permalink
Retain Bloop connection when restarting a build with --watch
Browse files Browse the repository at this point in the history
  • Loading branch information
Gedochao committed Dec 6, 2024
1 parent 58d4da8 commit b114d82
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 3 deletions.
14 changes: 11 additions & 3 deletions modules/build/src/main/scala/scala/build/Build.scala
Original file line number Diff line number Diff line change
Expand Up @@ -683,12 +683,12 @@ object Build {
val threads = BuildThreads.create()
val classesDir0 = classesRootDir(inputs.workspace, inputs.projectName)

def info: Either[BuildException, (ScalaCompiler, Option[ScalaCompiler], CrossSources, Inputs)] =
lazy val compilers: Either[BuildException, (ScalaCompiler, Option[ScalaCompiler])] =
either {
val (crossSources: CrossSources, inputs0: Inputs) =
value(allInputs(inputs, options, logger))
val sharedOptions = crossSources.sharedOptions(options)
val compiler: ScalaCompiler = value {
val compiler = value {
compilerMaker.create(
inputs0.workspace / Constants.workspaceDirName,
classesDir0,
Expand All @@ -697,13 +697,21 @@ object Build {
sharedOptions
)
}
val docCompilerOpt: Option[ScalaCompiler] = docCompilerMakerOpt.map(_.create(
val docCompilerOpt = docCompilerMakerOpt.map(_.create(
inputs0.workspace / Constants.workspaceDirName,
classesDir0,
buildClient,
logger,
sharedOptions
)).map(value)
compiler -> docCompilerOpt
}

def info: Either[BuildException, (ScalaCompiler, Option[ScalaCompiler], CrossSources, Inputs)] =
either {
val (crossSources: CrossSources, inputs0: Inputs) =
value(allInputs(inputs, options, logger))
val (compiler, docCompilerOpt) = value(compilers)
(compiler, docCompilerOpt, crossSources, inputs0)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -338,4 +338,32 @@ trait RunWithWatchTestDefinitions { _: RunTestDefinitions =>
}
}
}

if (actualScalaVersion.startsWith("3"))
test("watch mode doesnt hang on Bloop when rebuilding repeatedly") {
def expectedMessage(number: Int) = s"Hello $number"
def content(number: Int) =
s"@main def main(): Unit = println(\"${expectedMessage(number)}\")"
TestUtil.retryOnCi() {
val inputPath = os.rel / "example.scala"
TestInputs(inputPath -> content(0)).fromRoot { root =>
os.proc(TestUtil.cli, "--power", "bloop", "exit").call(cwd = root)
TestUtil.withProcessWatching(
proc = os.proc(TestUtil.cli, ".", "--watch", extraOptions)
.spawn(cwd = root, stderr = os.Pipe)
) { (proc, timeout, ec) =>
for (num <- 1 to 10) {
val output = TestUtil.readLine(proc.stdout, ec, timeout)
expect(output == expectedMessage(num - 1))
proc.printStderrUntilRerun(timeout)(ec)
Thread.sleep(200L)
if (num < 10) {
val newContent = content(num)
os.write.over(root / inputPath, newContent)
}
}
}
}
}
}
}

0 comments on commit b114d82

Please sign in to comment.