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

Fix #12318: Support options to repl #12370

Merged
merged 2 commits into from
May 10, 2021
Merged

Conversation

liufengyun
Copy link
Contributor

Fix #12318: Support options to repl

@liufengyun liufengyun requested a review from michelou May 7, 2021 14:20
@philwalk
Copy link
Contributor

philwalk commented May 8, 2021

Some things I found while manually verifying each option in the -help message:

The -d <destination-for-generated-files> option is broken, due to -d being treated as -debug in dist/bin/scala line 101.

scala -encoding utf8
Unrecognized option: -encoding

If a script name is provided, the error disappears, so maybe a difference between the repl.Main and scripting.Main.

Also, scripts should immediately capture all remaining arguments as soon as the target_script is initialized (dist\bin\scala near line 138). Otherwise, scripts are unable to have arguments such as -run or -verbose, etc.
This is similar to the a problem recently fixed in dist/bin/scalac (#11776)

@griggt
Copy link
Contributor

griggt commented May 8, 2021

The -d <destination-for-generated-files> option is broken, due to -d being treated as -debug in dist/bin/scala line 101.

I believe this has been "broken" for quite a long time, I have been using scalac -d /path/to/output -repl as a workaround for as long as I can remember.

It would be nice if this were fixed such that -d has the same meaning for both scalac and scala.

@michelou
Copy link
Contributor

michelou commented May 8, 2021

Fix #12318: Support options to repl

@liufengyun Got your request; I'll have a look.

@philwalk
Copy link
Contributor

philwalk commented May 9, 2021

Another existing issue with dist/bin scripts that hasn't yet been logged as a bug (AFAIK), is that there's an apparent conflict between jline3 and windows shell environments (cygwin, mingw, msys, etc.). The fix is simple, it would be nice to get it fixed here, if that's acceptable.

The problem can be illustrated with a Windows batch file for launching a REPL session:

@echo off
set SCALA_HOME="c:/opt/scala3"
set CP="%SCALA_HOME%/lib/scala-library-2.13.5.jar;%SCALA_HOME%/lib/scala3-library_3-3.0.1-RC1-bin-SNAPSHOT.jar;%SCALA_HOME%/lib/scala-asm-9.1.0-scala-1.jar;%SCALA_HOME%/lib/compiler-interface-1.3.5.jar;%SCALA_HOME%/lib/scala3-interfaces-3.0.1-RC1-bin-SNAPSHOT.jar;%SCALA_HOME%/lib/scala3-compiler_3-3.0.1-RC1-bin-SNAPSHOT.jar;%SCALA_HOME%/lib/tasty-core_3-3.0.1-RC1-bin-SNAPSHOT.jar;%SCALA_HOME%/lib/scala3-staging_3-3.0.1-RC1-bin-SNAPSHOT.jar;%SCALA_HOME%/lib/scala3-tasty-inspector_3-3.0.1-RC1-bin-SNAPSHOT.jar;%SCALA_HOME%/lib/jline-reader-3.19.0.jar;%SCALA_HOME%/lib/jline-terminal-3.19.0.jar;%SCALA_HOME%/lib/jline-terminal-jna-3.19.0.jar;%SCALA_HOME%/lib/jna-5.3.1.jar"
C:/opt/jdk/bin/java.exe -Xmx768m -Xms768m -classpath %CP% -Dscala.usejavacp=true dotty.tools.repl.Main %*

When launched from a CMD.EXE session, this launches a REPL session, as expected.

But if PWD is set, then the session output is garbled:

C:\opt\ue>s0.bat
←[90m~←[0m←[K                                                                                                     ←[?2004h←[34mscala> ←[0m:q
:q
←[?2004lC:\opt\ue>

The fix is to unset PWD before calls to "$JAVACMD", in bin/scala (see #12405 for a more complete explanation).

This garbled prompt appears in bash sessions as well, with the same fix.

@liufengyun
Copy link
Contributor Author

Thanks for all your input @philwalk @griggt @michelou .

I think we can make -d to mean the output directory, and remove the debug capability to be consistent with bin/scalac and align with Scala 2 behavior.

For the Windows issue, could you push a fix in another PR @philwalk ?

BTW, it seems it will help a lot if we add more bash tests, which can help us from regressions and save manual testing efforts. Do you have any suggestions for testing the bash REPL (jline3)?

@philwalk
Copy link
Contributor

philwalk commented May 9, 2021

@liufengyun

Do you have any suggestions for testing the bash REPL (jline3)?

I will give it some thought.

I will start a PR as soon as I can. Which of the problems I described should be included? I notice that scripting_args is referenced in dist/bin/scalac, but is not initialized anywhere. Probably it should be spelled script_args, and it would be relevant if someone calls bin/scalac to compile a script with -compile-only and -script <path> args.

Should I include the fix for the potential misdirected script arguments problem?

scripts should immediately capture all remaining arguments as soon as the target_script is initialized (dist\bin\scala near line 138).

@liufengyun
Copy link
Contributor Author

Which of the problems I described should be included? I notice that scripting_args is referenced in dist/bin/scalac, but is not initialized anywhere. Should I include the fix for this problem:

scripts should immediately capture all remaining arguments as soon as the target_script is initialized (dist\bin\scala near line 138).

@philwalk Yes, it will be better if the PR includes fix for the problem above. Your help is much appreciated.

@liufengyun
Copy link
Contributor Author

liufengyun commented May 9, 2021

@philwalk If there is a potential to conflict with the current PR, then you can make a PR on top of this PR. And you can rebase after this is merged.

Copy link
Contributor

@michelou michelou left a comment

Choose a reason for hiding this comment

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

LGTM. Debug was undocumented anyway.

@liufengyun
Copy link
Contributor Author

Thank you @michelou !

@liufengyun liufengyun merged commit 79ea6e2 into scala:master May 10, 2021
@liufengyun liufengyun deleted the fix-12318 branch May 10, 2021 11:40
@philwalk
Copy link
Contributor

PR for console problems is #12411

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.

Command line options to scala misbehaving
4 participants