Commit Graph

364 Commits

Author SHA1 Message Date
Amina Adewusi f12b0baef0 make -client the same as --client
The problem was that -client was different from --client, which
makes for a confusing user experience. So, this change makes
them the same and re-names -client to --java-client. The value
of this is that hopefully -client and --client being the same
feels more logical to users.
2021-05-07 16:07:42 +01:00
Eugene Yokota d0f540aea1 Patch for unidoc 2021-03-08 22:41:19 -05:00
Ondra Pelech 81457e60ec
Give an explanation in case of ServerAlreadyBootingException (#6353)
Give and explanation in case of ServerAlreadyBootingException
2021-03-04 23:21:42 -05:00
Eugene Yokota 22d12f6618 Use nowarn annotation 2021-02-06 22:31:47 -05:00
Sam Halliday 88baafa034 nohup the server from GNU Emacs 2021-01-21 10:51:00 +00:00
Adrien Piquerez fdcfe87dbf
Merge branch 'develop' into client-launch-jar 2021-01-11 13:20:49 +01:00
Eugene Yokota 8f5759e48d Cross build to Scala 2.13 2021-01-10 20:24:05 -05:00
eugene yokota 58d4ef41be
Merge pull request #6181 from smarter/dotty-library-rename
dotty-library is called scala3-library now
2020-12-24 11:53:18 -05:00
João Ferreira 08eaa9fb3b regen contraband 2020-12-21 17:21:54 +00:00
Guillaume Martres 7f3ce50014 dotty-library is called scala3-library now
I though this would help with
https://github.com/lampepfl/dotty/issues/10558 but `sbt repl` still
hides the input after typing a line and pressing enter even after this
change.
2020-11-30 17:08:04 +01:00
Ethan Atkins d167dee7d2 Add --sbt-launch-jar command line arg to client
The intellij bsp integration launches sbt with the launcher and runs
-bsp. This doesn't work if sbt is not on intellij's path. To try and
work around this, we can add an option --sbt-launch-jar that is
recognized by the network client and will make it use the launch jar
rather than the sbt script to launch a new server if needed.
2020-11-27 12:21:21 -08:00
Erlend Hamnaberg 341e09a07e Make it possible to not write the bsp connection file
Made the bspConfig task dependendant on the bspConfig value.
Changed the bspConfig setting to use a attributeKey so we can use it in the server as well.
2020-11-27 20:00:12 +01:00
Ethan Atkins 3f3e219e0f Update ipcsocket
The new version provides an apple silicon arm64 jni implementation of
the ipcsocket api. It also adds a jni implementation for getting the max
socket length which is necessary because jna isn't supported on the
apple arm64 platform yet.
2020-11-25 07:34:11 -08:00
Ethan Atkins 5769f80cbe Use jni if required when running client from xMain
See https://github.com/sbt/sbt/issues/6162#issuecomment-733207878.
2020-11-24 12:35:53 -08:00
Ethan Atkins ab2875e837 Use jni implementation of ipcsocket apis on arm macs
There isn't yet a version of the jna available that works with the new
apple silicon using arm64. To workaround this, we can use the jni
implementation by default on arm64 macs. If the user wants to force the
jni implementation for any supported platform, they can opt in with the
`sbt.ipcsocket.jni` system property and/or by setting the serverUseJni
setting.
2020-11-23 12:31:15 -08:00
Ethan Atkins 62ebe70e5c
Merge branch 'develop' into bsp-watch-fix 2020-11-20 07:51:26 -08:00
Ethan Atkins 2b45183d09 Cleanup user thread task submission
I found this code difficult to reason about so I refactored it so that
it was easier for me to understand.
2020-11-19 18:57:26 -08:00
Ethan Atkins f3b3148c58 Use NetworkClient to implement `sbt -bsp`
Network client already supports the -bsp command (since
65ab7c94d0). This commit reworks the
BspClient.run method so that it delegates to the NetworkClient. The
advantage to doing it this way is that improvements to starting up the
sbt server by the thin client will automatically propagate to the -bsp
command. The way that it is implemented, all of the output generated
during server startup will be redirected to System.err which is useful
for debugging without messing up the bsp protocol, which relies on only
bsp messages being written to System.out.
2020-11-19 16:03:26 -08:00
Ethan Atkins 8137c80782 Fix thin client sbt process startup output
The boot server socket was not working correctly when the sbt server was
started by the thin client. This was because it is necessary for us to
create a ConsoleTerminal in order for System.out and System.err to be
properly forwarded to the clients connected over the boot server socket.
As a result, if you started a server instance of sbt with the thin
client, you wouldn't see any output util you connected to the server.
The fix is to just make sure that we create a console terminal if sbt is
run as a subprocess.
2020-11-18 12:38:44 -08:00
Ethan Atkins 29ce18edec Don't print socket exception on exit
When exiting the thin client when using tcp rather than a domain socket,
an error message is printed about a socket exception.
2020-11-17 16:46:28 -08:00
Adrien Piquerez c71c9c9227 Detach stdio in BSP server 2020-11-16 15:01:42 +01:00
eugene yokota 031d2c6655
Merge pull request #6071 from eatkins/join-thread
Throw timeoutexception in JoinThread
2020-11-06 17:37:24 -05:00
Ethan Atkins 748dfd6e67 Throw timeoutexception in JoinThread
Rather than throwing an interrupted exception if we fail to join a
thread, we should throw a timeout exception.
2020-11-05 11:09:01 -08:00
Ethan Atkins 583ad06aac Remove unnecessary log line in thin client
When a batch command is run with the thin client, it logs an info
message that the command completed. This is unnecessary given that
completion is implied by the success or failure method that follows. It
made the output look a little different in the thin client vs the
console.
2020-11-05 10:13:21 -08:00
Ethan Atkins 65ab7c94d0 Support -bsp in thin client
This refactors the thin client so that it can run the BspClient if
invoked with -bsp.
2020-10-26 14:46:25 -07:00
Ethan Atkins 0d69705e73 Refactor BspClient
This is a refactoring so that the thin client can invoke the bsp client.
2020-10-26 14:46:25 -07:00
Ethan Atkins d255481ade Replace %20 with space in sbt script name
We replace spaces in the sbt script with %20 and we need to replace the
%20s with spaces.
2020-10-25 19:17:13 -07:00
Ethan Atkins c66f31d8a1 Avoid throwing interrupted exception in JoinThread
I saw a stacktrace when exiting sbtn on windows due to an interrupted
exception being thrown during thread joining. We only want to throw this
exception if we didn't successfully join the thread. I also noticed that
we would try to join the thread forever. There was supposed to be a
timelimit so that we would eventually stop blocking even if we were
unable to join the thread. The limit was set but not respected.
2020-10-25 15:14:04 -07:00
Ethan Atkins 69510b126b Parse network client arguments early
With sbtn, the system properties are passed in as regular command
arguments. We need to parse them before we call Terminal.withStreams or
else system properties like -Dsbt.color=false are ignored.
2020-10-24 12:54:14 -07:00
Ethan Atkins a0db985c36 Fix canonical input for network client
It is valid for the thin client input stream to return -1 as an EOF when
the user inputs ctrl+d in canonical mode.
2020-10-21 14:26:21 -07:00
Ethan Atkins 7ad20edbd3
Merge branch 'develop' into evaluate-task-memory-leak 2020-10-21 11:49:01 -07:00
Ethan Atkins d9acfed220 Fix EvaluateTask memory leak
EvaluateTask was holding references to SafeState that could be quite
large. This was reported as #5992. In that project, I ran the `ci` task
and observed the OOM as reported. I took a heap dump prior to OOM and
got the retained size graph from visualvm (which took hours to compute).
The lastEvaluatedState was holding a reference to SafeState that was
1.7GB. The project max heap size was set to 2GB. Instead of using the
lastEvaluatedState, we can just use StandardMain.exchange.withState.
The cached instances of state were used for task cancellation and
completions. While it is possible that early on in booting
StandardMain.exchange.withState could return a null state, in practice
this won't happen because it is set early on during the sbt boot
commands.

After this change, I successfully ran the `ci` task in the #5992 issue
project with the same memory parameters as their ci config.
2020-10-21 08:01:40 -07:00
Ethan Atkins 78620cd902 Manage ansi codes and color codes separately
The ConsoleAppender formatEnabledInEnv field was being used both as an
indicator that ansi codes were supported and that color codes are
enabled. There are cases in which general ansi codes are not supported
but color codes are and these use cases need to be handled separately.
To make things more explicit, this commit adds isColorEnabled and
isAnsiSupported to the Terminal companion object so that we can be more
specific about what the requirements are (general ansi escape codes or
just colors). There are a few cases in ConsoleAppender itself where
formatEnabledInEnv was used to set flags for both color and ansi codes.
When that is the case, we use Terminal.isAnsiSupported because when that
is true, colors should at least work but there are terminals that
support color but not general ansi escape codes.
2020-10-21 08:01:12 -07:00
Ethan Atkins efec7bce31 Check if target is directory before creating
When project/target is a symbolic link, sbt 1.4.0 crashes on startup
because Files.createDirectories will throw a FileAlreadyExistsException.
The fix is to first check if the target directory exists before trying
to create it.
2020-10-13 08:17:22 -07:00
eugene yokota 715bccacd9
Merge pull request #5945 from eatkins/boot-system-in-fix
Fix sbt hangs with invalid build.sbt and --batch
2020-10-06 16:20:54 -04:00
Ethan Atkins 10c549a0b9 Fix sbt hangs with invalid build.sbt and --batch
When sbt is starting up and there is an error with the build loading, we
need to read input from the user to determine to restart the build or
not. What is tricky is that there are potentially two sources of input:
thin clients connected through the boot server socket and the actual sbt
console process. If there are not connected thin clients and no system
console is available, we should return -1 in System.in.read, which will
cause sbt to exit.
2020-10-06 11:43:00 -07:00
Ethan Atkins 08aa64e703 Restore terminal prompt for some dumb terminals
A user reported that no prompt was displayed when they used sbt from the
jEdit console. The reason no prompt was displayed was because
System.console was null which caused the ConsoleChannel to be
initialized with its prompt set to NoPrompt. I don't remember why it was
doing this but this bug seems worse than whatever it was trying to
address.
2020-10-06 09:55:49 -07:00
Ethan Atkins 90f6d77d59 Send exit in network client before shutdown
In the client test, the sbt server would keep open the the client
connection even after it had exited because the client was only shutting
down its side of the connection. Since in the test it wasn't exiting the
jvm, the read side of the connection was still open.
2020-09-28 07:28:24 -07:00
Ethan Atkins 8a23f1e440 Add ability to timeout ClientTest cases
It is possible for the test cases in ClientTest to block indefinitely.
To avoid that, we can instead run them on a background thread and cancel
the thread if that happens.
2020-09-28 07:03:28 -07:00
Ethan Atkins e3731994de Timeout completion requests 2020-09-28 07:03:28 -07:00
Ethan Atkins 42393459a0 Log full exception 2020-09-28 07:03:28 -07:00
eugene yokota 23fd24c838
Merge pull request #5874 from eatkins/terminal-fixes
Fix a number of terminal io bugs
2020-09-21 22:19:39 -04:00
eugene yokota c2e81a23a0
Merge pull request #5876 from eed3si9n/wip/bat
sbt.cmd -> sbt.bat and --sbt-script update
2020-09-21 22:18:33 -04:00
Ethan Atkins 0427e5f9c5 Add timeouts for completion prompts
CI hung in the server test that checks completions because I broke
reading from the System.in. It occurred to me that we probably shouldn't
prompt indefinitely when the user is running tab completions anyway so I
set a timeout of 5 seconds for the user to respond to input. If they
decline to start a server within the timeout, we will just exit. If they
decline to run compilation within the timeout we just skip the
compilation step (so test or main class names will not be provided for
completions).
2020-09-21 13:42:03 -07:00
Ethan Atkins bb8b9a1c99 Fix switching between raw and canonical input
There were a number of issues with swithcing between raw and canonical
issues that affected both the server and the thin client. These were
reported in #5863 and #5856. In both cases, there were issues with
reading input or having the input be displayed. Debugging those issues
revealed a number of issues with how we were using the jline 3 system
terminal and the hybrid interaction with the jline 2 terminal. This
commit eliminates all of our internal jline 2 usage. The only remaining
jline 2 usage is that we create and override the global terminal for the
scala console for scala versions < 2.13. By moving away from jline 2, I
was also able to fix #5828, which reported that the home, end and delete
keys were not working.

One of the big issues that this commit addresses is that the
NetworkClient was always performing blocking reads on System.in. This
was problematic because it turns out that you can't switch between raw
and canonical modes when there is a read present. To fix this, the
server now sends a message to the client when it wants to read bytes and
only then does the client create a background thread to read a single
byte.

I also figured out how to set the terminal type properly for the thin
client on windows where we had been manually setting the capabilities to
ansi, which only worked for some keys. This fix required switching to
the WindowsInputStream that I introduced in a prior commit. Before we
were using the jline 2 wrapped input stream which was converting some
system events, like home and end, to the wrong escape sequence mappings.

The remainder of the commit is mostly just converting from jline 2 apis
to jline 3 apis.

I verified that tab completions, the scala console, the ammonite console
and a run task that read from System.in all work with both the server
and the thin client on mac, linux and windows after these changes.

Fixes #5828, #5863, #5856
2020-09-21 13:42:03 -07:00
Ethan Atkins 6247362725 Abort thin client on access denied exception
There are situations in windows where it is possible that a client
attempts to connect to a portfile that it did not have access to. This
can happen if, for example, the server is started in administrator mode
but the client is started as a regular user. When this happens, the
client would try to remove the portfile and start a new server. This new
server would not actually be able to start a server though becuase it
would not be able to open the named point because the other server had
it open. As a result, the client would just hang. The fix is to just
abort the thin client if it gets an access denied exception.
2020-09-21 10:58:57 -07:00
Eugene Yokota b631dffed6 Support whitespace after --sbt-script
`=` gets treated as a whitespace in batch, so it would be good to support whitespace.
2020-09-20 22:07:08 -04:00
Eugene Yokota 6ebbbe5e0a sbt.cmd -> sbt.bat 2020-09-20 21:31:55 -04:00
Ethan Atkins 7b31495ae3 Expand json rpc request input buffer if needed
When a json rpc request is specified without any headers, the size of
the message may exceed the buffer that was created for reading hdeaders.
This would cause an exception to be thrown when creating a string from
the header buffer because the number of bytes requested would exceed the
capacity of the buffer. To fix this, we can expand the buffer
dynamically if needed. For the common case when the headers are
specified, this should be a no-op.
2020-09-13 19:43:06 -07:00
Eugene Yokota d24cd2b3f7 Rename --close-io-streams to --detach-stdio 2020-09-12 14:19:37 -04:00