Skip to content

Commit

Permalink
bugfix: Forward standard output to logger
Browse files Browse the repository at this point in the history
  • Loading branch information
tgodzik committed Jun 28, 2024
1 parent 79f9e6e commit d7f08d0
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -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

Expand Down Expand Up @@ -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,
Expand All @@ -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"
Expand Down
32 changes: 32 additions & 0 deletions frontend/src/test/scala/bloop/BaseCompileSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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 <empty> {
| class Foo extends scala.AnyRef {
| def <init>(): Foo = {
| Foo.super.<init>();
| ()
| }
| }
|}
|""".stripMargin
)
}
}

test("compile a project, delete an analysis and then write it back during a no-op compilation") {
TestUtil.withinWorkspace { workspace =>
Expand Down

0 comments on commit d7f08d0

Please sign in to comment.