Skip to content

Instantly share code, notes, and snippets.

@shankybnl
Last active June 14, 2017 05:10
Show Gist options
  • Save shankybnl/a80b06775382e260e5e10472bd293489 to your computer and use it in GitHub Desktop.
Save shankybnl/a80b06775382e260e5e10472bd293489 to your computer and use it in GitHub Desktop.
Setting up Infer on Ubuntu via Docker

Infer - A tool by facebook to detect bugs in Java and C/C++/Objective-C code before it ships

It is a static analysis tool - if you give Infer some Java or C/C++/Objective-C code it produces a list of potential bugs.

Anyone can use Infer to intercept critical bugs before they have shipped to users, and help prevent crashes or poor performance.

Here's step by step description for setting up and running the Infer examples on Ubuntu via Docker:
  1. Docker should be installed as a prerequisite.

  2. Open the terminal. Create a new directory with name infer and change your directory:

    ~# mkdir infer

    ~# cd infer

  3. Now, run the below commands. It might take few minutes. Running as root user is not recommended Don't run the below commands as root user:

    ~# wget -O D ockerfile https://raw.githubusercontent.com/facebook/infer/master/docker/Dockerfile

    ~# wget -O run.sh https://raw.githubusercontent.com/facebook/infer/master/docker/run.sh

    ~# sh run~# .sh

  4. Below command will list all the docker images. It should display the infer image.

    ~# docker images

  5. Run a command on infer container: docker run -it < image name >

    ~# docker run -it infer

  6. Go to examples directory:

    ~# cd ../infer/examples/

  7. Always compile a file prior to running it with infer. This is to check there should be no compilation errors. Compile Hello.java file.

    ~# javac Hello.java

  8. If there are no errors, now run it with infer. You will see errors shown by infer.

    ~# infer -- javac Hello.java

  9. Running sample android app. Build the app so that there would be no errors.

    ~# cd /infer/examples/android_hello ~# ./gradlew build

  10. Finding errors in sample app with infer

    ~# infer -- ./gradlew build

  11. Running examples in java_hello folder:

    ~# cd /infer/examples/java_hello

    infer -- javac Hello.java Resources.java Pointers.java

  12. To exit from docker container:

    ~# exit

  13. To copy your files to docker container:

    ~# docker cp < path of file on your system > < docker container id > : <path of destination in container>

  14. To obtain container id, run:

    ~# docker ps

@vishusingh
Copy link

bitmoji

@shashankqv
Copy link

very nice @shankybnl

@shankybnl
Copy link
Author

shankybnl commented Jun 14, 2017

Thanks @vishusingh and @shashankqv :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment