Infer工具Docker image发布

来源:互联网 发布:港澳台直播软件下载 编辑:程序博客网 时间:2024/06/08 02:04

制作该Image的目的

由于Infer工具刚刚推出来,很多人想试用该工具,但是又苦于环境的配置略显复杂,最近有很多人找我解决关于环境配置的问题,这阻碍了Infer的推广。而Docker技术具有易移植的特性,将该工具的环境制作成Image,你只需下载在到本地就可以体验该新工具的特性,就可以对其做一个简单的了解。

注意:OC和iOS项目的分析是不支持的

Dockerfile

我并没有利用Dockerfile来制作该Image,但是我将我制作的Dockerfile贴出来,方便大家了解我的制作过程:

# Base imageFROM heikomaass/android-sdk# AuthorMAINTAINER doctorq <542113578@qq.com># Upgrade apt-get toolRUN apt-get updateRUN apt-get -y upgrade# Install toolsRUN apt-get install -y git m4 zlib1g-dev python-software-properties \    build-essential libgmp-dev libmpfr-dev libmpc-dev unzip software-properties-common python-software-properties# Install opamRUN add-apt-repository ppa:avsm/ppaRUN apt-get updateRUN apt-get install -y ocaml ocaml-native-compilers camlp4-extra opamRUN opam init --comp=4.01.0  # (answer 'y' to the question)ENV CAML_LD_LIBRARY_PATH /root/.opam/4.01.0/lib/stublibsENV MANPATH :/root/.opam/4.01.0/manENV PERL5LIB /root/.opam/4.01.0/lib/perl5ENV OCAML_TOPLEVEL_PATH /root/.opam/4.01.0/lib/toplevelENV OPAM_HOME /root/.opam/4.01.0/binENV PATH ${PATH}:${CAML_LD_LIBRARY_PATH}:${MANPATH}:${PERL5LIB}:${OCAML_TOPLEVEL_PATH}:${OPAM_HOME}#RUN opam updateRUN opam install sawja.1.5.1 atdgen.1.6.0 javalib.2.3.1 extlib.1.5.4# Download infer source codeRUN git clone https://github.com/facebook/infer.git# Install facebook-clang-plugin,clangRUN cd infer;./update-fcp.sh;RUN cd infer;apt-get install -y groffRUN cd infer;../facebook-clang-plugin/clang/setup.sh;RUN eval `opam config env`;cd infer;./compile-fcp.shRUN eval `opam config env`;cd infer;make -C inferENV INFER_HOME /infer/inferENV PATH ${PATH}:${INFER_HOME}/bin#Install gradle-2.5RUN add-apt-repository ppa:cwchien/gradleRUN apt-get update#RUN apt-cache search gradleRUN apt-get install gradle-2.5CMD eval `opam config env`

(我会实际操作一次,等我有时间的时候)

上传

在经历了1个礼拜的上传失败后,公司的网络终于给力了,infer 的image终于上传Docker Hub成功.

成功信息

58deMacBook-Pro:~ wuxian$ docker push doctorq/inferThe push refers to a repository [doctorq/infer] (len: 1)334f8536c724: Image already exists 79c86a401c9e: Image already exists b08982ff2ae7: Image already exists 295452c2332e: Image already exists 6f7ac6b3c22e: Image successfully pushed 2f723dfaaf02: Image successfully pushed 4f8c30699e9d: Image successfully pushed cd797a7e1a37: Image successfully pushed 3ebbcb595d4f: Image successfully pushed 2d901fe5706a: Image successfully pushed 2ab20d71784e: Image already exists 86f5a419baeb: Image successfully pushed 87936850fe94: Image already exists 6a34f2ecf1ae: Image already exists 896c84d68ec8: Image successfully pushed f95fdfd19566: Image successfully pushed 68f48e28c14b: Image successfully pushed 918558524beb: Image successfully pushed e81d2d3af07f: Image successfully pushed 569a964ec2cc: Image successfully pushed 1885bd64f8f7: Image successfully pushed c00c3cf3b2b4: Image successfully pushed d473f52c6131: Image successfully pushed 8d9b9414ed80: Image successfully pushed 76a68924d522: Image already exists 6be21d1e5d1e: Image already exists 020431a88ee9: Image successfully pushed 602e15acbcda: Image successfully pushed cab7c4dcf81b: Image successfully pushed Digest: sha256:ba58f6ad6d2725e2bc94bfc381217b2de7b477d4448eafd8366474aab873f609

成功截图

这里写图片描述

使用步骤

前提是你的docker环境已经配置完成

下载到本地

进入容器

docker run -it doctorq/infer /bin/bash

infer源码位置

root/infer

root@f71395f22159:/# cd root/inferroot@f71395f22159:~/infer# ls -ltotal 56-rw-r--r-- 1 root root  235 Jul 13 04:11 CONTRIBUTING.md-rw-r--r-- 1 root root 1206 Jul 13 04:11 FILES.md-rw-r--r-- 1 root root 3795 Jul 13 04:11 INSTALL.md-rw-r--r-- 1 root root 1501 Jul 13 04:11 LICENSE-rw-r--r-- 1 root root 1982 Jul 13 04:11 PATENTS-rw-r--r-- 1 root root  429 Jul 13 04:11 README.md-rwxr-xr-x 1 root root 1787 Jul 13 04:11 compile-fcp.shdrwxr-xr-x 4 root root 4096 Jul 13 04:11 dependenciesdrwxr-xr-x 6 root root 4096 Jul 16 07:39 examplesdrwxr-xr-x 9 root root 4096 Jul 13 04:19 infer-rw-r--r-- 1 root root  304 Jul 13 04:11 infer.install-rw-r--r-- 1 root root  545 Jul 13 04:11 opamdrwxr-xr-x 2 root root 4096 Jul 13 04:11 scripts-rwxr-xr-x 1 root root  739 Jul 13 04:11 update-fcp.sh

分析

我们以源码中的例子来分析,首先进入examples目录。

root@f71395f22159:~/infer# cd examples/root@f71395f22159:~/infer/examples# ls -ltotal 40-rw-r--r-- 1 root root  396 Jul 16 07:39 Hello.class-rw-r--r-- 1 root root   79 Jul 13 04:11 Hello.java-rw-r--r-- 1 root root  182 Jul 13 04:11 Hello.m-rw-r--r-- 1 root root 1221 Jul 13 04:11 READMEdrwxr-xr-x 7 root root 4096 Jul 13 09:16 android_hellodrwxr-xr-x 3 root root 4096 Jul 13 07:58 c_hello-rw-r--r-- 1 root root   65 Jul 13 04:11 hello.c-rw-r--r-- 1 root root 1240 Jul 13 07:58 hello.odrwxr-xr-x 8 root root 4096 Jul 16 07:39 infer-outdrwxr-xr-x 6 root root 4096 Jul 13 08:00 ios_hello

Java文件

root@f71395f22159:~/infer/examples# infer -- javac Hello.javaStarting analysis (Infer version git-1356fd331f3db485be9ee38446a7389c9310d344)Analysis done1 file analyzed/root/infer/examples/Hello.java:4: error: NULL_DEREFERENCE  object s last assigned on line 3 could be null and is dereferenced at line 4root@f71395f22159:~/infer/examples# 

Android项目

root@f71395f22159:~/infer/examples/android_hello# gradle clean:app:cleanBUILD SUCCESSFULTotal time: 6.522 secsThis build could be faster, please consider using the Gradle Daemon: http://gradle.org/docs/2.5/userguide/gradle_daemon.htmlroot@f71395f22159:~/infer/examples/android_hello# infer -- gradle build08:11:22.183 [ERROR] [org.gradle.api.Project] /root/infer/examples/android_hello/app/build/intermediates/exploded-aar/com.android.support/appcompat-v7/22.0.0/res/drawable-hdpi-v4/abc_spinner_mtrl_am_alpha.9.png: libpng warning: iCCP: Not recognizing known sRGB profile that has been edited08:11:36.470 [ERROR] [org.gradle.api.Project] /root/infer/examples/android_hello/app/build/intermediates/exploded-aar/com.android.support/appcompat-v7/22.0.0/res/drawable-hdpi-v4/abc_spinner_mtrl_am_alpha.9.png: libpng warning: iCCP: Not recognizing known sRGB profile that has been editedStarting analysis (Infer version git-1356fd331f3db485be9ee38446a7389c9310d344)Analysis done5 files analyzed/root/infer/examples/android_hello/app/src/main/java/infer/inferandroidexample/MainActivity.java:20: error: NULL_DEREFERENCE  object s last assigned on line 19 could be null and is dereferenced at line 20/root/infer/examples/android_hello/app/src/main/java/infer/inferandroidexample/MainActivity.java:37: error: RESOURCE_LEAK   resource acquired to fis by call to FileOutputStream(...) at line 34 is not released after line 37root@f71395f22159:~/infer/examples/android_hello# 

C文件

root@f71395f22159:~/infer/examples# infer -- gcc -c hello.cStarting analysis (Infer version git-1356fd331f3db485be9ee38446a7389c9310d344)Analysis done1 file analyzedhello.c:5: error: NULL_DEREFERENCE  pointer s last assigned on line 4 could be null and is dereferenced at line 5, column 3

C 项目

root@f71395f22159:~/infer/examples/c_hello# make cleanrm -rf example.oroot@f71395f22159:~/infer/examples/c_hello# infer -- makecc -c example.cStarting analysis (Infer version git-1356fd331f3db485be9ee38446a7389c9310d344)Analysis done1 file analyzedexample.c:22: error: NULL_DEREFERENCE  pointer max last assigned on line 21 could be null and is dereferenced at line 22, column 10example.c:36: error: NULL_DEREFERENCE  pointer joe last assigned on line 35 could be null and is dereferenced by call to get_age() at line 36, column 10example.c:45: error: RESOURCE_LEAK   resource acquired to fd by call to open() at line 41, column 12 is not released after line 45, column 5example.c:51: error: MEMORY_LEAK   memory dynamically allocated to p by call to malloc() at line 51, column 14 is not reachable after line 51, column 3example.c:57: error: MEMORY_LEAK   memory dynamically allocated to p by call to malloc() at line 56, column 14 is not reachable after line 57, column 3root@f71395f22159:~/infer/examples/c_hello# 
0 0
原创粉丝点击