mirror of https://github.com/sbt/sbt.git
runBlock
This commit is contained in:
parent
c37b7a1555
commit
1f71332edc
|
|
@ -110,3 +110,5 @@ abstract class JobHandle {
|
|||
def humanReadableName: String
|
||||
def spawningTask: ScopedKey[_]
|
||||
}
|
||||
|
||||
case class RunInfo(handle: JobHandle)
|
||||
|
|
|
|||
|
|
@ -1054,6 +1054,12 @@ object Defaults extends BuildCommon {
|
|||
},
|
||||
runMain := foregroundRunMainTask.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,
|
||||
fgRunMain := runMainTask(fullClasspath, (run / runner)).evaluated,
|
||||
copyResources := copyResourcesTask.value,
|
||||
|
|
@ -2146,7 +2152,7 @@ object Defaults extends BuildCommon {
|
|||
}
|
||||
|
||||
// `runMain` calls bgRunMain in the background and pauses the current channel
|
||||
def foregroundRunMainTask: Initialize[InputTask[RunVoid]] =
|
||||
def foregroundRunMainTask: Initialize[InputTask[RunInfo]] =
|
||||
Def.inputTask {
|
||||
val handle = bgRunMain.evaluated
|
||||
val service = bgJobService.value
|
||||
|
|
@ -2154,11 +2160,11 @@ object Defaults extends BuildCommon {
|
|||
st.remainingCommands match
|
||||
case Nil => service.waitForTry(handle).get
|
||||
case _ => service.pauseChannelDuringJob(st, handle)
|
||||
RunVoid
|
||||
RunInfo(handle)
|
||||
}
|
||||
|
||||
// `run` task calls bgRun in the background and pauses the current channel
|
||||
def foregroundRunTask: Initialize[InputTask[RunVoid]] =
|
||||
def foregroundRunTask: Initialize[InputTask[RunInfo]] =
|
||||
Def.inputTask {
|
||||
val handle = bgRun.evaluated
|
||||
val service = bgJobService.value
|
||||
|
|
@ -2166,7 +2172,7 @@ object Defaults extends BuildCommon {
|
|||
st.remainingCommands match
|
||||
case Nil => service.waitForTry(handle).get
|
||||
case _ => service.pauseChannelDuringJob(st, handle)
|
||||
RunVoid
|
||||
RunInfo(handle)
|
||||
}
|
||||
|
||||
def runMainTask(
|
||||
|
|
|
|||
|
|
@ -319,8 +319,9 @@ object Keys {
|
|||
// Run Keys
|
||||
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 run = inputKey[RunVoid]("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 run = inputKey[RunInfo]("Runs a main class, passing along arguments provided on the command line.").withRank(APlusTask)
|
||||
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 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)
|
||||
|
|
|
|||
|
|
@ -80,13 +80,13 @@ object Aggregation {
|
|||
case Result.Value(_) => true
|
||||
case Result.Inc(_) => false
|
||||
// run task ends earlier than the program run
|
||||
val isRunVoid = results match
|
||||
case Result.Value(Seq(KeyValue(_, RunVoid))) => true
|
||||
case _ => false
|
||||
val isRunInfo = results match
|
||||
case Result.Value(Seq(KeyValue(_, RunInfo(_)))) => true
|
||||
case _ => false
|
||||
results.toEither.foreach { r =>
|
||||
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)
|
||||
else ()
|
||||
|
||||
|
|
|
|||
|
|
@ -212,14 +212,3 @@ object Run:
|
|||
case str => str
|
||||
}).mkString(" ")
|
||||
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
|
||||
|
|
|
|||
|
|
@ -1,3 +1,3 @@
|
|||
addCommandAlias("demo-success", "run true")
|
||||
addCommandAlias("demo-failure", "run false")
|
||||
addCommandAlias("demo-success", "runBlock true")
|
||||
addCommandAlias("demo-failure", "runBlock false")
|
||||
addCommandAlias("z", "scalaVersion")
|
||||
|
|
|
|||
|
|
@ -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 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)
|
||||
|
||||
// ThisBuild / turbo := true
|
||||
|
|
@ -35,6 +35,6 @@ val root = (project in file(".")).settings(
|
|||
val cp = System.getProperty("java.library.path", "").split(":").dropRight(1)
|
||||
System.setProperty("java.library.path", cp.mkString(":"))
|
||||
},
|
||||
wrappedRun := wrap(Runtime / run).value,
|
||||
wrappedRun := wrap(Runtime / runBlock).value,
|
||||
wrappedTest := wrap(Test / testOnly).value
|
||||
)
|
||||
|
|
|
|||
|
|
@ -1,3 +1,3 @@
|
|||
$ delete output
|
||||
> run
|
||||
> runBlock
|
||||
$ exists output
|
||||
|
|
|
|||
|
|
@ -1,3 +1,3 @@
|
|||
$ delete output
|
||||
> run
|
||||
> runBlock
|
||||
$ exists output
|
||||
|
|
|
|||
|
|
@ -1,3 +1,3 @@
|
|||
$ delete output
|
||||
> run
|
||||
> runBlock
|
||||
$ exists output
|
||||
|
|
|
|||
|
|
@ -1,12 +1,12 @@
|
|||
> a/checkLibs
|
||||
> b/checkLibs
|
||||
|
||||
> b/run
|
||||
> b/runBlock
|
||||
$ exists s2.13.8.txt
|
||||
$ delete s2.13.8.txt
|
||||
|
||||
# don't crash when expanding the macro
|
||||
> b3/run
|
||||
> b3/runBlock
|
||||
$ exists s2.13.10.txt
|
||||
$ delete s2.13.10.txt
|
||||
|
||||
|
|
|
|||
|
|
@ -1,3 +1,3 @@
|
|||
$ delete output
|
||||
> run
|
||||
> runBlock
|
||||
$ exists output
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@
|
|||
|
||||
# This should fail because the Main object is in package jartest and the resource is directly
|
||||
# in src/main/resources
|
||||
-> run
|
||||
-> runBlock
|
||||
|
||||
> 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
|
||||
|
||||
# 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
|
||||
# high enough resolution to notice the above move of main_resource_test
|
||||
|
|
|
|||
|
|
@ -3,14 +3,14 @@
|
|||
$ copy-file changes/B.scala B.scala
|
||||
|
||||
$ copy-file changes/A1.scala A.scala
|
||||
> run 1
|
||||
> runBlock 1
|
||||
$ copy-file changes/A2.scala A.scala
|
||||
> run 2
|
||||
> runBlock 2
|
||||
|
||||
> clean
|
||||
> ++2.13.12!
|
||||
|
||||
$ copy-file changes/A1.scala A.scala
|
||||
> run 1
|
||||
> runBlock 1
|
||||
$ copy-file changes/A2.scala A.scala
|
||||
> run 2
|
||||
> runBlock 2
|
||||
|
|
|
|||
|
|
@ -1,2 +1 @@
|
|||
ThisBuild / scalaVersion := "2.12.17"
|
||||
|
||||
scalaVersion := "2.12.19"
|
||||
|
|
|
|||
|
|
@ -2,10 +2,10 @@ $ copy-file changes/A1.scala A.scala
|
|||
$ copy-file changes/B.scala B.scala
|
||||
$ copy-file changes/C.scala C.scala
|
||||
> compile
|
||||
-> run
|
||||
-> runBlock
|
||||
|
||||
$ copy-file changes/A2.scala A.scala
|
||||
$ sleep 1000
|
||||
|
||||
> compile
|
||||
> run
|
||||
> runBlock
|
||||
|
|
|
|||
|
|
@ -36,10 +36,10 @@ $ delete src/main/java/a/A.java
|
|||
# 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
|
||||
> compile
|
||||
-> run
|
||||
-> runBlock
|
||||
|
||||
|
||||
# Replace B with a new B that has a main method and should therefore run
|
||||
# if the main method was properly detected
|
||||
$ copy-file changes/B3.java src/main/java/a/b/B.java
|
||||
> run
|
||||
> runBlock
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
> compile
|
||||
|
||||
# the value of F.x should be 16
|
||||
> run 16
|
||||
> runBlock 16
|
||||
|
||||
# modify D.scala so that the linearization changes
|
||||
$ 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
|
||||
# and this will fail
|
||||
> run 11
|
||||
> runBlock 11
|
||||
|
|
@ -4,7 +4,7 @@
|
|||
> compile
|
||||
|
||||
# result should be 1
|
||||
> run 1
|
||||
> runBlock 1
|
||||
|
||||
# change order of arguments in A.x
|
||||
$ copy-file changes/A.scala A.scala
|
||||
|
|
@ -13,4 +13,4 @@ $ copy-file changes/A.scala A.scala
|
|||
> compile
|
||||
|
||||
# Should still get 1 and not -1
|
||||
> run 1
|
||||
> runBlock 1
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
> compile
|
||||
|
||||
# verify that erased A.x can be called normally and reflectively
|
||||
> run false
|
||||
> runBlock false
|
||||
|
||||
# make A.x specialized
|
||||
$ 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
|
||||
# NOTE: this test doesn't actually work correctly: have to check the output to see that B.scala was recompiled
|
||||
> run true
|
||||
> runBlock true
|
||||
Loading…
Reference in New Issue