Run Polyspace as You Code from Command Line and Export Results
You can run Polyspace as You Code on source files directly at the command line.
For IDEs that are not directly supported with a Polyspace as You Code plugin, you can open a terminal within the IDE and run the commands, or create a menu item to run the commands on the file currently open in the IDE. You can even incorporate these commands in a makefile, so that building your code also runs static analysis on the code. See also Integrate Polyspace as You Code in IDEs and Editors Without Plugins.
Add Install Folder to Path
To avoid typing the full path to Polyspace as You Code commands, add the paths to these commands to the PATH environment variable on your operating system.
The paths in the default installation folder are the following:
Windows® | C:\Program Files\Polyspace as You Code\R2024b\polyspace\bin |
Linux® | /usr/local/PolyspaceAsYouCode/R2024b/polyspace/bin
|
After you add the paths, you can enter commands such as the following in a terminal without errors:
polyspace-bug-finder-access -help
Run Analysis and See Results on Console
To run Polyspace as You Code, use the polyspace-bug-finder-access
command. Export the results
to the console using the polyspace-results-export
command.
polyspace-bug-finder-access -sources filename polyspace-results-export -format console
polyspace-bug-finder-access
command generates results in the current folder. The
polyspace-results-export
command reads results from the current folder and exports to the
console. The console
format is only available for Polyspace as You Code.The analysis typically takes a few seconds to complete (slightly longer for C++ files). If the analysis fails to
complete, further details of the error appear on the console. You can use the option -no-quiet
to see a more detailed analysis log on the console.
Store Results in Specific Folder
To use a specific results folder
instead of the
current folder, change the preceding lines as
follows:resultsFolder
polyspace-bug-finder-access -sources filename -results-dir resultsFolder polyspace-results-export -format console -results-dir resultsFolder
Export Results to JSON Format (SARIF Output)
Instead of displaying analysis results on the console, you can export the results to a JSON file. You can then parse this file using a JSON parser method in any language that you want.
polyspace-bug-finder-access -sources filename.c polyspace-results-export -format json-sarif -output-name outputFilePath
outputFilePath
is the full path to the JSON file.The JSON format follows the standard notation provided by the OASIS Static Analysis Results Interchange Format (SARIF).
Specify Analysis Options by Using Options Files
To adapt the Polyspace analysis configuration to your development environment and requirements, you have to
modify the default configuration through command-line options such as -compiler
. Options files
are a convenient way to collect multiple options together and reuse them across projects.
Options files are text files with one option per line. For instance, the content of an options file can look like this:
# Options for Polyspace analysis # Options apply to all projects in Controller module -compiler visual16.x -D _WIN32 -checkers-activation-file "Z:\utils\checkers.xml"
Specify an options file using the option -options-file
. For
instance:
polyspace-bug-finder-access -sources file.c -options-file "Z:\utils\polyspace\options.txt"
See also Options Files for Polyspace Analysis (Polyspace Bug Finder). For all options available with Polyspace as You Code, see Complete List of Polyspace Bug Finder Analysis Engine Options (Polyspace Bug Finder).
Create Options File by Analyzing Build
Instead of entering options by hand in an options file, you can create an options
file with all Polyspace options required for compilation by analyzing your build
system. For instance, you can trace your build command and save the options in a
file buildOptions.txt
that you can use for the subsequent
analysis.
polyspace-configure -no-sources -output-options-file buildOptions.txt buildCommand polyspace-bug-finder-access -sources file.c -options-file buildOptions.txt
buildCommand
is a build
command that performs a full build of your source code, for instance, make
-B
or make --always-make
. For build systems that
can output compilation options in the JSON compilation database format, you can
obtain the options from the JSON
file:polyspace-configure -no-sources -output-options-file buildOptions.txt -compilation-database jsonFile
jsonFile
is the full path to
the compilation database JSON file.You can also append a second options file with options related to the analysis
such as checkers. For instance, if the second options file is called
checkersOptions.txt
, you can run Polyspace as You Code as
follows:
polyspace-bug-finder-access -sources file.c -options-file buildOptions.txt -options-file checkersOptions.txt
See Also
polyspace-bug-finder-access
| polyspace-results-export
(Polyspace Bug Finder) | polyspace-configure
(Polyspace Bug Finder)