|
| 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