Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Properly wire stdin in client-server mode and enable "Enter to Re-run" for mill -w #1621

Merged
merged 5 commits into from
Dec 15, 2021

Conversation

lihaoyi
Copy link
Member

@lihaoyi lihaoyi commented Dec 15, 2021

This gets rid of our custom watchAndWait logic, standardizing it with what's upstream in Ammonite and allowing Mill to use the "Enter to re-run" functionality that was introduced in Ammonite 2.5.0.

While this worked for ./mill -i out of the box, some work was necessary to get it working for Mill's client-server mode. This fixes the wiring for the socket's stdin to ensure it gets plumbed through, and works around the broken available() implementation in the UnixDomainSocketInputStream by proxying it via an InputPumper.

Tested manually:

lihaoyi mill$ ./mill -i dev.run scratch -w foo.run
[90/647] de.tobiasroeser.mill.vcs.version.VcsVersion.vcsState
[647/647] dev.run
[44/44] foo.run
false
Watching for changes to 4 paths... (Enter to re-run, Ctrl-C to exit)

<ENTER>
[44/44] foo.run
false
Watching for changes to 4 paths... (Enter to re-run, Ctrl-C to exit)

<ENTER>
[44/44] foo.run
false
Watching for changes to 4 paths... (Enter to re-run, Ctrl-C to exit)

<ENTER>
[44/44] foo.run
false
Watching for changes to 4 paths... (Enter to re-run, Ctrl-C to exit)
<Ctrl-C>
Host JVM shutdown. Forcefully destroying subprocess ...

Notably, this change also allows you to run interactive mill foo.run programs without using -i, e.g. using this modified scratch/src/Foo.scala:

package foo
object Foo{

  def main(args: Array[String]): Unit = {
    println("enter any character: ")
    val c = System.in.read().toChar
    println("c: [" + c + "]")
  }
}
lihaoyi mill$ ./mill -i dev.run scratch -w foo.run
...
[44/44] foo.run
enter any character:
g<ENTER>
c: [g]
Watching for changes to 4 paths... (Enter to re-run, Ctrl-C to exit)

@lihaoyi lihaoyi requested a review from lefou December 15, 2021 03:34
Copy link
Member

@lefou lefou left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Another great change! I love that it fixes the need to use --interactive for interactive commands.

main/client/src/mill/main/client/InputPumper.java Outdated Show resolved Hide resolved
main/src/mill/modules/Jvm.scala Show resolved Hide resolved
main/src/mill/main/MillServerMain.scala Show resolved Hide resolved
scratch/foo/src/Foo.scala Outdated Show resolved Hide resolved
Copy link
Member

@lefou lefou left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@lihaoyi
Copy link
Member Author

lihaoyi commented Dec 15, 2021

Notably, even the interactive Scala console works without -i now

$ ./mill -i dev.run scratch foo.console
[90/647] de.tobiasroeser.mill.vcs.version.VcsVersion.vcsState
[647/647] dev.run
[39/39] foo.console
Welcome to Scala 2.13.2 (OpenJDK 64-Bit Server VM, Java 11.0.7).
Type in expressions for evaluation. Or try :help.
Dec 15, 2021 8:59:31 PM org.jline.utils.Log logr
WARNING: Unable to create a system terminal, creating a dumb terminal (enable debug logging for more information)
1
scala> + 1
val res0: Int = 2

scala> println(123, 456)
println(123, 456)(123,456)

Not 100%, Ctrl-D doesn't work properly to exit, and I'm guessing Ammonite won't work smoothly due to the clever TTY stuff it does. Nevertheless, it's moving in the right direction to get it all working for good

@lihaoyi lihaoyi merged commit 5d22c7a into main Dec 15, 2021
@lefou lefou deleted the enter-to-rerun branch December 15, 2021 14:52
@lefou lefou added this to the 0.10.0-M5 milestone Dec 15, 2021
@lefou lefou linked an issue Dec 15, 2021 that may be closed by this pull request
pbuszka pushed a commit to pbuszka/mill that referenced this pull request Dec 26, 2021
…" for mill -w (com-lihaoyi#1621)

This gets rid of our custom `watchAndWait` logic, standardizing it with what's upstream in Ammonite and allowing Mill to use the "Enter to re-run" functionality that was introduced in Ammonite 2.5.0.

While this worked for `./mill -i` out of the box, some work was necessary to get it working for Mill's client-server mode. This fixes the wiring for the socket's stdin to ensure it gets plumbed through, and works around the broken `available()` implementation in the `UnixDomainSocketInputStream` by proxying it via an `InputPumper`.

Tested manually:

```
lihaoyi mill$ ./mill -i dev.run scratch -w foo.run
[90/647] de.tobiasroeser.mill.vcs.version.VcsVersion.vcsState
[647/647] dev.run
[44/44] foo.run
false
Watching for changes to 4 paths... (Enter to re-run, Ctrl-C to exit)

<ENTER>
[44/44] foo.run
false
Watching for changes to 4 paths... (Enter to re-run, Ctrl-C to exit)

<ENTER>
[44/44] foo.run
false
Watching for changes to 4 paths... (Enter to re-run, Ctrl-C to exit)

<ENTER>
[44/44] foo.run
false
Watching for changes to 4 paths... (Enter to re-run, Ctrl-C to exit)
<Ctrl-C>
Host JVM shutdown. Forcefully destroying subprocess ...
```

Notably, this change also allows you to run interactive `mill foo.run` programs without using `-i`, e.g. using this modified `scratch/src/Foo.scala`:


```
package foo
object Foo{

  def main(args: Array[String]): Unit = {
    println("enter any character: ")
    val c = System.in.read().toChar
    println("c: [" + c + "]")
  }
}
```

```bash
lihaoyi mill$ ./mill -i dev.run scratch -w foo.run
...
[44/44] foo.run
enter any character:
g<ENTER>
c: [g]
Watching for changes to 4 paths... (Enter to re-run, Ctrl-C to exit)
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Let users re-run --watched commands by pressing enter
2 participants