Add gen_all --check-only to CI

Adds --check-only to tools/gen_all. This just passes down
the arg to the gen scripts. Adds the invocation to all CI bots.
Also does minor cleanups to the CI scripts.

Bug: 123498112
Change-Id: I3215b88a18f8e5b6ea6dd2e731134f96e64e9e8e
diff --git a/src/perfetto_cmd/perfetto_config.descriptor.h b/src/perfetto_cmd/perfetto_config.descriptor.h
index 3986752..8582caa 100644
--- a/src/perfetto_cmd/perfetto_config.descriptor.h
+++ b/src/perfetto_cmd/perfetto_config.descriptor.h
@@ -10,7 +10,7 @@
 // This file was autogenerated by tools/gen_binary_descriptors. Do not edit.
 
 // SHA1(tools/gen_binary_descriptors)
-// 5600f41770c36931db20de64a430f87e1a38fe05
+// 192b582ae52bb07b3d3ba66a94bcfd3127a5f42f
 // SHA1(protos/perfetto/config/perfetto_config.proto)
 // 8e2725637f1e6b1cffdd2de91ebb6570a9d3f9e2
 
diff --git a/src/trace_processor/metrics/metrics.descriptor.h b/src/trace_processor/metrics/metrics.descriptor.h
index f50e3ee..9a19aa6 100644
--- a/src/trace_processor/metrics/metrics.descriptor.h
+++ b/src/trace_processor/metrics/metrics.descriptor.h
@@ -10,7 +10,7 @@
 // This file was autogenerated by tools/gen_binary_descriptors. Do not edit.
 
 // SHA1(tools/gen_binary_descriptors)
-// 5600f41770c36931db20de64a430f87e1a38fe05
+// 192b582ae52bb07b3d3ba66a94bcfd3127a5f42f
 // SHA1(protos/perfetto/metrics/metrics.proto)
 // 9410d04aaa3afacc42cdfa881f34ab41f3bff56b
 
diff --git a/test/ci/android_tests.sh b/test/ci/android_tests.sh
index 9c9fcf0..89d27cf 100755
--- a/test/ci/android_tests.sh
+++ b/test/ci/android_tests.sh
@@ -13,19 +13,8 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
-set -eux -o pipefail
-
-# cd into the project root (two levels up from /test/ci).
-cd $(dirname ${BASH_SOURCE[0]})/../..
-
-OUT_PATH="out/dist"
-
-tools/install-build-deps
-
-if [[ -e buildtools/clang/bin/llvm-symbolizer ]]; then
-  export ASAN_SYMBOLIZER_PATH="buildtools/clang/bin/llvm-symbolizer"
-  export MSAN_SYMBOLIZER_PATH="buildtools/clang/bin/llvm-symbolizer"
-fi
+INSTALL_BUILD_DEPS_ARGS=""  # Run without args, without --no-android.
+source $(dirname ${BASH_SOURCE[0]})/common.sh
 
 # Run the emulator earlier so by the time we build it's booted.
 # tools/run_android_test will perform a wait-for-device. This is just an
diff --git a/test/ci/bazel_tests.sh b/test/ci/bazel_tests.sh
index a7a4359..492dec0 100755
--- a/test/ci/bazel_tests.sh
+++ b/test/ci/bazel_tests.sh
@@ -13,10 +13,8 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
-set -eux -o pipefail
-
-# cd into the project root (two levels up from /test/ci).
-cd $(dirname ${BASH_SOURCE[0]})/../..
+INSTALL_BUILD_DEPS_ARGS="SKIP"
+source $(dirname ${BASH_SOURCE[0]})/common.sh
 
 bazel build //:all --verbose_failures
 
@@ -28,3 +26,6 @@
 ./bazel-bin/perfetto -c :test -o $TRACE
 kill $(jobs -p)
 ./bazel-bin/trace_processor_shell -q <(echo 'select count(1) from sched') $TRACE
+
+# Check the amalgamated build here to avoid slowing down all the Linux bots.
+tools/test_gen_amalgamated.py
\ No newline at end of file
diff --git a/test/ci/common.sh b/test/ci/common.sh
new file mode 100644
index 0000000..3b51dac
--- /dev/null
+++ b/test/ci/common.sh
@@ -0,0 +1,33 @@
+#!/bin/bash
+# Copyright (C) 2019 The Android Open Source Project
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#      http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+set -eux -o pipefail
+
+cd $(dirname ${BASH_SOURCE[0]})/../..
+OUT_PATH="out/dist"
+
+if [[ -e buildtools/clang/bin/llvm-symbolizer ]]; then
+  export ASAN_SYMBOLIZER_PATH="buildtools/clang/bin/llvm-symbolizer"
+  export MSAN_SYMBOLIZER_PATH="buildtools/clang/bin/llvm-symbolizer"
+fi
+
+if [ "$INSTALL_BUILD_DEPS_ARGS" != "SKIP" ]; then
+tools/install-build-deps $INSTALL_BUILD_DEPS_ARGS
+fi
+
+# Performs checks on generated protos and build files.
+tools/gn gen out/tmp.protoc --args="is_debug=false cc_wrapper=\"ccache\""
+tools/gen_all --check-only out/tmp.protoc
+rm -f out/tmp.protoc &
diff --git a/test/ci/fuzzer_tests.sh b/test/ci/fuzzer_tests.sh
index 0ed6f8b..9ef9738 100755
--- a/test/ci/fuzzer_tests.sh
+++ b/test/ci/fuzzer_tests.sh
@@ -13,26 +13,12 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
-set -eux -o pipefail
-
-# cd into the project root (two levels up from /test/ci).
-cd $(dirname ${BASH_SOURCE[0]})/../..
-
-OUT_PATH="out/dist"
-
-tools/install-build-deps --no-android
-
-if [[ -e buildtools/clang/bin/llvm-symbolizer ]]; then
-  export ASAN_SYMBOLIZER_PATH="buildtools/clang/bin/llvm-symbolizer"
-  export MSAN_SYMBOLIZER_PATH="buildtools/clang/bin/llvm-symbolizer"
-fi
+INSTALL_BUILD_DEPS_ARGS="--no-android"
+source $(dirname ${BASH_SOURCE[0]})/common.sh
 
 tools/gn gen ${OUT_PATH} --args="${PERFETTO_TEST_GN_ARGS}" --check
 tools/ninja -C ${OUT_PATH} ${PERFETTO_TEST_NINJA_ARGS} fuzzers
 
-# Check the amalgamated build here to avoid slowing down all the Linux bots.
-tools/test_gen_amalgamated.py
-
 # Run a single iteration each to make sure they are not crashing.
 for fuzzer in $(find ${OUT_PATH} -name '*_fuzzer' -executable); do
   $fuzzer -runs=1
diff --git a/test/ci/linux_tests.sh b/test/ci/linux_tests.sh
index 571ad53..25d4b06 100755
--- a/test/ci/linux_tests.sh
+++ b/test/ci/linux_tests.sh
@@ -13,19 +13,8 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
-set -eux -o pipefail
-
-# cd into the project root (two levels up from /test/ci).
-cd $(dirname ${BASH_SOURCE[0]})/../..
-
-OUT_PATH="out/dist"
-
-tools/install-build-deps --no-android
-
-if [[ -e buildtools/clang/bin/llvm-symbolizer ]]; then
-  export ASAN_SYMBOLIZER_PATH="buildtools/clang/bin/llvm-symbolizer"
-  export MSAN_SYMBOLIZER_PATH="buildtools/clang/bin/llvm-symbolizer"
-fi
+INSTALL_BUILD_DEPS_ARGS="--no-android"
+source $(dirname ${BASH_SOURCE[0]})/common.sh
 
 tools/gn gen ${OUT_PATH} --args="${PERFETTO_TEST_GN_ARGS}" --check
 tools/ninja -C ${OUT_PATH} ${PERFETTO_TEST_NINJA_ARGS}
diff --git a/test/ci/ui_tests.sh b/test/ci/ui_tests.sh
index ef54437..5476840 100755
--- a/test/ci/ui_tests.sh
+++ b/test/ci/ui_tests.sh
@@ -13,14 +13,8 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
-set -eux -o pipefail
-
-# cd into the project root (two levels up from /test/ci).
-cd $(dirname ${BASH_SOURCE[0]})/../..
-
-OUT_PATH="out/dist"
-
-tools/install-build-deps --no-android --ui
+INSTALL_BUILD_DEPS_ARGS="--no-android --ui"
+source $(dirname ${BASH_SOURCE[0]})/common.sh
 
 tools/gn gen ${OUT_PATH} --args="${PERFETTO_TEST_GN_ARGS}" --check
 tools/ninja -C ${OUT_PATH} ${PERFETTO_TEST_NINJA_ARGS} ui
diff --git a/tools/gen_all b/tools/gen_all
index 72c8b04..094bd88 100755
--- a/tools/gen_all
+++ b/tools/gen_all
@@ -39,6 +39,7 @@
 
 def main():
   parser = argparse.ArgumentParser()
+  parser.add_argument('--check-only', default=False, action='store_true')
   parser.add_argument('OUT')
   args = parser.parse_args()
   out = args.OUT
@@ -46,13 +47,19 @@
   try:
     assert os.path.isdir(out), \
         'Output directory "{}" is not a directory'.format(out)
-    call('fix_include_guards')
-    call('gen_bazel')
-    call('gen_android_bp')
-    call('gen_merged_protos')
+    check_only = ['--check-only'] if args.check_only else []
+    call('check_include_violations')
+    call('fix_include_guards', *check_only)
+    call('gen_bazel', *check_only)
+    call('gen_android_bp', *check_only)
+    call('gen_merged_protos', *check_only)
     call('ninja', '-C', out, 'protoc')
-    call('gen_binary_descriptors', '--protoc', protoc_path(out))
-    call('gen_tracing_cpp_headers_from_protos', out)
+    call('gen_binary_descriptors', '--protoc', protoc_path(out), *check_only)
+
+    # TODO(primiano): gen_tracing_cpp_headers_from_protos is going away soon
+    # and there is no point adding --check-only support to that.
+    if not check_only:
+      call('gen_tracing_cpp_headers_from_protos', out)
 
   except AssertionError as e:
     if not str(e):
diff --git a/tools/gen_binary_descriptors b/tools/gen_binary_descriptors
index 1a9d633..1d26587 100755
--- a/tools/gen_binary_descriptors
+++ b/tools/gen_binary_descriptors
@@ -46,12 +46,9 @@
 
 
 def find_protoc():
-  for root, dirs, files in os.walk(ROOT_DIR):
+  for root, _, files in os.walk(os.path.join(ROOT_DIR, 'out')):
     if 'protoc' in files:
       return os.path.join(root, 'protoc')
-    for name in ('src', 'buildtools'):
-      if name in dirs:
-        dirs.remove(name)
   return None