facebook的infer检测工具的安装

缘由

由于公司产出代码的时候会使用静态扫描工具检测代码的质量,所以自己就想动手尝试一番infer整个的使用方式和使用效果,便动手安装了infer,结果安装过程中遇见太多的坑,导致很多时候都安装失败,这篇文章主要就是为记录各个坑而产生的

infer提供了在Mac和linux下安装的教程,我所使用的是Mac,所以在这里只介绍在Mac下的安装

首先是环境要求:

  • opam >= 1.2.0
  • Python 2.7
  • Java (only needed for the Java analysis)
  • clang in Xcode command line tools. You can install them with the command xcode-select --install (only needed for the C/Objective-C analysis)
  • Xcode >= 6.1 (only needed for the C/Objective-C analysis)

介绍安装:

  • 在安装opam前先安装brew,brew 又叫Homebrew,是Mac OSX上的软件包管理工具,能在Mac中方便的安装软件或者卸载软件, 只需要一个命令
    安装命令如下:
curl -LsSf http://github.com/mxcl/homebrew/tarball/master | sudo tar xvz -C/usr/local --strip 1
  • 接着安装opam:
sudo brew install opam # Homebrew, OSX Mavericks or later
  • 安装clang
xcode-select --install
  • 配置opam
  opam init -y --comp=4.01.0
  eval `opam config env`
  opam install -y extlib.1.5.4 atdgen.1.6.0 javalib.2.3.1 sawja.1.5.1
  • 安装JDK(我在这一步犯了很大的错误,我以为mac默认已经安装了JDK环境的,结果最后才知道我的电脑没有安装....)

[官方地址] :http://www.oracle.com/technetwork/java/javase/downloads/index.html

接下来是最主要的工作,也是很漫长的工作

安装infer

克隆infer的git地址:

git clone https://github.com/facebook/infer.git

cd infer

git submodule update --init --recursive

安装clang工具:

这里有两个需要注意的点: 一是在shell脚本里面是需要安装cmake工具的,所以你需要用到命令行: brew install cmake

二是整个过程大概10几20分钟,可以睡个觉~

facebook-clang-plugins/clang/setup.sh

接下来:

以下两步为原始答案:(但是我无论怎么试都是提示命令找不到)

  1. ./compile-fcp.sh
  2. make -C infer

所以只能另辟蹊径:

查阅官方文档:

https://github.com/facebook/infer/blob/master/INSTALL.md

得知使用下列命令可以解决:

./build-infer.sh clang(有可能还需要升级: 使用opam update)

参考链接:

  1. http://blog.csdn.net/elisa1988/article/details/46531745
  2. http://infer.liaohuqiu.net/docs/getting-started.html
  3. http://blog.csdn.net/itfootball/article/details/46474235
  4. http://www.cnblogs.com/hlfme/p/4623551.html
原文地址:https://www.cnblogs.com/WayneLiu/p/5806292.html