美文网首页iOS DeveloperiOS相关技术实现
项目代码监控优化 -- 利用infer进行代码质量检测

项目代码监控优化 -- 利用infer进行代码质量检测

作者: Dombo_Y | 来源:发表于2018-07-09 18:37 被阅读23次

facebook infer 代码静态检测

1. infer 相关网站

Infer 中文 | APP 的静态分析工具

2. 环境配置

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 上的 下载应该都会,不说了 -=-=-=-=-=-=-=-=-=-=-=-

image.png

配置 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 提示的页面中查看相关解决方法

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>'

解决方案(网页里有):

image.png

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

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

根据工程文件大小扫描时长不等。

5、扫描结果

扫描结果路径:/Users/yindongbo/Downloads/infer-master/examples/ios_hello/infer-out/bugs.txt

image.png

------ 2018/7/9 还没写完后面补 -------

相关文章

网友评论

    本文标题:项目代码监控优化 -- 利用infer进行代码质量检测

    本文链接:https://www.haomeiwen.com/subject/tfwtpftx.html