Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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/"
like image 372
Daniel Avatar asked May 11 '16 08:05

Daniel


2 Answers

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}
like image 102
Darren Ehlers Avatar answered Nov 04 '22 05:11

Darren Ehlers


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.

like image 25
trojanfoe Avatar answered Nov 04 '22 06:11

trojanfoe