You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
infer_clone/website/docs/01-analyzing-apps-or-projec...

4.5 KiB

id title
analyzing-apps-or-projects Analyzing apps or projects

To analyze files with Infer you can use the compilers javac and clang. You can also use Infer with gcc, however, internally Infer will use clang to compile your code. So, it may not work if your code does not compile with clang.

Moreover, you can run Infer with a variety of build systems. Notice that you can run infer faster by running the compilation command in parallel, e.g. infer run -- make -j8. Please also take into account that if you wish to analyze a project, you should probably do clean beforehand so that the compiler compiles all the files and so Infer also analyses all the files (see the previous section).

Here is an overview of the build systems supported by Infer. You can get more information about how a particular build system is supported by looking at the SYNOPSIS section of the infer-capture manual: infer capture --help.

ant

infer run -- ant

Buck

Running:

infer run -- buck <buck target>

will compute the list of Infer warnings in the targets passed as argument.

Running:

infer run -- buck --deep <buck target>

will compute the list of Infer warnings in the targets passed as argument and all the transitive dependencies.

The distinction between --deep and the normal Buck complation mode is only supported for Java projects. For the other kinds of projects, the --deep option has no effect.

cmake

The most robust way is to have cmake generate a compilation database that can be then processed by Infer:

cd build
cmake -DCMAKE_EXPORT_COMPILE_COMMANDS=1 ..
cd ..
infer run --compilation-database build/compile_commands.json

Alternatively, one can trick cmake into using infer instead of the system's compilers:

cd build
infer compile -- cmake ..
infer run -- make -j 4

Gradle

infer run -- gradle <gradle task, e.g. "build">
infer run -- ./gradlew <gradle task, e.g. "build">

Make

Infer can analyze projects that compile with make by switching the compilers (for C/C++/Objective-C or Java) called by make with infer wrappers. This doesn't always work, for instance if the Makefiles hardcode the absolute paths to the compilers (eg, if make calls /usr/bin/gcc instead of gcc). This is because this integration works by modifying PATH under the hood.

infer run -- make <make target>

Maven

infer run -- mvn <maven target>

Xcodebuild

The most robust way is to generate a compilation database, then pass that database to Infer:

xcodebuild <your build options> | tee xcodebuild.log
xcpretty -r json-compilation-database -o compile_commands.json < xcodebuild.log > /dev/null
infer run --skip-analysis-in-path Pods --clang-compilation-db-files-escaped compile_commands.json

See also this comment on GitHub.

Infer also provides a direct integration to xcodebuild that swaps the compiler used by xcodebuild under the hood. For instance, for an iOS app:

infer run -- xcodebuild -target <target name> -configuration <build configuration> -sdk iphonesimulator

There is an alternative xcodebuild integration that uses xcpretty under the hood; use it by passing --xcpretty to infer.

xctool

Use xctool to generate a compilation database then pass it to infer:

xctool.sh <your build options> -reporter json-compilation-database:compile_commands.json
infer run --skip-analysis-in-path Pods --clang-compilation-db-files-escaped compile_commands.json

See also this comment on GitHub.

Using a compilation database

Many build systems like cmake, Xcode or Buck generate compilation databases. infer is able to use this database directly, simplifying its usage.

infer --compilation-database compile_commands.json

Other build systems

If infer doesn't recognize your build system, you will get an error like this:

$ infer run -- foo
Usage Error: Unsupported build command foo

If your build system behaves like one of the above, you can tell infer to use the same integration with --force-integration. For instance this will proceed as if foo was working the same way as make:

infer run --force-integration make -- foo

If your build system is more exotic, and it doesn't support outputting compilation databases, please let us know by opening an issue.