Make static analysis fail on Travis

I have an iOS Objective-C library library on Travis CI. I just turned on static analysis in my .travis.yml file and it detected a problem (dead store), but it did not fail on Travis. Here is the corresponding line in my .travis.yml (line 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 to trigger a warning on this line about a build failure on Travis CI? You can see the corresponding transfer request in my project here .

+5
source share
3 answers

I managed to find a way to make this work with this blog post . Here are the relevant parts of the .travis.yml sample:

 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 
+1
source

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

Add these two options to the xcodebuild or scan -x command

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

This will create an HTML file if there are clang warnings. Therefore, check for the presence 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 
+4
source

I think you want to add -Wunused-value to the "Other warning flags" section of your build settings and set "Handle warnings as errors" to "Yes."

0
source

Source: https://habr.com/ru/post/1245807/


All Articles