简体   繁体   English

如何知道受 git commit 影响的所有 Bazel 目标?

[英]How to know all Bazel targets affected by a git commit?

A git commit may change some workspace rules , some source files, .bazelrc, etc. How to get all Bazel targets affected, thus need to rebuild and test, after such change?一次 git commit 可能会改变一些工作区规则、一些源文件、.bazelrc 等。如何让所有 Bazel 目标受到影响,从而需要在此类更改后重建和测试?

In Buck, we can run buck targets --show-rulekey //... to see all rule key changes between two Git revisions.在 Buck 中,我们可以运行buck targets --show-rulekey //...以查看两个 Git 修订版之间的所有规则键更改。 Is there any equivalent command in Bazel? Bazel 中是否有任何等效的命令?

我没有答案,但是这个 bazel-discuss 线程可能会有所帮助: https ://groups.google.com/d/msg/bazel-discuss/I9udqWIcEdI/iczVgWLOBQAJ“选择要在 CI 中运行的 bazel 目标 - 可能的方法”

See here: https://github.com/bazelbuild/bazel/blob/master/scripts/ci/ci.sh见这里: https : //github.com/bazelbuild/bazel/blob/master/scripts/ci/ci.sh

# 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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM