Skip to content

Commit c9e5d58

Browse files
Add 'bloop output' command
Printing the output of the Bloop server, when available
1 parent 661dce8 commit c9e5d58

File tree

2 files changed

+70
-0
lines changed

2 files changed

+70
-0
lines changed
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package scala.cli.commands.bloop
2+
3+
import caseapp._
4+
5+
import scala.cli.commands.{LoggingOptions, SharedCompilationServerOptions, SharedDirectoriesOptions}
6+
7+
// format: off
8+
final case class BloopOutputOptions(
9+
@Recurse
10+
logging: LoggingOptions = LoggingOptions(),
11+
@Recurse
12+
compilationServer: SharedCompilationServerOptions = SharedCompilationServerOptions(),
13+
@Recurse
14+
directories: SharedDirectoriesOptions = SharedDirectoriesOptions()
15+
)
16+
// format: on
17+
18+
object BloopOutputOptions {
19+
implicit lazy val parser: Parser[BloopOutputOptions] = Parser.derive
20+
implicit lazy val help: Help[BloopOutputOptions] = Help.derive
21+
}
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
package scala.cli.commands.bloop
2+
3+
import caseapp.core.RemainingArgs
4+
5+
import scala.build.blooprifle.BloopRifleConfig
6+
import scala.cli.CurrentParams
7+
import scala.cli.commands.{CoursierOptions, ScalaCommand}
8+
import scala.cli.commands.util.CommonOps._
9+
import scala.cli.commands.util.SharedCompilationServerOptionsUtil._
10+
11+
object BloopOutput extends ScalaCommand[BloopOutputOptions] {
12+
override def hidden = true
13+
override def inSipScala = false
14+
override def names: List[List[String]] = List(
15+
List("bloop", "output")
16+
)
17+
18+
def run(options: BloopOutputOptions, args: RemainingArgs): Unit = {
19+
CurrentParams.verbosity = options.logging.verbosity
20+
val logger = options.logging.logger
21+
val bloopRifleConfig = options.compilationServer.bloopRifleConfig(
22+
logger,
23+
CoursierOptions().coursierCache(logger.coursierLogger("Downloading Bloop")), // unused here
24+
options.logging.verbosity,
25+
"unused-java", // unused here
26+
options.directories.directories
27+
)
28+
val outputFile = bloopRifleConfig.address match {
29+
case s: BloopRifleConfig.Address.DomainSocket =>
30+
logger.debug(s"Bloop server directory: ${s.path}")
31+
logger.debug(s"Bloop server output path: ${s.outputPath}")
32+
os.Path(s.outputPath, os.pwd)
33+
case tcp: BloopRifleConfig.Address.Tcp =>
34+
if (options.logging.verbosity >= 0)
35+
System.err.println(
36+
s"Error: Bloop server is listening on TCP at ${tcp.render}, output not available."
37+
)
38+
sys.exit(1)
39+
}
40+
if (!os.isFile(outputFile)) {
41+
if (options.logging.verbosity >= 0)
42+
System.err.println(s"Error: $outputFile not found")
43+
sys.exit(1)
44+
}
45+
val content = os.read.bytes(outputFile)
46+
logger.debug(s"Read ${content.length} bytes from $outputFile")
47+
System.out.write(content)
48+
}
49+
}

0 commit comments

Comments
 (0)