blob: 87541c35faa2da366230365411eac26bd79b9667 [file] [log] [blame]
Yannic Bonenberger49794892019-07-20 12:49:03 +02001#!/bin/bash
2
3# This script verifies that BUILD files and cmake files are in sync with src/Makefile.am
4
Yannic Bonenbergerff21d0f2019-07-24 00:50:06 +02005set -eo pipefail
Yannic Bonenberger27e85ab2019-07-23 21:38:13 +02006
Yannic Bonenbergerff21d0f2019-07-24 00:50:06 +02007if [ "$(uname)" != "Linux" ]; then
8 echo "build_files_updated_unittest only supported on Linux. Skipping..."
9 exit 0
Yannic Bonenberger49794892019-07-20 12:49:03 +020010fi
11
Yannic Bonenbergerff21d0f2019-07-24 00:50:06 +020012# 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
Joshua Haberman1dcea0f2021-04-16 08:10:49 -070061 diff -du "${golden_dir}/${file}" "${test_dir}/${file}"
Yannic Bonenbergerff21d0f2019-07-24 00:50:06 +020062done