Skip to content

Commit 82de540

Browse files
authored
Retain Bloop connection when restarting a build with --watch (#3351)
1 parent 1e3746b commit 82de540

File tree

2 files changed

+50
-3
lines changed

2 files changed

+50
-3
lines changed

modules/build/src/main/scala/scala/build/Build.scala

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -683,12 +683,12 @@ object Build {
683683
val threads = BuildThreads.create()
684684
val classesDir0 = classesRootDir(inputs.workspace, inputs.projectName)
685685

686-
def info: Either[BuildException, (ScalaCompiler, Option[ScalaCompiler], CrossSources, Inputs)] =
686+
lazy val compilers: Either[BuildException, (ScalaCompiler, Option[ScalaCompiler])] =
687687
either {
688688
val (crossSources: CrossSources, inputs0: Inputs) =
689689
value(allInputs(inputs, options, logger))
690690
val sharedOptions = crossSources.sharedOptions(options)
691-
val compiler: ScalaCompiler = value {
691+
val compiler = value {
692692
compilerMaker.create(
693693
inputs0.workspace / Constants.workspaceDirName,
694694
classesDir0,
@@ -697,13 +697,21 @@ object Build {
697697
sharedOptions
698698
)
699699
}
700-
val docCompilerOpt: Option[ScalaCompiler] = docCompilerMakerOpt.map(_.create(
700+
val docCompilerOpt = docCompilerMakerOpt.map(_.create(
701701
inputs0.workspace / Constants.workspaceDirName,
702702
classesDir0,
703703
buildClient,
704704
logger,
705705
sharedOptions
706706
)).map(value)
707+
compiler -> docCompilerOpt
708+
}
709+
710+
def info: Either[BuildException, (ScalaCompiler, Option[ScalaCompiler], CrossSources, Inputs)] =
711+
either {
712+
val (crossSources: CrossSources, inputs0: Inputs) =
713+
value(allInputs(inputs, options, logger))
714+
val (compiler, docCompilerOpt) = value(compilers)
707715
(compiler, docCompilerOpt, crossSources, inputs0)
708716
}
709717

modules/integration/src/test/scala/scala/cli/integration/RunWithWatchTestDefinitions.scala

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -338,4 +338,43 @@ trait RunWithWatchTestDefinitions { _: RunTestDefinitions =>
338338
}
339339
}
340340
}
341+
342+
def testRepeatedRerunsWithWatch(): Unit = {
343+
def expectedMessage(number: Int) = s"Hello $number"
344+
345+
def content(number: Int) =
346+
s"@main def main(): Unit = println(\"${expectedMessage(number)}\")"
347+
348+
TestUtil.retryOnCi() {
349+
val inputPath = os.rel / "example.scala"
350+
TestInputs(inputPath -> content(0)).fromRoot { root =>
351+
os.proc(TestUtil.cli, "--power", "bloop", "exit").call(cwd = root)
352+
TestUtil.withProcessWatching(
353+
proc = os.proc(TestUtil.cli, ".", "--watch", extraOptions)
354+
.spawn(cwd = root, stderr = os.Pipe)
355+
) { (proc, timeout, ec) =>
356+
for (num <- 1 to 10) {
357+
val output = TestUtil.readLine(proc.stdout, ec, timeout)
358+
expect(output == expectedMessage(num - 1))
359+
proc.printStderrUntilRerun(timeout)(ec)
360+
Thread.sleep(200L)
361+
if (num < 10) {
362+
val newContent = content(num)
363+
os.write.over(root / inputPath, newContent)
364+
}
365+
}
366+
}
367+
}
368+
}
369+
}
370+
371+
if (actualScalaVersion.startsWith("3") && Properties.isMac && TestUtil.isCI)
372+
// TODO make this pass reliably on Mac CI (seems to work fine locally)
373+
test("watch mode doesnt hang on Bloop when rebuilding repeatedly".flaky) {
374+
testRepeatedRerunsWithWatch()
375+
}
376+
else if (actualScalaVersion.startsWith("3"))
377+
test("watch mode doesnt hang on Bloop when rebuilding repeatedly") {
378+
testRepeatedRerunsWithWatch()
379+
}
341380
}

0 commit comments

Comments
 (0)