最近想对iOS项目的代码进行静态分析,最后在几个成熟的工具中选择了Facebook的Infer工具。
然后对照github上的说明安装:https://github.com/facebook/infer/blob/master/INSTALL.md
中间踩了一些坑,记录下来方便后面自己再遇到时查阅。
1. 安装brew: curl -LsSf http://github.com/mxcl/homebrew/tarball/master | sudo tar xvz -C/usr/local --strip 1 sudo brew update 2. 安装wget:
brew install wget (不一定需要,顺便安装下) 3.
使用brew安装一些工具: brew install autoconf automake cmake opam pkg-config brew install caskroom/cask/brew-cask brew cask install java 4.
opam工具更新和配置:
opam update =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= 1. To configure OPAM in the current shell session, you need to run: eval `opam config env` 2. To correctly configure OPAM for subsequent use, add the following line to your profile file (for instance ~/.bash_profile): . /Users/Ben/.opam/opam-init/init.sh > /dev/null 2> /dev/null || true 3. To avoid issues related to non-system installations of `ocamlfind` add the following lines to ~/.ocamlinit (create it if necessary): let () = try Topdirs.dir_directory (Sys.getenv "OCAML_TOPLEVEL_PATH") with Not_found -> () ;; =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= 5.
安装xcpretty工具: sudo gem install xcpretty -n/usr/local/bin 6.
从源码安装编译Infer工具:(安装过程中根据需要修改目录下面的opam配置文件中相关工具版本号) git clone https://github.com/facebook/infer.git cd infer ./build-infer.sh clang export PATH=`pwd`/infer/bin:$PATH echo "export PATH=\"\$PATH:`pwd`/infer/bin\"" \ >> ~/.bash_profile source ~/.bash_profile 7.
进入需要检查的项目目录下,使用命令进行静态分析,最终会在项目目录中生成infer-out文件夹,里面会有report.json、report.csv、bugs.txt三种格式的结果文件:
xcodebuild -workspace ./xxxx.xcworkspace -scheme xxxx -configuration Debug -sdk iphonesimulator clean infer -- xcodebuild -workspace ./xxxx.xcworkspace -scheme xxxx -configuration Debug -sdk iphonesimulator
增量分析的话接着上面执行:
infer --incremental -- xcodebuild -workspace ./xxxx.xcworkspace -scheme xxxx -configuration Debug -sdk iphonesimulator (--incremental可以写成--i)