-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathcheck-public-headers.sh
More file actions
executable file
·38 lines (30 loc) · 999 Bytes
/
check-public-headers.sh
File metadata and controls
executable file
·38 lines (30 loc) · 999 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#!/bin/bash
#
# Checks that all headers referenced from public api headers are also
# in the public set.
public_hdrs=$(bazel query 'labels(hdrs, attr("visibility", ".*//visibility:public.*", kind("cc_.* rule", //...)))' 2>/dev/null | sed -e 's|^//||' -e 's|:|/|')
echo "$public_hdrs" | sort > /tmp/public_hdrs.txt
echo "Public header list:"
cat /tmp/public_hdrs.txt
echo ""
exit_code=0
if grep -q "^ift/common/try\.h$" /tmp/public_hdrs.txt; then
echo "Error: ift/common/try.h should not be in the public headers list."
exit_code=1
fi
for hdr in $public_hdrs; do
if [[ ! -f "$hdr" ]]; then
continue
fi
includes=$(grep -h -E '^[ \t]*#[ \t]*include[ \t]+"[^"]+"' "$hdr" | sed -E 's/.*"([^"]+)".*/\1/')
for inc in $includes; do
if [[ -f "$inc" ]]; then
if ! grep -q "^${inc}$" /tmp/public_hdrs.txt; then
echo "Error: Public header '$hdr' includes non-public header '$inc'"
exit_code=1
fi
fi
done
done
rm /tmp/public_hdrs.txt
exit $exit_code