Skip to content

Commit 8adb242

Browse files
authored
Disable selection execution for run that occurs when enter is pressed during watch (#4149)
No tests for now, since our integration test suite doesn't easily support feeding stdin to the mill subprocess
1 parent 2c6157d commit 8adb242

File tree

2 files changed

+20
-11
lines changed

2 files changed

+20
-11
lines changed

runner/src/mill/runner/MillMain.scala

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ object MillMain {
233233
watch = config.watch.value,
234234
streams = streams,
235235
setIdle = setIdle,
236-
evaluate = (prevState: Option[RunnerState]) => {
236+
evaluate = (enterKeyPressed: Boolean, prevState: Option[RunnerState]) => {
237237
adjustJvmProperties(userSpecifiedProperties, initialSystemProperties)
238238

239239
withOutLock(
@@ -256,6 +256,9 @@ object MillMain {
256256
colored = colored,
257257
colors = colors
258258
)) { logger =>
259+
// Enter key pressed, removing mill-selective-execution.json to
260+
// ensure all tasks re-run even though no inputs may have changed
261+
if (enterKeyPressed) os.remove(out / OutFiles.millSelectiveExecution)
259262
SystemStreams.withStreams(logger.systemStreams) {
260263
tailManager.withOutErr(logger.outputStream, logger.errorStream) {
261264
new MillBuildBootstrap(

runner/src/mill/runner/Watching.scala

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,13 @@ object Watching {
2020
watch: Boolean,
2121
streams: SystemStreams,
2222
setIdle: Boolean => Unit,
23-
evaluate: Option[T] => Result[T],
23+
evaluate: (Boolean, Option[T]) => Result[T],
2424
colors: Colors
2525
): (Boolean, T) = {
2626
var prevState: Option[T] = None
27+
var enterKeyPressed = false
2728
while (true) {
28-
val Result(watchables, errorOpt, result) = evaluate(prevState)
29+
val Result(watchables, errorOpt, result) = evaluate(enterKeyPressed, prevState)
2930
prevState = Some(result)
3031
errorOpt.foreach(streams.err.println)
3132
if (ringBell) {
@@ -42,8 +43,9 @@ object Watching {
4243
}
4344

4445
val alreadyStale = watchables.exists(!_.validate())
46+
enterKeyPressed = false
4547
if (!alreadyStale) {
46-
Watching.watchAndWait(streams, setIdle, streams.in, watchables, colors)
48+
enterKeyPressed = Watching.watchAndWait(streams, setIdle, streams.in, watchables, colors)
4749
}
4850
}
4951
???
@@ -55,7 +57,7 @@ object Watching {
5557
stdin: InputStream,
5658
watched: Seq[Watchable],
5759
colors: Colors
58-
): Unit = {
60+
): Boolean = {
5961
setIdle(true)
6062
val watchedPaths = watched.collect { case p: Watchable.Path => p.p.path }
6163
val watchedValues = watched.size - watchedPaths.size
@@ -68,21 +70,25 @@ object Watching {
6870
).toString
6971
)
7072

71-
statWatchWait(watched, stdin)
73+
val enterKeyPressed = statWatchWait(watched, stdin)
7274
setIdle(false)
75+
enterKeyPressed
7376
}
7477

75-
def statWatchWait(watched: Seq[Watchable], stdin: InputStream): Unit = {
78+
// Returns `true` if enter key is pressed to re-run tasks explicitly
79+
def statWatchWait(watched: Seq[Watchable], stdin: InputStream): Boolean = {
7680
val buffer = new Array[Byte](4 * 1024)
7781

78-
@tailrec def statWatchWait0(): Unit = {
82+
@tailrec def statWatchWait0(): Boolean = {
7983
if (watched.forall(_.validate())) {
80-
if (lookForEnterKey()) ()
81-
else {
84+
if (lookForEnterKey()) {
85+
mill.main.client.DebugLog.println("ENTER KEY DETECTED")
86+
true
87+
} else {
8288
Thread.sleep(100)
8389
statWatchWait0()
8490
}
85-
}
91+
} else false
8692
}
8793

8894
@tailrec def lookForEnterKey(): Boolean = {

0 commit comments

Comments
 (0)