build_files_updated_unittest.sh 1.7 KB

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