Eclipse: Generate Build Options for Polyspace as You Code
Polyspace® as You Code™ checks the source code of the file that is currently active in your Eclipse™ 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 Eclipse project, 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.
Configure Polyspace as You Code to Extract Build Configuration
You can configure Polyspace as You Code to extract the build configuration from your Eclipse project, build command, or JSON compilation database. If you extract build configuration from build command, Polyspace executes the command and gathers build information from the executes processes. If you extract build configuration from an Eclipse project or JSON compilation database, Polyspace can read the build configuration from the project or JSON database.
Get Build Configuration from Eclipse Project
To extract your build configuration information from your Eclipse project:
Go to Window > Preferences and select the Polyspace as You Code node.
On the Analysis node, select
Get from Eclipse C/C++ projectfrom the Build list. See Eclipse: Configure Polyspace as You Code Plugin.
Polyspace automatically extracts the build options from your project toolchain. The Polyspace analysis engine uses those options in the subsequent analysis.
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.
To view the details of the toolchain configuration:
Select a project in the Project Explorer and go to Project > Properties.
Under the C/C++ General node, select Paths and symbols and Preprocessor Include Paths, Macros, etc.
Get Build Configuration from Build Command
To extract your build configuration information from your build command:
Go to Window > Preferences and select the Polyspace as You Code node.
On the Analysis node, select
Get from build commandfrom the Build list. See Eclipse: Configure Polyspace as You Code Plugin.The build command that you specify must perform a full build. For example:
gcc -g -o helloworld hello.c main.cClick
in the
Configuration view of the
Polyspace as You Code perspective.
Polyspace runs your build command, traces the build to extract the configuration information, and generates an options file. The Polyspace as You Code analysis engine uses the generated options file in subsequent analyses.
The generated options file is stored in the
.polyspace-configure folder under the
folder or one of its subfolders. workingDirectory/projectName
Here, workingDirectory is the Working
directory path that you specify on the Polyspace as You
Code node and projectName is the name
of the project that contains the files you are currently analyzing.
Get Build Configuration from JSON Compilation Database
If your build system supports the generation of a JSON compilation database file, use this workflow. The JSON compilation database 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).
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.
Go to Window > Preferences and select the Polyspace as You Code node.
On the Analysis node, select
Get from JSON Compilation Database filefrom the Build list and specify the full path to the JSON compilation database file that you generated in step 1. See Eclipse: Configure Polyspace as You Code Plugin.
Polyspace automatically extracts the build configuration information from the compilation database and generates an options file. The Polyspace as You Code analysis engine uses the generated options file in subsequent analyses.
The generated options file is stored in the
.polyspace-configure folder under the
folder or one of its subfolders. workingDirectory/projectName
Here, workingDirectory is the Working
directory path that you specify on the Polyspace as You
Code node and projectName is the name
of the project that contains the files you are currently analyzing.
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, click
in the Configuration
view of the Polyspace as You Code perspective.
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
Specify analysis options manually in an options file that you create 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.
To specify an analysis options file:
Go to Window > Preferences and select the Polyspace as You Code node.
On the Analysis node, select
Get from Polyspace build options filefrom the Build list and specify the full path to the options file. See Eclipse: Configure Polyspace as You Code Plugin.
The Polyspace as You Code analysis engine uses the options file that you specify in subsequent analyses.
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.
To import the analysis options from a .psprjx file, open a
terminal in Eclipse and enter this command:
polyspace-project -generate-launching-script-for <projectPath> -product bug-finder
<projectPath> is the relative path of the
.psprjx file.The command polyspace-project is located in the folder
.
Here, 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
.
The generated files are stored in the same location as the
module_projectName_activation_file.xml.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.
To complete the configuration of the Polyspace as You Code analysis:
Go to Window > Preferences and select the Polyspace as You Code node.
On the Analysis node, select
Get from Polyspace build options filefrom the Build list. See Eclipse: Configure Polyspace as You Code Plugin.Specify the path of the generated options file
options_command.txtin the Other Analysis Options File box.Specify the path of the generated checkers activation file
module_projectName_activation_file.xmlin the Checkers File box.
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
(options_command.txt) to reflect those changes. See Configure Sources and Build Options in Project for Polyspace Analysis and Testing (Polyspace Bug Finder).