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

Upgrade JLine to 3.19.0 #11707

Merged
merged 1 commit into from
Mar 12, 2021
Merged

Conversation

griggt
Copy link
Contributor

@griggt griggt commented Mar 12, 2021

Aligns with Scala 2.13.5: scala/scala#9467 and sbt 1.4.8: sbt/sbt#6366

Fixes #11488

Aligns with Scala 2.13.5: scala/scala#9467 and sbt 1.4.8: sbt/sbt#6366

Fixes scala#11488
Copy link
Contributor

@OlivierBlanvillain OlivierBlanvillain left a comment

Choose a reason for hiding this comment

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

Thanks!

@OlivierBlanvillain OlivierBlanvillain merged commit e08fd59 into scala:master Mar 12, 2021
@griggt griggt deleted the jline-3.19.0 branch March 12, 2021 09:04
@smarter
Copy link
Member

smarter commented Mar 14, 2021

Shouldn't we upgrade sbt too so that it uses the same version of jline?

@harpocrates
Copy link
Contributor

harpocrates commented Mar 14, 2021

sbt repl recently stopped working for me and git bisect landed on this commit as the one where it ceased functioning.

$ sbt repl       
[info] welcome to sbt 1.4.7 (AdoptOpenJDK Java 15.0.2)
[info] loading settings for project global-plugins from metals.sbt ...
[info] loading global plugins from /Users/atheriault/.sbt/1.0/plugins
[info] loading settings for project dotty-build-build from build.sbt ...
[info] loading project definition from /Users/atheriault/Code/dotty/project/project
[info] loading settings for project dotty-build from build.sbt,plugins.sbt ...
[info] loading project definition from /Users/atheriault/Code/dotty/project
[info] compiling 1 Scala source to /Users/atheriault/Code/dotty/project/target/scala-2.12/sbt-1.0/classes ...
[info] loading settings for project scala3 from build.sbt ...
[info] resolving key references (30179 settings) ...
[info] set current project to scala3 (in build file:/Users/atheriault/Code/dotty/)
[info] compiling 3 Scala sources to /Users/atheriault/Code/dotty/compiler/target/scala-3.0.0-RC1/classes ..
[info] running (fork) dotty.tools.repl.Main -classpath /Users/atheriault/Library/Caches/Coursier/v1/https/repo1.maven.org/maven2/org/scala-lang/scala-library/2.13.5/scala-library-2.13.5.jar:/Users/atheriault/Code/dotty/library/../out/bootstrap/scala3-library-bootstrapped/scala-3.0.0-RC2/scala3-library_3.0.0-RC2-3.0.0-RC2-bin-SNAPSHOT.jar
Exception in thread "main" java.lang.IllegalStateException: Unable to create a system terminal
	at org.jline.terminal.TerminalBuilder.doBuild(TerminalBuilder.java:323)
	at org.jline.terminal.TerminalBuilder.build(TerminalBuilder.java:265)
	at dotty.tools.repl.JLineTerminal.<init>(JLineTerminal.scala:23)
	at dotty.tools.repl.ReplDriver.runUntilQuit(ReplDriver.scala:123)
	at dotty.tools.repl.ReplDriver.tryRunning(ReplDriver.scala:114)
	at dotty.tools.repl.Main$.main(Main.scala:6)
	at dotty.tools.repl.Main.main(Main.scala)
[error] Nonzero exit code returned from runner: 1
[error] (scala3-compiler / Compile / runMain) Nonzero exit code returned from runner: 1
[error] Total time: 15 s, completed Mar 14, 2021, 8:33:32 PM

Some additional information:

  • Switching SBT to 1.4.9 did not help
  • The scala 2.13.5 REPL (also using this version of JLine) works fine in other projects
  • sbt scala3-compiler-bootstrapped/console works fine

@griggt griggt mentioned this pull request Mar 15, 2021
@griggt
Copy link
Contributor Author

griggt commented Mar 15, 2021

So the cause of the error above while invoking sbt repl is this JLine 3 commit, entitled JLine3 should not allow building a system terminal if input or output is not a tty, which is new in JLine 3.19.0.

This presents a problem, as the repl task in the dotty build is run as a forked task, and forked tasks in sbt have their stdout and stderr file descriptors connected to the parent process via a pipe rather than inheriting those file descriptors.

Since the stdout file descriptor is connected to a pipe, the call to isatty() returns false, and JLine refuses to create a system terminal.

Ordinarily, JLine would then fall back to attempting to create a dumb terminal, but we have this:

https://github.com/lampepfl/dotty/blob/02cee1f2c511d222b12d850dcd3475bc07b3b45b/compiler/src/dotty/tools/repl/JLineTerminal.scala#L22-L23

which prevents it from doing so.

Incidentally, this also affects the scala/scala repo since they have upgraded to JLine 3.19.0, however the fallback to a dumb terminal is permitted there:

/src/scala$ sbt scala
[info] welcome to sbt 1.4.9 (AdoptOpenJDK Java 1.8.0_282)
[info] loading global plugins from /home/tgrigg/.sbt/1.0/plugins
[info] loading settings for project scala-build-build from plugins.sbt ...
[info] loading project definition from /src/scala/project/project
[info] loading settings for project scala-build from plugins.sbt ...
[info] loading project definition from /src/scala/project
[info] loading settings for project root from build.sbt ...
[info] resolving key references (21978 settings) ...
[info] *** Welcome to the sbt build definition for Scala! ***
[info] version=2.13.6-bin-SNAPSHOT scalaVersion=2.13.5
[info] Check README.md for more information.
[info] running (fork) scala.tools.nsc.MainGenericRunner -usejavacp
Welcome to Scala 2.13.6-20210312-021334-93ec1f0 (OpenJDK 64-Bit Server VM, Java 1.8.0_282).
Type in expressions for evaluation. Or try :help.
WARNING: Unable to create a system terminal, creating a dumb terminal (enable debug logging for more information)

scala> 

Since AFAIK this only affects the sbt repl task in the lampepfl/dotty repo and the sbt scala task in the scala/scala repo, which were already somewhat broken since upgrading to sbt 1.4.x (see #10558 and scala/scala-dev#755), I'm not sure there's much we should do on our end.

The workaround given here of using scala3-compiler-bootstrapped/console instead of repl is still valid. In fact, perhaps we could remove or rename the repl task in the dotty build and alias repl to scala3-compiler-bootstrapped/console.

Another workaround is to force usage of a dumb terminal by setting the environment variable TERM=dumb:

/src/dotty$ TERM=dumb sbt repl
[info] welcome to sbt 1.4.9 (AdoptOpenJDK Java 1.8.0_282)
[info] loading global plugins from /home/tgrigg/.sbt/1.0/plugins
[info] loading settings for project dotty-build-build from build.sbt ...
[info] loading project definition from /src/dotty/project/project
[info] loading settings for project dotty-build from build.sbt,plugins.sbt ...
[info] loading project definition from /src/dotty/project
[info] loading settings for project scala3 from build.sbt ...
[info] resolving key references (30179 settings) ...
[info] set current project to scala3 (in build file:/src/dotty/)
[info] compiling 1 Scala source to /src/dotty/compiler/target/scala-3.0.0-RC1/classes ...
[info] done compiling
[info] running (fork) dotty.tools.repl.Main -classpath /home/tgrigg/.cache/coursier/v1/https/repo1.maven.org/maven2/org/scala-lang/scala-library/2.13.5/scala-library-2.13.5.jar:/src/dotty/library/../out/bootstrap/scala3-library-bootstrapped/scala-3.0.0-RC2/scala3-library_3.0.0-RC2-3.0.0-RC2-bin-SNAPSHOT.jar
scala> 

@smarter
Copy link
Member

smarter commented Mar 15, 2021

Ordinarily, JLine would then fall back to attempting to create a dumb terminal, but we have this:

Regardless of everything else, maybe we should remove this if it prevents creating dumb terminals in situation where that would be possible otherwise

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.

REPL tab completion shows methods in unsorted order
4 participants