項目代碼監(jiān)控優(yōu)化 -- 利用infer進行代碼質(zhì)量檢測

facebook infer 代碼靜態(tài)檢測

1. infer 相關(guān)網(wǎng)站

Infer 中文 | APP 的靜態(tài)分析工具

2. 環(huán)境配置

infer 安裝過程中會依賴一些工具(HomebrewOPAM

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 下載 與 安裝配置

infer github地址

infer 安裝配置手冊

-=-=-=-=-=-=-=-=- github 上的 下載應(yīng)該都會,不說了 -=-=-=-=-=-=-=-=-=-=-=-

image.png

配置 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)解決方法

image.png

報錯:

=-=- 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)頁里有):

image.png

到這,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

github issues


問題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

image.png

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

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容