Main Content

Configure Polyspace as You Code Extension in Visual Studio

Polyspace® as You Code allows you to find bugs and coding rule violations while you work in Visual Studio® IDE.

After you install the Polyspace as You Code analysis engine and Visual Studio extension, configure the extension so that a Polyspace analysis runs smoothly when you save your code or explicitly start an analysis. An analysis has run smoothly if results appear as you expect, either as source code markers with tooltips or in a list on the Results List pane.

To configure the extension, in Visual Studio, select Tools > Options and select the Polyspace as You Code node in the Options window. Under the Polyspace as You Code node, select:

  • General to configure the installation folder and working directory

  • Analysis Options to configure the analysis options for the projects

  • Baseline to configure the use of analysis results you download from Polyspace Access™ as a baseline

To save your configuration, click OK. All settings retain their current values when you reopen the extension.

Specify Polyspace as You Code Preferences

Specify general configuration settings such as the root folder of your Polyspace as You Code installation, the port the extension uses, and your working directory.

SettingDescription
Polyspace installation folder

Root folder of the Polyspace as You Code installation, for example, C:\Program Files\Polyspace as You Code\R2024a.

Working directory

Folder where Polyspace stores analysis results. Each new run overwrites results of the previous run.

The default working directory is stored under your system temporary folder:

  • Windows®%temp%, for example C:\Users\jsmith\AppData\Local\Temp

  • Linux®/tmp

Debug Mode

Option to enable or disable debugging.

  • off (default) — The Console view shows only errors, warnings, and status messages such as messages about the start and end of analysis.

  • on — The Console view shows all debugging information. Enable this setting to troubleshoot issues with the Visual Studio extension.

Help Improve Polyspace as You Code

Option to enable or disable the sharing of user experience information with MathWorks®.

  • on (default) — Polyspace shares user experience information with MathWorks and uses this information to improve the Visual Studio extension.

  • off — Polyspace does not share user experience information.

Port

Port number that the Polyspace as You Code extension uses on startup to establish an internal connection with the analysis engine. Use this setting if your machine is configured with a firewall and you want to specify an open port in the firewall.

By default, the extension specifies port 0 and Visual Studio queries your system for an available port and uses whichever port your system returns.

If you run multiple instances of Visual Studio that access different workspaces, specify a different port for each instance.

If you change this setting, you might need to restart Visual Studio. If you let Polyspace obtain a port number automatically (port 0), the extension could connect to a different port once Visual Studio restarts. For certain configurations, this requires you to regenerate your build options. See Generate Build Options for Polyspace as You Code Analysis in Visual Studio.

Configure Analysis Settings

Specify which actions the extension performs when you save your code and how the extension obtains information about your build system.

SettingDescription
Add to Quality Monitoring list on save

Option to add files to the Quality Monitoring list when you save the file. Polyspace as You Code analyzes only files in this list.

  • on (default) — Polyspace adds the current file to the Quality Monitoring list when you save the file.

  • off — Add files to the Quality Monitoring list manually. To add a file manually, right-click the file in the editor or the Solution Explorer view.

Start analysis on save

Option to select when Polyspace as You Code runs on files that are in the Quality Monitoring list.

  • on — Polyspace as You Code runs each time you save your code.

  • off (default) — Run the analysis manually. Right-click the source code or a file in the Project Explorer and select Run Polyspace Analysis.

Analysis Setup

Option to select between manual setup and a script.

  • Manual setup (default) — Set up Polyspace as You Code through extension settings. Specify build-related options and other options in the Manual setup group of settings.

  • Script — Run a script each time you save your code (or right-click a source file and select Run Polyspace Analysis). Specify the path of the script file in Script File.

Set up Analysis by Using Script

Use these settings to run a script each time you save your code or explicitly run an analysis.

SettingDescription
Script File

Use a script if you switch between files from components that have different build configurations or you use a custom tool to set up your build environment.

Full path to a script that runs each time you start a Polyspace as You Code analysis. You can write the script in any language. On Windows, the extension supports scripting languages only for scripts that are executable from the Command Prompt window.

Use this setting if you choose Script for Analysis Setup.

The extension passes these setting values as parameters to the script:

  • Path of the current file as the first argument

  • Working directory as the second argument.

  • Polyspace installation folder as the third argument.

Optionally, the extension passes these additional settings to the script if you specify them:

  • The path of the options file from Other Analysis Options File, prefixed by -options-file. For example, if you specify the file C:\polyspace\myOpts.txt, the extension passes -options-file C:\polyspace\myOpts.txt as a parameter.

  • The path of the checkers activation XML file from Checkers File, prefixed by -checkers-activation-file. For example, if you specify the file C:\polyspace\myCheckers.xml, the extension passes -checkers-activation-file C:\polyspace\myCheckers.xml as a parameter.

  • Any additional parameters you specify with the setting Script File Arguments.

Script File Arguments

Additional parameters that the extension passes to the script when you run an analysis. For example, running a command on preprocessed files to work around a compilation error. See Command/script to apply to preprocessed files (-post-preprocessing-command) (Polyspace Bug Finder).

For example, this Windows batch script assigns the paths of the source file (SOURCES), the results folder (RESULTS_FOLDER), and the installation folder (INSTALL_DIR), and assigns any additional parameters to OTHER_PARAMS. The script then analyzes the current file, using any analysis options stored in OTHER_PARAMS, and imports the review information from a previously downloaded baseline:

@echo off

set SOURCES=%1
set RESULTS_FOLDER=%2
set INSTALL_DIR=%3
set ANALYZE=%INSTALL_DIR%\polyspace\bin\polyspace-bug-finder-access.exe
set BASELINE_DIR=%RESULTS_FOLDER%\..\..\..\baseline

set OTHER_PARAMS=
REM loop through additional parameters if any
:loop
    if [%4] == [] (
    goto :done)
    set OTHER_PARAMS=%OTHER_PARAMS% %4
    shift
    goto :loop
:done

"%ANALYZE%" -sources %SOURCES% -import-comments %BASELINE_DIR%^
 -results-dir %RESULTS_FOLDER% %OTHER_PARAMS% 
IF %ERRORLEVEL% NEQ 0 EXIT 1
For more on downloading a baseline and importing its review information at the command line, see Set Baseline Polyspace as You Code Results on Command Line.

If you set Analysis Setup to Script, the extension ignores the Manual setup and Baseline settings.

Note

The Polyspace as You Code extension does not check the exit status of the commands in your script. Make sure your script checks exit codes (for example, by using %ERRORLEVEL%) and returns a meaningful exit status.

Typically, the Polyspace binaries return 0 on success and a nonzero value on failure.

Set up Analysis Manually

Use these settings to provide Polyspace as You Code with your build configuration specifics and analysis options.

SettingDescription
Build

Specifics of your build configuration. Provide Polyspace as You Code with build configuration information such as data type sizes and compiler macro definitions so that the analysis runs without errors. For more information on how to generate these options, see Generate Build Options for Polyspace as You Code Analysis in Visual Studio.

  • Build options file not required (default)

    The extension does not require Polyspace options related to your build configuration. The analysis uses the default Polyspace options related to your build configuration. This is a basic option for simple projects.

  • Get from build command

    The analysis traces the build command that you specify and generates a build options file.

    Specify the build command in Build Command. For example, make -B. Click Generate build options icon in the Configuration view of the Polyspace as You Code perspective to have the extension generate build options from your build command. See Get Build Configuration from Build Command.

  • Get from Visual Studio C/C++ project

    The analysis extracts the build configuration from the Visual Studio project and generates a build options file.

    If your workspace contains multiple projects, Polyspace extracts the build options for all the projects and then applies only the relevant options when you analyze a file in a specific project.

    After selecting this option, click Generate build options icon in the Configuration view of the Polyspace as You Code perspective to generate the build options.

  • Get from JSON Compilation Database file

    The analysis extracts the build configuration from the JSON compilation database that you specify and generates a build options file. See Get Build Configuration from JSON Compilation Database.

    Specify the full path to the JSON file (typically named compile_commands.json) in JSON Compilation Database file. Click Generate build options icon in the Configuration view of the Polyspace as You Code perspective to generate the build options.

    If you use a build system generator such as CMake, you can use this setting to set up Polyspace as You Code. For example, if you use CMake projects in Visual Studio, CMake also allows you to generate a JSON compilation database with the commands used for building the project. You can then provide the path to the compilation database to JSON Compilation Database file. For an example of how to generate this JSON file, see Create Polyspace Options File from JSON Compilation Database (Polyspace Bug Finder).

  • Get from Polyspace build options file

    When you select this value, you provide an options file that you generate or fill in manually with all the necessary build options. See Specify Analysis Options Manually.

    Specify the full path of the options file in Polyspace Build Options File.

Build Command

Build command name exactly as you would enter on a command-line terminal or console.

Use a build command that performs a complete build of all files in your workspace and not an incremental build.

Use this setting if you select Get from build command from the Build list. See Get Build Configuration from Build Command.

JSON Compilation Database file

Full path to a JSON compilation database file (typically named compile_commands.json).

Use a build command that performs a complete build of all files in your workspace and not an incremental build.

Use this setting if you select Get from JSON Compilation Database file from the Build list. See Create Polyspace Options File from JSON Compilation Database (Polyspace Bug Finder).

Polyspace Build Options File

Full path to a Polyspace build options file. The options file is a text file with one Polyspace analysis option per line.

Use this setting if you select Get from Polyspace build options file from the Build list. See Options Files for Polyspace Analysis (Polyspace Bug Finder).

Checkers File

Path to a checkers configuration file.

To create this file, click Configure checkers icon in the Configuration view of the Polyspace as You Code perspective. Select the checkers that you want to enable and save the file.

If you select Script from the Analysis Setup list, the extension passes the checkers configuration file path prefixed with -checkers-activation-file as a parameter to the script.

See also Configure Checkers for Polyspace as You Code in Visual Studio.

Other Analysis Option File

Path to an options file. The options file contains one Polyspace analysis option per line. For example:

-D _WIN32
-termination-functions exit_handler

You typically do not need to specify additional options in an options file. However, using an options file is helpful in some situations. For example, if you want to manually specify Polyspace options related to your build command, select Build options file not required from the Build list and enter the options in an options file.

If you select Script the Analysis Setup list, the extension passes the options file path prefixed with -options-file as a parameter to the script.

See also Options Files for Polyspace Analysis (Polyspace Bug Finder).

Configure Baseline Settings

Use these settings to select whether you import review information from a baseline run into your analysis and to configure the connection to a Polyspace Access Server from which you download the baseline.

SettingDescription
Show Baseline information

Method for using information from the baseline run:

  • Show local findings only (default)

    When you run an analysis, Polyspace does not use information from the baseline run. You see only local findings in the Error List pane.

  • Show local findings and baseline info

    When you run an analysis, Polyspace imports review information from the baseline run. Results that are already justified in the baseline run are suppressed in the Error List pane.

  • Show new findings only

    When you run an analysis, Polyspace imports review information from the baseline run. Results that are already present in the baseline run are suppressed in the Error List pane.

    Select this value to focus only on new findings.

See also Set Baseline Polyspace as You Code Results in Visual Studio.

Polyspace Access URL

URL of the Polyspace Access instance from which you get a baseline.

After you obtain a baseline from Polyspace Access, subsequent runs of Polyspace as You Code allow you to distinguish between new results and results that are present in existing code.

See also Set Baseline Polyspace as You Code Results in Visual Studio.

Polyspace Access Login

Username that you use to log in to Polyspace Access.

Later, when you click the Download baseline icon in the Baseline view of the Polyspace as You Code perspective, Polyspace prompts you for the password that corresponds to this username.

Project path

Path of the project in the Polyspace Access Project Explorer that you use as a baseline.

Related Topics