Show TODO comments as warnings excluding the Pods folder

。_饼干妹妹 提交于 2019-12-13 11:42:44

问题


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/"

回答1:


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.




回答2:


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}


来源:https://stackoverflow.com/questions/37157027/show-todo-comments-as-warnings-excluding-the-pods-folder

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!