Add --close-io-streams flag to sbt

When we start sbt with the thin client, we want to close the server io
streams after it loads so that the client exiting won't crash the
server. When we are running the server as part of the server tests, it
is nice to have the server output. By setting the --close-io-streams
flag when we launch the server in the client, we are able to achieve
both.
This commit is contained in:
Ethan Atkins 2020-06-24 15:18:38 -07:00
parent 18cb839c47
commit a7cb186924
5 changed files with 18 additions and 7 deletions

View File

@ -203,6 +203,7 @@ $AliasCommand name=
"Provides an interactive prompt from which commands can be run on a server."
def DashClient: String = "-client"
def DashDashClient: String = "--client"
def CloseIOStreams: String = "--close-io-streams"
def StashOnFailure: String = "sbtStashOnFailure"
def PopOnFailure: String = "sbtPopOnFailure"

View File

@ -114,6 +114,11 @@ object BasicKeys {
"List of template resolver infos.",
1000
)
private[sbt] val closeIOStreams = AttributeKey[Boolean](
"close-io-streams",
"Toggles wheter or not to close system in, out and error when the server starts.",
1000
)
}
case class TemplateResolverInfo(module: ModuleID, implementationClass: String)

View File

@ -160,7 +160,7 @@ class NetworkClient(
else Nil
val args = color ++ superShell ++ arguments.sbtArguments
val cmd = arguments.sbtScript +: args
val cmd = arguments.sbtScript +: args :+ BasicCommandStrings.CloseIOStreams
val process =
new ProcessBuilder(cmd: _*)
.directory(arguments.baseDirectory)

View File

@ -68,11 +68,14 @@ private[sbt] object xMain {
NetworkClient.run(configuration, args)
Exit(0)
} else {
val state = StandardMain.initialState(
configuration,
Seq(defaults, early),
runEarly(DefaultsCommand) :: runEarly(InitCommand) :: BootCommand :: Nil
)
val closeStreams = userCommands.exists(_ == BasicCommandStrings.CloseIOStreams)
val state = StandardMain
.initialState(
configuration,
Seq(defaults, early),
runEarly(DefaultsCommand) :: runEarly(InitCommand) :: BootCommand :: Nil
)
.put(BasicKeys.closeIOStreams, closeStreams)
StandardMain.runManaged(state)
}
}
@ -183,7 +186,8 @@ object StandardMain {
sys.props.put("jna.nosys", "true")
import BasicCommandStrings.isEarlyCommand
val userCommands = configuration.arguments.map(_.trim)
val userCommands =
configuration.arguments.map(_.trim).filterNot(_ == BasicCommandStrings.CloseIOStreams)
val (earlyCommands, normalCommands) = (preCommands ++ userCommands).partition(isEarlyCommand)
val commands = (earlyCommands ++ normalCommands).toList map { x =>
Exec(x, None)

View File

@ -217,6 +217,7 @@ private[sbt] final class CommandExchange {
server = None
firstInstance.set(false)
}
if (s.get(BasicKeys.closeIOStreams).getOrElse(false)) Terminal.close()
}
s
}