When launching Polyspace in command line, it is possible to specify an options file (a text file containing the list of options), by using the parameter '-options-file'.
This option can still be used graphically by specifying this option in the "Other" field (in Advanced Settings).
The idea here is then to call polyspace-configure in order to generate an options file (that will then contain the compilation related options only), and then to use this options file in the Polyspace project generated by the Polyspace Eclipse plugin.
When the verification will be started, the options coming from the options file and the ones defined in the project will be merged.
To implement this solution in Eclipse, you can create a script that will be used to launch polyspace-configure on the build command.
This script can be called via a "Build target".
Then use the generated options file with the extra option -options-file in the Polyspace project (Polyspace>configure project).
The script itself will call polyspace-configure with the build command as parameter.
Since a conflict will occur due to the source files specification in both the project file and the options file, the list of source files needs to be removed from the generated options file.
You may see additional warnings at the beginning of the verification for similar reasons, but these can safely be ignored.
Since R2018b, there is an option that prevents the generation of the list of source files : -no-sources.
Before this version, it has to be done in the script.
Here is an example where the build command is a call to the command ninja.exe, used to compile a project using the Ninja open-source build system:
set BUILD_COMMAND="C:\PROGRA~1\NINJA-~1\ninja.exe"
set CLEAN_COMMAND="C:\PROGRA~1\NINJA-~1\ninja.exe -t clean"
set MATLAB_ROOT="C:\Program Files\MATLAB\R2017a"
set DUMMY_FILE=dummy.txt
set OPTION_FILE=option_file.txt
cmd /C %CLEAN_COMMAND%
%MATLAB_ROOT%\polyspace\bin\polyspace-configure.exe -output-options-file %DUMMY_FILE% -allow-overwrite %BUILD_COMMAND%
findstr /v /r /c:"^-sources " %DUMMY_FILE% > %OPTION_FILE%
First, the ninja clean command is called to ensure that a full build will be done.
Then polyspace-configure is called with the build command in parameter.
Lastly, the options file is modified to remove the lines starting with -sources.
In R2018b, the end of the script is simply:
%MATLAB_ROOT%\polyspace\bin\polyspace-configure.exe -output-options-file %DUMMY_FILE% -no-sources -allow-overwrite %BUILD_COMMAND%
Best Answer
It is possible to launch Polyspace from the IDE on your projects since IAR EW allows custom commands and menus (that can be used with environment variables), and because the compiler can be called in command line.
This integration described below will be based on the call to polyspace-configure to create an options file from the build command. A second command will be used to launch Bug Finder using this options file.
The first step is to create two .bat files, one to launch polyspace-configure and the other to call Polyspace Bug Finder.
Here is the contents of the first script, let's call it launch_configure.bat:
And here is the contents of the second script, let's call it launch_bug_finder.bat:
We will need a working folder where the scripts will be located and launched. Let's say it's : C:\EW_Integration.
To adapt the scripts to your environment, open each file and change the value of these variables:
The next step is to create two items in the Tools menu of your IDE will call these scripts.
Select Tools > Configure Tools.
Create two new entries. Each entry runs a .bat file.
Provide the path to the script <your_working_folder>\launch_configure.bat.
Enter the following:
Menu Text:
Polyspace Configure
Command:
<your_working_folder>\launch_configure.bat
Argument:
$PROJ_PATH$ $CONFIG_NAME$
Initial Directory:
<your_working_folder>
Make sure that the box 'Redirect to Output Window' is selected.
For the command Polyspace Bug Finder:
Provide the path to the script <your_working_folder>\launch_bug_finder.bat
Enter the following:
Menu Text:
Polyspace Bug Finder
Command:
<your_working_folder>\launch_configure.bat
Argument:
None
Initial Directory:
<your_working_folder>
Usage
Now that the tool commands have been added, here is how to use them.
Open your IAR EW project. Select Tools > Polyspace Configure. The script uses the polyspace-configure command which invokes your build configuration and builds your project. Note that the operation takes more time than the regular build process because of additional instrumentation.
If the polyspace-configure command completes execution, you see this message:
An options file is created in the working folder. The options file contains information about source files and compiler options.+ You use this options file to launch Polyspace Bug Finder.
Select Tools > Polyspace Bug Finder. Follow the progress of analysis in the Tool Output window:
After analysis, the Polyspace results open automatically.
The analysis uses default Bug Finder options.
To modify them, use the file extra_options in your working folder.
The file is empty by default. Enter one Polyspace Bug Finder option per line.
For example, to enable checking of the mandatory and required subset of MISRA-C:2012 rules, add this line:
Repeat these two steps each time you change something related to compilation, for instance, when you add or remove a new file or define a new symbol.
If you modify an existing source file, use the Polyspace Bug Finder menu item only.
Creating a project file
If you prefer to change Polyspace options graphically and launch the analysis in the Polyspace user interface, create a third menu item.
This menu item uses the polyspace-configure command with the -output-project option so that a project is created instead of an options file.
Similar to the previous scripts, add a new entry to the Tools menu:
Menu Text:
Create Polyspace project
Command:
<your_working_folder>\create_project_file.bat
Argument:
$PROJ_PATH$ $CONFIG_NAME$
Initial Directory:
<your_working_folder>
When you select Tools > Create Polyspace project, a project file (with extension .psprj) is created in the working folder.
Open this project file in the Polyspace user interface: