File: build_files_updated_unittest.sh

package info (click to toggle)
protobuf 3.21.12-11
  • links: PTS
  • area: main
  • in suites: trixie
  • size: 41,628 kB
  • sloc: cpp: 179,370; java: 87,796; objc: 60,661; ansic: 37,810; cs: 28,526; python: 22,443; php: 11,464; ruby: 6,127; sh: 3,635; makefile: 3,341; pascal: 2,354; xml: 2,317; javascript: 311; lisp: 87; awk: 17
file content (62 lines) | stat: -rwxr-xr-x 1,725 bytes parent folder | download | duplicates (7)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#!/bin/bash

# This script verifies that BUILD files and cmake files are in sync with src/Makefile.am

set -eo pipefail

if [ "$(uname)" != "Linux" ]; then
  echo "build_files_updated_unittest only supported on Linux. Skipping..."
  exit 0
fi

# Keep in sync with files needed by update_file_lists.sh
generated_files=(
  "BUILD"
  "cmake/extract_includes.bat.in"
  "cmake/libprotobuf-lite.cmake"
  "cmake/libprotobuf.cmake"
  "cmake/libprotoc.cmake"
  "cmake/tests.cmake"
  "src/Makefile.am"
)

# If we're running in Bazel, use the Bazel-provided temp-dir.
if [ -n "${TEST_TMPDIR}" ]; then
  # Env-var TEST_TMPDIR is set, assume that this is Bazel.
  # Bazel may have opinions whether we are allowed to delete TEST_TMPDIR.
  test_root="${TEST_TMPDIR}/build_files_updated_unittest"
  mkdir "${test_root}"
else
  # Seems like we're not executed by Bazel.
  test_root=$(mktemp -d)
fi

# From now on, fail if there are any unbound variables.
set -u

# Remove artifacts after test is finished.
function cleanup {
  rm -rf "${test_root}"
}
trap cleanup EXIT

# Create golden dir and add snapshot of current state.
golden_dir="${test_root}/golden"
mkdir -p "${golden_dir}/cmake" "${golden_dir}/src"
for file in ${generated_files[@]}; do
  cp "${file}" "${golden_dir}/${file}"
done

# Create test dir, copy current state into it, and execute update script.
test_dir="${test_root}/test"
cp -R "${golden_dir}" "${test_dir}"

cp "update_file_lists.sh" "${test_dir}/update_file_lists.sh"
chmod +x "${test_dir}/update_file_lists.sh"
cd "${test_root}/test"
bash "${test_dir}/update_file_lists.sh"

# Test whether there are any differences
for file in ${generated_files[@]}; do
  diff -du "${golden_dir}/${file}" "${test_dir}/${file}"
done