This commit is contained in:
Eugene Yokota 2024-09-21 01:07:27 -04:00
parent c37b7a1555
commit 1f71332edc
20 changed files with 46 additions and 49 deletions

View File

@ -110,3 +110,5 @@ abstract class JobHandle {
def humanReadableName: String def humanReadableName: String
def spawningTask: ScopedKey[_] def spawningTask: ScopedKey[_]
} }
case class RunInfo(handle: JobHandle)

View File

@ -1054,6 +1054,12 @@ object Defaults extends BuildCommon {
}, },
runMain := foregroundRunMainTask.evaluated, runMain := foregroundRunMainTask.evaluated,
run := foregroundRunTask.evaluated, run := foregroundRunTask.evaluated,
runBlock := {
val r = run.evaluated
val service = bgJobService.value
service.waitForTry(r.handle).get
r
},
fgRun := runTask(fullClasspath, (run / mainClass), (run / runner)).evaluated, fgRun := runTask(fullClasspath, (run / mainClass), (run / runner)).evaluated,
fgRunMain := runMainTask(fullClasspath, (run / runner)).evaluated, fgRunMain := runMainTask(fullClasspath, (run / runner)).evaluated,
copyResources := copyResourcesTask.value, copyResources := copyResourcesTask.value,
@ -2146,7 +2152,7 @@ object Defaults extends BuildCommon {
} }
// `runMain` calls bgRunMain in the background and pauses the current channel // `runMain` calls bgRunMain in the background and pauses the current channel
def foregroundRunMainTask: Initialize[InputTask[RunVoid]] = def foregroundRunMainTask: Initialize[InputTask[RunInfo]] =
Def.inputTask { Def.inputTask {
val handle = bgRunMain.evaluated val handle = bgRunMain.evaluated
val service = bgJobService.value val service = bgJobService.value
@ -2154,11 +2160,11 @@ object Defaults extends BuildCommon {
st.remainingCommands match st.remainingCommands match
case Nil => service.waitForTry(handle).get case Nil => service.waitForTry(handle).get
case _ => service.pauseChannelDuringJob(st, handle) case _ => service.pauseChannelDuringJob(st, handle)
RunVoid RunInfo(handle)
} }
// `run` task calls bgRun in the background and pauses the current channel // `run` task calls bgRun in the background and pauses the current channel
def foregroundRunTask: Initialize[InputTask[RunVoid]] = def foregroundRunTask: Initialize[InputTask[RunInfo]] =
Def.inputTask { Def.inputTask {
val handle = bgRun.evaluated val handle = bgRun.evaluated
val service = bgJobService.value val service = bgJobService.value
@ -2166,7 +2172,7 @@ object Defaults extends BuildCommon {
st.remainingCommands match st.remainingCommands match
case Nil => service.waitForTry(handle).get case Nil => service.waitForTry(handle).get
case _ => service.pauseChannelDuringJob(st, handle) case _ => service.pauseChannelDuringJob(st, handle)
RunVoid RunInfo(handle)
} }
def runMainTask( def runMainTask(

View File

@ -319,8 +319,9 @@ object Keys {
// Run Keys // Run Keys
val selectMainClass = taskKey[Option[String]]("Selects the main class to run.").withRank(BMinusTask) val selectMainClass = taskKey[Option[String]]("Selects the main class to run.").withRank(BMinusTask)
val mainClass = taskKey[Option[String]]("Defines the main class for packaging or running.").withRank(BPlusTask) val mainClass = taskKey[Option[String]]("Defines the main class for packaging or running.").withRank(BPlusTask)
val run = inputKey[RunVoid]("Runs a main class, passing along arguments provided on the command line.").withRank(APlusTask) val run = inputKey[RunInfo]("Runs a main class, passing along arguments provided on the command line.").withRank(APlusTask)
val runMain = inputKey[RunVoid]("Runs the main class selected by the first argument, passing the remaining arguments to the main method.").withRank(ATask) val runBlock = inputKey[RunInfo]("Runs a main class, and blocks until it's done.").withRank(DTask)
val runMain = inputKey[RunInfo]("Runs the main class selected by the first argument, passing the remaining arguments to the main method.").withRank(ATask)
val discoveredMainClasses = taskKey[Seq[String]]("Auto-detects main classes.").withRank(BMinusTask) val discoveredMainClasses = taskKey[Seq[String]]("Auto-detects main classes.").withRank(BMinusTask)
val runner = taskKey[ScalaRun]("Implementation used to run a main class.").withRank(DTask) val runner = taskKey[ScalaRun]("Implementation used to run a main class.").withRank(DTask)
val trapExit = settingKey[Boolean]("If true, enables exit trapping and thread management for 'run'-like tasks. This was removed in sbt 1.6.0 due to JDK 17 deprecating Security Manager.").withRank(CSetting) val trapExit = settingKey[Boolean]("If true, enables exit trapping and thread management for 'run'-like tasks. This was removed in sbt 1.6.0 due to JDK 17 deprecating Security Manager.").withRank(CSetting)

View File

@ -80,13 +80,13 @@ object Aggregation {
case Result.Value(_) => true case Result.Value(_) => true
case Result.Inc(_) => false case Result.Inc(_) => false
// run task ends earlier than the program run // run task ends earlier than the program run
val isRunVoid = results match val isRunInfo = results match
case Result.Value(Seq(KeyValue(_, RunVoid))) => true case Result.Value(Seq(KeyValue(_, RunInfo(_)))) => true
case _ => false case _ => false
results.toEither.foreach { r => results.toEither.foreach { r =>
if show.taskValues then printSettings(r, show.print) else () if show.taskValues then printSettings(r, show.print) else ()
} }
if show.success && !isRunVoid && !state.get(suppressShow).getOrElse(false) then if show.success && !isRunInfo && !state.get(suppressShow).getOrElse(false) then
printSuccess(start, stop, extracted, success, cacheSummary, log) printSuccess(start, stop, extracted, success, cacheSummary, log)
else () else ()

View File

@ -212,14 +212,3 @@ object Run:
case str => str case str => str
}).mkString(" ") }).mkString(" ")
end Run end Run
/**
* RunVoid is a special `Unit` type used to indicate that it's a `run` task.
* When a task returns RunVoid, [success] log is omitted.
*/
sealed trait RunVoid
/**
* The only resident of RunVoid type.
*/
case object RunVoid extends RunVoid

View File

@ -1,3 +1,3 @@
addCommandAlias("demo-success", "run true") addCommandAlias("demo-success", "runBlock true")
addCommandAlias("demo-failure", "run false") addCommandAlias("demo-failure", "runBlock false")
addCommandAlias("z", "scalaVersion") addCommandAlias("z", "scalaVersion")

View File

@ -7,7 +7,7 @@ val dropLibraryPath = taskKey[Unit]("Drop the last path from the java.library.pa
val wrappedRun = taskKey[Unit]("Run with modified java.library.path") val wrappedRun = taskKey[Unit]("Run with modified java.library.path")
val wrappedTest = taskKey[Unit]("Test with modified java.library.path") val wrappedTest = taskKey[Unit]("Test with modified java.library.path")
def wrap(task: InputKey[Unit]): Def.Initialize[Task[Unit]] = def wrap[A1](task: InputKey[A1]): Def.Initialize[Task[Unit]] =
Def.sequential(appendToLibraryPath, task.toTask(""), dropLibraryPath) Def.sequential(appendToLibraryPath, task.toTask(""), dropLibraryPath)
// ThisBuild / turbo := true // ThisBuild / turbo := true
@ -35,6 +35,6 @@ val root = (project in file(".")).settings(
val cp = System.getProperty("java.library.path", "").split(":").dropRight(1) val cp = System.getProperty("java.library.path", "").split(":").dropRight(1)
System.setProperty("java.library.path", cp.mkString(":")) System.setProperty("java.library.path", cp.mkString(":"))
}, },
wrappedRun := wrap(Runtime / run).value, wrappedRun := wrap(Runtime / runBlock).value,
wrappedTest := wrap(Test / testOnly).value wrappedTest := wrap(Test / testOnly).value
) )

View File

@ -1,3 +1,3 @@
$ delete output $ delete output
> run > runBlock
$ exists output $ exists output

View File

@ -1,3 +1,3 @@
$ delete output $ delete output
> run > runBlock
$ exists output $ exists output

View File

@ -1,3 +1,3 @@
$ delete output $ delete output
> run > runBlock
$ exists output $ exists output

View File

@ -1,12 +1,12 @@
> a/checkLibs > a/checkLibs
> b/checkLibs > b/checkLibs
> b/run > b/runBlock
$ exists s2.13.8.txt $ exists s2.13.8.txt
$ delete s2.13.8.txt $ delete s2.13.8.txt
# don't crash when expanding the macro # don't crash when expanding the macro
> b3/run > b3/runBlock
$ exists s2.13.10.txt $ exists s2.13.10.txt
$ delete s2.13.10.txt $ delete s2.13.10.txt

View File

@ -1,3 +1,3 @@
$ delete output $ delete output
> run > runBlock
$ exists output $ exists output

View File

@ -4,7 +4,7 @@
# This should fail because the Main object is in package jartest and the resource is directly # This should fail because the Main object is in package jartest and the resource is directly
# in src/main/resources # in src/main/resources
-> run -> runBlock
> package > package
@ -18,7 +18,7 @@ $ copy-file src/main/resources/main_resource_test src/main/resources/jartest/mai
$ delete src/main/resources/main_resource_test $ delete src/main/resources/main_resource_test
# This should succeed because sbt should put the resource on the runClasspath # This should succeed because sbt should put the resource on the runClasspath
> run > runBlock
# This is necessary because package bases whether or not to run on last modified times, which don't have # This is necessary because package bases whether or not to run on last modified times, which don't have
# high enough resolution to notice the above move of main_resource_test # high enough resolution to notice the above move of main_resource_test

View File

@ -3,14 +3,14 @@
$ copy-file changes/B.scala B.scala $ copy-file changes/B.scala B.scala
$ copy-file changes/A1.scala A.scala $ copy-file changes/A1.scala A.scala
> run 1 > runBlock 1
$ copy-file changes/A2.scala A.scala $ copy-file changes/A2.scala A.scala
> run 2 > runBlock 2
> clean > clean
> ++2.13.12! > ++2.13.12!
$ copy-file changes/A1.scala A.scala $ copy-file changes/A1.scala A.scala
> run 1 > runBlock 1
$ copy-file changes/A2.scala A.scala $ copy-file changes/A2.scala A.scala
> run 2 > runBlock 2

View File

@ -1,2 +1 @@
ThisBuild / scalaVersion := "2.12.17" scalaVersion := "2.12.19"

View File

@ -2,10 +2,10 @@ $ copy-file changes/A1.scala A.scala
$ copy-file changes/B.scala B.scala $ copy-file changes/B.scala B.scala
$ copy-file changes/C.scala C.scala $ copy-file changes/C.scala C.scala
> compile > compile
-> run -> runBlock
$ copy-file changes/A2.scala A.scala $ copy-file changes/A2.scala A.scala
$ sleep 1000 $ sleep 1000
> compile > compile
> run > runBlock

View File

@ -36,10 +36,10 @@ $ delete src/main/java/a/A.java
# It shouldn't run though, because it doesn't have a main method # It shouldn't run though, because it doesn't have a main method
$ copy-file changes/B1.java src/main/java/a/b/B.java $ copy-file changes/B1.java src/main/java/a/b/B.java
> compile > compile
-> run -> runBlock
# Replace B with a new B that has a main method and should therefore run # Replace B with a new B that has a main method and should therefore run
# if the main method was properly detected # if the main method was properly detected
$ copy-file changes/B3.java src/main/java/a/b/B.java $ copy-file changes/B3.java src/main/java/a/b/B.java
> run > runBlock

View File

@ -1,7 +1,7 @@
> compile > compile
# the value of F.x should be 16 # the value of F.x should be 16
> run 16 > runBlock 16
# modify D.scala so that the linearization changes # modify D.scala so that the linearization changes
$ copy-file changes/D.scala D.scala $ copy-file changes/D.scala D.scala
@ -12,4 +12,4 @@ $ sleep 1000
# if F is recompiled, the value of x should be 11, otherwise it will still be 16 # if F is recompiled, the value of x should be 11, otherwise it will still be 16
# and this will fail # and this will fail
> run 11 > runBlock 11

View File

@ -4,7 +4,7 @@
> compile > compile
# result should be 1 # result should be 1
> run 1 > runBlock 1
# change order of arguments in A.x # change order of arguments in A.x
$ copy-file changes/A.scala A.scala $ copy-file changes/A.scala A.scala
@ -13,4 +13,4 @@ $ copy-file changes/A.scala A.scala
> compile > compile
# Should still get 1 and not -1 # Should still get 1 and not -1
> run 1 > runBlock 1

View File

@ -2,7 +2,7 @@
> compile > compile
# verify that erased A.x can be called normally and reflectively # verify that erased A.x can be called normally and reflectively
> run false > runBlock false
# make A.x specialized # make A.x specialized
$ copy-file changes/A.scala A.scala $ copy-file changes/A.scala A.scala
@ -12,4 +12,4 @@ $ copy-file changes/A.scala A.scala
# verify that specialized A.x can be called normally and reflectively # verify that specialized A.x can be called normally and reflectively
# NOTE: this test doesn't actually work correctly: have to check the output to see that B.scala was recompiled # NOTE: this test doesn't actually work correctly: have to check the output to see that B.scala was recompiled
> run true > runBlock true