Merge pull request #9082 from eed3si9n/bport2/client-side-run-fix

[2.0.x] Backport sbtn related fixes
This commit is contained in:
eugene yokota 2026-04-13 01:31:07 -04:00 committed by GitHub
commit f2e1bf8be6
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 45 additions and 10 deletions

View File

@ -179,6 +179,7 @@ class NetworkClient(
def success(message: => String): Unit = ()
def log(level: Level.Value, message: => String): Unit = console.appendLog(level, message)
}
private val interactive = arguments.commandArguments.isEmpty
private[sbt] def connectOrStartServerAndConnect(
promptCompleteUsers: Boolean,
@ -706,8 +707,19 @@ class NetworkClient(
case (`clientJob`, Some(json)) =>
import sbt.internal.worker.codec.JsonProtocol.given
Converter.fromJson[ClientJobParams](json) match {
case Success(params) => clientSideRun(params).get; Vector.empty
case Failure(_) => Vector.empty
case Success(params) =>
clientSideRun(params) match
case Success(_) =>
if interactive then console.success("ok")
else ()
Vector.empty
case Failure(e) =>
if interactive then
Vector(
(Level.Error, e.getMessage)
)
else throw e
case Failure(_) => Vector.empty
}
case (`Shutdown`, Some(_)) => Vector.empty
case (msg, _) if msg.startsWith("build/") => Vector.empty
@ -915,9 +927,8 @@ class NetworkClient(
withSignalHandler(contHandler, Signals.CONT) {
interactiveThread.set(Thread.currentThread)
val cleaned = arguments.commandArguments
val userCommands = cleaned.takeWhile(_ != TerminateAction)
val interactive = cleaned.isEmpty
val exit = cleaned.nonEmpty && userCommands.isEmpty
val userCommands = arguments.commandArguments.takeWhile(_ != TerminateAction)
val exit = arguments.commandArguments.nonEmpty && userCommands.isEmpty
attachUUID.set(sendJson(attach, s"""{"interactive": $interactive}"""))
val handler: () => Unit = () => {
def exitAbruptly() = {

View File

@ -1088,12 +1088,20 @@ object BuiltinCommands {
.getOpt(Keys.minForcegcInterval)
.getOrElse(GCUtil.defaultMinForcegcInterval)
val exec: Exec = getExec(s1, minGCInterval)
val isInteractive = exec.source match {
case Some(src) if src.channelName.startsWith("network") =>
exchange.channelForName(src.channelName) match {
case Some(nc: NetworkChannel) => nc.isInteractive
case _ => true
}
case _ => true
}
val newState = s1
.copy(
onFailure = Some(Exec(Shell, None)),
remainingCommands = exec +: Exec(Shell, None) +: s1.remainingCommands
)
.setInteractive(true)
.setInteractive(isInteractive)
val res =
if (exec.commandLine.trim.isEmpty) newState
else newState.clearGlobalLog

View File

@ -17,6 +17,7 @@ import sbt.internal.util.complete.Parser
import sbt.internal.util.complete.Parser.{ failure, seq, success }
import sbt.internal.util.*
import sbt.internal.client.NetworkClient
import sbt.internal.worker.ClientJobParams
import sbt.std.Transform.DummyTaskMap
import sbt.util.{ Logger, Show }
import scala.annotation.tailrec
@ -87,16 +88,18 @@ object Aggregation {
import complete.*
val log = state.log
val extracted = Project.extract(state)
val success = results match
case Result.Value(_) => true
case Result.Inc(_) => false
// omit success printing for client-side run
val (success, jobParams) = results match
case Result.Value(Seq(KeyValue(_, p: ClientJobParams))) => (true, true)
case Result.Value(_) => (true, false)
case Result.Inc(_) => (false, false)
val isPaused = currentChannel(state) match
case Some(channel) => channel.isPaused
case None => false
results.toEither.foreach { r =>
if show.taskValues then printSettings(r, show.print) else ()
}
if !isPaused && show.success && !state.get(suppressShow).getOrElse(false) then
if !isPaused && show.success && !state.get(suppressShow).getOrElse(false) && !jobParams then
printSuccess(start, stop, extracted, success, cacheSummary, log)
else ()

View File

@ -0,0 +1,11 @@
lazy val helloWithoutStreams = taskKey[Unit]("")
lazy val helloWithStreams = taskKey[Unit]("")
helloWithoutStreams := {
throw new RuntimeException("boom without streams!")
}
helloWithStreams := {
val log = streams.value.log
throw new RuntimeException("boom with streams!")
}

View File

@ -0,0 +1,2 @@
-> helloWithoutStreams
-> helloWithStreams