【问题标题】:Clang scan-build won't work with Xcode 4.2 LLVM 3.0 build configurationClang scan-build 不适用于 Xcode 4.2 LLVM 3.0 构建配置
【发布时间】:2011-12-10 19:47:44
【问题描述】:

我已经安装了 Xcode 4.2 最终版本,以便能够为 iOS 5 编译。

我们使用 Jenkins 进行 CI 并从 llvm.org 项目页面运行 Clang scan-build。 (版本 258)该项目配置为使用 LLVM 3.0(自 Xcode 4.2 以来这是默认设置)。现在每次我尝试运行 scan-build 时都会出现以下错误:

CompileC build/Cortado.build/Debug-iphonesimulator/Cortado.build/Objects-normal/i386/TPContentDetailViewController_iPad.o Classes/iPad/TPContentDetailViewController_iPad.m normal i386 objective-c com.apple.compilers.llvm.clang.1_0.compiler
    cd "/Volumes/Sources/Starteam - Main View/Workplace/Cortado"
    setenv LANG en_US.US-ASCII
    setenv PATH "/Developer/Platforms/iPhoneSimulator.platform/Developer/usr/bin:/Developer/usr/bin:/Applications/android-sdk-mac_x86/android-ndk-r6b:/Applications/android-sdk-mac_x86/platform-tools:/Applications/android-sdk-mac_x86/tools:/Volumes/Sources/Starteam - Main View/Tools:/Volumes/Sources/Tools:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/X11/bin"
    /Users/thwee/Downloads/checker-258/libexec/ccc-analyzer -x objective-c -arch i386 -fmessage-length=0 -fdiagnostics-print-source-range-info -fdiagnostics-show-category=id -fdiagnostics-parseable-fixits -Wno-trigraphs -fpascal-strings -O0 -Wreturn-type -Wparentheses -Wswitch -Wno-unused-parameter -Wunused-variable -Wunused-value -Wno-shorten-64-to-32 -DDEBUG -isysroot /Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator5.0.sdk -fexceptions -fasm-blocks -fprofile-arcs -ftest-coverage -mmacosx-version-min=10.6 -gdwarf-2 -Wno-sign-conversion -fobjc-abi-version=2 -fobjc-legacy-dispatch "-DIBOutlet=__attribute__((iboutlet))" "-DIBOutletCollection(ClassName)=__attribute__((iboutletcollection(ClassName)))" "-DIBAction=void)__attribute__((ibaction)" -D__IPHONE_OS_VERSION_MIN_REQUIRED=40100 -iquote "/Volumes/Sources/Starteam - Main View/Workplace/Cortado/build/Cortado.build/Debug-iphonesimulator/Cortado.build/Cortado-generated-files.hmap" "-I/Volumes/Sources/Starteam - Main View/Workplace/Cortado/build/Cortado.build/Debug-iphonesimulator/Cortado.build/Cortado-own-target-headers.hmap" "-I/Volumes/Sources/Starteam - Main View/Workplace/Cortado/build/Cortado.build/Debug-iphonesimulator/Cortado.build/Cortado-all-target-headers.hmap" -iquote "/Volumes/Sources/Starteam - Main View/Workplace/Cortado/build/Cortado.build/Debug-iphonesimulator/Cortado.build/Cortado-project-headers.hmap" "-I/Volumes/Sources/Starteam - Main View/Workplace/Cortado/build/Debug-iphonesimulator/include" "-I/Volumes/Sources/Starteam - Main View/Workplace/Cortado/build/Cortado.build/Debug-iphonesimulator/Cortado.build/DerivedSources/i386" "-I/Volumes/Sources/Starteam - Main View/Workplace/Cortado/build/Cortado.build/Debug-iphonesimulator/Cortado.build/DerivedSources" "-F/Volumes/Sources/Starteam - Main View/Workplace/Cortado/build/Debug-iphonesimulator" -include "/Volumes/Sources/Starteam - Main View/Workplace/Cortado/Cortado_Prefix.pch" -MMD -MT dependencies -MF "/Volumes/Sources/Starteam - Main View/Workplace/Cortado/build/Cortado.build/Debug-iphonesimulator/Cortado.build/Objects-normal/i386/TPContentDetailViewController_iPad.d" -c "/Volumes/Sources/Starteam - Main View/Workplace/Cortado/Classes/iPad/TPContentDetailViewController_iPad.m" -o "/Volumes/Sources/Starteam - Main View/Workplace/Cortado/build/Cortado.build/Debug-iphonesimulator/Cortado.build/Objects-normal/i386/TPContentDetailViewController_iPad.o"
cc1obj: error: unrecognized command line option "-Wno-sign-conversion"
cc1obj: error: unrecognized command line option "-fdiagnostics-print-source-range-info"
cc1obj: error: unrecognized command line option "-fdiagnostics-show-category=id"
cc1obj: error: unrecognized command line option "-fdiagnostics-parseable-fixits"

如果我使用 Xcode self 的静态代码分析,我会得到以下输出,可以正常工作:

CompileC build/Cortado.build/Debug-iphonesimulator/Cortado.build/Objects-normal/i386/TPInfoCell.o Classes/TPInfoCell.m normal i386 objective-c com.apple.compilers.llvm.clang.1_0.compiler
    cd "/Volumes/Sources/Starteam - Main View/Workplace/Cortado"
    setenv LANG en_US.US-ASCII
    setenv PATH "/Developer/Platforms/iPhoneSimulator.platform/Developer/usr/bin:/Developer/usr/bin:/usr/bin:/bin:/usr/sbin:/sbin"
    /Developer/Platforms/iPhoneSimulator.platform/Developer/usr/bin/clang -x objective-c -arch i386 -fmessage-length=0 -fdiagnostics-print-source-range-info -fdiagnostics-show-category=id -fdiagnostics-parseable-fixits -Wno-trigraphs -fpascal-strings -O0 -Wreturn-type -Wparentheses -Wswitch -Wno-unused-parameter -Wunused-variable -Wunused-value -Wno-shorten-64-to-32 -DDEBUG -isysroot /Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator5.0.sdk -fexceptions -fasm-blocks -fprofile-arcs -ftest-coverage -mmacosx-version-min=10.6 -gdwarf-2 -Wno-sign-conversion -fobjc-abi-version=2 -fobjc-legacy-dispatch "-DIBOutlet=__attribute__((iboutlet))" "-DIBOutletCollection(ClassName)=__attribute__((iboutletcollection(ClassName)))" "-DIBAction=void)__attribute__((ibaction)" -D__IPHONE_OS_VERSION_MIN_REQUIRED=40100 -iquote "/Volumes/Sources/Starteam - Main View/Workplace/Cortado/build/Cortado.build/Debug-iphonesimulator/Cortado.build/Cortado-generated-files.hmap" "-I/Volumes/Sources/Starteam - Main View/Workplace/Cortado/build/Cortado.build/Debug-iphonesimulator/Cortado.build/Cortado-own-target-headers.hmap" "-I/Volumes/Sources/Starteam - Main View/Workplace/Cortado/build/Cortado.build/Debug-iphonesimulator/Cortado.build/Cortado-all-target-headers.hmap" -iquote "/Volumes/Sources/Starteam - Main View/Workplace/Cortado/build/Cortado.build/Debug-iphonesimulator/Cortado.build/Cortado-project-headers.hmap" "-I/Volumes/Sources/Starteam - Main View/Workplace/Cortado/build/Debug-iphonesimulator/include" "-I/Volumes/Sources/Starteam - Main View/Workplace/Cortado/build/Cortado.build/Debug-iphonesimulator/Cortado.build/DerivedSources/i386" "-I/Volumes/Sources/Starteam - Main View/Workplace/Cortado/build/Cortado.build/Debug-iphonesimulator/Cortado.build/DerivedSources" "-F/Volumes/Sources/Starteam - Main View/Workplace/Cortado/build/Debug-iphonesimulator" -include /var/folders/m7/1lwxj7113xb17b8k635bn0200000gn/C/com.apple.Xcode.501/SharedPrecompiledHeaders/Cortado_Prefix-curmpedgpezkvsgarfuwvmdrauwa/Cortado_Prefix.pch -MMD -MT dependencies -MF "/Volumes/Sources/Starteam - Main View/Workplace/Cortado/build/Cortado.build/Debug-iphonesimulator/Cortado.build/Objects-normal/i386/TPInfoCell.d" -c "/Volumes/Sources/Starteam - Main View/Workplace/Cortado/Classes/TPInfoCell.m" -o "/Volumes/Sources/Starteam - Main View/Workplace/Cortado/build/Cortado.build/Debug-iphonesimulator/Cortado.build/Objects-normal/i386/TPInfoCell.o"

有人知道在不禁用 LLVM 3.0 使用的情况下我可以做些什么来让 scan-build 再次运行吗?!

【问题讨论】:

    标签: xcode llvm clang clang-static-analyzer


    【解决方案1】:

    找到了构建 checker-258 的解决方案:

    将此参数传递给scan-build:--use-cc=`which clang`

    然后让它由 jenkins 和 scan-build 插件构建......这有点棘手:

    将scan-build移动到scan-build.bin,然后将scan-build变成一个脚本:

    #!/bin/sh
    
    dir=$(dirname $0)
    $dir/scan-build.bin --use-cc=`which clang` $@
    

    which clang 的结果是:/usr/bin/clang

    编辑:为两个项目工作,一个使用 LLVM 3.0,另一个使用 llvm-gcc4.2。

    【讨论】:

    • 非常好。这对我有用。感谢您对此问题的调查。
    • 哇,很棒的答案!请注意,上面的命令 --use-cc=which clang 需要反引号(Stack Overflow 的标记语言将反引号字符解释为格式)。所以它应该看起来像这样:--use-cc='which clang'(将撇号 (') 替换为反引号字符(重音符号;ascii 字符 96)。
    【解决方案2】:

    我向 Apple 提出了一个关于此问题和其他问题的错误(例如 scan-build 无法识别 ARC 代码)。

    修复方法是安装 checker-260,参见 http://clang-analyzer.llvm.org/release_notes.html 以及对 ccc-analyzer 的修改 - http://llvm.org/viewvc/llvm-project?view=rev&revision=149094。希望对 ccc-analyzer 的修复将被合并到 scan-build 的未来版本中。

    使用最新版本的 scan-build 将避免您必须对上一个答案中描述的 scan-build 进行修改。

    【讨论】:

      【解决方案3】:

      看起来 scan-build 决定使用 llvm-gcc,这让 Xcode 感到困惑,因为它期望运行 clang。可能只是扫描构建中的一个错误;我建议向 cfe-dev 发送电子邮件。

      【讨论】:

      • 好的,我会尝试通过邮件发送给 cfe-dev。谢谢
      • cfe-dev 让我等到他们解决这个问题。问题是,如果当前 Xcode 项目设置配置为使用 llvm 或 gcc,则 scan-build 不会扫描。 scan-build 每次使用 gcc 或 g++ 取决于您在命令行中设置的内容。 :/ 所以我必须重新配置我的项目设置以使用 gcc 或禁用 jenkins 中的扫描构建。 ://
      猜你喜欢
      • 2012-06-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-05-10
      • 1970-01-01
      • 2011-11-22
      相关资源
      最近更新 更多