How to treat warnings from clang static code analysis as errors in Xcode 3? -


question

the run_clang_static_analyzer ("run static analyzer") project setting has found important issues in our project. have addressed them , want prevent future issues creeping in.

we're trying clang analysis warnings treated errors break our build. far no success despite having -werror ("treat warnings errors") enabled.

example of problem

the following analysis call generated within xcode:

/developer/usr/bin/clang -x objective-c [...] --analyze [...]/troubledcode.m -o [...]/troubledtarget.build/staticanalyzer/normal/i386/troubledcode.plist

produces static code analysis warning:

[...]/troubledcode.m:38:34: warning: potential leak of object allocated on line 38 , stored 'leakingmanager'     manager *leakingmanager = [[manager alloc] init];                               ^ 1 warning generated. 

but xcode reports "build succeeded ... 1 analyzer result". solution we're looking make example above generate "build failed".


solution

i took jim's advice , created build script.

to avoid false alarms, went through trouble of making sure ignores extraneous analysis residue. solution should work when building xcode ide , when building project using xcodebuild.

to turn xcode 3 analysis warnings build errors:

  • double click project or target in question.
  • under build tab, check box under settings > linking > write link map file

that setting known ld_generate_map_file.

  • under "groups & files" > "targets", click disclosure triangle of target you'd add feature to.
  • right-click "link binary libraries" phase.
  • select add > new build phase > new run script build phase
  • optional: rename "run script" phase added "treat clang warnings errors".
  • double-click new script phase if it's not open.

copy content below , paste "script" section.

error_count=0  ##  function verify_clang_analysis_at_path() {   local analysis_path=$1   local plist_tool=/usr/libexec/plistbuddy   local diagnostics=$($plist_tool -c "print diagnostics" $analysis_path)    if [[ $diagnostics != $'array {\n}' ]]       ((error_count++))   fi }  function verify_clang_analysis_for_object_file() {   local object_file=$1   local analysis_directory=$target_temp_dir/staticanalyzer/$current_variant/$current_arch   local analysis_path=$analysis_directory/${object_file%.*}.plist    # if object file corresponds source file clang analyzed...   if [ -e $analysis_path ]       verify_clang_analysis_at_path $analysis_path   fi }  ##  object_directory=$object_file_dir-$current_variant/$current_arch object_path_pattern=${object_directory}'/\(.\)\+\.o$'  index_pattern='\[[[:space:]0-9]*\][[:space:]]'  object_paths=$(    grep $object_path_pattern $ld_map_file_path | sed s/$index_pattern// )  ##  object_path in $object_paths    object_file=${object_path##*/}   verify_clang_analysis_for_object_file $object_file done  if [ $error_count -gt 0 ]    echo "clang static code analysis failed for" $error_count "source file(s)." fi  exit $error_count 

update

mike vosseller has upgraded version of script xcode 5.

we've been planning on having separate build step run analyzer , check results. we'll fail build on build server way. won't locally, though.


Comments

Popular posts from this blog

apache - Add omitted ? to URLs -

redirect - bbPress Forum - rewrite to wwww.mysite prohibits login -

php - How can I stop spam on my custom forum/blog? -