Skip to content

Commit

Permalink
Add all the sources to //:srcs filegroup and add a check to detect
Browse files Browse the repository at this point in the history
missing file to it.

We need to activate this check on presubmits

--
Change-Id: Ia95e92d3816ce92bb69bc0e2cf56e9c60b68d970
Reviewed-on: https://bazel-review.googlesource.com/#/c/3949/
MOS_MIGRATED_REVID=126404792
  • Loading branch information
damienmg committed Jul 1, 2016
1 parent fdb5a8c commit 7d265e0
Show file tree
Hide file tree
Showing 50 changed files with 291 additions and 23 deletions.
1 change: 1 addition & 0 deletions BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ filegroup(
"bazel-*", # convenience symlinks
"out", # IntelliJ with setup-intellij.sh
"output", # output of compile.sh
"WORKSPACE.user.bzl", # generated workspace file
".*", # mainly .git* files
],
) + [
Expand Down
34 changes: 33 additions & 1 deletion compile.sh
Original file line number Diff line number Diff line change
Expand Up @@ -39,21 +39,24 @@ function usage() {
echo " Commands for developers:" >&2
echo " all = compile,determinism,test" >&2
echo " determinism = test for stability of Bazel builds" >&2
echo " srcs = test that //:srcs contains all the sources" >&2
echo " test = run the full test suite of Bazel" >&2
exit 1
}

function parse_options() {
local keywords="(compile|all|determinism|bootstrap|test)"
local keywords="(compile|all|determinism|bootstrap|srcs|test)"
COMMANDS="${1:-compile}"
[[ "${COMMANDS}" =~ ^$keywords(,$keywords)*$ ]] || usage "$@"
DO_COMPILE=
DO_CHECKSUM=
DO_FULL_CHECKSUM=1
DO_TESTS=
DO_SRCS_TEST=
[[ "${COMMANDS}" =~ (compile|all) ]] && DO_COMPILE=1
[[ "${COMMANDS}" =~ (bootstrap|determinism|all) ]] && DO_CHECKSUM=1
[[ "${COMMANDS}" =~ (bootstrap) ]] && DO_FULL_CHECKSUM=
[[ "${COMMANDS}" =~ (srcs|all) ]] && DO_SRCS_TEST=1
[[ "${COMMANDS}" =~ (test|all) ]] && DO_TESTS=1

BAZEL_BIN=${2:-"bazel-bin/src/bazel"}
Expand Down Expand Up @@ -127,6 +130,35 @@ if [ $DO_CHECKSUM ]; then
fi
fi

#
# Test that //:srcs contains all the sources
#
if [ $DO_SRCS_TEST ]; then
new_step "Checking that //:srcs contains all the sources"
log "Querying //:srcs"
${BAZEL} query 'kind("source file", deps(//:srcs))' 2>/dev/null \
| grep -v '^@' \
| sed -e 's|^//||' | sed 's|^:||' | sed 's|:|/|' \
| sort -u >"${OUTPUT_DIR}/srcs-query"

log "Finding all files"
# See file BUILD for the list of grep -v exceptions.
# tools/defaults package is hidden by Bazel so cannot be put in the srcs.
find . -type f | sed 's|./||' \
| grep -v '^bazel-' | grep -v '^WORKSPACE.user.bzl' \
| grep -v '^\.' | grep -v '^out/' | grep -v '^output/' \
| grep -v '^tools/defaults/BUILD' \
| sort -u >"${OUTPUT_DIR}/srcs-find"

log "Diffing"
res="$(diff -U 0 "${OUTPUT_DIR}/srcs-find" "${OUTPUT_DIR}/srcs-query" | sed 's|^-||' | grep -Ev '^(@@|\+\+|--)' || true)"

if [ -n "${res}" ]; then
fail "//:srcs filegroup do not contains all the sources, missing:
${res}"
fi
fi

#
# Tests
#
Expand Down
4 changes: 3 additions & 1 deletion examples/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@ package(default_visibility = ["//visibility:public"])

filegroup(
name = "srcs",
srcs = [
srcs = glob(["**"]) + [
"//examples/android/java/bazel:srcs",
"//examples/cpp:srcs",
"//examples/gen:srcs",
"//examples/java-native:srcs",
"//examples/java-skylark:srcs",
"//examples/j2objc:srcs",
"//examples/objc:srcs",
"//examples/py:srcs",
"//examples/py_native:srcs",
Expand Down
6 changes: 6 additions & 0 deletions examples/android/java/bazel/BUILD
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
filegroup(
name = "srcs",
srcs = glob(["**"]),
visibility = ["//examples:__pkg__"],
)

android_library(
name = "lib",
srcs = ["Lib.java"],
Expand Down
5 changes: 1 addition & 4 deletions examples/cpp/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,5 @@ cc_test(

filegroup(
name = "srcs",
srcs = ["BUILD"] + glob([
"**/*.cc",
"**/*.h",
]),
srcs = glob(["**"]),
)
6 changes: 1 addition & 5 deletions examples/j2objc/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,6 @@ objc_binary(

filegroup(
name = "srcs",
srcs = glob([
"J2ObjcExample/*",
"src/**",
"BUILD",
]),
srcs = glob(["**"]),
visibility = ["//examples:__pkg__"],
)
2 changes: 1 addition & 1 deletion examples/java-native/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package(default_visibility = ["//visibility:public"])

filegroup(
name = "srcs",
srcs = [
srcs = glob(["**"]) + [
"//examples/java-native/src/main/java/com/example/myproject:srcs",
"//examples/java-native/src/main/resources:srcs",
"//examples/java-native/src/test/java/com/example/myproject:srcs",
Expand Down
2 changes: 1 addition & 1 deletion examples/java-skylark/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package(default_visibility = ["//visibility:public"])

filegroup(
name = "srcs",
srcs = [
srcs = glob(["**"]) + [
"//examples/java-skylark/src/main/java/com/example/myproject:srcs",
"//examples/java-skylark/src/main/resources:srcs",
"//examples/java-skylark/src/test/java/com/example/myproject:srcs",
Expand Down
2 changes: 1 addition & 1 deletion examples/shell/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,5 @@ sh_test(

filegroup(
name = "srcs",
srcs = ["BUILD"] + glob(["**/*.sh"]) + glob(["**/*.txt"]),
srcs = glob(["**"]),
)
5 changes: 4 additions & 1 deletion scripts/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ sh_test(

filegroup(
name = "srcs",
srcs = glob(["**"]),
srcs = glob(["**"]) + [
"//scripts/release:srcs",
"//scripts/packages:srcs",
],
visibility = ["//:__pkg__"],
)
6 changes: 6 additions & 0 deletions scripts/packages/BUILD
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
filegroup(
name = "srcs",
srcs = glob(["**"]),
visibility = ["//scripts:__pkg__"],
)

sh_binary(
name = "package-info-generator",
srcs = ["package_info_generator.sh"],
Expand Down
6 changes: 6 additions & 0 deletions scripts/release/BUILD
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
# Scripts for building Bazel releases
package(default_visibility = ["//visibility:private"])

filegroup(
name = "srcs",
srcs = glob(["**"]),
visibility = ["//scripts:__pkg__"],
)

sh_library(
name = "relnotes",
srcs = ["relnotes.sh"],
Expand Down
10 changes: 9 additions & 1 deletion src/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ genrule(
"//third_party:gpl-srcs",
"//third_party/iossim:srcs",
"//third_party/java/jarjar:srcs",
"//third_party/java/jdk/langtools:srcs",
"//third_party/java/jdk/langtools:test-srcs",
"//third_party/py/concurrent:srcs",
"//third_party/py/gflags:srcs",
"//src/java_tools/buildjar/java/com/google/devtools/build/buildjar/jarhelper:srcs",
Expand Down Expand Up @@ -295,6 +295,13 @@ filegroup(
"//src/objc_tools/bundlemerge:srcs",
"//src/objc_tools/plmerge:srcs",
"//src/objc_tools/xcodegen:srcs",
"//src/test/cpp:srcs",
"//src/test/java/com/google/devtools/build/android:srcs",
"//src/test/java/com/google/devtools/build/docgen:srcs",
"//src/test/java/com/google/devtools/build/lib:srcs",
"//src/test/java/com/google/devtools/build/skyframe:srcs",
"//src/test/java/com/google/devtools/common/options:srcs",
"//src/test/shell:srcs",
"//src/tools/android/java/com/google/devtools/build/android:srcs",
"//src/tools/generate_workspace:srcs",
"//src/tools/xcode/actoolwrapper:srcs",
Expand All @@ -309,6 +316,7 @@ filegroup(
"//src/tools/xcode/xcodelocator:srcs",
"//src/tools/xcode/xcrunwrapper:srcs",
"//src/tools/xcode-common:srcs",
"//src/tools/remote_worker:srcs",
],
visibility = ["//:__pkg__"],
)
2 changes: 2 additions & 0 deletions src/java_tools/buildjar/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ filegroup(
"//src/java_tools/buildjar/java/com/google/devtools/build/buildjar:srcs",
"//src/java_tools/buildjar/java/com/google/devtools/build/java/bazel:srcs",
"//src/java_tools/buildjar/java/com/google/devtools/build/java/turbine:srcs",
"//src/java_tools/buildjar/javatests/com/google/devtools/build/java/bazel:srcs",
"//src/java_tools/buildjar/javatests/com/google/devtools/build/java/turbine:srcs",
],
visibility = ["//src:__pkg__"],
)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
filegroup(
name = "srcs",
srcs = glob(["**"]),
visibility = ["//src/java_tools/buildjar:__pkg__"],
)

java_test(
name = "BazelJavaCompilerTest",
size = "small",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
filegroup(
name = "srcs",
srcs = glob(["**"]) + ["//src/java_tools/buildjar/javatests/com/google/devtools/build/java/turbine/javac:srcs"],
visibility = ["//src/java_tools/buildjar:__pkg__"],
)

package_group(
name = "packages",
packages = ["//src/java_tools/buildjar/..."],
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
filegroup(
name = "srcs",
srcs = glob(["**"]),
visibility = ["//src/java_tools/buildjar/javatests/com/google/devtools/build/java/turbine:__pkg__"],
)

java_test(
name = "JavacTurbineTest",
srcs = ["JavacTurbineTest.java"],
Expand Down
6 changes: 6 additions & 0 deletions src/test/cpp/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@
# C++ utility tests for Bazel
package(default_visibility = ["//visibility:public"])

filegroup(
name = "srcs",
srcs = glob(["**"]) + ["//src/test/cpp/util:srcs"],
visibility = ["//src:__pkg__"],
)

cc_test(
name = "blaze_util_test",
srcs = ["blaze_util_test.cc"],
Expand Down
6 changes: 6 additions & 0 deletions src/test/cpp/util/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@
# C++ utility tests for Bazel
package(default_visibility = ["//visibility:public"])

filegroup(
name = "srcs",
srcs = glob(["**"]),
visibility = ["//src/test/cpp:__pkg__"],
)

cc_test(
name = "md5_test",
srcs = ["md5_test.cc"],
Expand Down
11 changes: 11 additions & 0 deletions src/test/java/com/google/devtools/build/android/BUILD
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
filegroup(
name = "srcs",
srcs = glob(["**"]) + [
"//src/test/java/com/google/devtools/build/android/ideinfo:srcs",
"//src/test/java/com/google/devtools/build/android/idlclass:srcs",
"//src/test/java/com/google/devtools/build/android/resources:srcs",
"//src/test/java/com/google/devtools/build/android/ziputils:srcs",
],
visibility = ["//src:__pkg__"],
)

java_test(
name = "AndroidResourceCompilationActionTest",
size = "medium",
Expand Down
6 changes: 6 additions & 0 deletions src/test/java/com/google/devtools/build/android/ideinfo/BUILD
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
filegroup(
name = "srcs",
srcs = glob(["**"]),
visibility = ["//src/test/java/com/google/devtools/build/android:__pkg__"],
)

java_test(
name = "PackageParserTest",
size = "small",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
filegroup(
name = "srcs",
srcs = glob(["**"]),
visibility = ["//src/test/java/com/google/devtools/build/android:__pkg__"],
)

java_test(
name = "IdlClassTest",
size = "medium",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
filegroup(
name = "srcs",
srcs = glob(["**"]),
visibility = ["//src/test/java/com/google/devtools/build/android:__pkg__"],
)

java_test(
name = "RClassWriterTest",
size = "medium",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
filegroup(
name = "srcs",
srcs = glob(["**"]),
visibility = ["//src/test/java/com/google/devtools/build/android:__pkg__"],
)

java_test(
name = "ziputils-tests",
srcs = glob(["*.java"]),
Expand Down
6 changes: 6 additions & 0 deletions src/test/java/com/google/devtools/build/docgen/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@ package(

licenses(["notice"]) # Apache 2.0

filegroup(
name = "srcs",
srcs = glob(["**"]),
visibility = ["//src:__pkg__"],
)

test_suite(
name = "all_tests",
tags = ["docgen"],
Expand Down
12 changes: 12 additions & 0 deletions src/test/java/com/google/devtools/build/lib/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,18 @@ package(
default_visibility = ["//src/test/java/com/google/devtools/build/lib:__subpackages__"],
)

filegroup(
name = "srcs",
srcs = glob(["**"]) + [
"//src/test/java/com/google/devtools/build/lib/skylark:srcs",
"//src/test/java/com/google/devtools/build/lib/skyframe:srcs",
"//src/test/java/com/google/devtools/build/lib/rules/repository:srcs",
"//src/test/java/com/google/devtools/build/lib/bazel/repository:srcs",
"//src/test/java/com/google/devtools/build/lib/buildtool:srcs",
],
visibility = ["//src:__pkg__"],
)

# This should correspond to the list of "EMBEDDED_TOOLS" in TestConstants.java.bazel.
filegroup(
name = "embedded_scripts",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
filegroup(
name = "srcs",
srcs = glob(["**"]) + ["//src/test/java/com/google/devtools/build/lib/bazel/repository/downloader:srcs"],
visibility = ["//src/test/java/com/google/devtools/build/lib:__pkg__"],
)

java_test(
name = "RepositoryTests",
srcs = glob([
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
filegroup(
name = "srcs",
srcs = glob(["**"]),
visibility = ["//src/test/java/com/google/devtools/build/lib/bazel/repository:__pkg__"],
)

java_test(
name = "DownloaderTests",
srcs = glob(["*.java"]),
Expand Down
6 changes: 6 additions & 0 deletions src/test/java/com/google/devtools/build/lib/buildtool/BUILD
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
filegroup(
name = "srcs",
srcs = glob(["**"]),
visibility = ["//src/test/java/com/google/devtools/build/lib:__pkg__"],
)

java_library(
name = "testutil",
srcs = glob(["util/*.java"]),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
filegroup(
name = "srcs",
srcs = glob(["**"]),
visibility = ["//src/test/java/com/google/devtools/build/lib:__pkg__"],
)

java_test(
name = "RepositoryTests",
srcs = glob(["*.java"]),
Expand Down
Loading

0 comments on commit 7d265e0

Please sign in to comment.