2

可以在https://github.com/versemonger/bazel-test找到一个示例 repo

4

1 回答 1

4

Bazel 默认情况下根本不实施任何标头隐私检查。但是,在 clang 和最新版本的 Bazel 下,可以使用该功能启用所谓的“分层检查”验证layering_check。例如,使用 OP 的示例存储库和 Bazel 4.0.0,我看到:

$ CC=clang bazel build //sub --features layering_check
INFO: Analyzed target //sub:sub (16 packages loaded, 56 targets configured).
INFO: Found 1 target...
ERROR: sub/BUILD:3:10: Compiling sub/greet.cpp failed: (Exit 1): clang failed: error executing command /usr/bin/clang -U_FORTIFY_SOURCE -fstack-protector -Wall -Wthread-safety -Wself-assign -fcolor-diagnostics -fno-omit-frame-pointer '-std=c++0x' -MD -MF ... (remaining 28 argument(s) skipped)

Use --sandbox_debug to see verbose messages from the sandbox clang failed: error executing command /usr/bin/clang -U_FORTIFY_SOURCE -fstack-protector -Wall -Wthread-safety -Wself-assign -fcolor-diagnostics -fno-omit-frame-pointer '-std=c++0x' -MD -MF ... (remaining 28 argument(s) skipped)

Use --sandbox_debug to see verbose messages from the sandbox
sub/greet.cpp:1:10: error: use of private header from outside its module: 'f.h' [-Wprivate-header]
#include "f.h"
         ^

layering_check也可以通过在文件中设置features = ['layering_check']BUILD每个目标的基础上启用。

于 2021-04-20T19:21:27.497 回答