-
Notifications
You must be signed in to change notification settings - Fork 128
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Printing the output of the Bloop server, when available
- Loading branch information
1 parent
661dce8
commit e909068
Showing
2 changed files
with
70 additions
and
0 deletions.
There are no files selected for viewing
21 changes: 21 additions & 0 deletions
21
modules/cli-options/src/main/scala/scala/cli/commands/bloop/BloopOutputOptions.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package scala.cli.commands.bloop | ||
|
||
import caseapp._ | ||
|
||
import scala.cli.commands.{LoggingOptions, SharedCompilationServerOptions, SharedDirectoriesOptions} | ||
|
||
// format: off | ||
final case class BloopOutputOptions( | ||
@Recurse | ||
logging: LoggingOptions = LoggingOptions(), | ||
@Recurse | ||
compilationServer: SharedCompilationServerOptions = SharedCompilationServerOptions(), | ||
@Recurse | ||
directories: SharedDirectoriesOptions = SharedDirectoriesOptions() | ||
) | ||
// format: on | ||
|
||
object BloopOutputOptions { | ||
implicit lazy val parser: Parser[BloopOutputOptions] = Parser.derive | ||
implicit lazy val help: Help[BloopOutputOptions] = Help.derive | ||
} |
49 changes: 49 additions & 0 deletions
49
modules/cli/src/main/scala/scala/cli/commands/bloop/BloopOutput.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package scala.cli.commands.bloop | ||
|
||
import caseapp.core.RemainingArgs | ||
|
||
import scala.build.blooprifle.BloopRifleConfig | ||
import scala.cli.CurrentParams | ||
import scala.cli.commands.util.CommonOps._ | ||
import scala.cli.commands.util.SharedCompilationServerOptionsUtil._ | ||
import scala.cli.commands.{CoursierOptions, ScalaCommand} | ||
|
||
object BloopOutput extends ScalaCommand[BloopOutputOptions] { | ||
override def hidden = true | ||
override def inSipScala = false | ||
override def names: List[List[String]] = List( | ||
List("bloop", "output") | ||
) | ||
|
||
def run(options: BloopOutputOptions, args: RemainingArgs): Unit = { | ||
CurrentParams.verbosity = options.logging.verbosity | ||
val logger = options.logging.logger | ||
val bloopRifleConfig = options.compilationServer.bloopRifleConfig( | ||
logger, | ||
CoursierOptions().coursierCache(logger.coursierLogger("Downloading Bloop")), // unused here | ||
options.logging.verbosity, | ||
"unused-java", // unused here | ||
options.directories.directories | ||
) | ||
val outputFile = bloopRifleConfig.address match { | ||
case s: BloopRifleConfig.Address.DomainSocket => | ||
logger.debug(s"Bloop server directory: ${s.path}") | ||
logger.debug(s"Bloop server output path: ${s.outputPath}") | ||
os.Path(s.outputPath, os.pwd) | ||
case tcp: BloopRifleConfig.Address.Tcp => | ||
if (options.logging.verbosity >= 0) | ||
System.err.println( | ||
s"Error: Bloop server is listening on TCP at ${tcp.render}, output not available." | ||
) | ||
sys.exit(1) | ||
} | ||
if (!os.isFile(outputFile)) { | ||
if (options.logging.verbosity >= 0) | ||
System.err.println(s"Error: $outputFile not found") | ||
sys.exit(1) | ||
} | ||
val content = os.read.bytes(outputFile) | ||
logger.debug(s"Read ${content.length} bytes from $outputFile") | ||
System.out.write(content) | ||
} | ||
} |