如何知道受 git commit 影响的所有 Bazel 目标?
Posted
技术标签:
【中文标题】如何知道受 git commit 影响的所有 Bazel 目标?【英文标题】:How to know all Bazel targets affected by a git commit? 【发布时间】:2019-04-08 17:39:32 【问题描述】:一个 git commit 可能会改变一些workspace rules,一些源文件,.bazelrc 等。如何让所有的 Bazel 目标受到影响,因此需要重新构建和测试,在这样的变化之后?
在 Buck 中,我们可以运行 buck targets --show-rulekey //...
来查看两个 Git 修订版之间的所有规则键更改。 Bazel中有没有等价的命令?
【问题讨论】:
【参考方案1】:见here:
# Under Apache 2.0 licence
COMMIT_RANGE=$COMMIT_RANGE:-$(git merge-base origin/master HEAD)".."
# Go to the root of the repo
cd "$(git rev-parse --show-toplevel)"
# Get a list of the current files in package form by querying Bazel.
files=()
for file in $(git diff --name-only $COMMIT_RANGE ); do
files+=($(bazel query $file))
echo $(bazel query $file)
done
# Query for the associated buildables
buildables=$(bazel query \
--keep_going \
--noshow_progress \
"kind(.*_binary, rdeps(//..., set($files[*])))")
# Run the tests if there were results
if [[ ! -z $buildables ]]; then
echo "Building binaries"
bazel build $buildables
fi
tests=$(bazel query \
--keep_going \
--noshow_progress \
"kind(test, rdeps(//..., set($files[*]))) except attr('tags', 'manual', //...)")
# Run the tests if there were results
if [[ ! -z $tests ]]; then
echo "Running tests"
bazel test $tests
fi
也可以看看bazel-diff。
【讨论】:
【参考方案2】:我没有答案,但这个 bazel-discuss 线程可能会有所帮助:https://groups.google.com/d/msg/bazel-discuss/I9udqWIcEdI/iczVgWLOBQAJ“选择 bazel 目标以在 CI 中运行 - 可能的方法”
【讨论】:
以上是关于如何知道受 git commit 影响的所有 Bazel 目标?的主要内容,如果未能解决你的问题,请参考以下文章