diff --git a/.travis.yml b/.travis.yml index 359a7039ff..4cd4f468f5 100644 --- a/.travis.yml +++ b/.travis.yml @@ -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 diff --git a/beacon-chain/network/BUILD.bazel b/beacon-chain/network/BUILD.bazel index db27f9401b..aad899e82a 100644 --- a/beacon-chain/network/BUILD.bazel +++ b/beacon-chain/network/BUILD.bazel @@ -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", diff --git a/beacon-chain/sync/BUILD.bazel b/beacon-chain/sync/BUILD.bazel index 08e177dcdf..e0d37de9b1 100644 --- a/beacon-chain/sync/BUILD.bazel +++ b/beacon-chain/sync/BUILD.bazel @@ -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", diff --git a/check_visibility.sh b/check_visibility.sh new file mode 100755 index 0000000000..2bfcb64458 --- /dev/null +++ b/check_visibility.sh @@ -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