I have written script that shows Xcode warnings. e.g TODO
warnings. This script will run on each build of XCode. (I have written script in "Run Phase" option).
Now I want to collect and export all these warnings to text files. Is there any way to export all warnings or build errors to a text file?
(the first bit of this is what you've already done, or something like it)
Outputting TODO, etc, as warnings.
Select your project, click the Build Phases tab, and select 'Add Build Phase > Add Run Script Build Phase' from the 'Editor' menu.
In the script box use a script something like this:
KEYWORDS="TODO:|FIXME:|\?\?\?:|\!\!\!:"
find "${SRCROOT}" \( -name "*.h" -or -name "*.m" \) -print0 | xargs -0 egrep --with-filename --line-number --only-matching "($KEYWORDS).*\$" | perl -p -e "s/($KEYWORDS)/ warning: \$1/"
(courtesy of: http://deallocatedobjects.com/posts/show-todos-and-fixmes-as-warnings-in-xcode-4)
The KEYWORDS
regular expression matches TODO:
, FIXME:
, ???:
and !!!:
, but could be adjusted to find whichever indicators you want.
Making this output to a file.
The script currently outputs to stdout
, which is picked up by XCode and parsed. To make it also log to a file, use tee
as part of the script (see the end of line 2 for the change):
KEYWORDS="TODO:|FIXME:|\?\?\?:|\!\!\!:"
find "${SRCROOT}" \( -name "*.h" -or -name "*.m" \) -print0 | xargs -0 egrep --with-filename --line-number --only-matching "($KEYWORDS).*\$" | perl -p -e "s/($KEYWORDS)/ warning: \$1/" | tee "${SRCROOT}/NOTICES.txt"
This approach can be as complex as you like, of course, as well as tee
ing to a file, we can augment the script to do anything we choose:
KEYWORDS="TODO:|FIXME:|\?\?\?:|\!\!\!:"
find "${SRCROOT}" \( -name "*.h" -or -name "*.m" \) -print0 | xargs -0 egrep --with-filename --line-number --only-matching "($KEYWORDS).*\$" | perl -p -e "s/($KEYWORDS)/ warning: \$1/" | tee ${SRCROOT}/NOTICES.txt
mail -s NOTICES idmillington@example.com < ${SRCROOT}/NOTICES.txt
That emails it to me.
I've confirmed this works with XCode 5.0.2, including emailing.
Note that this does not export all warnings from the build to a file, which is strictly what you asked. I can't find a way to automate this in XCode 5.0.2, though you can do it with xcodebuild
. From within the UI, the only option is to copy the log text from the log navigator to the clipboard, it seems.