facebook infer 代码静态检测
1. infer 相关网站
2. 环境配置
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 上的 下载应该都会,不说了 -=-=-=-=-=-=-=-=-=-=-=-
配置 infer 相关依赖库
在终端中 使用 homebrew 安装 贼鸡儿方便
(1)brew install autoconf automake cmake opam pkg-config sqlite
10-20分钟
(2)brew cask install java
10-20分钟
(3) brew install infer
(这里可能出现报错)
前俩安装需要翻墙。(手动狗头.jpg)
brew install infer 如果出现类似报错,进入read this 提示的页面中查看相关解决方法
报错:
=-=- 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>'
解决方案(网页里有):
到这,infer 算是安装完成了
4.使用infer 进行项目静态检测:
(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
根据工程文件大小扫描时长不等。
5、扫描结果
扫描结果路径:/Users/yindongbo/Downloads/infer-master/examples/ios_hello/infer-out/bugs.txt
------ 2018/7/9 还没写完后面补 -------