Skip to content

Instantly share code, notes, and snippets.

@dodikk
Created March 21, 2013 08:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dodikk/5211532 to your computer and use it in GitHub Desktop.
Save dodikk/5211532 to your computer and use it in GitHub Desktop.
This makes xCode fail the build and show analyzer warnings as errors. It is useful when "scan-build" does not work for some reasons. Saved from http://stackoverflow.com/questions/5033417/how-to-treat-warnings-from-clang-static-code-analysis-as-errors-in-xcode-3
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}' ]]
then
((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 this object file corresponds to a source file that clang analyzed...
if [ -e $analysis_path ]
then
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//
)
##
for object_path in $object_paths
do
object_file=${object_path##*/}
verify_clang_analysis_for_object_file $object_file
done
if [ $error_count -gt 0 ]
then
echo "Clang static code analysis failed for" $error_count "source file(s)."
fi
exit $error_count
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment