Skip to content

Commit

Permalink
Fixes sbt#1345 - do not buffer logging for native-image output
Browse files Browse the repository at this point in the history
  • Loading branch information
nikolaylagutko committed Apr 6, 2023
1 parent 5216d42 commit 921ab76
Showing 1 changed file with 12 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.typesafe.sbt.packager.graalvmnativeimage

import java.io.ByteArrayInputStream

import sbt._
import sbt.Keys.{mainClass, name, _}
Expand All @@ -11,6 +10,8 @@ import com.typesafe.sbt.packager.archetypes.JavaAppPackaging
import com.typesafe.sbt.packager.docker.{Cmd, DockerPlugin, Dockerfile, ExecCmd}
import com.typesafe.sbt.packager.universal.UniversalPlugin

import java.io.ByteArrayInputStream

/**
* Plugin to compile ahead-of-time native executables.
*
Expand Down Expand Up @@ -73,7 +74,7 @@ object GraalVMNativeImagePlugin extends AutoPlugin {
className,
classpathJars.map(_._1),
extraOptions,
streams.log
UnbufferedProcessLogger(streams.log)
)

case Some(image) =>
Expand Down Expand Up @@ -152,7 +153,7 @@ object GraalVMNativeImagePlugin extends AutoPlugin {
s"-H:Name=$binaryName"
) ++ extraOptions ++ Seq(className)

sys.process.Process(command) ! streams.log match {
sys.process.Process(command) ! UnbufferedProcessLogger(streams.log) match {
case 0 => targetDirectory / binaryName
case x => sys.error(s"Failed to run $command, exit status: " + x)
}
Expand Down Expand Up @@ -218,3 +219,11 @@ object GraalVMNativeImagePlugin extends AutoPlugin {
Stager.stage(GraalVMBaseImage)(streams, stageDir, mappings)
}
}

private case class UnbufferedProcessLogger(logger: Logger) extends ProcessLogger {
override def out(s: => String): Unit = logger.out(s)

override def err(s: => String): Unit = logger.err(s)

override def buffer[T](f: => T): T = f
}

0 comments on commit 921ab76

Please sign in to comment.