我们将 clang-tidy 作为 Action 监听器运行。它可以很容易地消耗与 gcc 编译一样多的 CPU,如果不是更多的话。
这些是否会被计入 --jobs 计数,还是我们必须自己为听众计划(例如,当“正确调整”机器/容器/任何东西时)?
最佳答案
是的,他们是。
演示
我正在运行 3 个 Action + 3 个额外 Action 。他们每个人都睡 3 秒钟,并在他们开始和结束时打印出来。
使用 --jobs=2
,您可以看到叶子 2 和叶子 3 一起构建(从 15:10:00 开始),然后是叶子 1 和叶子 1 监听器(在 15:10:03),最后是叶子 2 监听器和叶子 3 监听器(从 15:10:06 开始) )。
$ bazel clean >&/dev/null && time bazel build //:root --jobs=2 --experimental_action_listener="//:clang-tidy-listener" 2>/dev/null
Start action listener at 15:10:03, argc=1, argv=(--extra_action_file=bazel-out/local-fastbuild/extra_actions/clang-tidy/cc4b710d2c96f16eb0bcc5df6f009f08.xa)
Done action listener at 15:10:06
Start action listener at 15:10:06, argc=1, argv=(--extra_action_file=bazel-out/local-fastbuild/extra_actions/clang-tidy/3001ea27a871bf7b111ee4bbbc1d79dc.xa)
Done action listener at 15:10:09
Start action listener at 15:10:06, argc=1, argv=(--extra_action_file=bazel-out/local-fastbuild/extra_actions/clang-tidy/f88e13a970ce3a66354583c477067b29.xa)
Done action listener at 15:10:09
real 0m9.698s
user 0m0.004s
sys 0m0.012s
$ cat bazel-genfiles/root.txt
leaf1.txt
start: 15:10:03
start: 15:10:06
leaf2.txt
start: 15:10:00
start: 15:10:03
leaf3.txt
start: 15:10:00
start: 15:10:03
使用
--jobs=8
,所有操作都从 15:08:58 开始: $ bazel clean >&/dev/null && time bazel build //:root --jobs=8 --experimental_action_listener="//:clang-tidy-listener" 2>/dev/null
Start action listener at 15:08:58, argc=1, argv=(--extra_action_file=bazel-out/local-fastbuild/extra_actions/clang-tidy/f88e13a970ce3a66354583c477067b29.xa)
Done action listener at 15:09:01
Start action listener at 15:08:58, argc=1, argv=(--extra_action_file=bazel-out/local-fastbuild/extra_actions/clang-tidy/3001ea27a871bf7b111ee4bbbc1d79dc.xa)
Done action listener at 15:09:01
Start action listener at 15:08:58, argc=1, argv=(--extra_action_file=bazel-out/local-fastbuild/extra_actions/clang-tidy/cc4b710d2c96f16eb0bcc5df6f009f08.xa)
Done action listener at 15:09:01
real 0m3.609s
user 0m0.004s
sys 0m0.016s
$ cat bazel-genfiles/root.txt
leaf1.txt
start: 15:08:58
start: 15:09:01
leaf2.txt
start: 15:08:58
start: 15:09:01
leaf3.txt
start: 15:08:58
start: 15:09:01
来源
//:BUILD
:load(":myrule.bzl", "myrule")
genrule(
name = "root",
srcs = [
"leaf1",
"leaf2",
"leaf3",
],
outs = ["root.txt"],
cmd = "( for f in $(SRCS); do basename $$f ; cat $$f ; echo ; done ; ) > $@",
)
[myrule(name = "leaf%d" % i) for i in [1, 2, 3]]
sh_binary(
name = "listener",
srcs = ["listener.sh"],
)
action_listener(
name = "clang-tidy-listener",
mnemonics = ["FooAction"],
extra_actions = [":clang-tidy"],
)
extra_action(
name = "clang-tidy",
tools = [":listener"],
cmd = "$(location :listener) --extra_action_file=$(EXTRA_ACTION_FILE)",
)
//:myrule.bzl
:# Based on https://bazel.build/versions/master/docs/skylark/cookbook.html#simple-shell-command
def _impl(ctx):
output = ctx.outputs.out
ctx.action(
outputs=[output],
mnemonic="FooAction",
command="( echo \"start: $(date +%%H:%%M:%%S)\" ; sleep 3 ; echo \"start: $(date +%%H:%%M:%%S)\" ; ) > %s" % output.path)
myrule = rule(
implementation=_impl,
outputs={"out": "%{name}.txt"},
)
//:listener.sh
:#!/bin/bash
echo "Start action listener at $(date +%H:%M:%S), argc=$#, argv=($@)"
sleep 3
echo "Done action listener at $(date +%H:%M:%S)"
关于bazel - --experimental_action_listeners 是否计入 --jobs?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/44449785/