Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/scala/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Scala 使用sbt构建凿子时,如何关闭进度条等,以使输出干净?_Scala_Sbt_Chisel - Fatal编程技术网

Scala 使用sbt构建凿子时,如何关闭进度条等,以使输出干净?

Scala 使用sbt构建凿子时,如何关闭进度条等,以使输出干净?,scala,sbt,chisel,Scala,Sbt,Chisel,当使用sbt构建凿子时,当作为批处理运行时,如何关闭进度条等,使输出像大多数编译器一样干净 也就是说,我喜欢在makefile中使用sbt构建凿子,如下所示: ${VLOG_DIR}/${NAME}.v: ${NAME}.scala setsid sbt \ 'runMain ${NAME}.${NAME} --top-name ${NAME} --target-dir ${VLOG_DIR}' 然而,sbt/scala/凿子喜欢在构建时尝试生成某种进度条,

当使用sbt构建凿子时,当作为批处理运行时,如何关闭进度条等,使输出像大多数编译器一样干净

也就是说,我喜欢在makefile中使用sbt构建凿子,如下所示:

${VLOG_DIR}/${NAME}.v: ${NAME}.scala
        setsid sbt \
          'runMain ${NAME}.${NAME} --top-name ${NAME} --target-dir ${VLOG_DIR}'
然而,sbt/scala/凿子喜欢在构建时尝试生成某种进度条,这些进度条发出终端转义码,以尝试就地更新输出。在我的shell中运行时,这不太好,但在emacs中运行时,会造成巨大的混乱:

make
setsid sbt \
  'runMain HelloWorld.HelloWorld --top-name HelloWorld --target-dir Gen_HelloWor\
ld.verilog_dir'
^[[0m[^[[0m^[[0minfo^[[0m] ^[[0m^[[0mLoading project definition from /home/user/h\
ello-chisel/project^[[0m
^[[2K
^[[2K
^[[2K
^[[2K
^[[2K
^[[5A^[[2K
^[[2K
^[[2K
^[[2K
^[[2K
^[[2K  | => hello-chisel-build / update 0s
^[[6A^[[2K
^[[2K
尤其是当出现错误消息时:

^[[2K
^[[2K
^[[2K  | => hello-chisel / Compile / compileIncremental 1s
^[[6A^[[2K^[[0m[^[[0m^[[31merror^[[0m] ^[[0m^[[0m/home/user/hello-chisel/HelloWor\
ld.scala:46:17: overloaded method value apply with alternatives:^[[0m
^[[2K
如何关闭所有这些功能,并获得外观正常、错误消息清晰的输出?

简短回答 根据,在命令行上将
-no colors
传递到
sbt
:

尽管名称为“无颜色”,但它会抑制所有终端转义内容,包括进度条

其他选择 该选项也可以拼写为
--no colors
(两个连字符),这就是它在
sbt--help
(和
sbt--help
)输出中的显示方式

通过将
-Dsbt.log.noformat=true
传递到
sbt
(或者直接调用
java
),可以实现相同的效果,如所示:

也可以通过将
JAVA_OPTS
环境变量设置为
-Dsbt.log.noformat=true

$ JAVA_OPTS=-Dsbt.log.noformat=true sbt 'test:runMain gcd.GCDMain'
如果正在使用,则必须使用
-D
开关,因为在该上下文中无法识别
-no colors
(sbtshell脚本可识别
-no colors
):

最后,当
sbt
检测到其标准输出不是TTY时,它将抑制颜色输出:

$ sbt 'test:runMain gcd.GCDMain' | cat
但是,在Makefile中,这不是一个好选项,因为您将丢失
sbt
的退出状态(无需进一步修改)

不幸的是,
sbt
不尊重

凿子输出仍然有一些颜色 例如,使用时,即使使用
-无颜色
,一些终端转义码仍会显示在输出中:

$ 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$
请注意结尾附近的
[^[[35minfo^[[0m]
输出。之所以出现这种情况,是因为无条件打印颜色转义序列(请参阅
标记
函数),这可以说是凿子中的一个缺陷,因为其输出显然与
sbt
输出类似

setsid的作用 在您的示例Makefile中,您正在通过调用
sbt
。据我所知,我所说的一切都同样适用于这种情况。但是,您可能希望将
--wait
传递到
setId
,因此它将等待
sbt
完成,然后退出。在我的测试中,
setId
将隐式地只有当stdout不是TTY时,我怀疑你是否真的想要隐藏的可变性

$ java -jar ~/opt/sbt-1.3.4/bin/sbt-launch.jar -Dsbt.log.noformat=true 'test:runMain gcd.GCDMain'
$ sbt 'test:runMain gcd.GCDMain' | cat
$ 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$