Main Content

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

Polyspace® as You Code checks the source code file that is currently active in your Visual Studio® Code editor 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 build task or build command, or JSON compilation database. Note that running polyspace-configure on a build task or command involves first executing the task or command and gathering information from the processes executed. On the other hand, polyspace-configure can simply read all required information from a 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.

Configure Polyspace as You Code to Extract Build Configuration

To extract your build configuration information from the build task, build command, or JSON compilation database:

  1. Open the Visual Studio Code settings by pressing Ctrl+, (comma).

    Enter polyspace.analysisoptions in the settings search bar and set Polyspace > Analysis Options: Analysis Setup to Manual setup.

  2. Set the appropriate Polyspace > Analysis Options > Manual Setup: Build options and fill out the corresponding Build Setting field.

    See Configure Polyspace as You Code Extension in Visual Studio Code.

  3. Open the Command Palette (Ctrl+Shift+P) and enter Polyspace: Generate Build Options.

Note

On Windows, if you enable remote development and if any of your project files or folders on the remote machine are on a network drive, provide the UNC path for that network drive. See Configure Polyspace as You Code for Remote Development. The Polyspace as You Code extension cannot resolve the path of a network drive that is mapped to a drive letter when you enable remote development and the Polyspace: Generate Build Options command might fail.

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.

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 Polyspace > Analysis Engine: Result Folder path that you specify in the Polyspace as You Code extension settings. The projectName is the name of the top-level folder in the EXPLORER that contains the files that you are currently analyzing.

Get Build Configuration from Build Task

Visual Studio Code enables you to define tasks so that you can run an external tool from your code editor. See Integrate with External Tools via Tasks.

If you define a custom task that calls your compiler to perform a full build of your project, Polyspace can extract your build configuration from this build task.

  1. Open the Visual Studio Code settings by pressing Ctrl+, (comma).

    Enter polyspace.analysisoptions in the settings search bar.

  2. Set these Polyspace > Analysis Options settings to the values listed in the table.

    SettingValue
    Analysis SetupManual setup
    Manual Setup: BuildGet from build task
    Manual Setup > Build Setting: Build Task

    Specify the name of the build task. This corresponds to the "label" field of the task definition in the tasks.json file. The task that you specify must perform a full build.

    Polyspace supports the use of only these Visual Studio Code predefined variables in task definitions:

    • ${workspaceFolder}

    • ${workspaceFolderBasename}

  3. Open the Command Palette (Ctrl+Shift+P) and enter Polyspace: Generate Build Options.

Polyspace runs the build command specified by the task, 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. Open the Visual Studio Code settings by pressing Ctrl+, (comma).

    Enter polyspace.analysisoptions in the settings search bar.

  2. Set these Polyspace > Analysis Options settings to the values listed in the table.

    SettingValue
    Analysis SetupManual setup
    Manual Setup: BuildGet from build command
    Manual Setup > Build Setting: Build Command

    Specify your build command, for instance:

    gcc -g -o helloworld hello.c main.c

    The command that you specify must perform a full build

  3. Open the Command Palette (Ctrl+Shift+P) and enter Polyspace: Generate Build Options.

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 (Polyspace Bug Finder).

    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. Open the Visual Studio Code settings by pressing Ctrl+, (comma).

    Enter polyspace.analysisoptions in the settings search bar.

  3. Set these Polyspace > Analysis Options settings to the values listed in the table.

    SettingValue
    Analysis SetupManual setup
    Manual Setup: BuildGet from JSON Compilation Database file
    Manual Setup > Build Setting: JSON Compilation Database File

    Specify the full path to the file that you generated in step 1. The file is typically named compile_commands.json.

  4. Open the Command Palette (Ctrl+Shift+P) and enter Polyspace: Generate Build Options.

Polyspace extracts the build configuration information from the compilation database and generates an 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, Open the Command Palette (Ctrl+Shift+P) and enter Polyspace: Generate Build Options.

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

To specify an analysis options file:

  1. Open the Visual Studio Code settings by pressing Ctrl+, (comma).

    Enter polyspace.analysisoptions in the settings search bar.

  2. Set these Polyspace > Analysis Options settings to the values listed in the table.

    SettingValue
    Analysis SetupManual setup
    Manual Setup: BuildGet from Polyspace build options file
    Manual Setup > Build Setting: Polyspace Build Options File

    Specify the full path to the Polyspace options file.

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 (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, open a terminal in Visual Studio Code and enter this command:

polyspace-checkers-selection -import-options-from-psprj pathToPsprjFile
The polyspace-checkers-selection binary is available under the polyspace/bin folder in your Polyspace as You Code installation folder. 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.

To complete the configuration of the Polyspace as You Code analysis:

  1. Open the Visual Studio Code settings by pressing Ctrl+, (comma).

    Enter polyspace.analysisoptions in the settings search bar.

  2. Set these Polyspace > Analysis Options settings to the values listed in the table.

    SettingValue
    Analysis SetupManual setup
    Manual Setup: Build

    Build options file not required

    This setting ignores the file specified in the Build Setting: Polyspace Build Options File field.

    Manual Setup: Checkers File

    Full file path of checkers_activation_file.xml

    Manual Setup: Other Analysis Options

    Full file path of analysis_options.txt

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 (Polyspace Bug Finder).

Related Topics