Skip to content
Browse files

Copy files to temp-dir for testing

  • Loading branch information...
Yannic authored and acozzette committed Jul 23, 2019
1 parent edbc27f commit ff21d0f8777b9cce3864e424f1355cdcfe888eeb
Showing with 54 additions and 15 deletions.
  1. +54 −15
@@ -2,22 +2,61 @@

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

set -euo pipefail
set -eo pipefail

cp "BUILD" "BUILD.orginal"
cp "cmake/" "cmake/"
cp "cmake/libprotobuf-lite.cmake" "cmake/libprotobuf-lite.cmake.orginal"
cp "cmake/libprotobuf.cmake" "cmake/libprotobuf.cmake.orginal"
cp "cmake/libprotoc.cmake" "cmake/libprotoc.cmake.orginal"
cp "cmake/tests.cmake" "cmake/tests.cmake.orginal"
if [ "$(uname)" != "Linux" ]; then
echo "build_files_updated_unittest only supported on Linux. Skipping..."
exit 0

# Keep in sync with files needed by

if [ "$(uname)" == "Linux" ]; then
# 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.
mkdir "${test_root}"
# Seems like we're not executed by Bazel.
test_root=$(mktemp -d)

diff "BUILD.orginal" "BUILD"
diff "cmake/" "cmake/"
diff "cmake/libprotobuf-lite.cmake.orginal" "cmake/libprotobuf-lite.cmake"
diff "cmake/libprotobuf.cmake.orginal" "cmake/libprotobuf.cmake"
diff "cmake/libprotoc.cmake.orginal" "cmake/libprotoc.cmake"
diff "cmake/tests.cmake.orginal" "cmake/tests.cmake"
# 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.
mkdir -p "${golden_dir}/cmake" "${golden_dir}/src"
for file in ${generated_files[@]}; do
cp "${file}" "${golden_dir}/${file}"

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

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

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

0 comments on commit ff21d0f

Please sign in to comment.
You can’t perform that action at this time.