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.

To run the analysis without errors, provide Polyspace as You Code with the details of your build configuration, such as data type sizes and compiler macro definitions. To provide your build configuration information, use one of these methods:

  • Use the polyspace-configure (Polyspace Bug Finder) command to extract the build configuration information from your build command or 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) command enables you to extract the build configuration information from a build command or a JSON compilation database file. If you run polyspace-configure on a build command, Polyspace executes the build command and gathers the build options executed process. If you run polyspace-configure on a JSON compilation database, Polyspace simply reads all required build options from the database. From the extracted information, polyspace-configure generates a build options file that emulates 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/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/buildOptions. 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/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/buildOptions.txt \
     -merge-common-options \
    -compilation-database otherPath/To/compile_command/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/buildOptions.txt 

Update Generated Build Options File

If you make changes to your build configuration, such as adding a source file to your project or workspace or renaming 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:

ps-migrate-checkers-selection -import-options-from-psprj pathToPsprjFile

The ps-migrate-checkers-selection command is available in the polyspace/bin/arch folder in your Polyspace as You Code installation folder, where arch is one of win64, glnxa64, or maci64. If you did not add this installation folder to your PATH environment variable, include the full path of the binary to execute this command.

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