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.
Import and Export Polyspace as You Code Settings in Visual Studio
In situations where several developers all require the same project configuration,
it can be easier to set up one instance of Polyspace as You Code and export the
extension settings as a vssettings
file. You can then share the
settings file with the developers who require it and import the settings into
Visual Studio.
Visual Studio contains an Import and Export Settings option that allows you to export your selected environment settings including your Polyspace as You Code configuration settings.
To export your Polyspace as You Code settings:
Open the Import and Export Settings Wizard by going to Tools > Import and Export Settings....
Select Export selected environment settings then select Next.
Uncheck anything you do not want to export in addition to the Polyspace as You Code settings. Expand the Options node and select Polyspace as You Code to export all Polyspace as You Code settings. Alternatively, expand the Polyspace as You Code node to customize which Polyspace as You Code settings to export. Then click Next.
Enter a name for your settings file and select a directory to save your settings file. Then click Finish.
You can import Polyspace as You Code settings in three ways.
Use the Import and Export Settings Wizard in Visual Studio.
Open the Import and Export Settings Wizard by going to Tools > Import and Export Settings....
Select Import selected environment settings and then Next.
Choose if you want to save your current settings or select not to and click Next.
Click the Browse button to navigate to your settings file and open it. Expand the All Settings and Options nodes to confirm all your Polyspace as You Code settings are selected, then click Finish.
Import settings from the Visual Studio Command Window.
Click on View > Other Windows > Command Window. In the command window, enter the command replacing
PathToSettingsFile.vssettings
with your own settings full file path.Tools.ImportandExportSettings/import:PathToSettingsFile.vssettings
Create a shortcut to the Visual Studio program and append the settings file to the Target value. For example:
"C:\Program Files\Microsoft Visual Studio\2022\Professional\Common7\IDE\devenv.exe" /ResetSettings <PathToSettingsFile.vssettings>
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.
Setting | Description |
---|---|
Polyspace installation folder | Root folder of the Polyspace as You Code installation, for example, |
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:
|
Justification catalog | Specify the full file path of the justification catalog JSON file. Use this setting if your team or organization has a predefined set of comments that they use to justify results. You can store these justifications in a catalog file and associate one or more justifications with a specific result or result family. If you use the Polyspace syntax to annotate a result, the annotation comment is autofilled with the justifications that you store in the catalog for that result. For details of the Polyspace syntax, see Annotation Syntax Details (Polyspace Bug Finder). To create a justification catalog, see Use a Justification Catalog to Autocomplete Annotations in Polyspace as You Code plugins. |
Debug Mode | Option to enable or disable debugging.
|
Help Improve Polyspace as You Code | Option to enable or disable the sharing of user experience information with MathWorks®.
|
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.
Setting | Description |
---|---|
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.
|
Start analysis on save | Option to select when Polyspace as You Code runs on files that are in the Quality Monitoring list.
|
Perform analysis in fast-mode | Toggle on or off fast analysis mode. This option is disabled by default. Fast analysis decreases the duration of your Polyspace as You Code analysis by checking only for specific types of issues. This option enables only checkers for issues that are syntactic and do not require abstraction or data flow calculations. Polyspace excludes checkers that are not syntactic or require abstraction of the code from a fast analysis. These exclusions are in addition to the Checkers Deactivated in Polyspace as You Code Analysis. Use fast analysis to iteratively identify and address bugs that are smaller in scope and addressable earlier in the development process. To take full advantage of the defects that Polyspace as You Code can find, use fast analysis as a precursor to a full Polyspace as You Code analysis of your code. The icon shows next to files you analyze in fast-mode. Enabling fast-mode affects all files in the Quality Monitoring list. The Configuration view
shows |
Analysis Setup | Option to select between manual setup and a script.
|
Set Up Analysis by Using Script
Use these settings to run a script each time you save your code or explicitly run an analysis.
Setting | Description |
---|---|
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
The extension passes these setting values as parameters to the script:
Optionally, the extension passes these additional settings to the script if you specify them:
|
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 |
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
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.
Setting | Description |
---|---|
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 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 |
JSON Compilation Database file | Full path to a JSON compilation database file
(typically named
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 |
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 |
Checkers File | Path to a checkers configuration file. To create this file, click 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
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
If you select
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.
Setting | Description |
---|---|
Show Baseline information | Method for using information from the baseline run:
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 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. |