-
Notifications
You must be signed in to change notification settings - Fork 128
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Send the Bloop server output to a file when possible #853
Merged
romanowski
merged 5 commits into
VirtusLab:main
from
alexarchambault:write-bloop-output-to-file
Apr 14, 2022
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
c929601
Move migration-tests deeper in the job list
alexarchambault fe90e27
Use domain socket for Bloop server stuff in build tests on Windows too
alexarchambault ee162ee
Hide the pgp* commands in native launcher
alexarchambault 6151584
Send the Bloop server output to a file when possible
alexarchambault c868eba
Add 'bloop output' command
alexarchambault File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
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
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
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) | ||
} | ||
} |
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
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
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder why we do need to check the bloop version if we control the version of bloop ourselves? I think if we see too old version running (e.g. after update of scala-cli) we should restart it with newer version
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's for if users manually force an earlier version to something else. Earlier Bloop versions can't truncate their output file, so redirecting the output this way would create a file that might grow too big.