Daniel Klöck
Daniel Klöck

Reputation: 21137

Show TODO comments as warnings excluding the Pods folder

I have a script to show all my //TODO: comments which looks like this:

KEYWORDS="TODO:|FIXME:|\?\?\?:|\!\!\!:"

find "${SRCROOT}" \( -name "*.h" -or -name "*.m" -or -name "*.swift" \) -print0 | 
  xargs -0 egrep --with-filename --line-number --only-matching "($KEYWORDS).*\$" | 
  perl -p -e "s/($KEYWORDS)/ warning: \$1/"

I want to exclude my Pods folder, therefore I have added -not -path "./Pods/*":

find "${SRCROOT}" \( -name "*.h" -or -name "*.m" -or -name "*.swift" \) -not -path "./Pods/*" -print0 | 
  xargs -0 egrep --with-filename --line-number --only-matching "($KEYWORDS).*\$" | 
  perl -p -e "s/($KEYWORDS)/ warning: \$1/"

This works as expected when I try it on the Terminal (replacing "${SRCROOT}" with "."), but when it is run by Xcode it uses the Pods folder as well.

How can I exclude the folder in the build phase script?

Final version

This seems to work:

KEYWORDS="TODO:|FIXME:|\?\?\?:|\!\!\!:"
find "." \( -name "*.h" -or -name "*.m" -or -name "*.swift" \) -not -path "./Pods/*" -print0 | 
  xargs -0 egrep --with-filename --line-number --only-matching "($KEYWORDS).*\$" | 
  perl -p -e "s/($KEYWORDS)/ warning: \$1/"

Upvotes: 10

Views: 980

Answers (3)

Gregorian.st
Gregorian.st

Reputation: 171

As for me, it's very convenient to use #warning for this. For example:

#warning("TODO - Replace this code")

string in Swift code will generate custom warning in XCode with text "TODO - Replace this code".

Upvotes: 1

Darren Ehlers
Darren Ehlers

Reputation: 633

I couldn't get it to work correctly without using ${SRCROOT} macro, as you couldn't click on the warning to go to the source line.

I split up the recognized tokens into Warnings and Errors for my own use, thought I would share it here:

KEYWORDS="STUB:|WARNING:|TODO:|FIXME:|DevTeam:|\?\?\?:" 
find "${SRCROOT}" \( -name "*.h" -or -name "*.m" -or -name "*.swift" \) -not -path "${SRCROOT}/Pods/*" -print0 | xargs -0 egrep --with-filename --line-number --only-matching "($KEYWORDS).*\$" | perl -p -e "s/($KEYWORDS)/1: warning: \$1/"

KEYWORDS="ERROR:|XXX:|\!\!\!:" 
find "${SRCROOT}" \( -name "*.h" -or -name "*.m" -or -name "*.swift" \) -not -path "${SRCROOT}/Pods/*" -print0 | xargs -0 egrep --with-filename --line-number --only-matching "($KEYWORDS).*\$" | perl -p -e "s/($KEYWORDS)/1: error: \$1/"
ERROR_OUTPUT=`find "${SRCROOT}" \( -name "*.h" -or -name "*.m" -or -name "*.swift" \) -not -path "${SRCROOT}/Pods/*" -print0 | xargs -0 egrep --with-filename --line-number --only-matching "($KEYWORDS).*\$" | perl -p -e "s/($KEYWORDS)/1: error: \$1/"`

exit ${#ERROR_OUTPUT}

Upvotes: 3

trojanfoe
trojanfoe

Reputation: 122391

I would use find . and set the working directory of the build script to ${SRCROOT}. This should allow the . in -not -path "./Pods/*" to make sense to find.

Upvotes: 7

Related Questions