目录

前言:

制作该 Image 的目的

Dockerfile

上传

成功信息

使用步骤

下载到本地

进入容器

infer 源码位置

分析

Java 文件

Android 项目

C 文件

C 项目


前言:

Infer 是来自 Facebook 的一个静态类型检测工具,它可以对 TypeScript 代码进行扫描,检测出代码中可能存在的类型错误和不安全的代码行为,并给出相应的提示和建议。Infer 使用了语言服务和代码分析技术,支持多种编程语言,包括 TypeScript、JavaScript、TypeScript 和 Dart 等。

制作该 Image 的目的

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

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

Dockerfile

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

# Base image
FROM heikomaass/android-sdk# Author
MAINTAINER doctorq <542113578@qq.com># Upgrade apt-get tool
RUN apt-get update
RUN apt-get -y upgrade# Install tools
RUN 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 opam
RUN add-apt-repository ppa:avsm/ppa
RUN apt-get update
RUN apt-get install -y ocaml ocaml-native-compilers camlp4-extra opam
RUN opam init --comp=4.01.0  # (answer 'y' to the question)
ENV CAML_LD_LIBRARY_PATH /root/.opam/4.01.0/lib/stublibs
ENV MANPATH :/root/.opam/4.01.0/man
ENV PERL5LIB /root/.opam/4.01.0/lib/perl5
ENV OCAML_TOPLEVEL_PATH /root/.opam/4.01.0/lib/toplevel
ENV OPAM_HOME /root/.opam/4.01.0/bin
ENV PATH ${PATH}:${CAML_LD_LIBRARY_PATH}:${MANPATH}:${PERL5LIB}:${OCAML_TOPLEVEL_PATH}:${OPAM_HOME}
#RUN opam update
RUN opam install sawja.1.5.1 atdgen.1.6.0 javalib.2.3.1 extlib.1.5.4# Download infer source code
RUN git clone https://github.com/facebook/infer.git# Install facebook-clang-plugin,clang
RUN cd infer;./update-fcp.sh;
RUN cd infer;apt-get install -y groff
RUN cd infer;../facebook-clang-plugin/clang/setup.sh;
RUN eval `opam config env`;cd infer;./compile-fcp.sh
RUN eval `opam config env`;cd infer;make -C infer
ENV INFER_HOME /infer/infer
ENV PATH ${PATH}:${INFER_HOME}/bin#Install gradle-2.5
RUN add-apt-repository ppa:cwchien/gradle
RUN apt-get update
#RUN apt-cache search gradle
RUN apt-get install gradle-2.5
CMD eval `opam config env`

(已验证成功,使用该 dockerfile 文件可以成功制作)

上传

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

成功信息


58deMacBook-Pro:~ wuxian$ docker push doctorq/infer:v1.1
The 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:v1.0 /bin/bash

infer 源码位置

infer

root@f71395f22159:/# cd infer
root@f71395f22159:~/infer# ls -l
total 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.sh
drwxr-xr-x 4 root root 4096 Jul 13 04:11 dependencies
drwxr-xr-x 6 root root 4096 Jul 16 07:39 examples
drwxr-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 opam
drwxr-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 -l
total 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 README
drwxr-xr-x 7 root root 4096 Jul 13 09:16 android_hello
drwxr-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.o
drwxr-xr-x 8 root root 4096 Jul 16 07:39 infer-out
drwxr-xr-x 6 root root 4096 Jul 13 08:00 ios_hello

Java 文件

root@f71395f22159:~/infer/examples# infer -- javac Hello.java
Starting analysis (Infer version git-1356fd331f3db485be9ee38446a7389c9310d344)
Analysis done1 file analyzed/root/infer/examples/Hello.java:4: error: NULL_DEREFERENCEobject 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.html
root@f71395f22159:~/infer/examples/android_hello# infer -- gradle build
08: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 edited
08: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 edited
Starting 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_DEREFERENCEobject 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_LEAKresource 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.c
Starting analysis (Infer version git-1356fd331f3db485be9ee38446a7389c9310d344)
Analysis done1 file analyzedhello.c:5: error: NULL_DEREFERENCEpointer 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 clean
rm -rf example.o
root@f71395f22159:~/infer/examples/c_hello# infer -- make
cc -c example.c
Starting analysis (Infer version git-1356fd331f3db485be9ee38446a7389c9310d344)
Analysis done1 file analyzedexample.c:22: error: NULL_DEREFERENCEpointer max last assigned on line 21 could be null and is dereferenced at line 22, column 10example.c:36: error: NULL_DEREFERENCEpointer 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_LEAKresource acquired to fd by call to open() at line 41, column 12 is not released after line 45, column 5example.c:51: error: MEMORY_LEAKmemory 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_LEAKmemory 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# 

作为一位过来人也是希望大家少走一些弯路

在这里我给大家分享一些自动化测试前进之路的必须品,希望能对你带来帮助。

(软件测试相关资料,自动化测试相关资料,技术问题答疑等等)

相信能使你更好的进步!

点击下方小卡片

【自动化测试交流】:574737577(备注ccc)http://qm.qq.com/cgi-bin/qm/qr?_wv=1027&k=ledrw146THUXWAAMrtLLjnhKSTOm3Jrc&authKey=S92q%2FlmbMwgBHO%2FRCTCMtfIJLDUX2u3md7DJhmtOWsSt2nt76MOFKR1gfRHA7nba&noverify=0&group_code=574737577

Infer 工具 Docker image相关推荐

  1. Infer工具Docker image发布

    制作该Image的目的 由于Infer工具刚刚推出来,很多人想试用该工具,但是又苦于环境的配置略显复杂,最近有很多人找我解决关于环境配置的问题,这阻碍了Infer的推广.而Docker技术具有易移植的 ...

  2. 安装容器编排工具 Docker Compose

    安装容器编排工具 Docker Compose  curl -L https://get.daocloud.io/docker/compose/releases/download/1.22.0/doc ...

  3. 【云原生】第二篇--容器管理工具 Docker生态架构及部署

    容器管理工具 Docker生态架构及部署 一.Docker生态架构 1.1 Docker Containers Are Everywhere 1.2 生态架构 1.2.1 Docker Host 1. ...

  4. linux安装nsenter工具,Docker 使用nsenter工具进入容器的操作

    在使用Docker容器的时候,利用nsenter工具会比较方便,如果我们的系统没有的话,那就需要我们自己来安装了 1.首先访问该网址找到最新版本的nsenter工具 2.然后下载nsenter工具的源 ...

  5. 容器单机编排工具 Docker Compose,swap 限制,配置默认的CFS调度程序,Stress-ng 压力测试工具,docker官网镜像上传,及阿里云镜像上传,Docker 的资源限制

    目录 Docker Compose介绍   有版本问题 一键生成 docker-compose.yml docker官网镜像上传,及阿里云镜像上传 Docker 之分布式仓库 Harbor Docke ...

  6. 开发工具-Docker学习

    完整文章地址 Docker概述 Docker应用 部署环境复杂,非常费时费力 环境不能跨平台 docker可以把环境打包成镜像,直接运行即可 docker通过隔离机制,可以将服务器利用到极致 Dock ...

  7. 在AWS Lambda上部署标准FFmpeg工具——Docker方案

    大纲 1 确定Lambda运行时环境 1.1 Lambda系统.镜像.内核版本 1.2 运行时 1.2.1 Python 1.2.2 Java 2 启动EC2 3 编写调用FFmpeg的代码 4 生成 ...

  8. 架构师工具-docker环境篇

    文章目录 环境 VirtualBox安装 Vagrant安装 安装centos7 使用ModaXterm/XShell链接centos7 Vagrantfile通用写法 vagrant box的打包分 ...

  9. libgdx 3d_使用Java和libgdx进行3D游戏编程,使用Blender建立模型

    libgdx 3d Or- the journey through the x, y, and z axes through the lens of a computer screen. 或 -通过x ...

  10. Docker 图形化页面管理工具使用

    点击上方蓝色"方志朋",选择"设为星标" 回复"666"获取独家整理的学习资料! 来源:https://my.oschina.net/u/2 ...

最新文章

  1. idea调试怎么跳出循环_使用IDEA的Debug调试功能,查看程序的运行过程
  2. View的Measure流程总结
  3. CodeAnyWhere
  4. bootstrap-响应式导航条
  5. 264. 丑数 II---LeetCode---JAVA(动态规划)
  6. suse查找oracle安装路径,Suse11sp3安装Oracle 11gR2
  7. c语言牛顿方法,C语言编写牛顿迭代法的跟踪
  8. 河北大学工商学院计算机分数线,河北大学工商学院录取分数线()
  9. HTTP详解(1)-工作原理
  10. sz命令获取文件到本地路径设置
  11. java 分词获取词性_jie分词之分词、词性分析、关键词抽取
  12. VS2013配置OpenCV3.4.0
  13. linux下安装虚拟天文馆,【地理软件】虚拟天文馆——stellarium
  14. 伪原创视频软件 视频MD5怎么更改
  15. Navicat中出现MySQL server has gone away错误
  16. 太难受了,,公司规章制度
  17. XP下安装IIS6.0的办法
  18. C++ 小白 学习记录15
  19. ssm基于BS架构的校园爱心捐赠与物品交换平台的设计与实现毕业设计源码
  20. 在ipv4的网络上使用utorrent3.0下…

热门文章

  1. 基于ssh大学生社交平台mysql
  2. 2020年最新的大数据学习路线及职业规划指南
  3. [Skr-Shop]做电商还搞不清一元秒杀、常规秒杀、限时购?
  4. win7桌面运行html,Win7桌面小工具 随时监视电脑运行状况
  5. 模型展示 | 一起来看中华瑰宝:瓷器
  6. Java三大特性,五大原则,深刻解读,读完这一篇就够了!
  7. RxJava+Retrofit框架概要设计
  8. X-MATA市场藏品价格查询插件/QQ机器人框架
  9. win2000/xp忘记密码的方法(转)
  10. TGRS2023/遥感/目标检测:CoF-Net: A Progressive Coarse-to-Fine Framework for Object Detection