Last active
April 26, 2016 21:31
-
-
Save POMBuilds/37fd586c196c99b66d288d5f946c2a6d to your computer and use it in GitHub Desktop.
Add warnings and errors to xcode swift projects.
This file contains hidden or 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
#!/usr/bin/env bash | |
# This work is based on answers in this Stack Overflow thread: http://stackoverflow.com/questions/24183812/swift-warning-equivalent | |
# Generates build warnings in non-release builds. | |
if [ "${CONFIGURATION}" != "Release" ]; then | |
DEBUG_WARNING_TAGS="\/\/ TODO:|\/\/ FIXME:|\/\/ WARNING:|\/\/ CRITICAL:" | |
find "${SRCROOT}" \( -name "*.h" -or -name "*.m" -or -name "*.swift" \) -print0 | xargs -0 egrep --with-filename --line-number --only-matching "($DEBUG_WARNING_TAGS).*\$" | perl -p -e "s/($DEBUG_WARNING_TAGS)/ warning: \$1/" | |
fi | |
# Generates build errors or warnings in Release | |
if [ "${CONFIGURATION}" = "Release" ]; then | |
# TODO will still be considered a warning in Release builds | |
RELEASE_WARNING_TAGS="\/\/ TODO:|\/\/ WARNING:" | |
find "${SRCROOT}" \( -name "*.h" -or -name "*.m" -or -name "*.swift" \) -print0 | xargs -0 egrep --with-filename --line-number --only-matching "($RELEASE_WARNING_TAGS).*\$" | perl -p -e "s/($RELEASE_WARNING_TAGS)/ warning: \$1/" | |
# FIXME and CRITICAL are errors in Release builds | |
RELEASE_ERROR_TAGS="\/\/ FIXME:|\/\/ CRITICAL:" | |
ERRORS_FOUND=0 | |
FIND_RESULT=( $(find "${SRCROOT}" \( -name "*.h" -or -name "*.m" -or -name "*.swift" \)) ) | |
# We must sequence each file individually, so we can detect if an error tag is present | |
for FILEPATH in ${FIND_RESULT[*]} | |
do | |
GREP_RESULTS=$(egrep --with-filename --line-number --only-matching "($RELEASE_ERROR_TAGS).*\$" $FILEPATH) | |
# If GREP_RESULTS is not empty, then an error tag has been found. Output the errors, then flip ERRORS_FOUND | |
if [ "$GREP_RESULTS" ]; then | |
echo "$GREP_RESULTS" | perl -p -e "s/($RELEASE_ERROR_TAGS)/ error: \$1/" | |
ERRORS_FOUND=1 | |
fi | |
done | |
# Errors that are outputted during the build do not actually cause the build to fail, so we must manually call exit 1 | |
if [ $ERRORS_FOUND = 1 ]; then | |
exit 1 | |
fi | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment