A project-specific coverity.conf file contains details about the project to analyze, and how to do so.

The project-specific configuration must be manually created. There should be one project-specific coverity.conf file per project per development environment.

Each developer who works on that code base should use the same project-specific coverity.conf, and the project-specific configuration should be stored at the root of the project. The easiest way to ensure this is to store the coverity.conf file in the root directory of the same repository as the code itself.

The project-specific configuration can specify a variety of things:

Alternative configuration settings

Whether your client system connects via a Coverity on Polaris server or a Coverity Connect server, you can use the project-specific coverity.conf file to specify custom analysis settings.

There are a number of reasons you might want to use a project-specific coverity.conf file:

  1. As already described, to specify the Coverity Connect server and the Coverity Connect stream.

    This applies only when Coverity Analysis connects to a Coverity Connect server. It does not apply when Coverity Analysis connects via Coverity on Polaris.

  2. To specify an alternative installation directory for Coverity Analysis.

    To do so, you would use the KnownInstallation object: Please see the Coverity Desktop Analysis User Guide for details.

  3. To specify a compiler configuration that is not the standard configuration for the IDE you use.

    See “Special-purpose compiler configurations”.

  4. To specify alternative build tools.

    Certain development environments require explicit build specification. See “Frequently asked questions”

  5. For Code Sight running Coverity Analysis in Eclipse or in Visual Studio, to enable MISRA compliance testing. See “Enabling MISRA compliance testing”.
  6. To specify custom analysis settings.

    Analysis settings are described elsewhere. There are too many to list here, but Custom analysis settings lists resources for learning about analysis options.

Important: The coverity.conf JSON file format is standard for desktop configurations of Coverity Analysis. For more information about it, please see the Coverity Desktop Analysis User Guide.

Special-purpose compiler configurations

Here are a couple of use cases for specifying a custom compiler configuration, and examples of how to do so.

Use case: Your build uses the ARM (RISC) compiler rather than the more widespread GCC (GNU Compiler Collection). The following coverity.conf code specifies this:

{
    "type": "Coverity configuration",
    "format_version": 1,
    "format_minor_version": 7,
    "settings": {
        "add_compiler_configurations": [
            /* arm-none-eabi-gcc is a common gcc variant
               for ARM-based embedded development */
            {
                "cov_configure_args": [
                    "--template",
                    "--compiler",
                    "arm-none-eabi-gcc",
                    "--comptype",
                    "gcc"
                ]
            }
        ]
    }
}

Use case: You want to continue using the Clang compiler front end, but you want to invoke it using the old-style (and self-descriptive) aliases cc and c++. The following coverity.conf code specifies this:

{
    "type": "Coverity configuration",
    "format_version": 1,
    "format_minor_version": 7,
    "settings": {
        "add_compiler_configurations": [
            /* On a Mac, CMake will use the "cc" and "c++" aliases
               instead of "clang" */
            {
                "cov_configure_args": [
                    "--template",
                    "--compiler",
                    "cc",
                    "--comptype",
                    "clangcc"
                ]
            },
            {
                "cov_configure_args": [
                    "--template",
                    "--compiler",
                    "c++",
                    "--comptype",
                    "clangcxx"
                ]
            }
        ]
    }
}
Note: On a site that connects via Coverity Connect, these sample configurations would also require server and stream fields.

Specifying custom build tools

To use build tools that differ from the standard tools used by your development environment, specify these with a cov_run_desktop object in the coverity.conf file.

Here is a sample configuration file that contains a cov_run_desktop object:

{
    "type": "Coverity configuration",
    "format_version": 1,
    "format_minor_version": 7,
    "settings": {
        "cov_run_desktop": {
            "build_cmd": ["make", "all"],
            "clean_cmd": ["make", "clean"]
        },
        "ide": {
            "build_strategy": "CUSTOM"
        }
    }
}

This particular sample configuration sets up a project that uses the make build system. In your own file, you would replace the "build_cmd" and "clean_cmd" values with the names of the build and clean commands that your project actually uses.

For example, to use Apache Maven as your build tool, the "cov_run_desktop" fields would look like this:

        "cov_run_desktop": {
            "build_cmd": ["mvn", "compile"],
            "clean_cmd": ["mvn", "clean"]
        }

Don’t forget: In the "ide" object, you must set "build_strategy" to equal "CUSTOM". If this field is missing, or is set to a different value, Code Sight does not recognize the custom settings, or use the alternative tools you specified.

Building with Bazel

If you run Coverity 2024.3.0 or a newer version, you can use the Bazel build tool.

Before you begin to configure Bazel, please see the "requirements and limitations" for Coverity and Bazel.

To enable the Coverity-Bazel integration:

  1. Follow the steps in the Coverity documentation: See "Building with Bazel" in the Coverity Analysis User and Administrator Guide.

    You will need to modify the Bazel build file and either the workspace file or the module file. More steps are needed if you use Bazel 7 or a newer version.

  2. Add a coverity.conf file to the root of your project and configure it for Bazel support.

    Here is an example of such a configuration file:

    {
        "type": "Coverity configuration",
        "format_version": 1,
        "format_minor_version": 7,
        "settings": {
            "cov_run_desktop": {
                "build_options": [
                    "--bazel"
                ],
                "build_cmd": [
                    "bazel",
                    "build",
                    "--registry=file:///<myLocn>/../../cov-registry",
                    "--registry=http://<myURL>/../packages/bazel/central-registry",
                    ":coverity_build"
                ]
            },
            "ide": {
                "build_strategy": "CUSTOM"
            }
        }
    }

    If you already have a project-specific coverity.conf file, add the "settings" fields to it.

Exclude files or directories from Coverity Analysis

You can exclude files or directories from Coverity Analysis scans.

CAUTION: This functionality applies when using the Coverity tools and not when using Polaris scans.

There are two ways to exclude files or directories from a Coverity Analysis scan, as the following sections describe.

• Use the project-specific coverity.conf file

Add the following "settings" section to this file:

{
    "type": "Coverity configuration",
    "format_version": 1,
    "format_minor_version": 7,
    "settings": {
        "cov_run_desktop": {
            "ignore_all_files_regex":"<regex>"
        }
    }
}

• Use the Advanced options for your Coverity scan configuration

Add the option string to the Coverity section of the Advanced section of the Scan Configuration dialog (IntelliJ) or tab (VS Code).

Figure 1. --ignore-all-files-regex option in a Coverity scan configuration for IntelliJ

Advanced scan configuration for Coverity showing the --ignore-all-files-regex option (IntelliJ)

Figure 2. --ignore-all-files-regex option in a Coverity scan configuration for VS Code

Advanced scan configuration for Coverity showing the --ignore-all-files-regex option (VS Code)

The regular expression

In either case, the format of the string represented by <regex> depends on the operating system that you use:

Linus or macOS
Here is an example:

.*/<folder_name>/.*

Windows
Here is an example:

.*\\\\<folder_name>\\\\.*

Set up Kotlin analysis for Android Studio

While running Coverity Analysis 2022.3.1 or a later version of Coverity, the Android Studio development environment can analyze Kotlin source code and combined Kotlin/Java projects. Some additional setup is required.

Setting up Kotlin analysis

To enable Kotlin analysis in Android Studio, you must first run the cov-configure --kotlin command to enable the build capture of Kotlin Android source and the filesystem capture of Android configuration files.

You also need to specify --fs-capture-search when you invoke the cov-build command. Coverity will capture Kotlin Android files that are needed by the analysis, including the manifest (AndroidManifest.xml) and the layout resource files.

No special flags are needed for the cov-analyze command, because Kotlin checkers are enabled by default.

Setting up Kotlin/Java analysis

Run both cov-configure --java and cov-configure --kotlin to enable the build capture of both Java and Kotlin Android source and the filesystem capture of Android configuration files. (Filesystem capture can be used as a fallback only for Java.)

Pass --fs-capture-search to the cov-build command. Coverity will capture Java and Kotlin Android files that are needed by the analysis, including the manifest (AndroidManifest.xml) and the layout resource files.

Specify --android-security when you invoke the cov-analyze command.

Note: Coverity analyzes Java and Kotlin source code separately.

Sample coverity.conf code for both use cases

Here is an example of a coverity.conf file that meets the requirements for analyzing Kotlin and analyzing a Kotlin/Java combined project:

{
    "type": "Coverity configuration",
    "format_version": 1,
    "format_minor_version": 7,
    "settings": {
        "cov_run_desktop": {
            "build_cmd": ["./gradlew", "build"],
            "build_options": [
                "--fs-capture-search", "<project_directory>"
            ],
            "analysis_args":["--android-security"],
            "clean_cmd": ["./gradlew", "clean"]
        },
                
        "ide": {
            "build_strategy": "CUSTOM"
        },
        "add_compiler_configurations": [
             { "cov_configure_args": ["--kotlin"] }
        ]

    }
}

Set up Kotlin analysis for Eclipse, IntelliJ, or Visual Studio Code

While running Coverity Analysis 2022.12.0 or a later version of Coverity, the Eclipse, IntelliJ, and VS Code development environments can analyze Kotlin source code. Some additional setup is required.

In your project-specific coverity-conf file, add the string "--kotlin" to the compiler configuration settings. In the same file, specify custom build and clean commands that are compatible with Kotlin.

The following code sample shows a bare-minimum coverity.conf file that can be used to analyze a Kotlin project:

{
    "type": "Coverity configuration",
    "format_version": 1,
    "format_minor_version": 7,
    "settings": {
        "cov_run_desktop": {       
            "build_cmd": ["gradle", "build"],
            "clean_cmd": ["gradle", "clean"]     
        },
        "ide": {       
            "build_strategy": "CUSTOM"     
        },
        "add_compiler_configurations": [
            { "cov_configure_args": ["--kotlin"] }
        ]
    }
}
Attention: In certain cases, when the Gradle® build files have been configured to override the standard Kotlin compilation strategy, you might need to add the following option to the invocation of the build command:
-Pkotlin.compiler.execution.strategy=in-process

Enabling MISRA compliance testing

Within the Eclipse and Visual Studio environments, Code Sight can run the Coverity MISRA compliance tests.

To enable MISRA testing, add the following entry to the "settings" section of the current coverity.conf file:

"cov_run_desktop": {
    "coding_standard_configs": [
        "$(code_base_dir)/MISRA_c2012_7.config"
    ]
}

Custom analysis settings

Another use of coverity.conf is to specify custom settings for Coverity Analysis.

Changing the settings used for Coverity Analysis is described in existing documentation. We won’t go into details here. If you do edit coverity.conf to specify custom settings, proceed with caution.

These are resources that provide more information about editing coverity.conf:

  • The Coverity Desktop Analysis User Guide describes the coverity.conf settings in detail.

    The Coverity document set, which includes the Desktop Analysis User Guide, where coverity.conf is described, is installed on a client system when Coverity Analysis is installed.

    The default location of these documents depends on the operating system you are using. See the following table:

    Table 1. Where Coverity docs are installed by default
    Platform Location of Coverity documents
    Linux or Mac /Users/<username>/.blackduck/desktop/controller/installedtools/coverity-analysis/<version>/doc/en/
    Windows C:\Users\<Username>\AppData\Roaming\BlackDuck\desktop\controller\installedtools\coverity-analysis\<version>\doc\en\
  • The following lesson on the Black Duck Community web site describes how to edit coverity.conf for use with Code Sight: “How to Set Up the Coverity Desktop Analysis Configuration File – coverity.conf”.