Short answer
Pass -no-colors
to sbt
on the command line, per the
sbt FAQ:
$ sbt -no-colors 'test:runMain gcd.GCDMain'
Despite the name "no colors", it suppresses all terminal escape stuff, including the progress bars.
Other alternatives
The option can also be spelled --no-colors
(two hyphens), which is how it appears in the output of sbt --help
(and sbt -help
).
The same effect can be achieved by passing -Dsbt.log.noformat=true
to sbt
(or to java
if invoking that directly) as indicated in this answer:
$ sbt -Dsbt.log.noformat=true 'test:runMain gcd.GCDMain'
It can also be achieved by setting the JAVA_OPTS
environment variable to -Dsbt.log.noformat=true
:
$ JAVA_OPTS=-Dsbt.log.noformat=true sbt 'test:runMain gcd.GCDMain'
If you are using sbt-launch.jar
, then you have to use the -D
switch because -no-colors
is not recognized in that context (the sbt
shell script is what recognizes -no-colors
):
$ java -jar ~/opt/sbt-1.3.4/bin/sbt-launch.jar -Dsbt.log.noformat=true 'test:runMain gcd.GCDMain'
Finally, when sbt
detects that its stdout is not a TTY, it will suppress color output:
$ sbt 'test:runMain gcd.GCDMain' | cat
That's not a good option in a Makefile though because you lose the exit status of sbt
(without further shenanigans).
Unfortunately, sbt
does not respect NO_COLOR
.
Chisel output has some colors anyway
When using Chisel, for example the chisel template, even with -no-colors
, some terminal escape codes appear in the output anyway:
$ sbt -no-colors 'test:runMain gcd.GCDMain' | cat -tev
[info] Loading settings for project chisel-template-build from plugins.sbt ...$
[info] Loading project definition from /home/scott/wrk/learn/chisel/chisel-template/project$
[info] Loading settings for project chisel-template from build.sbt ...$
[info] Set current project to chisel-module-template (in build file:/home/scott/wrk/learn/chisel/chisel-template/)$
[warn] Multiple main classes detected. Run 'show discoveredMainClasses' to see the list$
[info] running gcd.GCDMain $
[^[[35minfo^[[0m] [0.001] Elaborating design...$
[^[[35minfo^[[0m] [1.064] Done elaborating.$
Total FIRRTL Compile Time: 512.0 ms$
file loaded in 0.114380184 seconds, 22 symbols, 17 statements$
[^[[35minfo^[[0m] [0.001] SEED 1581769687441$
test GCD Success: 168 tests passed in 1107 cycles in 0.047873 seconds 23123.91 Hz$
[^[[35minfo^[[0m] [0.037] RAN 1102 CYCLES PASSED$
[success] Total time: 3 s, completed Feb 15, 2020 4:28:09 AM$
Note the [^[[35minfo^[[0m]
output near the end. This happens because chiselFrontend/src/main/scala/chisel3/internal/Error.scala unconditionally prints color escape sequences (see the tag
function), which is arguably a bug in Chisel since its output is clearly meant to look similar to sbt
output.
Effect of setsid
In your example Makefile, you're invoking sbt
via setsid
. As far as I can tell, everything I've said applies equally to that circumstance. However, you probably want to pass --wait
to setsid
so it will wait for sbt
to complete before exiting. In my testing, setsid
will implicitly wait only when stdout is not a TTY, but I doubt you actually want that hidden variability.