可以在 https://github.com/versemonger/bazel-test 找到一个示例存储库
默认情况下,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"
^
还可以通过在BUILD
文件中设置features = ['layering_check']
来按目标启用layering_check
。