Yannic Bonenberger | 4979489 | 2019-07-20 12:49:03 +0200 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | |
| 3 | # This script verifies that BUILD files and cmake files are in sync with src/Makefile.am |
| 4 | |
Yannic Bonenberger | ff21d0f | 2019-07-24 00:50:06 +0200 | [diff] [blame] | 5 | set -eo pipefail |
Yannic Bonenberger | 27e85ab | 2019-07-23 21:38:13 +0200 | [diff] [blame] | 6 | |
Yannic Bonenberger | ff21d0f | 2019-07-24 00:50:06 +0200 | [diff] [blame] | 7 | if [ "$(uname)" != "Linux" ]; then |
| 8 | echo "build_files_updated_unittest only supported on Linux. Skipping..." |
| 9 | exit 0 |
Yannic Bonenberger | 4979489 | 2019-07-20 12:49:03 +0200 | [diff] [blame] | 10 | fi |
| 11 | |
Yannic Bonenberger | ff21d0f | 2019-07-24 00:50:06 +0200 | [diff] [blame] | 12 | # Keep in sync with files needed by update_file_lists.sh |
| 13 | generated_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. |
| 24 | if [ -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}" |
| 29 | else |
| 30 | # Seems like we're not executed by Bazel. |
| 31 | test_root=$(mktemp -d) |
| 32 | fi |
| 33 | |
| 34 | # From now on, fail if there are any unbound variables. |
| 35 | set -u |
| 36 | |
| 37 | # Remove artifacts after test is finished. |
| 38 | function cleanup { |
| 39 | rm -rf "${test_root}" |
| 40 | } |
| 41 | trap cleanup EXIT |
| 42 | |
| 43 | # Create golden dir and add snapshot of current state. |
| 44 | golden_dir="${test_root}/golden" |
| 45 | mkdir -p "${golden_dir}/cmake" "${golden_dir}/src" |
| 46 | for file in ${generated_files[@]}; do |
| 47 | cp "${file}" "${golden_dir}/${file}" |
| 48 | done |
| 49 | |
| 50 | # Create test dir, copy current state into it, and execute update script. |
| 51 | test_dir="${test_root}/test" |
| 52 | cp -R "${golden_dir}" "${test_dir}" |
| 53 | |
| 54 | cp "update_file_lists.sh" "${test_dir}/update_file_lists.sh" |
| 55 | chmod +x "${test_dir}/update_file_lists.sh" |
| 56 | cd "${test_root}/test" |
| 57 | bash "${test_dir}/update_file_lists.sh" |
| 58 | |
| 59 | # Test whether there are any differences |
| 60 | for file in ${generated_files[@]}; do |
| 61 | diff "${golden_dir}/${file}" "${test_dir}/${file}" |
| 62 | done |