代码扫描

使用infer进行静态分析总结

2020-11-18  本文已影响0人  yanhooIT

infer的安装

brew install infer

使用infer过程中遇到的问题及解决方案

问题1

# 直接分析我这里没有成功
infer run --skip-analysis-in-path Pods --no-xcpretty --keep-going -- xcodebuild -workspace xxxx.xcworkspace -scheme xxxx -configuration Debug -sdk iphoneos

# 使用上述分析命令会有编译失败的问题(已脱敏)
** BUILD FAILED **

The following build commands failed:
    这一段省略了...
(8 failures)
Internal Error:   /usr/local/Cellar/infer/0.17.0/lib/infer/infer/bin/../lib/python/infer.py
  -j 8 --project-root /Users/xxx/Desktop/Code/xxx-iOS/xxx --out
  /Users/xxx/Desktop/Code/xxx-iOS/xxx/infer-out -- xcodebuild
  -workspace xxx.xcworkspace -scheme xxx -configuration Debug -sdk
  iphoneos:
  exited with code 65
Error backtrace:
Raised at file "string.ml", line 145, characters 16-31
Called from file "string.ml" (inlined), line 149, characters 17-46
Called from file "src/string.ml", line 407, characters 12-33
Called from file "src/string.ml", line 416, characters 11-33
Re-raised at file "base/Die.ml", line 26, characters 8-56
Called from file "integration/Driver.ml", line 171, characters 2-16
Called from file "integration/Driver.ml", line 272, characters 6-409
Called from file "integration/Driver.ml", line 323, characters 2-29
Called from file "base/Utils.ml", line 398, characters 16-20
Called from file "scuba/ScubaLogging.ml", line 66, characters 29-44
Called from file "infer.ml", line 20, characters 2-36
Called from file "base/Utils.ml", line 398, characters 16-20
Called from file "scuba/ScubaLogging.ml", line 66, characters 29-44
Called from file "infer.ml", line 137, characters 8-54

问题2

Error message:
clang-8: error: unknown argument: '-index-store-path'

*** Infer needs a working compilation command to run.

使用infer进行项目分析

infer run -- xcodebuild -target <target name> -configuration <build configuration> -sdk iphoneos
# 进入项目根目录
cd projectRootMenu

# infer默认是增量编译,只会分析变动的代码,如果我们想整体编译的话,需要clean一下项目
xcodebuild clean
或者
xcodebuild -workspace xxx.xcworkspace -scheme xxx -sdk iphoneos clean

# 可以通过如下命令查看-sdk版本,如果使用iphoneos需要**检查证书**
xcodebuild -showsdks

# 分析项目命令步骤如下
# 第1步:编译工程生成编译日志xcodebuild.log文件
xcodebuild -workspace xxx.xcworkspace -scheme xxx -configuration Debug -sdk iphoneos COMPILER_INDEX_STORE_ENABLE=NO | tee xcodebuild.log
# 第2步:根据编译日志生成编译数据compile_commands.json文件
xcpretty -r json-compilation-database -o compile_commands.json < xcodebuild.log > /dev/null
# 第3步:基于编译数据compile_commands.json文件进行静态分析
infer run --skip-analysis-in-path Pods --no-xcpretty --keep-going --compilation-database-escaped compile_commands.json

infer检测的错误类型说明

参考资料

上一篇下一篇

猜你喜欢

热点阅读