-
Notifications
You must be signed in to change notification settings - Fork 88
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge removed extended globs in bash scripts
In an effort to support a wider range of shells (especially the bash shell on macOS), all requested extended globs (requested via `shopt -s`) like `globstar` and `extglob` were removed and any usage of these extended globs replaced. Additionally, all scripts which will be automatically executed when a form of `make` is called were extended to include more debug information if an error occurs. Related PR: #280
- Loading branch information
Showing
2 changed files
with
127 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,79 @@ | ||
#!/usr/bin/env bash | ||
shopt -s globstar | ||
shopt -s extglob | ||
|
||
THIS_DIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" &>/dev/null && pwd ) | ||
GINKGO_ROOT_DIR="${THIS_DIR}/../.." | ||
# ${THIS_DIR} is expected to be: ${GINKGO_ROOT_DIR}/dev_tools/scripts | ||
|
||
# Use local paths, so there is less chance of a newline being in a path of a found file | ||
cd "${THIS_DIR}/../.." | ||
GINKGO_ROOT_DIR="." | ||
|
||
|
||
LICENSE_FILE="${GINKGO_ROOT_DIR}/LICENSE" | ||
PATTERNS="cpp|hpp|cuh|cu|hpp.in" | ||
EXCLUDED_DIRECTORIES="build|third_party" | ||
GINKGO_LICENSE_BEACON="******************************<GINKGO LICENSE>******************************" | ||
|
||
echo -e "/*${GINKGO_LICENSE_BEACON}\n$(cat ${LICENSE_FILE})\n${GINKGO_LICENSE_BEACON}*/\n" > commented_license.tmp | ||
|
||
for i in ${GINKGO_ROOT_DIR}/!(${EXCLUDED_DIRECTORIES})/**/*.@(${PATTERNS}) | ||
do | ||
if ! grep -q "${GINKGO_LICENSE_BEACON}" $i | ||
then | ||
cat commented_license.tmp $i >$i.new && mv $i.new $i | ||
else | ||
beginning=$(grep -n "/\*${GINKGO_LICENSE_BEACON}" $i | cut -d":" -f1) | ||
end=$(grep -n "${GINKGO_LICENSE_BEACON}.*/" $i | cut -d":" -f1) | ||
end=$((end+1)) | ||
diff -u <(sed -n "${beginning},${end}p" $i) commented_license.tmp > diff.patch | ||
if [ "$(cat diff.patch)" != "" ] | ||
# These two files are temporary files which will be created (and deleted). | ||
# Therefore, the files should not already exist. | ||
COMMENTED_LICENSE_FILE="${THIS_DIR}/commented_license.tmp" | ||
DIFF_FILE="${THIS_DIR}/diff.patch.tmp" | ||
|
||
# Test if required commands are present on the system: | ||
command -v find &> /dev/null | ||
if [ ${?} -ne 0 ]; then | ||
echo 'The command `find` is required for this script to work, but not supported by your system.' 1>&2 | ||
exit 1 | ||
fi | ||
command -v diff &> /dev/null | ||
if [ ${?} -ne 0 ]; then | ||
echo 'The command `diff` is required for this script to work, but not supported by your system.' 1>&2 | ||
exit 1 | ||
fi | ||
command -v patch &> /dev/null | ||
if [ ${?} -ne 0 ]; then | ||
echo 'The command `patch` is required for this script to work, but not supported by your system.' 1>&2 | ||
exit 1 | ||
fi | ||
command -v grep &> /dev/null | ||
if [ ${?} -ne 0 ]; then | ||
echo 'The command `grep` is required for this script to work, but not supported by your system.' 1>&2 | ||
exit 1 | ||
fi | ||
command -v sed &> /dev/null | ||
if [ ${?} -ne 0 ]; then | ||
echo 'The command `sed` is required for this script to work, but not supported by your system.' 1>&2 | ||
exit 1 | ||
fi | ||
command -v cut &> /dev/null | ||
if [ ${?} -ne 0 ]; then | ||
echo 'The command `cut` is required for this script to work, but not supported by your system.' 1>&2 | ||
exit 1 | ||
fi | ||
|
||
|
||
echo -e "/*${GINKGO_LICENSE_BEACON}\n$(cat ${LICENSE_FILE})\n${GINKGO_LICENSE_BEACON}*/\n" > "${COMMENTED_LICENSE_FILE}" | ||
|
||
# Does not work if a found file (including the path) contains a newline | ||
find "${GINKGO_ROOT_DIR}" \ | ||
! \( -name "build" -prune -o -name "third_party" -prune \) \ | ||
\( -name '*.cuh' -o -name '*.hpp' -o -name '*.hpp.in' -o -name '*.cpp' -o -name '*.cu' \) \ | ||
-type f -print \ | ||
| \ | ||
while IFS='' read -r i; do | ||
# `grep -F` is important here because the characters in the beacon should be matched against | ||
# and not interpreted as an expression. | ||
if ! grep -F -q -e "${GINKGO_LICENSE_BEACON}" "${i}" | ||
then | ||
patch $i diff.patch | ||
cat "${COMMENTED_LICENSE_FILE}" "${i}" >"${i}.new" && mv "${i}.new" "${i}" | ||
else | ||
beginning=$(grep -F -n -e "/*${GINKGO_LICENSE_BEACON}" "${i}" | cut -d":" -f1) | ||
end=$(grep -F -n -e "${GINKGO_LICENSE_BEACON}*/" "${i}" | cut -d":" -f1) | ||
end=$((end+1)) | ||
diff -u <(sed -n "${beginning},${end}p" "${i}") "${COMMENTED_LICENSE_FILE}" > "${DIFF_FILE}" | ||
if [ "$(cat "${DIFF_FILE}")" != "" ] | ||
then | ||
patch "${i}" "${DIFF_FILE}" | ||
fi | ||
rm "${DIFF_FILE}" | ||
fi | ||
rm diff.patch | ||
fi | ||
done | ||
done | ||
|
||
rm commented_license.tmp | ||
rm "${COMMENTED_LICENSE_FILE}" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters