• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/bin/bash
2
3# This script verifies that BUILD files and cmake files are in sync with src/Makefile.am
4
5set -eo pipefail
6
7if [ "$(uname)" != "Linux" ]; then
8  echo "build_files_updated_unittest only supported on Linux. Skipping..."
9  exit 0
10fi
11
12# Keep in sync with files needed by update_file_lists.sh
13generated_files=(
14  "BUILD"
15  "cmake/extract_includes.bat.in"
16  "cmake/libprotobuf-lite.cmake"
17  "cmake/libprotobuf.cmake"
18  "cmake/libprotoc.cmake"
19  "cmake/tests.cmake"
20  "src/Makefile.am"
21)
22
23# If we're running in Bazel, use the Bazel-provided temp-dir.
24if [ -n "${TEST_TMPDIR}" ]; then
25  # Env-var TEST_TMPDIR is set, assume that this is Bazel.
26  # Bazel may have opinions whether we are allowed to delete TEST_TMPDIR.
27  test_root="${TEST_TMPDIR}/build_files_updated_unittest"
28  mkdir "${test_root}"
29else
30  # Seems like we're not executed by Bazel.
31  test_root=$(mktemp -d)
32fi
33
34# From now on, fail if there are any unbound variables.
35set -u
36
37# Remove artifacts after test is finished.
38function cleanup {
39  rm -rf "${test_root}"
40}
41trap cleanup EXIT
42
43# Create golden dir and add snapshot of current state.
44golden_dir="${test_root}/golden"
45mkdir -p "${golden_dir}/cmake" "${golden_dir}/src"
46for file in ${generated_files[@]}; do
47  cp "${file}" "${golden_dir}/${file}"
48done
49
50# Create test dir, copy current state into it, and execute update script.
51test_dir="${test_root}/test"
52cp -R "${golden_dir}" "${test_dir}"
53
54cp "update_file_lists.sh" "${test_dir}/update_file_lists.sh"
55chmod +x "${test_dir}/update_file_lists.sh"
56cd "${test_root}/test"
57bash "${test_dir}/update_file_lists.sh"
58
59# Test whether there are any differences
60for file in ${generated_files[@]}; do
61  diff -du "${golden_dir}/${file}" "${test_dir}/${file}"
62done
63