Command Line: Generate Build Options for Polyspace as You Code Analysis
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 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
folder, where polyspaceAsYouCodeRoot/polyspace/binpolyspaceAsYouCodeRoot 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-as-you-code -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:
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.
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-as-you-code -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 Configuration (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 Configure Sources and Build Options in Project for Polyspace Analysis and Testing (Polyspace Bug Finder).
Import Analysis Options from Polyspace Platform Project
If you configure an analysis in the Polyspace Platform user interface, you can use the information from the
resulting Polyspace Platform project file (.psprjx) to configure your
Polyspace
as You Code analysis.
Using the polyspace-project command, you can generate an
options_command.txt file. The
options_command.txt file contains project information from
your .psprjx file that you can import into your Polyspace
as You Code configuration. To create this options_command.txt
file, run the following command from the folder where your
.psprjx file is located:
polyspace-project -generate-launching-script-for <psprjx> -product bug-finder
<psprjx> is the relative path of the
.psprjx file.The command polyspace-project is located in the folder
.
polyspaceroot\polyspace\bin is the location
of the Polyspace installation folder in your development environment. If you did not
add this installation folder to your polyspacerootPATH environment variable,
include the full path of the binary to execute this command.
Polyspace generates an options file options_command.txt and
an XML checkers
activation file
<module>_<projectName>_activation_file.xml. The generated
files are stored in the same location as the .psprjx file. Open
the options_command.txt file and remove the line for
-sources-list-file. This line is unnecessary in a Polyspace
as You Code analysis because you already specify the file to analyze as an option
of the polyspace-as-you-code command.
Use the generated options file and checkers activation file in subsequent analyses of source files from your project. For instance:
polyspace-as-you-code -sources file.c \ -options-file path/To/analysis_options.txt \ -checkers-activation-file path/To/projectName_checkers/module1_projectName_activation_file.xml
If you make changes to your build configuration, edit the options file
(options_command.txt) to reflect those changes. See Configure Sources and Build Options in Project for Polyspace Analysis and Testing (Polyspace Bug Finder).
See Also
polyspace-configure (Polyspace Bug Finder) | polyspace-as-you-code