Generate Build Options for Polyspace as You Code Analysis in Visual Studio

Polyspace® as You Code checks the source code file that is currently active in your Visual Studio® IDE for bugs and coding standards violations.

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:

  • Configure Polyspace as You Code to extract the build configuration information from your Visual Studio solution, 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.

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

Configure Polyspace as You Code to Extract Build Configuration

To extract your build configuration information from the Visual Studio solution, build command, or JSON compilation database:

  1. Go to Tools > Options.

  2. Select the appropriate Build configuration option on the Project subnode of the Polyspace node. See Configure Polyspace as You Code Extension in Visual Studio.

The Build configuration option that you select applies to all the projects in the Visual Studio solution.

Polyspace extracts the build information and generates an options file that the Polyspace as You Code analysis engine uses in subsequent analyses. The file contains analysis options that emulate your build configuration. Make sure that the build completes successfully before your extract the build information.

The generated options file is stored in the .polyspace-configure folder under the workingDirectory/projectName folder or one of its subfolders. The workingDirectory path is the Working directory of extension folder path that you specify in the General options of the Polyspace extension. The projectName is the name of the project that contains the files you are currently analyzing.

When you configure Polyspace as You Code to extract your build configuration information from the Visual Studio solution, build command, or JSON compilation database, the software extracts the build configuration only if:

  • You start an analysis and Polyspace cannot find a generated options file in the .polyspace-configure folder for the project that contains the currently analyzed file.

  • You explicitly regenerate an options file, for instance after you make changes to your build configuration. See Update Generated Build Options File.

Get Build Configuration from Visual Studio Solution

To extract your build configuration information from the Visual Studio solution:

  1. Go to Tools > Options.

  2. Select Get from solution on the Project subnode of the Polyspace node. See Configure Polyspace as You Code Extension in Visual Studio.

The Build configuration option that you select applies to all the projects in the Visual Studio solution.

Polyspace builds your solution, traces the build to extract the configuration information, and generates an options file.

Get Build Configuration from Build Command

To extract your build configuration information from your build command:

  1. Go to Tools > Options.

  2. Select Get from build command line on the Project subnode of the Polyspace node. See Configure Polyspace as You Code Extension in Visual Studio.

  3. Specify your build command in the Build command line field. The build command that you specify must perform a full build. For instance:

    "C:\Program Files\Polyspace as You Code\R2021a\sys\tcc\win64\tcc.exe" -g -o output dll.c fib.c hello_dll.c hello_win.c

  4. Specify the full path of the folder where Polyspace runs the build command in the Working directory field. For instance:

    C:\Program Files\Polyspace as You Code\R2021a\sys\tcc\win64\examples

The Build configuration option that you select applies to all the projects in the Visual Studio solution.

Polyspace runs your build command, traces the build to extract the configuration information, and generates an options file.

Get Build Configuration from JSON Compilation Database

If your build system supports the generation of a JSON compilation database file, use this setting. The 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.

    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. Go to Tools > Options.

  3. Select Get from JSON Compilation Database on the Project subnode of the Polyspace node. See Configure Polyspace as You Code Extension in Visual Studio.

  4. Specify the full path to the JSON compilation database file that you generated in step 1 in the Path to JSON file field.

The Build configuration option that you select applies to all the projects in the Visual Studio solution.

Polyspace extracts the build configuration information from the compilation database and generates an options file.

If you make changes to your build configuration, regenerate the compilation database file before you update the generated options file.

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, from the project context menu in the Solution Explorer, select Generate Polyspace build configuration.

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

See also Troubleshoot Failed Analysis or Unexpected Results in Polyspace as You Code.

Specify Analysis Options Manually

Use this setting 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.

    For a list of available analysis options, see Polyspace as You Code Analysis Engine Options.

  • 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.

To specify an analysis options file:

  1. Go to Tools > Options.

  2. Select Get from Polyspace build options file on the Project subnode of the Polyspace node. See Configure Polyspace as You Code Extension in Visual Studio.

  3. Specify the full path to the options file in the Build options file field.

The Polyspace as You Code analysis engine uses the specified options file in subsequent analyses.

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

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:

  1. Go to Tools > Options.

  2. Select Build options file not required on the Project subnode of the Polyspace node. See Configure Polyspace as You Code Extension in Visual Studio.

    This selection allows you to leave the Build options file field empty.

  3. Click Import from Polyspace desktop project and select the PSPRJ file that you import from.

Polyspace generates an options file and an XML checkers activation file, and populates the corresponding Analysis configuration fields. The Polyspace as You Code analysis engine uses these files in subsequent analyses.

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

Related Topics