facebook infer 代碼靜態(tài)檢測
1. infer 相關(guān)網(wǎng)站
2. 環(huán)境配置
infer 安裝過程中會依賴一些工具(Homebrew,OPAM)
1、HomeBrew 安裝:
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
2、OPAM 安裝:
sudo brew install opam
3、clane 安裝
xcode-select --install
3. infer 下載 與 安裝配置
-=-=-=-=-=-=-=-=- github 上的 下載應(yīng)該都會,不說了 -=-=-=-=-=-=-=-=-=-=-=-

配置 infer 相關(guān)依賴庫
在終端中 使用 homebrew 安裝 賊雞兒方便
(1)brew install autoconf automake cmake opam pkg-config sqlite
10-20分鐘
(2)brew cask install java
10-20分鐘
(3) brew install infer
(這里可能出現(xiàn)報錯)
前倆安裝需要翻墻。(手動狗頭.jpg)
brew install infer 如果出現(xiàn)類似報錯,進入read this 提示的頁面中查看相關(guān)解決方法

報錯:
=-=- Installing compiler 4.06.1+flambda -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
[4.06.1+flambda: http]
[ERROR] https://github.com/ocaml/ocaml/archive/4.06.1.tar.gz is not available.
*** ERROR: `opam switch set -j 4 infer-4.06.1+flambda --alias-of 4.06.1+flambda` failed
READ THIS: https://docs.brew.sh/Troubleshooting
/usr/local/Homebrew/Library/Homebrew/utils/github.rb:222:in `raise_api_error': curl failed! (GitHub::Error)
curl: (35) LibreSSL SSL_connect: SSL_ERROR_SYSCALL in connection to api.github.com:443
curl: (3) <url> malformed
from /usr/local/Homebrew/Library/Homebrew/utils/github.rb:180:in `open_api'
from /usr/local/Homebrew/Library/Homebrew/utils/github.rb:294:in `search'
from /usr/local/Homebrew/Library/Homebrew/utils/github.rb:227:in `search_issues'
from /usr/local/Homebrew/Library/Homebrew/utils/github.rb:240:in `issues_for_formula'
from /usr/local/Homebrew/Library/Homebrew/exceptions.rb:368:in `fetch_issues'
from /usr/local/Homebrew/Library/Homebrew/exceptions.rb:364:in `issues'
from /usr/local/Homebrew/Library/Homebrew/exceptions.rb:418:in `dump'
from /usr/local/Homebrew/Library/Homebrew/brew.rb:137:in `rescue in <main>'
from /usr/local/Homebrew/Library/Homebrew/brew.rb:29:in `<main>'
解決方案(網(wǎng)頁里有):

到這,infer 算是安裝完成了
4.使用infer 進行項目靜態(tài)檢測:
(1)單文件檢測自己看說明很簡單 ,這里不說了(點這里自己看??)
(2)項目檢測坑有點多 ,遇見一堆問題
問題1:
Xcode: xcode-select: error: tool 'xcodebuild' requires Xcode, but active developer directory '/Library/Developer/CommandLineTools' is a command line tools instance
sudo xcode-select -s /Applications/Xcode.app/Contents/Developer
問題2:
like
BUILD FAILED
Error backtrace:
Raised at file "integration/Driver.ml", line 297, characters 16-78
Called from file "integration/Driver.ml", line 176, characters 2-16
Called from file "backend/infer.ml", line 23, characters 2-36
Called from file "backend/infer.ml", line 106, characters 6-52
Uncaught error: ("InferModules__Driver.Infer_error("exited with code 65")")
解決辦法:
infer --keep-going --no-xcpretty -- xcodebuild build -scheme HelloWorldApp -workspace HelloWorldApp.xcworkspace -configuration Debug -sdk iphoneos
這里用的是 infer 中的 examples,其中 HelloWorldApp 為 appName
infer --keep-going --no-xcpretty -- xcodebuild build -scheme appName -workspace appName.xcworkspace -configuration Debug -sdk iphoneos
infer --keep-going --no-xcpretty -- xcodebuild build -scheme laoyuegou -workspace laoyuegou.xcworkspace -configuration Debug -sdk iphoneos
項目掃描
cd infer-master/examples/ios_hello
infer --keep-going --no-xcpretty -- xcodebuild build -scheme HelloWorldApp -workspace HelloWorldApp.xcworkspace -configuration Debug -sdk iphoneos
根據(jù)工程文件大小掃描時長不等。
5、掃描結(jié)果
掃描結(jié)果路徑:/Users/yindongbo/Downloads/infer-master/examples/ios_hello/infer-out/bugs.txt

------ 2018/7/9 還沒寫完后面補 -------