Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Further improve the update_ginkgo_header.sh script
- Add additional tests for access privileges
- Add `rm` parameter
  • Loading branch information
Thomas Grützmacher committed Nov 19, 2019
commit 9cc2881c1b846b74331cb78670b3a3c6c63c533a
51 changes: 32 additions & 19 deletions dev_tools/scripts/update_ginkgo_header.sh
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
#!/usr/bin/env bash

# Note: every exit code is 0 because any other exit code would terminate the
# whole `make` procedure, which is a too extreme reaction.
# This script is supposed to support the developer and not to hinder
# Note: This script is supposed to support the developer and not to hinder
# the development process by setting more restrictions.
# This is the reason why every exit code is 0, otherwise, the whole
# `make` procedure would fail.

PLACE_HOLDER="#PUBLIC_HEADER_PLACE_HOLDER"

WARNING_PREFIX="[WARNING] update_header failed because: "
WARNING_PREFIX="[WARNING] ginkgo.hpp update script failed because:"

RM_PARAMETER="--interactive=never"
Comment thread
tcojean marked this conversation as resolved.
Outdated


THIS_DIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" &>/dev/null && pwd )
Expand All @@ -25,17 +27,17 @@ HEADER_LIST="global_includes.hpp.tmp"
# Test if required commands are present on the system:
command -v find &> /dev/null
if [ ${?} -ne 0 ]; then
echo "${WARNING_PREFIX}"'The command `find` is required for this script to work, but not supported by your system.' 1>&2
echo "${WARNING_PREFIX} "'The command `find` is required for this script to work, but not supported by your system.' 1>&2
exit 0
fi
command -v sort &> /dev/null
if [ ${?} -ne 0 ]; then
echo "${WARNING_PREFIX}"'The command `sort` is required for this script to work, but not supported by your system.' 1>&2
echo "${WARNING_PREFIX} "'The command `sort` is required for this script to work, but not supported by your system.' 1>&2
exit 0
fi
command -v cmp &> /dev/null
if [ ${?} -ne 0 ]; then
echo "${WARNING_PREFIX}"'The command `cmp` is required for this script to work, but not supported by your system.' 1>&2
echo "${WARNING_PREFIX} "'The command `cmp` is required for this script to work, but not supported by your system.' 1>&2
exit 0
fi

Expand All @@ -45,8 +47,8 @@ fi
find "${TOP_HEADER_FOLDER}" -name '*.hpp' -type f -print > "${HEADER_LIST}"

if [ ${?} -ne 0 ]; then
echo "${WARNING_PREFIX}"'The `find` command returned with an error!' 1>&2
rm "${HEADER_LIST}"
echo "${WARNING_PREFIX} "'The `find` command returned with an error!' 1>&2
rm "${RM_PARAMETER}" "${HEADER_LIST}"
exit 0
fi

Expand All @@ -56,14 +58,20 @@ export LC_ALL=C
sort -o "${HEADER_LIST}" "${HEADER_LIST}"

if [ ${?} -ne 0 ]; then
echo "${WARNING_PREFIX}"'The `sort` command returned with an error!' 1>&2
rm "${HEADER_LIST}"
echo "${WARNING_PREFIX} "'The `sort` command returned with an error!' 1>&2
rm "${RM_PARAMETER}" "${HEADER_LIST}"
exit 0
fi

if [ ! -r "${GINKGO_HEADER_TEMPLATE_FILE}" ]; then
echo "${WARNING_PREFIX} The file '${GINKGO_HEADER_TEMPLATE_FILE}' can not be read!" 1>&2
rm "${RM_PARAMETER}" "${HEADER_LIST}"
exit 0
fi

# Detect the end of line type (CRLF/LF) by ${GINKGO_HEADER_TEMPLATE_FILE}
END="";
if [[ "$(file ${GINKGO_HEADER_TEMPLATE_FILE})" == *"CRLF"* ]]; then
if [[ "$(file "${GINKGO_HEADER_TEMPLATE_FILE}")" == *"CRLF"* ]]; then
END="\r"
fi

Expand All @@ -73,15 +81,15 @@ fi
# (e.g. benchmarks and examples)
GINKGO_HEADER_TMP="${GINKGO_HEADER_FILE}.tmp"

# See if we have write permissions to ${GINKGO_HEADER_TEMP}
echo "Test for write permissions" > "${GINKGO_HEADER_TEMP}"
# See if we have write permissions to ${GINKGO_HEADER_TMP}
echo "Test for write permissions" > "${GINKGO_HEADER_TMP}"
if [ ${?} -ne 0 ]; then
echo "${WARNING_PREFIX}No write permissions in path '$(pwd)/ginkgo'" 1>&2
rm "${HEADER_LIST}"
echo "${WARNING_PREFIX} No write permissions for temporary file '${GINKGO_HEADER_TMP}'!" 1>&2
rm "${RM_PARAMETER}" "${HEADER_LIST}"
exit 0
fi
# Remove file again, so the test does not corrupt the result
rm "${GINKGO_HEADER_TEMP}"
rm "${RM_PARAMETER}" "${GINKGO_HEADER_TMP}"



Expand Down Expand Up @@ -122,14 +130,19 @@ while IFS='' read -r line; do
fi
done < "${GINKGO_HEADER_TEMPLATE_FILE}"

rm "${HEADER_LIST}"
rm "${RM_PARAMETER}" "${HEADER_LIST}"

# Use the generated file ONLY when the public header does not exist yet
# or the generated one is different to the existing one
if [ ! -f "${GINKGO_HEADER_FILE}" ] || \
! cmp -s "${GINKGO_HEADER_TMP}" "${GINKGO_HEADER_FILE}"
then
mv "${GINKGO_HEADER_TMP}" "${GINKGO_HEADER_FILE}"
if [ ${?} -ne 0 ]; then
echo "${WARNING_PREFIX} No permission to replace the header '${GINKGO_HEADER_FILE}'!" 1>&2
rm "${RM_PARAMETER}" "${GINKGO_HEADER_TMP}"
exit 0
fi
else
rm "${GINKGO_HEADER_TMP}"
rm "${RM_PARAMETER}" "${GINKGO_HEADER_TMP}"
fi