Add boolean flag isAutoCancel

Address PR feedback from Eugene
This commit is contained in:
friendseeker 2024-11-26 23:40:07 -08:00
parent 9494033bd6
commit b49fe9dc97
No known key found for this signature in database
GPG Key ID: 7DD5039728A27160
4 changed files with 16 additions and 2 deletions

View File

@ -1071,6 +1071,7 @@ lazy val mainProj = (project in file("main"))
exclude[MissingClassProblem]("sbt.internal.server.BuildServerReporter$"),
exclude[IncompatibleTemplateDefProblem]("sbt.internal.server.BuildServerReporter"),
exclude[MissingClassProblem]("sbt.internal.CustomHttp*"),
exclude[ReversedMissingMethodProblem]("sbt.JobHandle.isAutoCancel"),
)
)
.configure(

View File

@ -100,4 +100,5 @@ abstract class JobHandle {
def id: Long
def humanReadableName: String
def spawningTask: ScopedKey[_]
def isAutoCancel: Boolean
}

View File

@ -2039,6 +2039,11 @@ object Defaults extends BuildCommon {
def foregroundRunMainTask: Initialize[InputTask[Unit]] =
Def.inputTask {
val handle = bgRunMain.evaluated
handle match {
case threadJobHandle: AbstractBackgroundJobService#ThreadJobHandle =>
threadJobHandle.isAutoCancel = true
case _ =>
}
val service = bgJobService.value
service.waitForTry(handle).get
}
@ -2047,6 +2052,11 @@ object Defaults extends BuildCommon {
def foregroundRunTask: Initialize[InputTask[Unit]] =
Def.inputTask {
val handle = bgRun.evaluated
handle match {
case threadJobHandle: AbstractBackgroundJobService#ThreadJobHandle =>
threadJobHandle.isAutoCancel = true
case _ =>
}
val service = bgJobService.value
service.waitForTry(handle).get
}

View File

@ -114,7 +114,8 @@ private[sbt] abstract class AbstractBackgroundJobService extends BackgroundJobSe
override val spawningTask: ScopedKey[_],
val logger: ManagedLogger,
val workingDirectory: File,
val job: BackgroundJob
val job: BackgroundJob,
@volatile var isAutoCancel: Boolean = false,
) extends AbstractJobHandle {
// EC for onStop handler below
implicit val executionContext: ExecutionContext =
@ -140,6 +141,7 @@ private[sbt] abstract class AbstractBackgroundJobService extends BackgroundJobSe
private final class DeadHandle(override val id: Long, override val humanReadableName: String)
extends AbstractJobHandle {
override val spawningTask: ScopedKey[_] = unknownTask
override val isAutoCancel = false
}
def doRunInBackground(
@ -513,7 +515,7 @@ private[sbt] object DefaultBackgroundJobService {
backgroundJobServices
.values()
.forEach(jobService => {
jobService.jobs.foreach(jobService.stop)
jobService.jobs.filter(_.isAutoCancel).foreach(jobService.stop)
})
}