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.
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
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With