Main Content

Generate Build Options for Polyspace as You Code Analysis at the Command Line

Polyspace® as You Code checks your code for bugs and coding standards violations while you work in your IDE or code editor.

So that the analysis runs without errors, provide Polyspace as You Code with the specificities of your build configuration, such as data type sizes and compiler macro definitions. To provide your build configuration information, you can:

  • Use the polyspace-configure (Polyspace Bug Finder) binary to extract the build configuration information from your build command or JSON compilation database. Note that running polyspace-configure on a build command involves first executing the command and gathering information from the processes executed. On the other hand, polyspace-configure can simply read all required information from a JSON compilation database.

  • Manually specify analysis options that emulate your build configuration in an options file. See Options Files for Polyspace Analysis (Polyspace Bug Finder).

  • Import the analysis options from a Polyspace desktop product project file.

Use polyspace-configure to Generate Build Options File

The polyspace-configure (Polyspace Bug Finder) binary enables you to extract the build configuration information from a build command or a JSON compilation database file. The binary uses the extracted information to generate a build options file which contains a set of options that emulate your build configuration.

polyspace-configure is available with your Polyspace as You Code installation, in the polyspaceAsYouCodeRoot/polyspace/bin folder, where polyspaceAsYouCodeRoot is your Polyspace as You Code installation folder.

Get Build Configuration from Build Command

To extract the build configuration information from your build command, provide a build command that performs a full build. For instance, if you use make on Linux to build your project, use this command:

polyspace-configure \ 
 -no-sources -allow-overwrite \
 -output-options-file path/To/buildOptions.txt \
 -merge-common-options make -B

Polyspace runs your build command, traces the build to extract the configuration information, and generates buildOptions.txt inside path/To. For more information about the polyspace-configure options, see polyspace-configure (Polyspace Bug Finder).

Use the generated options file in subsequent analyses of source files from your project. For instance:

polyspace-bug-finder-access -sources file.c -options-file path/To/buildOptions.txt 

Get Build Configuration from JSON Compilation Database

If your build system supports the generation of a JSON compilation database file, use this workflow.

The compilation database file contains compiler calls for all the translation units in your project. See JSON compilation database.

To extract your build configuration information from the JSON compilation database:

  1. Generate a JSON compilation database file. For an example of how to generate this file, see Create Polyspace Options File from JSON Compilation Database (Polyspace Bug Finder). The generated file is typically named compile_commands.json.

    If you use a JSON compilation database that was not generated on your local machine, make sure that the paths listed in the file are accessible from the location where you run Polyspace as You Code.

  2. Pass the compilation database file to polyspace-configure. For instance:

    polyspace-configure \ 
     -no-sources -allow-overwrite \
     -output-options-file path/To/buildOptions.txt \
     -merge-common-options \
    -compilation-database otherPath/To/compile_commands.json

Polyspace extracts the build configuration information from the compilation database and generates an options file. For more information about the polyspace-configure options, see polyspace-configure (Polyspace Bug Finder)

Use the generated options file in subsequent analyses of source files from your project. For instance:

polyspace-bug-finder-access -sources file.c -options-file path/To/buildOptions.txt 

Update Generated Build Options File

If you make changes to your build configuration, for instance if you add a source file to your project or workspace or rename an existing file, update the generated options file to reflect those changes. Before you update the options file, make sure that your build completes successfully with the new configuration.

To update the options file, rerun the command that you used to generate the file and specify the same set of options you used.

If you extract your build information from a JSON compilation database file, regenerate the compilation database before you update the build options file.

Specify Analysis Options Manually

Use this workflow if:

  • You know the details of your build system and you want to specify the Polyspace analysis options that emulate your build configuration in an options file. See Options Files for Polyspace Analysis (Polyspace Bug Finder).

    For a list of available analysis options, see Complete List of Polyspace Bug Finder Analysis Engine Options (Polyspace Bug Finder).

  • You reuse a Polyspace options file that you or someone else on your team has configured for your build system.

    If you reuse an options file that was not configured or generated on your local machine, make sure that the paths listed in the file are accessible from the location where you run Polyspace as You Code.

If you make changes to your build configuration, edit the options file to reflect those changes. See Specify Target Environment and Compiler Behavior (Polyspace Bug Finder).

Import Analysis Options from Polyspace Desktop Project

If you configure an analysis in the Polyspace desktop product, you can use the information from the resulting Polyspace desktop PSPRJ file to configure your Polyspace as You Code analysis.

To import the analysis options from a Polyspace desktop PSPRJ file, use this command:

polyspace-checkers-selection -import-options-from-psprj pathToPsprjFile
The polyspace-checkers-selection binary is available under the polyspace/bin folder in your Polyspace as You Code installation folder.

The pathToPsprjFile path is the full path of the PSPRJ file.

Polyspace generates an options file (analysis_options.txt) and an XML checkers activation file (checkers_activation_file.xml). The generated files are stored in the import folder in the same location as the PSPRJ file.

Use the generated options file and checkers activation file in subsequent analyses of source files from your project. For instance:

polyspace-bug-finder-access -sources file.c \
-options-file path/To/import/analysis_options.txt \
-checkers-activation-file path/To/import/checkers_activation_file.xml

If you make changes to your build configuration, edit the options file (analysis_options.txt) to reflect those changes. See Specify Target Environment and Compiler Behavior (Polyspace Bug Finder).

See Also

(Polyspace Bug Finder) |

Related Topics