Infer of facebook使用简介 Mac篇

Infer是一款静态代码检查工具, 最初由Monoidics(2009年成立、专门设计代码分析工具的公司)开发。

后来facebook收购了Monoidics公司,infer就成为了facebook的内部工具。后来facebook将infer开源了(https://github.com/facebook/infer)。

Infer 支持 Objective-C / Java / C代码。 Facebook主要利用Infer进行Android平台和iOS平台Objective-C代码的分析。

本文就来看下如何进行infer的安装及使用。

安装:

1. 安装相关的依赖

1) install opam

brew install opam, 需要点时间。

opam init -y --comp=4.01.0

eval $(opam config env) 

opam update 

opam install -y atdgen.1.6.0 extlib.1.5.4  javalib.2.3.1 sawja.1.5.1

2) python 2.7

3) Java (only needed for the Java analysis)

4) clang in Xcode command line tools. You can install them with the command xcode-select --install (only needed for the C/Objective-C analysis)

5) Xcode >= 6.1 (only needed for the C/Objective-C analysis)

2. 下载最新的infer release版本:

https://github.com/facebook/infer/releases/latest/

目前最新的版本是infer-osx-v0.4.0.tar.xz

3. 解压缩及加入PATH

tar xf infer-*-v0.4.0.tar.xz 

cd infer-*-v0.4.0 

make -C infer 

export PATH=`pwd`/infer/bin:$PATH

4. infer 可用:

infer -v

Infer version v0.4.0

Copyright 2009 - present Facebook. All Rights Reserved.

更多信息可参考:http://fbinfer.com/docs/getting-started.html

遇到的问题:

1. make -C infer出错

Infer of facebook使用简介 Mac篇_第1张图片

原因是, 没有安装CommandLineTools, 所以补安装Xcode


2. 运行infer -- javac Hello.java出错:     

self.analysis.start()

  File "/Users/xxxx/Library/Infer/infer-osx-v0.4.0/infer/bin/inferlib.py", line 692, in start

    if self.capture() == os.EX_OK:

  File "/Users/xxxx/Library/Infer/infer-osx-v0.4.0/infer/bin/inferlib.py", line 478, in capture

    return self.run_infer_frontend()

  File "/Users/xxxx/Library/Infer/infer-osx-v0.4.0/infer/bin/inferlib.py", line 469, in run_infer_frontend

    self.args.analyzer

  File "/Users/xxxx/Library/Infer/infer-osx-v0.4.0/infer/bin/inferlib.py", line 376, in run_command

    return subprocess.check_call(cmd)

  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/subprocess.py", line 535, in check_call

    retcode = call(*popenargs, **kwargs)

  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/subprocess.py", line 522, in call

    return Popen(*popenargs, **kwargs).wait()

  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/subprocess.py", line 709, in __init__

    errread, errwrite)

  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/subprocess.py", line 1326, in _execute_child

    raise child_exception

OSError: [Errno 2] No such file or directory

解决方法: 将File "/Users/xxxx/Library/Infer/infer-osx-v0.4.0/infer/bin/inferlib.py"的第376行 return subprocess.check_call(cmd) ==》 

return subprocess.check_call(cmd,shell=True)

3.  运行infer -- javac Hello.java出错:ll

infer -- javac Hello.java

-project_root: /Users/xxxx/Library/Infer/infer-osx-v0.4.0/infer/bin/InferJava: No such file or directory

解决方法:没解决, 一会就有了。




你可能感兴趣的:(代码分析,infer)