【问题标题】:Make static analysis failure cause build failure on Travis使静态分析失败导致 Travis 上的构建失败
【发布时间】:2016-11-01 09:34:01
【问题描述】:

我有一个基于 Travis CI 的 Objective-C iOS 库。我刚刚在我的.travis.yml 文件中启用了静态分析,它发现了一个问题(一个死存储),但它并没有在 Travis 上构建失败。这是我的.travis.yml 中的相关行(为便于阅读而换行):

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

为了在 Travis CI 上的构建失败,我需要做什么才能在此行中引起警告?你可以在我的项目here看到相关的拉取请求。

【问题讨论】:

    标签: xcode continuous-integration travis-ci static-analysis


    【解决方案1】:

    我可以让它工作的唯一方法是使用详细的方法here

    将这两个参数添加到您的xcodebuildscan -x 命令中

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

    如果有 clang 警告,这将生成一个 HTML 文件。所以检查这个文件是否存在。

    if [[ -z `find clang -name "*.html"` ]]; then
        echo "Static Analyzer found no issues"
    else
        echo "Static Analyzer found some issues"
        exit 123
    fi
    

    【讨论】:

      【解决方案2】:

      this blog post 的帮助下,我设法找到了一种方法来完成这项工作。以下是示例.travis.yml 文件的相关部分:

      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
      

      【讨论】:

        【解决方案3】:

        我认为您想将 -Wunused-value 添加到构建设置的“其他警告标志”部分,并将“将警告视为错误”设置为“是”。

        【讨论】:

        • 我不只是希望这个特定的警告使构建失败。我希望 all 静态分析警告使构建失败。 将警告视为错误会将蓝色静态分析结果视为警告吗?
        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2019-09-21
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多