From d7f08d0b86c85439d9ffd11c9963aac09e4ff473 Mon Sep 17 00:00:00 2001 From: Tomasz Godzik Date: Fri, 28 Jun 2024 18:30:08 +0200 Subject: [PATCH] bugfix: Forward standard output to logger Causes https://github.com/VirtusLab/scala-cli/issues/1023 --- .../internal/BloopHighLevelCompiler.scala | 7 ++++ .../test/scala/bloop/BaseCompileSpec.scala | 32 +++++++++++++++++++ 2 files changed, 39 insertions(+) diff --git a/backend/src/main/scala/sbt/internal/inc/bloop/internal/BloopHighLevelCompiler.scala b/backend/src/main/scala/sbt/internal/inc/bloop/internal/BloopHighLevelCompiler.scala index 43deccb562..3125ae77da 100644 --- a/backend/src/main/scala/sbt/internal/inc/bloop/internal/BloopHighLevelCompiler.scala +++ b/backend/src/main/scala/sbt/internal/inc/bloop/internal/BloopHighLevelCompiler.scala @@ -1,6 +1,8 @@ // scalafmt: { maxColumn = 250 } package sbt.internal.inc.bloop.internal +import java.io.ByteArrayOutputStream +import java.io.PrintStream import java.nio.file.Files import java.util.Optional @@ -120,6 +122,9 @@ final class BloopHighLevelCompiler( throw new CompileFailed(new Array(0), s"Expected Scala library jar in Scala instance containing ${scalac.scalaInstance.allJars().mkString(", ")}", new Array(0)) } try { + val out = System.out + val baos = new ByteArrayOutputStream(); + System.setOut(new PrintStream(baos)); scalac.compile( sources.toArray, classpath.toArray, @@ -132,6 +137,8 @@ final class BloopHighLevelCompiler( config.progress.toOptional, logger ) + System.setOut(out) + logger.info(baos.toString) } catch { case t: StackOverflowError => val msg = "Encountered a StackOverflowError coming from the compiler. You might need to restart your Bloop build server" diff --git a/frontend/src/test/scala/bloop/BaseCompileSpec.scala b/frontend/src/test/scala/bloop/BaseCompileSpec.scala index 7dba45821a..936acf8096 100644 --- a/frontend/src/test/scala/bloop/BaseCompileSpec.scala +++ b/frontend/src/test/scala/bloop/BaseCompileSpec.scala @@ -63,6 +63,38 @@ abstract class BaseCompileSpec extends bloop.testing.BaseSuite { } } } + test("compile-with-Vprint:typer") { + TestUtil.withinWorkspace { workspace => + val sources = List( + """/main/scala/Foo.scala + |class Foo + """.stripMargin + ) + + val logger = new RecordingLogger(ansiCodesSupported = false) + val `A` = TestProject(workspace, "a", sources, scalacOptions = List("-Vprint:typer")) + val projects = List(`A`) + val state = loadState(workspace, projects, logger) + val compiledState = state.compile(`A`) + assertExitStatus(compiledState, ExitStatus.Ok) + assertValidCompilationState(compiledState, projects) + + assertNoDiff( + logger.infos.filterNot(_.contains("Compiled")).mkString("\n").trim(), + """|Compiling a (1 Scala source) + |[[syntax trees at end of typer]] // Foo.scala + |package { + | class Foo extends scala.AnyRef { + | def (): Foo = { + | Foo.super.(); + | () + | } + | } + |} + |""".stripMargin + ) + } + } test("compile a project, delete an analysis and then write it back during a no-op compilation") { TestUtil.withinWorkspace { workspace =>