Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Make static analysis failure cause build failure on Travis

I have an Objective-C iOS library building on Travis CI. I just enabled static analysis in my .travis.yml file, and it found an issue (a dead store), but it did not fail the build on Travis. Here is the relevant line in my .travis.yml (line-wrapped for readability):

- set -o pipefail && xcodebuild analyze
    -workspace Example/BonMot.xcworkspace
    -scheme BonMot-Example
    -destination 'name=iPhone 6' ONLY_ACTIVE_ARCH=NO | xcpretty

What do I need to do in order to cause a warning in this line to fail the build on Travis CI? You can see the relevant pull request on my project here.

like image 564
Zev Eisenberg Avatar asked Mar 26 '16 03:03

Zev Eisenberg


2 Answers

The only way I could get this to work is to use the method detailed here

Add these two parameters to your xcodebuild or scan -x command

CLANG_ANALYZER_OUTPUT=plist-html \
CLANG_ANALYZER_OUTPUT_DIR="$(pwd)/clang"

This will produce a HTML file if there are clang warnings. So check for existence of this file.

if [[ -z `find clang -name "*.html"` ]]; then
    echo "Static Analyzer found no issues"
else
    echo "Static Analyzer found some issues"
    exit 123
fi
like image 85
Robert Avatar answered Sep 25 '22 11:09

Robert


I managed to work out a way to make this work with some help from this blog post. Here are the relevant parts of a sample .travis.yml file:

language: objective-c
rvm:
 - 2.2.4
osx_image: xcode7.3
install:
 - gem install xcpretty --no-rdoc --no-ri --no-document --quiet
 - export PYTHONUSERBASE=~/.local
 - easy_install --user scan-build
script:
 # use scan-build with --status-bugs to fail the build for static analysis warnings per http://jonboydell.blogspot.ca/2013/02/clang-static-analysis.html
 - export PATH="${HOME}/.local/bin:${PATH}" # I forget whether this was necessary. Try omitting it and see what happens!
 - set -o pipefail && scan-build --status-bugs xcodebuild analyze -workspace MyWorkspace.xcworkspace -scheme MyScheme -destination 'name=iPhone 6' ONLY_ACTIVE_ARCH=NO | xcpretty
like image 27
Zev Eisenberg Avatar answered Sep 25 '22 11:09

Zev Eisenberg