Add script to ensure visibility is OK (#332)

* Add script to ensure visibility is OK

* typo

* another typo
This commit is contained in:
Preston Van Loon 2018-07-26 01:13:07 -04:00 committed by Nishant Das
parent 2bd1e334bc
commit 5776e573ed
4 changed files with 35 additions and 3 deletions

View File

@ -65,9 +65,12 @@ matrix:
test \
//... $REMOTE_FLAGS
# Check that BUILD files are formatted correctly.
# Check that BUILD files are formatted correctly.
- ./check_gazelle.sh
# Check that target visibility is correct..
- ./check_visibility.sh
# Shutdown must be last.
- bazel shutdown

View File

@ -4,7 +4,7 @@ go_library(
name = "go_default_library",
srcs = ["service.go"],
importpath = "github.com/prysmaticlabs/prysm/beacon-chain/network",
visibility = ["//visibility:public"],
visibility = ["//beacon-chain:__subpackages__"],
deps = [
"//beacon-chain/types:go_default_library",
"@com_github_sirupsen_logrus//:go_default_library",

View File

@ -4,7 +4,7 @@ go_library(
name = "go_default_library",
srcs = ["service.go"],
importpath = "github.com/prysmaticlabs/prysm/beacon-chain/sync",
visibility = ["//visibility:public"],
visibility = ["//beacon-chain:__subpackages__"],
deps = [
"//beacon-chain/types:go_default_library",
"@com_github_sirupsen_logrus//:go_default_library",

29
check_visibility.sh Executable file
View File

@ -0,0 +1,29 @@
#!/bin/bash
# Continous Integration script to check that BUILD.bazel files have the correct
# visibility.
# Protected packages are:
# //beacon-chain/...
# //client/...
# Duplicate redirect 5 to stdout so that it can be captured, but still printed
# nicely.
exec 5>&1
# Run gazelle while piping a copy of the output to stdout via 5.
changes=$(
bazel query 'visible(//... except (//beacon-chain/... union //client/...), (//beacon-chain/... union //client/...))' | tee >(cat - >&5)
)
# If the captured stdout is not empty then targets are exposed!
if [ -z "$changes" ]
then
echo "OK: Visibility is good."
exit 0
else
echo "FAIL: The above targets belong to protected packages and the targets \
are visible outside of their package!"
echo "Please reduce the target visibility."
exit 1
fi