Commit Graph

9143 Commits

Author SHA1 Message Date
Eugene Yokota 2feecf8a1f Selective functor
This implements Selective functor for `Either[A, B]` "task" (`Initialize[Task[Either[A, B]]]`).
The selective functor allows an encoding of if-expression:

```
  def ifS[A](
      x: Def.Initialize[Task[Boolean]]
  )(t: Def.Initialize[Task[A]])(e: Def.Initialize[Task[A]]): Def.Initialize[Task[A]]
```

The benefit of this approach is that task dependencies are still visible to inspect command.
2020-05-17 23:36:04 -04:00
eugene yokota 4592493617
Merge pull request #5549 from adpi2/issue/json-response
Prevent more than one response per json RPC request
2020-05-12 22:07:11 -04:00
eugene yokota ea608ccd77
Merge pull request #5540 from bjaglin/service-loader
enable ServiceLoader discovery across classloader layers
2020-05-12 22:05:53 -04:00
Adrien Piquerez c221f57812 code review 2020-05-12 19:20:43 +02:00
Adrien Piquerez 42e4c5a7c0 evict some mima errors in sbt.internal 2020-05-12 19:20:43 +02:00
Adrien Piquerez 8df754eeb1 rename publish to either respond or notify 2020-05-12 16:26:33 +02:00
Adrien Piquerez 255a0a6ea6 send response to the source channel only 2020-05-12 14:44:10 +02:00
Adrien Piquerez df293fbfd5 prevent multiple response to a single request 2020-05-12 10:38:47 +02:00
Adrien Piquerez e040eebd21 "add failing json rpc response tests" 2020-05-12 10:37:48 +02:00
Adrien Piquerez 781584d137 id is mandatory in json rpc responses 2020-05-11 16:51:34 +02:00
eugene yokota e84e414328
Merge pull request #5546 from eed3si9n/wip/bumpio
IO 1.4.0-M6
2020-05-09 17:08:28 -04:00
Eugene Yokota e8ad695623 IO 1.4.0-M6 2020-05-09 15:53:33 -04:00
eugene yokota 9eedbce815
Merge pull request #5545 from eed3si9n/fport/duplicated-strings
[fport] Avoid tens of thousands of duplicated "TypeFuntions.const(())" strings
2020-05-09 15:04:46 -04:00
Jason Zaugg 43cc55a24c Avoid tens of thousands of duplicated "TypeFuntions.const(())" strings 2020-05-09 13:02:16 -04:00
Brice Jaglin 331ca6ec9b enable ServiceLoader discovery across classloader layers
java.util.ServiceLoader uses findResources(), which was not
overriden in ReverseLookupClassLoader, causing resources available
in the descendant classloader not to be discovered when a service
loader instance was using the top classloader.
2020-05-08 12:41:44 +02:00
eugene yokota f5eae27c69
Merge pull request #5531 from eatkins/optimize-task-progress
Optimize task progress performance
2020-05-06 23:07:39 -04:00
eugene yokota d2fa0f100e
Merge pull request #5533 from eatkins/ivy-xml
Make IvyXml.writeFiles private[sbt]
2020-05-06 11:46:29 -04:00
eugene yokota f6e64b0a14
Merge pull request #5530 from eatkins/build-sources
Rework build source monitoring
2020-05-06 11:31:56 -04:00
Ethan Atkins e3e53df797 Make IvyXml.writeFiles private[sbt]
I got confused an changed the access for the wrong method to support
https://github.com/sbt/sbt/pull/5364.

Partially reverts 5c55393f1b.
2020-05-06 07:43:22 -07:00
Ethan Atkins 9b2bbdd4cc Report progress on background thread
Having the progress reports directly generated in beforeWork delays the
task from being submitted to the executor. This commit moves all of the
reporting onto the background thread to avoid these delays since
progress is less important than task evaluation.
2020-05-05 21:28:08 -07:00
Ethan Atkins f4c11a63ab Re-implement meta build source checking
The old implementation of checkBuildSources can easily take 20ms to run
when called in MainLoop.processCommand. It is rarely faster than 4-5ms.
To reduce this overhead, I stopped using the checkBuildSources task in
processCommand. Instead, I manually cache the build source hashes in a
global state variable and add a file monitor that invalidate the entire
set of source hashes if any changes are detected. This could probably be
more efficient, but I figure that build sources change infrequently
enough that it's fine to just invalidate the entire list of source
hashes.

Because the CheckBuildSources instance is already watching the meta
build, I reworked Continuous to use that FileTreeRepository for the
build sources if it is available.

Bonus: fixes https://github.com/sbt/sbt/issues/5482
2020-05-05 21:26:04 -07:00
Ethan Atkins b829ac9796 Remove FileManagement
This was unused.
2020-05-05 21:25:56 -07:00
Ethan Atkins 0a06bfe2d5 Optimize TaskProgress.containsSkipTasks
I was surprised to find this method in a flamegraph* so I optimized it.
TaskProgress was actually on the hotpath of task evaluation so every
single task was slower to be enqueued with the CompletionService. After
this change, containsSkipTasks dropped out of the flamegraph.

*The flamegraph was for a compile loop where sbt constantly modified a
single source file and re-compiled it. The containsSkipTasks method
appeared in over 2% of the method calls.
2020-05-05 21:04:09 -07:00
eugene yokota 77cc7285ae
Merge pull request #5517 from eed3si9n/wip/js_workaround
Revert "Mark scala-js-macro pending"
2020-05-05 22:26:32 -04:00
Eugene Yokota de098b94d2 IO 1.4.0-M4 2020-05-05 21:47:48 -04:00
eugene yokota c39ed52112
Merge pull request #5529 from eatkins/dead-contra
Remove TaskProgressFormats autogenerated file
2020-05-05 12:58:24 -04:00
Ethan Atkins ae978b9337 Remove TaskProgressFormats autogenerated file
This file somehow got stuck in the repo although it wasn't actually
used. In fact, it fails to compile at all because
sbt.internal.util.TaskProgress is defined in main, not util-logging. I
noticed this because metals wasn't working well because it was failing
to compile util-logging because of this file. I think the file was
checked in by accident in e28e052b5b.
2020-05-05 08:23:56 -07:00
eugene yokota 5d97d643b4
Merge pull request #5527 from frosforever/tag-fork-groups
Add user defined tags to Tests.Group to allow for better concurrency control
2020-05-04 11:50:47 -04:00
frosforever d1cf37b2ca Update Tests.Group to be bin compat by manually implementing case class methods 2020-05-04 09:29:31 -04:00
frosforever 2e4e3bbe13 Add scripted tests 2020-05-04 09:29:31 -04:00
frosforever 18d51eac58 Add tags to inProccess group as well 2020-05-04 09:29:31 -04:00
frosforever b2942f6321 Add user defined tags to Tests.Group 2020-05-04 09:29:31 -04:00
eugene yokota 5a529bf10c
Merge pull request #5319 from eatkins/terminal
Overhaul terminal io
2020-05-01 22:36:47 -04:00
Ethan Atkins a1ea5b72f3 Support capital letter options in doLoadFailed
Also display invalid response character.
2020-05-01 13:12:37 -07:00
Ethan Atkins 73235d12e0 Switch to lower case for some messages
There is push to move away from complete sentences in warnings.
2020-05-01 13:12:13 -07:00
Ethan Atkins 079cf2178c Add ClearScreenAfterCursor
This communicates intent better than clearScreen(0).
2020-05-01 13:02:48 -07:00
Ethan Atkins 24d4b3549b Set default supershell blank zone to 1
We do not need a large blank zone with the virtual system.out.
2020-05-01 12:35:43 -07:00
Ethan Atkins 5c42c20cdc Simplify setting dumbTerm variable 2020-05-01 12:35:43 -07:00
Ethan Atkins 58822cc3f5 Add virtual System.out for supershell
In order to make supershell work with println, this commit introduces a
virtual System.out to sbt. While sbt is running, we override the default
java.lang.System.out, java.lang.System.in, scala.Console.out and
scala.Console.in (unless the property `sbt.io.virtual` is set to
something other than true). When using virtual io, we buffer all of the
bytes that are written to System.out and Console.out until flush is
called. When flushing the output, we check if there are any progress
lines. If so, we interleave them with the new lines to print.

The flushing happens on a background thread so it should hopefully not
impede task progress.

This commit also adds logic for handling progress when the cursor is not
all the way to the left. We now track all of the bytes that have been
written since the last new line. Supershell will then calculate the
cursor position from those bytes* and move the cursor back to the
correct position. The motivation for this was to make the run command
work with supershell even when multiple main classes were specified.

* This might not be completely reliable if the string contains ansi
cursor movement characters.
2020-05-01 12:35:43 -07:00
Ethan Atkins a0012bab75 Apply minimum task progress length threshold
To reduce the noise of supershell, this commit imposes a 10 millisecond
minimum duration before a task will appear in the supershell lines.
2020-05-01 12:35:43 -07:00
Ethan Atkins a449b1ff2d Move JLine apis into LineReader
It is better that sbt not expose the implementation detail that
LineReader is implemented by JLine. Other terminal related apis should
be handled by sbt.internal.util.Terminal.
2020-05-01 12:35:43 -07:00
Ethan Atkins 9218d3c087 Redraw command prompt after network command
Presently if a server command comes in while in the shell, the client
output can appear on the same line as the command prompt and the command
prompt will not appear again until the user hits enter. This is a
confusing ux. For example, if I start an sbt server and type
the partial command "comp" and then start up a client and run the clean
command followed by a compile, the output looks like:

[info] sbt server started at local:///Users/ethanatkins/.sbt/1.0/server/51cfad3281b3a8a1820a/sock
sbt:scala-compile> comp[info] new client connected: network-1
[success] Total time: 0 s, completed Dec 12, 2019, 7:23:24 PM
[success] Total time: 0 s, completed Dec 12, 2019, 7:23:27 PM
[success] Total time: 2 s, completed Dec 12, 2019, 7:23:31 PM

Now, if I type "ile\n", I get:
[info] sbt server started at local:///Users/ethanatkins/.sbt/1.0/server/51cfad3281b3a8a1820a/sock
ile
[success] Total time: 0 s, completed Dec 12, 2019, 7:23:34 PM
sbt:scala-compile>

Following the same set of inputs after this change, I get:
[info] sbt server started at local:///Users/ethanatkins/.sbt/1.0/server/51cfad3281b3a8a1820a/sock
sbt:scala-compile> comp
[info] new client connected: network-1
[success] Total time: 0 s, completed Dec 12, 2019, 7:25:58 PM
sbt:scala-compile> comp
[success] Total time: 0 s, completed Dec 12, 2019, 7:26:14 PM
sbt:scala-compile> comp
[success] Total time: 1 s, completed Dec 12, 2019, 7:26:17 PM
sbt:scala-compile> compile
[success] Total time: 0 s, completed Dec 12, 2019, 7:26:19 PM
sbt:scala-compile>

To implement this change, I added the redraw() method to LineReader
which is a wrapper around ConsoleReader.drawLine; ConsoleReader.flush().
We invoke LineReader.redraw whenever the ConsoleChannel receives a
ConsolePromptEvent and there is a running thread.

To prevent log lines from being appended to the prompt line, in the
CommandExchange we print a newline character whenever a new command is
received from the network or a network client connects and we believe
that there is an active prompt.
2020-05-01 12:35:43 -07:00
Ethan Atkins 08091d64c1 Log server commands
Prior to this change, if a network command came in, it would run in the
background with no real feedback in the server ui. Prior to this change,
running compile from the thin client would look like:

sbt:scala-compile>
[success] Total time: 1 s, completed Dec 12, 2019, 7:24:43 PM
sbt:scala-compile>

Now it looks like:
sbt:scala-compile>
[info] Running remote command: compile
[success] Total time: 1 s, completed Dec 12, 2019, 7:26:17 PM
sbt:scala-compile>
2020-05-01 12:35:43 -07:00
Ethan Atkins 5afc0f0fdf Don't require newline for load failed commands
It's a bit annoying to have to hit enter here.

Also, this should fix https://github.com/sbt/sbt/issues/5162 because if
there is no System.in attached, the read will return -1 which will cause
sbt to quit.
2020-05-01 12:35:43 -07:00
Ethan Atkins c7b52203a0 Don't require newlines for main classes
There typically are fewer than 10 main classes in a project so allow the
user to just input a single digit in those cases. Otherwise fallback to
a line reader.
2020-05-01 12:35:43 -07:00
Ethan Atkins 44ef718448 Improve run command warning
When the user inputs `run` or `runMain` we shouldn't print the warning
about multiple classes because in the case of run they already will be
prompted to select the classes and in the case of runMain, they are
already required to specify the class name.

Bonus:
 * improve punctuation
 * add clear screen to selector dialogue
 * print selector dialogue in one call to println -- this should prevent
   the possibility of messages from other threads being interlaced with
   the dialogue
2020-05-01 12:35:43 -07:00
Ethan Atkins 293e83ef9f Add Delete line to terminal prompt 2020-05-01 12:35:43 -07:00
Ethan Atkins 2e3a1e767d Don't poll System.in in ConsoleChannel
The ask user thread is a background thread so it's fine for it to block
on System.in. By blocking rather than polling, the cpu utilization of
sbt drops to 0 on idle. We have to explicitly handle <ctrl+d> if we
block though because the JLine console reader will return null both if
the input stream returns -1
2020-05-01 12:35:43 -07:00
Ethan Atkins 7902ec3b7d Add Terminal abstraction
This commit aims to centralize all of the terminal interactions
throughout sbt. It also seeks to hide the jline implementation details
and only expose the apis that sbt needs for interacting with the
terminal.

In general, we should be able to assume that the terminal is in
canonical (line buffered) mode with echo enabled. To switch to raw mode
or to enable/disable echo, there are apis: Terminal.withRawSystemIn and
Terminal.withEcho that take a thunk as parameter to ensure that the
terminal is reset back to the canonical mode afterwards.
2020-05-01 12:35:43 -07:00
Ethan Atkins cd65543d10 Deprecate unused ConsoleUnpromptEvent 2020-05-01 12:28:44 -07:00